Commit c3e23538 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

nfblock: convert to blk_alloc_disk/blk_cleanup_disk

Convert the nfblock driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-20-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f165fb89
...@@ -55,7 +55,6 @@ struct nfhd_device { ...@@ -55,7 +55,6 @@ struct nfhd_device {
int id; int id;
u32 blocks, bsize; u32 blocks, bsize;
int bshift; int bshift;
struct request_queue *queue;
struct gendisk *disk; struct gendisk *disk;
}; };
...@@ -119,32 +118,24 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize) ...@@ -119,32 +118,24 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
dev->bsize = bsize; dev->bsize = bsize;
dev->bshift = ffs(bsize) - 10; dev->bshift = ffs(bsize) - 10;
dev->queue = blk_alloc_queue(NUMA_NO_NODE); dev->disk = blk_alloc_disk(NUMA_NO_NODE);
if (dev->queue == NULL)
goto free_dev;
blk_queue_logical_block_size(dev->queue, bsize);
dev->disk = alloc_disk(16);
if (!dev->disk) if (!dev->disk)
goto free_queue; goto free_dev;
dev->disk->major = major_num; dev->disk->major = major_num;
dev->disk->first_minor = dev_id * 16; dev->disk->first_minor = dev_id * 16;
dev->disk->minors = 16;
dev->disk->fops = &nfhd_ops; dev->disk->fops = &nfhd_ops;
dev->disk->private_data = dev; dev->disk->private_data = dev;
sprintf(dev->disk->disk_name, "nfhd%u", dev_id); sprintf(dev->disk->disk_name, "nfhd%u", dev_id);
set_capacity(dev->disk, (sector_t)blocks * (bsize / 512)); set_capacity(dev->disk, (sector_t)blocks * (bsize / 512));
dev->disk->queue = dev->queue; blk_queue_logical_block_size(dev->disk->queue, bsize);
add_disk(dev->disk); add_disk(dev->disk);
list_add_tail(&dev->list, &nfhd_list); list_add_tail(&dev->list, &nfhd_list);
return 0; return 0;
free_queue:
blk_cleanup_queue(dev->queue);
free_dev: free_dev:
kfree(dev); kfree(dev);
out: out:
...@@ -186,8 +177,7 @@ static void __exit nfhd_exit(void) ...@@ -186,8 +177,7 @@ static void __exit nfhd_exit(void)
list_for_each_entry_safe(dev, next, &nfhd_list, list) { list_for_each_entry_safe(dev, next, &nfhd_list, list) {
list_del(&dev->list); list_del(&dev->list);
del_gendisk(dev->disk); del_gendisk(dev->disk);
put_disk(dev->disk); blk_cleanup_disk(dev->disk);
blk_cleanup_queue(dev->queue);
kfree(dev); kfree(dev);
} }
unregister_blkdev(major_num, "nfhd"); unregister_blkdev(major_num, "nfhd");
......
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