Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Christoph Hellwig and committed by
Jens Axboe
807d4af2 de65b012

+15 -13
+2
block/blk.h
··· 204 204 e->type->ops.sq.elevator_deactivate_req_fn(q, rq); 205 205 } 206 206 207 + struct hd_struct *__disk_get_part(struct gendisk *disk, int partno); 208 + 207 209 #ifdef CONFIG_FAIL_IO_TIMEOUT 208 210 int blk_should_fake_timeout(struct request_queue *); 209 211 ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
+13 -13
block/genhd.c
··· 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 95 * disk_get_part - get partition 87 96 * @disk: disk to look partition from ··· 107 98 */ 108 99 struct hd_struct *disk_get_part(struct gendisk *disk, int partno) 109 100 { 110 - struct hd_struct *part = NULL; 111 - struct disk_part_tbl *ptbl; 112 - 113 - if (unlikely(partno < 0)) 114 - return NULL; 101 + struct hd_struct *part; 115 102 116 103 rcu_read_lock(); 117 - 118 - ptbl = rcu_dereference(disk->part_tbl); 119 - if (likely(partno < ptbl->len)) { 120 - part = rcu_dereference(ptbl->part[partno]); 121 - if (part) 122 - get_device(part_to_dev(part)); 123 - } 124 - 104 + part = __disk_get_part(disk, partno); 105 + if (part) 106 + get_device(part_to_dev(part)); 125 107 rcu_read_unlock(); 126 108 127 109 return part;