mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
block: hold a request_queue reference for the lifetime of struct gendisk
Acquire the queue ref dropped in disk_release in __blk_alloc_disk so any allocate gendisk always has a queue reference. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210816131910.615153-9-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
4a1fa41d30
commit
61a35cfc26
@ -551,15 +551,6 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
|
|||||||
register_disk(parent, disk, groups);
|
register_disk(parent, disk, groups);
|
||||||
blk_register_queue(disk);
|
blk_register_queue(disk);
|
||||||
|
|
||||||
/*
|
|
||||||
* Take an extra ref on queue which will be put on disk_release()
|
|
||||||
* so that it sticks around as long as @disk is there.
|
|
||||||
*/
|
|
||||||
if (blk_get_queue(disk->queue))
|
|
||||||
set_bit(GD_QUEUE_REF, &disk->state);
|
|
||||||
else
|
|
||||||
WARN_ON_ONCE(1);
|
|
||||||
|
|
||||||
disk_add_events(disk);
|
disk_add_events(disk);
|
||||||
blk_integrity_add(disk);
|
blk_integrity_add(disk);
|
||||||
}
|
}
|
||||||
@ -1087,8 +1078,7 @@ static void disk_release(struct device *dev)
|
|||||||
disk_release_events(disk);
|
disk_release_events(disk);
|
||||||
kfree(disk->random);
|
kfree(disk->random);
|
||||||
xa_destroy(&disk->part_tbl);
|
xa_destroy(&disk->part_tbl);
|
||||||
if (test_bit(GD_QUEUE_REF, &disk->state) && disk->queue)
|
blk_put_queue(disk->queue);
|
||||||
blk_put_queue(disk->queue);
|
|
||||||
iput(disk->part0->bd_inode); /* frees the disk */
|
iput(disk->part0->bd_inode); /* frees the disk */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1259,9 +1249,12 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
|
|||||||
{
|
{
|
||||||
struct gendisk *disk;
|
struct gendisk *disk;
|
||||||
|
|
||||||
|
if (!blk_get_queue(q))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
|
disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
|
||||||
if (!disk)
|
if (!disk)
|
||||||
return NULL;
|
goto out_put_queue;
|
||||||
|
|
||||||
disk->bdi = bdi_alloc(node_id);
|
disk->bdi = bdi_alloc(node_id);
|
||||||
if (!disk->bdi)
|
if (!disk->bdi)
|
||||||
@ -1296,6 +1289,8 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
|
|||||||
bdi_put(disk->bdi);
|
bdi_put(disk->bdi);
|
||||||
out_free_disk:
|
out_free_disk:
|
||||||
kfree(disk);
|
kfree(disk);
|
||||||
|
out_put_queue:
|
||||||
|
blk_put_queue(q);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__alloc_disk_node);
|
EXPORT_SYMBOL(__alloc_disk_node);
|
||||||
|
@ -149,7 +149,6 @@ struct gendisk {
|
|||||||
unsigned long state;
|
unsigned long state;
|
||||||
#define GD_NEED_PART_SCAN 0
|
#define GD_NEED_PART_SCAN 0
|
||||||
#define GD_READ_ONLY 1
|
#define GD_READ_ONLY 1
|
||||||
#define GD_QUEUE_REF 2
|
|
||||||
|
|
||||||
struct mutex open_mutex; /* open/close mutex */
|
struct mutex open_mutex; /* open/close mutex */
|
||||||
unsigned open_partitions; /* number of open partitions */
|
unsigned open_partitions; /* number of open partitions */
|
||||||
|
Loading…
Reference in New Issue
Block a user