Commit 35efb594 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

ubd: use blk_mq_alloc_disk and blk_cleanup_disk

Use blk_mq_alloc_disk and blk_cleanup_disk to simplify the gendisk and
request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210614060759.3965724-3-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7eb90f7e
...@@ -825,7 +825,6 @@ static void ubd_device_release(struct device *dev) ...@@ -825,7 +825,6 @@ static void ubd_device_release(struct device *dev)
{ {
struct ubd *ubd_dev = dev_get_drvdata(dev); struct ubd *ubd_dev = dev_get_drvdata(dev);
blk_cleanup_queue(ubd_dev->queue);
blk_mq_free_tag_set(&ubd_dev->tag_set); blk_mq_free_tag_set(&ubd_dev->tag_set);
*ubd_dev = ((struct ubd) DEFAULT_UBD); *ubd_dev = ((struct ubd) DEFAULT_UBD);
} }
...@@ -865,17 +864,12 @@ static const struct attribute_group *ubd_attr_groups[] = { ...@@ -865,17 +864,12 @@ static const struct attribute_group *ubd_attr_groups[] = {
NULL, NULL,
}; };
static int ubd_disk_register(int major, u64 size, int unit, static void ubd_disk_register(int major, u64 size, int unit,
struct gendisk **disk_out) struct gendisk *disk)
{ {
struct gendisk *disk;
disk = alloc_disk(1 << UBD_SHIFT);
if(disk == NULL)
return -ENOMEM;
disk->major = major; disk->major = major;
disk->first_minor = unit << UBD_SHIFT; disk->first_minor = unit << UBD_SHIFT;
disk->minors = 1 << UBD_SHIFT;
disk->fops = &ubd_blops; disk->fops = &ubd_blops;
set_capacity(disk, size / 512); set_capacity(disk, size / 512);
sprintf(disk->disk_name, "ubd%c", 'a' + unit); sprintf(disk->disk_name, "ubd%c", 'a' + unit);
...@@ -889,9 +883,6 @@ static int ubd_disk_register(int major, u64 size, int unit, ...@@ -889,9 +883,6 @@ static int ubd_disk_register(int major, u64 size, int unit,
disk->private_data = &ubd_devs[unit]; disk->private_data = &ubd_devs[unit];
disk->queue = ubd_devs[unit].queue; disk->queue = ubd_devs[unit].queue;
device_add_disk(&ubd_devs[unit].pdev.dev, disk, ubd_attr_groups); device_add_disk(&ubd_devs[unit].pdev.dev, disk, ubd_attr_groups);
*disk_out = disk;
return 0;
} }
#define ROUND_BLOCK(n) ((n + (SECTOR_SIZE - 1)) & (-SECTOR_SIZE)) #define ROUND_BLOCK(n) ((n + (SECTOR_SIZE - 1)) & (-SECTOR_SIZE))
...@@ -903,6 +894,7 @@ static const struct blk_mq_ops ubd_mq_ops = { ...@@ -903,6 +894,7 @@ static const struct blk_mq_ops ubd_mq_ops = {
static int ubd_add(int n, char **error_out) static int ubd_add(int n, char **error_out)
{ {
struct ubd *ubd_dev = &ubd_devs[n]; struct ubd *ubd_dev = &ubd_devs[n];
struct gendisk *disk;
int err = 0; int err = 0;
if(ubd_dev->file == NULL) if(ubd_dev->file == NULL)
...@@ -927,32 +919,24 @@ static int ubd_add(int n, char **error_out) ...@@ -927,32 +919,24 @@ static int ubd_add(int n, char **error_out)
if (err) if (err)
goto out; goto out;
ubd_dev->queue = blk_mq_init_queue(&ubd_dev->tag_set); disk = blk_mq_alloc_disk(&ubd_dev->tag_set, ubd_dev);
if (IS_ERR(ubd_dev->queue)) { if (IS_ERR(disk)) {
err = PTR_ERR(ubd_dev->queue); err = PTR_ERR(disk);
goto out_cleanup_tags; goto out_cleanup_tags;
} }
ubd_dev->queue = disk->queue;
ubd_dev->queue->queuedata = ubd_dev;
blk_queue_write_cache(ubd_dev->queue, true, false); blk_queue_write_cache(ubd_dev->queue, true, false);
blk_queue_max_segments(ubd_dev->queue, MAX_SG); blk_queue_max_segments(ubd_dev->queue, MAX_SG);
blk_queue_segment_boundary(ubd_dev->queue, PAGE_SIZE - 1); blk_queue_segment_boundary(ubd_dev->queue, PAGE_SIZE - 1);
err = ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, &ubd_gendisk[n]); ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, disk);
if(err){ ubd_gendisk[n] = disk;
*error_out = "Failed to register device"; return 0;
goto out_cleanup_tags;
}
err = 0;
out:
return err;
out_cleanup_tags: out_cleanup_tags:
blk_mq_free_tag_set(&ubd_dev->tag_set); blk_mq_free_tag_set(&ubd_dev->tag_set);
if (!(IS_ERR(ubd_dev->queue))) out:
blk_cleanup_queue(ubd_dev->queue); return err;
goto out;
} }
static int ubd_config(char *str, char **error_out) static int ubd_config(char *str, char **error_out)
...@@ -1055,7 +1039,7 @@ static int ubd_remove(int n, char **error_out) ...@@ -1055,7 +1039,7 @@ static int ubd_remove(int n, char **error_out)
ubd_gendisk[n] = NULL; ubd_gendisk[n] = NULL;
if(disk != NULL){ if(disk != NULL){
del_gendisk(disk); del_gendisk(disk);
put_disk(disk); blk_cleanup_disk(disk);
} }
err = 0; err = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment