summaryrefslogtreecommitdiffstats
path: root/block/genhd.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-08-23 19:10:30 +0200
committerJens Axboe <axboe@kernel.dk>2017-08-23 12:49:52 -0600
commit807d4af2f64ed79fdbb28e582e330be3dbe10d23 (patch)
tree11ed994bb09f7739c8d746f8d39b82df07aa7740 /block/genhd.c
parentde65b0123216a8e1dbe3ca1eb20a45572b9e71d9 (diff)
downloadlinux-807d4af2f64ed79fdbb28e582e330be3dbe10d23.tar.bz2
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.c26
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,
}
}
+struct hd_struct *__disk_get_part(struct gendisk *disk, int partno)
+{
+ struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl);
+
+ if (unlikely(partno < 0 || partno >= ptbl->len))
+ return NULL;
+ return rcu_dereference(ptbl->part[partno]);
+}
+
/**
* disk_get_part - get partition
* @disk: disk to look partition from
@@ -98,21 +107,12 @@ void part_in_flight(struct request_queue *q, struct hd_struct *part,
*/
struct hd_struct *disk_get_part(struct gendisk *disk, int partno)
{
- struct hd_struct *part = NULL;
- struct disk_part_tbl *ptbl;
-
- if (unlikely(partno < 0))
- return NULL;
+ struct hd_struct *part;
rcu_read_lock();
-
- ptbl = rcu_dereference(disk->part_tbl);
- if (likely(partno < ptbl->len)) {
- part = rcu_dereference(ptbl->part[partno]);
- if (part)
- get_device(part_to_dev(part));
- }
-
+ part = __disk_get_part(disk, partno);
+ if (part)
+ get_device(part_to_dev(part));
rcu_read_unlock();
return part;