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>
This commit is contained in:
parent
de65b01232
commit
807d4af2f6
2 changed files with 15 additions and 13 deletions
|
@ -204,6 +204,8 @@ static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq
|
||||||
e->type->ops.sq.elevator_deactivate_req_fn(q, rq);
|
e->type->ops.sq.elevator_deactivate_req_fn(q, rq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct hd_struct *__disk_get_part(struct gendisk *disk, int partno);
|
||||||
|
|
||||||
#ifdef CONFIG_FAIL_IO_TIMEOUT
|
#ifdef CONFIG_FAIL_IO_TIMEOUT
|
||||||
int blk_should_fake_timeout(struct request_queue *);
|
int blk_should_fake_timeout(struct request_queue *);
|
||||||
ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
|
ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
|
||||||
|
|
|
@ -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_get_part - get partition
|
||||||
* @disk: disk to look partition from
|
* @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 *disk_get_part(struct gendisk *disk, int partno)
|
||||||
{
|
{
|
||||||
struct hd_struct *part = NULL;
|
struct hd_struct *part;
|
||||||
struct disk_part_tbl *ptbl;
|
|
||||||
|
|
||||||
if (unlikely(partno < 0))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
part = __disk_get_part(disk, partno);
|
||||||
ptbl = rcu_dereference(disk->part_tbl);
|
if (part)
|
||||||
if (likely(partno < ptbl->len)) {
|
get_device(part_to_dev(part));
|
||||||
part = rcu_dereference(ptbl->part[partno]);
|
|
||||||
if (part)
|
|
||||||
get_device(part_to_dev(part));
|
|
||||||
}
|
|
||||||
|
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
|
|
Loading…
Add table
Reference in a new issue