diff options
author | Christoph Hellwig <hch@lst.de> | 2017-08-23 13:10:30 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-08-23 14:49:52 -0400 |
commit | 807d4af2f64ed79fdbb28e582e330be3dbe10d23 (patch) | |
tree | 11ed994bb09f7739c8d746f8d39b82df07aa7740 /block/genhd.c | |
parent | de65b0123216a8e1dbe3ca1eb20a45572b9e71d9 (diff) |
block: add a __disk_get_part helper
This helper allows looking up a partion under RCU protection without
grabbing a reference to it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/block/genhd.c b/block/genhd.c index 3380a1e73ea0..713b7d4fe7a1 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -82,6 +82,15 @@ void part_in_flight(struct request_queue *q, struct hd_struct *part, | |||
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | struct hd_struct *__disk_get_part(struct gendisk *disk, int partno) | ||
86 | { | ||
87 | struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl); | ||
88 | |||
89 | if (unlikely(partno < 0 || partno >= ptbl->len)) | ||
90 | return NULL; | ||
91 | return rcu_dereference(ptbl->part[partno]); | ||
92 | } | ||
93 | |||
85 | /** | 94 | /** |
86 | * disk_get_part - get partition | 95 | * disk_get_part - get partition |
87 | * @disk: disk to look partition from | 96 | * @disk: disk to look partition from |
@@ -98,21 +107,12 @@ void part_in_flight(struct request_queue *q, struct hd_struct *part, | |||
98 | */ | 107 | */ |
99 | struct hd_struct *disk_get_part(struct gendisk *disk, int partno) | 108 | struct hd_struct *disk_get_part(struct gendisk *disk, int partno) |
100 | { | 109 | { |
101 | struct hd_struct *part = NULL; | 110 | struct hd_struct *part; |
102 | struct disk_part_tbl *ptbl; | ||
103 | |||
104 | if (unlikely(partno < 0)) | ||
105 | return NULL; | ||
106 | 111 | ||
107 | rcu_read_lock(); | 112 | rcu_read_lock(); |
108 | 113 | part = __disk_get_part(disk, partno); | |
109 | ptbl = rcu_dereference(disk->part_tbl); | 114 | if (part) |
110 | if (likely(partno < ptbl->len)) { | 115 | get_device(part_to_dev(part)); |
111 | part = rcu_dereference(ptbl->part[partno]); | ||
112 | if (part) | ||
113 | get_device(part_to_dev(part)); | ||
114 | } | ||
115 | |||
116 | rcu_read_unlock(); | 116 | rcu_read_unlock(); |
117 | 117 | ||
118 | return part; | 118 | return part; |