From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:47
Hi all,
this series is the first part of cleaning up lifetimes and allocation of
the gendisk and request_queue structure. It adds a new interface to
allocate the disk and queue together for bio based drivers, and a helper
for cleanup/free them when a driver is unloaded or a device is removed.
Together this removes the need to treat the gendisk and request_queue
as separate entities for bio based drivers.
Diffstat:
arch/m68k/emu/nfblock.c | 20 +---
arch/xtensa/platforms/iss/simdisk.c | 29 +------
block/blk-core.c | 1
block/blk.h | 6 -
block/genhd.c | 149 +++++++++++++++++++-----------------
block/partitions/core.c | 19 ++--
drivers/block/brd.c | 94 +++++++---------------
drivers/block/drbd/drbd_main.c | 23 +----
drivers/block/n64cart.c | 8 -
drivers/block/null_blk/main.c | 38 ++++-----
drivers/block/pktcdvd.c | 11 --
drivers/block/ps3vram.c | 31 +------
drivers/block/rsxx/dev.c | 39 +++------
drivers/block/rsxx/rsxx_priv.h | 1
drivers/block/zram/zram_drv.c | 19 ----
drivers/lightnvm/core.c | 24 +----
drivers/md/bcache/super.c | 15 ---
drivers/md/dm.c | 16 +--
drivers/md/md.c | 25 ++----
drivers/memstick/core/ms_block.c | 1
drivers/nvdimm/blk.c | 27 +-----
drivers/nvdimm/btt.c | 25 +-----
drivers/nvdimm/btt.h | 2
drivers/nvdimm/pmem.c | 17 +---
drivers/nvme/host/core.c | 1
drivers/nvme/host/multipath.c | 46 +++--------
drivers/s390/block/dcssblk.c | 26 +-----
drivers/s390/block/xpram.c | 26 ++----
include/linux/blkdev.h | 1
include/linux/genhd.h | 23 +++++
30 files changed, 297 insertions(+), 466 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:51
Keep this together with the first place that actually looks at
->minors and prepare for not passing a minors argument to
alloc_disk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:52
Untangle the mess around blk_alloc_devt by moving the check for
the used allocation scheme into the callers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 4 +-
block/genhd.c | 96 ++++++++++++++++-------------------------
block/partitions/core.c | 15 +++++--
3 files changed, 49 insertions(+), 66 deletions(-)
@@ -335,52 +335,22 @@ static int blk_mangle_minor(int minor)returnminor;}-/**-*blk_alloc_devt-allocateadev_tforablockdevice-*@bdev:blockdevicetoallocatedev_tfor-*@devt:outparameterforresultingdev_t-*-*Allocateadev_tforblockdevice.-*-*RETURNS:-*0onsuccess,allocateddev_tisreturnedin*@devt.-errnoon-*failure.-*-*CONTEXT:-*Mightsleep.-*/-intblk_alloc_devt(structblock_device*bdev,dev_t*devt)+intblk_alloc_ext_minor(void){-structgendisk*disk=bdev->bd_disk;intidx;-/* in consecutive minor range? */-if(bdev->bd_partno<disk->minors){-*devt=MKDEV(disk->major,disk->first_minor+bdev->bd_partno);-return0;-}-idx=ida_alloc_range(&ext_devt_ida,0,NR_EXT_DEVT,GFP_KERNEL);-if(idx<0)-returnidx==-ENOSPC?-EBUSY:idx;--*devt=MKDEV(BLOCK_EXT_MAJOR,blk_mangle_minor(idx));-return0;+if(idx<0){+if(idx==-ENOSPC)+return-EBUSY;+returnidx;+}+returnblk_mangle_minor(idx);}-/**-*blk_free_devt-freeadev_t-*@devt:dev_ttofree-*-*Free@devtwhichwasallocatedusingblk_alloc_devt().-*-*CONTEXT:-*Mightsleep.-*/-voidblk_free_devt(dev_tdevt)+voidblk_free_ext_minor(unsignedintminor){-if(MAJOR(devt)==BLOCK_EXT_MAJOR)-ida_free(&ext_devt_ida,blk_mangle_minor(MINOR(devt)));+ida_free(&ext_devt_ida,blk_mangle_minor(minor));}staticchar*bdevt_str(dev_tdevt,char*buf)
@@ -379,9 +380,15 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,pdev->type=&part_type;pdev->parent=ddev;-err=blk_alloc_devt(bdev,&devt);-if(err)-gotoout_put;+/* in consecutive minor range? */+if(bdev->bd_partno<disk->minors){+devt=MKDEV(disk->major,disk->first_minor+bdev->bd_partno);+}else{+err=blk_alloc_ext_minor();+if(err<0)+gotoout_put;+devt=MKDEV(BLOCK_EXT_MAJOR,err);+}pdev->devt=devt;/* delay uevent until 'holders' subdir is created */
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:54
Add a flag to indicate that __device_add_disk did grab a queue reference
so that disk_release only drops it if we actually had it. This sort
out one of the major pitfals with partially initialized gendisk that
a lot of drivers did get wrong or still do.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 7 +++++--
include/linux/genhd.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:56
Automatically set the GENHD_FL_EXT_DEVT flag for all disks allocated
without an explicit number of minors. This is what all new block
drivers should do, so make sure it is the default without boilerplate
code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 2 +-
block/partitions/core.c | 4 ----
drivers/block/n64cart.c | 2 +-
drivers/lightnvm/core.c | 1 -
drivers/memstick/core/ms_block.c | 1 -
drivers/nvdimm/blk.c | 1 -
drivers/nvdimm/btt.c | 1 -
drivers/nvdimm/pmem.c | 1 -
drivers/nvme/host/core.c | 1 -
drivers/nvme/host/multipath.c | 1 -
10 files changed, 2 insertions(+), 13 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:51:59
Add two new APIs to allocate and free a gendisk including the
request_queue for use with BIO based drivers. This is to avoid
boilerplate code in drivers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/genhd.h | 22 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:03
Convert the brd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation. This also
allows to remove the request_queue pointer in struct request_queue,
and to simplify the initialization as blk_cleanup_disk can be called
on any disk returned from blk_alloc_disk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/brd.c | 94 ++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 61 deletions(-)
@@ -380,64 +378,55 @@ static struct brd_device *brd_alloc(int i)brd=kzalloc(sizeof(*brd),GFP_KERNEL);if(!brd)-gotoout;+return-ENOMEM;brd->brd_number=i;spin_lock_init(&brd->brd_lock);INIT_RADIX_TREE(&brd->brd_pages,GFP_ATOMIC);-brd->brd_queue=blk_alloc_queue(NUMA_NO_NODE);-if(!brd->brd_queue)-gotoout_free_dev;-snprintf(buf,DISK_NAME_LEN,"ram%d",i);if(!IS_ERR_OR_NULL(brd_debugfs_dir))debugfs_create_u64(buf,0444,brd_debugfs_dir,&brd->brd_nr_pages);-/* This is so fdisk will align partitions on 4k, because of-*direct_accessAPIneeding4kalignment,returningaPFN-*(Thisisonlyaproblemonverysmalldevices<=4M,-*otherwisefdiskwillalignon1M.Regardlessthiscall-*isharmless)-*/-blk_queue_physical_block_size(brd->brd_queue,PAGE_SIZE);-disk=brd->brd_disk=alloc_disk(max_part);+disk=brd->brd_disk=blk_alloc_disk(NUMA_NO_NODE);if(!disk)-gotoout_free_queue;+gotoout_free_dev;+disk->major=RAMDISK_MAJOR;disk->first_minor=i*max_part;+disk->minors=max_part;disk->fops=&brd_fops;disk->private_data=brd;disk->flags=GENHD_FL_EXT_DEVT;strlcpy(disk->disk_name,buf,DISK_NAME_LEN);set_capacity(disk,rd_size*2);++/*+*Thisissofdiskwillalignpartitionson4k,becauseof+*direct_accessAPIneeding4kalignment,returningaPFN+*(Thisisonlyaproblemonverysmalldevices<=4M,+*otherwisefdiskwillalignon1M.Regardlessthiscall+*isharmless)+*/+blk_queue_physical_block_size(disk->queue,PAGE_SIZE);/* Tell the block layer that this is not a rotational device */-blk_queue_flag_set(QUEUE_FLAG_NONROT,brd->brd_queue);-blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM,brd->brd_queue);+blk_queue_flag_set(QUEUE_FLAG_NONROT,disk->queue);+blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM,disk->queue);+add_disk(disk);+list_add_tail(&brd->brd_list,&brd_devices);-returnbrd;+return0;-out_free_queue:-blk_cleanup_queue(brd->brd_queue);out_free_dev:kfree(brd);-out:-returnNULL;-}--staticvoidbrd_free(structbrd_device*brd)-{-put_disk(brd->brd_disk);-blk_cleanup_queue(brd->brd_queue);-brd_free_pages(brd);-kfree(brd);+return-ENOMEM;}staticvoidbrd_probe(dev_tdev){-structbrd_device*brd;inti=MINOR(dev)/max_part;+structbrd_device*brd;mutex_lock(&brd_devices_mutex);list_for_each_entry(brd,&brd_devices,brd_list){
@@ -511,22 +496,11 @@ static int __init brd_init(void)mutex_lock(&brd_devices_mutex);for(i=0;i<rd_nr;i++){-brd=brd_alloc(i);-if(!brd)+err=brd_alloc(i);+if(err)gotoout_free;-list_add_tail(&brd->brd_list,&brd_devices);}-/* point of no return */--list_for_each_entry(brd,&brd_devices,brd_list){-/*-*associatewithqueuejustbeforeaddingdiskfor-*avoidingtomessupfailurepath-*/-brd->brd_disk->queue=brd->brd_queue;-add_disk(brd->brd_disk);-}mutex_unlock(&brd_devices_mutex);pr_info("brd: module loaded\n");
@@ -535,15 +509,13 @@ static int __init brd_init(void)out_free:debugfs_remove_recursive(brd_debugfs_dir);-list_for_each_entry_safe(brd,next,&brd_devices,brd_list){-list_del(&brd->brd_list);-brd_free(brd);-}+list_for_each_entry_safe(brd,next,&brd_devices,brd_list)+brd_del_one(brd);mutex_unlock(&brd_devices_mutex);unregister_blkdev(RAMDISK_MAJOR,"ramdisk");pr_info("brd: module NOT loaded !!!\n");-return-ENOMEM;+returnerr;}staticvoid__exitbrd_exit(void)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:06
Convert the drbd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/drbd/drbd_main.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
@@ -2231,8 +2231,7 @@ void drbd_destroy_device(struct kref *kref)if(device->bitmap)/* should no longer be there. */drbd_bm_cleanup(device);__free_page(device->md_io.page);-put_disk(device->vdisk);-blk_cleanup_queue(device->rq_queue);+blk_cleanup_disk(device->vdisk);kfree(device->rs_plan_s);/* not for_each_connection(connection, resource):
@@ -2723,29 +2721,26 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigdrbd_init_set_defaults(device);-q=blk_alloc_queue(NUMA_NO_NODE);-if(!q)-gotoout_no_q;-device->rq_queue=q;--disk=alloc_disk(1);+disk=blk_alloc_disk(NUMA_NO_NODE);if(!disk)gotoout_no_disk;+device->vdisk=disk;+device->rq_queue=disk->queue;set_disk_ro(disk,true);-disk->queue=q;disk->major=DRBD_MAJOR;disk->first_minor=minor;+disk->minors=1;disk->fops=&drbd_ops;sprintf(disk->disk_name,"drbd%d",minor);disk->private_data=device;-blk_queue_write_cache(q,true,true);+blk_queue_write_cache(disk->queue,true,true);/* Setting the max_hw_sectors to an odd value of 8kibyte hereThistriggersamax_bio_sizemessageuponfirstattachorconnect*/-blk_queue_max_hw_sectors(q,DRBD_MAX_BIO_SIZE_SAFE>>8);+blk_queue_max_hw_sectors(disk->queue,DRBD_MAX_BIO_SIZE_SAFE>>8);device->md_io.page=alloc_page(GFP_KERNEL);if(!device->md_io.page)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:12
Convert the pktcdvd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/pktcdvd.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:22
Convert the rsxx driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/rsxx/dev.c | 39 +++++++++++++---------------------
drivers/block/rsxx/rsxx_priv.h | 1 -
2 files changed, 15 insertions(+), 25 deletions(-)
@@ -154,7 +154,6 @@ struct rsxx_cardinfo {boolbdev_attached;intdisk_id;intmajor;-structrequest_queue*queue;structgendisk*gendisk;struct{/* Used to convert a byte address to a device address. */
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:25
Convert the zram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zram/zram_drv.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
@@ -1906,27 +1905,20 @@ static int zram_add(void)#ifdef CONFIG_ZRAM_WRITEBACKspin_lock_init(&zram->wb_limit_lock);#endif-queue=blk_alloc_queue(NUMA_NO_NODE);-if(!queue){-pr_err("Error allocating disk queue for device %d\n",-device_id);-ret=-ENOMEM;-gotoout_free_idr;-}/* gendisk structure */-zram->disk=alloc_disk(1);+zram->disk=blk_alloc_disk(NUMA_NO_NODE);if(!zram->disk){pr_err("Error allocating disk structure for device %d\n",device_id);ret=-ENOMEM;-gotoout_free_queue;+gotoout_free_idr;}zram->disk->major=zram_major;zram->disk->first_minor=device_id;+zram->disk->minors=1;zram->disk->fops=&zram_devops;-zram->disk->queue=queue;zram->disk->private_data=zram;snprintf(zram->disk->disk_name,16,"zram%d",device_id);
@@ -1969,8 +1961,6 @@ static int zram_add(void)pr_info("Added device: %s\n",zram->disk->disk_name);returndevice_id;-out_free_queue:-blk_cleanup_queue(queue);out_free_idr:idr_remove(&zram_index_idr,device_id);out_free_dev:
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:26
Convert the lightnvm driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/lightnvm/core.c | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:33
Convert the dm driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/dm.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:34
Convert the bcache driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/bcache/super.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:35
Convert the md driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/md.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:38
Convert the nvdimm-blk driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/blk.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:45
Convert the nvdimm-btt driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/btt.c | 24 +++++++-----------------
drivers/nvdimm/btt.h | 2 --
2 files changed, 7 insertions(+), 19 deletions(-)
@@ -1521,34 +1521,25 @@ static int btt_blk_init(struct btt *btt)structnd_btt*nd_btt=btt->nd_btt;structnd_namespace_common*ndns=nd_btt->ndns;-/* create a new disk and request queue for btt */-btt->btt_queue=blk_alloc_queue(NUMA_NO_NODE);-if(!btt->btt_queue)+btt->btt_disk=blk_alloc_disk(NUMA_NO_NODE);+if(!btt->btt_disk)return-ENOMEM;-btt->btt_disk=alloc_disk(0);-if(!btt->btt_disk){-blk_cleanup_queue(btt->btt_queue);-return-ENOMEM;-}-nvdimm_namespace_disk_name(ndns,btt->btt_disk->disk_name);btt->btt_disk->first_minor=0;btt->btt_disk->fops=&btt_fops;btt->btt_disk->private_data=btt;-btt->btt_disk->queue=btt->btt_queue;-blk_queue_logical_block_size(btt->btt_queue,btt->sector_size);-blk_queue_max_hw_sectors(btt->btt_queue,UINT_MAX);-blk_queue_flag_set(QUEUE_FLAG_NONROT,btt->btt_queue);+blk_queue_logical_block_size(btt->btt_disk->queue,btt->sector_size);+blk_queue_max_hw_sectors(btt->btt_disk->queue,UINT_MAX);+blk_queue_flag_set(QUEUE_FLAG_NONROT,btt->btt_disk->queue);if(btt_meta_size(btt)){intrc=nd_integrity_init(btt->btt_disk,btt_meta_size(btt));if(rc){del_gendisk(btt->btt_disk);-put_disk(btt->btt_disk);-blk_cleanup_queue(btt->btt_queue);+blk_cleanup_disk(btt->btt_disk);returnrc;}}
@@ -1563,8 +1554,7 @@ static int btt_blk_init(struct btt *btt)staticvoidbtt_blk_cleanup(structbtt*btt){del_gendisk(btt->btt_disk);-put_disk(btt->btt_disk);-blk_cleanup_queue(btt->btt_queue);+blk_cleanup_disk(btt->btt_disk);}/**
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:45
Convert the nvdimm-pmem driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/pmem.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:55
Convert the nvme-multipath driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/pmem.c | 1 -
drivers/nvme/host/multipath.c | 45 ++++++++++-------------------------
2 files changed, 13 insertions(+), 33 deletions(-)
@@ -443,33 +442,24 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)if(!(ctrl->subsys->cmic&NVME_CTRL_CMIC_MULTI_CTRL)||!multipath)return0;-q=blk_alloc_queue(ctrl->numa_node);-if(!q)-gotoout;-blk_queue_flag_set(QUEUE_FLAG_NONROT,q);-/* set to a default value for 512 until disk is validated */-blk_queue_logical_block_size(q,512);-blk_set_stacking_limits(&q->limits);--/* we need to propagate up the VMC settings */-if(ctrl->vwc&NVME_CTRL_VWC_PRESENT)-vwc=true;-blk_queue_write_cache(q,vwc,vwc);--head->disk=alloc_disk(0);+head->disk=blk_alloc_disk(ctrl->numa_node);if(!head->disk)-gotoout_cleanup_queue;+return-ENOMEM;head->disk->fops=&nvme_ns_head_ops;head->disk->private_data=head;-head->disk->queue=q;sprintf(head->disk->disk_name,"nvme%dn%d",ctrl->subsys->instance,head->instance);-return0;-out_cleanup_queue:-blk_cleanup_queue(q);-out:-return-ENOMEM;+blk_queue_flag_set(QUEUE_FLAG_NONROT,head->disk->queue);+/* set to a default value of 512 until the disk is validated */+blk_queue_logical_block_size(head->disk->queue,512);+blk_set_stacking_limits(&head->disk->queue->limits);++/* we need to propagate up the VMC settings */+if(ctrl->vwc&NVME_CTRL_VWC_PRESENT)+vwc=true;+blk_queue_write_cache(head->disk->queue,vwc,vwc);+return0;}staticvoidnvme_mpath_set_live(structnvme_ns*ns)
@@ -768,16 +758,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)/* make sure all pending bios are cleaned up */kblockd_schedule_work(&head->requeue_work);flush_work(&head->requeue_work);-blk_cleanup_queue(head->disk->queue);-if(!test_bit(NVME_NSHEAD_DISK_LIVE,&head->flags)){-/*-*ifdevice_add_diskwasn'tcalled,prevent-*diskreleasetoputabogusreferenceonthe-*requestqueue-*/-head->disk->queue=NULL;-}-put_disk(head->disk);+blk_cleanup_disk(head->disk);}voidnvme_mpath_init_ctrl(structnvme_ctrl*ctrl)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:56
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: Christoph Hellwig <hch@lst.de>
---
arch/m68k/emu/nfblock.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:57
Convert the simdisk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/xtensa/platforms/iss/simdisk.c | 29 +++++++----------------------
1 file changed, 7 insertions(+), 22 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:52:59
Convert the ps3vram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/ps3vram.c | 31 ++++++++-----------------------
1 file changed, 8 insertions(+), 23 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:53:00
Convert the n64cart driver to use the blk_alloc_disk helper to simplify
gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/n64cart.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:53:01
Convert the dcssblk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/s390/block/dcssblk.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:53:10
Convert the xpram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/s390/block/xpram.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:53:12
Convert the null_blk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation. Note that the
blk-mq mode is left with its own allocations scheme, to be handled later.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/null_blk/main.c | 38 +++++++++++++++++------------------
1 file changed, 19 insertions(+), 19 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 05:53:13
blk_alloc_queue is just an internal helper now, unexport it and remove
it from the public header.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-core.c | 1 -
block/blk.h | 2 ++
include/linux/blkdev.h | 1 -
3 files changed, 2 insertions(+), 2 deletions(-)
Convert the bcache driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/bcache/super.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
The above 2 lines are added on purpose to prevent an refcount
underflow. It is from commit 86da9f736740 ("bcache: fix refcount
underflow in bcache_device_free()").
Maybe add a parameter to blk_cleanup_disk() or checking (disk->flags &
GENHD_FL_UP) inside blk_cleanup_disk() ?
Coly Li
quoted hunk
}
bioset_exit(&d->bio_split);
@@ -946,7 +942,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size, BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER)) goto err;- d->disk = alloc_disk(BCACHE_MINORS);+ d->disk = blk_alloc_disk(NUMA_NO_NODE); if (!d->disk) goto err;
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-21 06:23:08
On Fri, May 21, 2021 at 02:15:32PM +0800, Coly Li wrote:
The above 2 lines are added on purpose to prevent an refcount
underflow. It is from commit 86da9f736740 ("bcache: fix refcount
underflow in bcache_device_free()").
Maybe add a parameter to blk_cleanup_disk() or checking (disk->flags &
GENHD_FL_UP) inside blk_cleanup_disk() ?
On Fri, May 21, 2021 at 7:52 AM Christoph Hellwig [off-list ref] wrote:
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: Christoph Hellwig <hch@lst.de>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
@@ -379,9 +380,15 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,pdev->type=&part_type;pdev->parent=ddev;-err=blk_alloc_devt(bdev,&devt);-if(err)-gotoout_put;+/* in consecutive minor range? */+if(bdev->bd_partno<disk->minors){+devt=MKDEV(disk->major,disk->first_minor+bdev->bd_partno);+}else{+err=blk_alloc_ext_minor();+if(err<0)+gotoout_put;+devt=MKDEV(BLOCK_EXT_MAJOR,err);+}pdev->devt=devt;/* delay uevent until 'holders' subdir is created */
... and why we only add this here now.
Other than that, this looks like a super nice cleanup!
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-05-21 17:18:11
On Fri, May 21, 2021 at 07:50:52AM +0200, Christoph Hellwig wrote:
Keep this together with the first place that actually looks at
->minors and prepare for not passing a minors argument to
alloc_disk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-05-21 17:22:47
On Fri, May 21, 2021 at 07:50:53AM +0200, Christoph Hellwig wrote:
Automatically set the GENHD_FL_EXT_DEVT flag for all disks allocated
without an explicit number of minors. This is what all new block
drivers should do, so make sure it is the default without boilerplate
code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-05-21 17:28:47
On Fri, May 21, 2021 at 07:50:54AM +0200, Christoph Hellwig wrote:
Add a flag to indicate that __device_add_disk did grab a queue reference
so that disk_release only drops it if we actually had it. This sort
out one of the major pitfals with partially initialized gendisk that
a lot of drivers did get wrong or still do.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-05-21 17:44:12
On Fri, May 21, 2021 at 07:50:55AM +0200, Christoph Hellwig wrote:
quoted hunk
Add two new APIs to allocate and free a gendisk including the
request_queue for use with BIO based drivers. This is to avoid
boilerplate code in drivers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/genhd.h | 22 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
@@ -1302,6 +1302,25 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)}EXPORT_SYMBOL(__alloc_disk_node);+structgendisk*__blk_alloc_disk(intnode)+{+structrequest_queue*q;+structgendisk*disk;++q=blk_alloc_queue(node);+if(!q)+returnNULL;++disk=__alloc_disk_node(0,node);+if(!disk){+blk_cleanup_queue(q);+returnNULL;+}+disk->queue=q;+returndisk;+}+EXPORT_SYMBOL(__blk_alloc_disk);
Its not obvious to me why using this new API requires you then to
set minors explicitly to 1, and yet here underneath we see the minors
argument passed is 0.
Nor is it clear from the documentation.
Luis
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:46:08
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Untangle the mess around blk_alloc_devt by moving the check for
the used allocation scheme into the callers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 4 +-
block/genhd.c | 96 ++++++++++++++++-------------------------
block/partitions/core.c | 15 +++++--
3 files changed, 49 insertions(+), 66 deletions(-)
... and also fixes an issue with GENHD_FL_UP remained set in an error
path in __device_add_disk().
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:48:26
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Keep this together with the first place that actually looks at
->minors and prepare for not passing a minors argument to
alloc_disk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:50:26
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Automatically set the GENHD_FL_EXT_DEVT flag for all disks allocated
without an explicit number of minors. This is what all new block
drivers should do, so make sure it is the default without boilerplate
code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 2 +-
block/partitions/core.c | 4 ----
drivers/block/n64cart.c | 2 +-
drivers/lightnvm/core.c | 1 -
drivers/memstick/core/ms_block.c | 1 -
drivers/nvdimm/blk.c | 1 -
drivers/nvdimm/btt.c | 1 -
drivers/nvdimm/pmem.c | 1 -
drivers/nvme/host/core.c | 1 -
drivers/nvme/host/multipath.c | 1 -
10 files changed, 2 insertions(+), 13 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:54:11
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Add a flag to indicate that __device_add_disk did grab a queue reference
so that disk_release only drops it if we actually had it. This sort
out one of the major pitfals with partially initialized gendisk that
pitfalls
a lot of drivers did get wrong or still do.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 7 +++++--
include/linux/genhd.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:55:19
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Add two new APIs to allocate and free a gendisk including the
request_queue for use with BIO based drivers. This is to avoid
boilerplate code in drivers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/genhd.h | 22 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 07:58:54
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
quoted hunk
Convert the brd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation. This also
allows to remove the request_queue pointer in struct request_queue,
and to simplify the initialization as blk_cleanup_disk can be called
on any disk returned from blk_alloc_disk.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/brd.c | 94 ++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 61 deletions(-)
@@ -380,64 +378,55 @@ static struct brd_device *brd_alloc(int i)brd=kzalloc(sizeof(*brd),GFP_KERNEL);if(!brd)-gotoout;+return-ENOMEM;brd->brd_number=i;spin_lock_init(&brd->brd_lock);INIT_RADIX_TREE(&brd->brd_pages,GFP_ATOMIC);-brd->brd_queue=blk_alloc_queue(NUMA_NO_NODE);-if(!brd->brd_queue)-gotoout_free_dev;-snprintf(buf,DISK_NAME_LEN,"ram%d",i);if(!IS_ERR_OR_NULL(brd_debugfs_dir))debugfs_create_u64(buf,0444,brd_debugfs_dir,&brd->brd_nr_pages);-/* This is so fdisk will align partitions on 4k, because of-*direct_accessAPIneeding4kalignment,returningaPFN-*(Thisisonlyaproblemonverysmalldevices<=4M,-*otherwisefdiskwillalignon1M.Regardlessthiscall-*isharmless)-*/-blk_queue_physical_block_size(brd->brd_queue,PAGE_SIZE);-disk=brd->brd_disk=alloc_disk(max_part);+disk=brd->brd_disk=blk_alloc_disk(NUMA_NO_NODE);if(!disk)-gotoout_free_queue;+gotoout_free_dev;+disk->major=RAMDISK_MAJOR;disk->first_minor=i*max_part;+disk->minors=max_part;disk->fops=&brd_fops;disk->private_data=brd;disk->flags=GENHD_FL_EXT_DEVT;strlcpy(disk->disk_name,buf,DISK_NAME_LEN);set_capacity(disk,rd_size*2);++/*+*Thisissofdiskwillalignpartitionson4k,becauseof+*direct_accessAPIneeding4kalignment,returningaPFN+*(Thisisonlyaproblemonverysmalldevices<=4M,+*otherwisefdiskwillalignon1M.Regardlessthiscall+*isharmless)+*/+blk_queue_physical_block_size(disk->queue,PAGE_SIZE);
Maybe converting the comment to refer to 'PAGE_SIZE' instead of 4k while
you're at it ...
@@ -485,7 +470,7 @@ static inline void brd_check_and_reset_par(void) static int __init brd_init(void) { struct brd_device *brd, *next;- int i;+ int err, i; /* * brd module now has a feature to instantiate underlying device
@@ -511,22 +496,11 @@ static int __init brd_init(void) mutex_lock(&brd_devices_mutex); for (i = 0; i < rd_nr; i++) {- brd = brd_alloc(i);- if (!brd)+ err = brd_alloc(i);+ if (err) goto out_free;- list_add_tail(&brd->brd_list, &brd_devices); }- /* point of no return */-- list_for_each_entry(brd, &brd_devices, brd_list) {- /*- * associate with queue just before adding disk for- * avoiding to mess up failure path- */- brd->brd_disk->queue = brd->brd_queue;- add_disk(brd->brd_disk);- } mutex_unlock(&brd_devices_mutex); pr_info("brd: module loaded\n");
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:00:00
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Convert the drbd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/drbd/drbd_main.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:00:57
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Convert the pktcdvd driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/pktcdvd.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:01:14
On 5/21/21 7:50 AM, Christoph Hellwig wrote:
Convert the rsxx driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/rsxx/dev.c | 39 +++++++++++++---------------------
drivers/block/rsxx/rsxx_priv.h | 1 -
2 files changed, 15 insertions(+), 25 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:01:44
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the zram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zram/zram_drv.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:02:26
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the lightnvm driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/lightnvm/core.c | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:05:03
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the bcache driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/bcache/super.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:11:09
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
quoted hunk
Convert the dm driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/dm.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
Can't these conditionals be merged into a single 'if (md->disk)'?
Eg like:
if (md->disk) {
spin_lock(&_minor_lock);
md->disk->private_data = NULL;
spin_unlock(&_minor_lock);
del_gendisk(md->disk);
dm_queue_destroy_keyslot_manager(md->queue);
blk_cleanup_disk(md->queue);
}
We're now always allocating 'md->disk' and 'md->queue' together,
so how can we end up in a situation where one is set without the other?
quoted hunk
@@ -1869,13 +1869,10 @@ static struct mapped_device *alloc_dev(int minor) * established. If request-based table is loaded: blk-mq will * override accordingly. */- md->queue = blk_alloc_queue(numa_node_id);- if (!md->queue)- goto bad;-- md->disk = alloc_disk_node(1, md->numa_node_id);+ md->disk = blk_alloc_disk(md->numa_node_id); if (!md->disk) goto bad;+ md->queue = md->disk->queue; init_waitqueue_head(&md->wait); INIT_WORK(&md->work, dm_wq_work);
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:12:54
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
quoted hunk
Convert the md driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/md.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
@@ -5711,20 +5709,13 @@ static int md_alloc(dev_t dev, char *name)gotoabort;error=-ENOMEM;-mddev->queue=blk_alloc_queue(NUMA_NO_NODE);-if(!mddev->queue)+disk=blk_alloc_disk(NUMA_NO_NODE);+if(!disk)gotoabort;-blk_set_stacking_limits(&mddev->queue->limits);--disk=alloc_disk(1<<shift);-if(!disk){-blk_cleanup_queue(mddev->queue);-mddev->queue=NULL;-gotoabort;-}disk->major=MAJOR(mddev->unit);disk->first_minor=unit<<shift;+disk->minors=1<<shift;if(name)strcpy(disk->disk_name,name);elseif(partitioned)
@@ -5733,7 +5724,9 @@ static int md_alloc(dev_t dev, char *name)sprintf(disk->disk_name,"md%d",unit);disk->fops=&md_fops;disk->private_data=mddev;-disk->queue=mddev->queue;++mddev->queue=disk->queue;+blk_set_stacking_limits(&mddev->queue->limits);blk_queue_write_cache(mddev->queue,true,true);/* Allow extended partitions. This makes the*'mdp'deviceredundant,butwecan'treally
Wouldn't it make sense to introduce a helper 'blk_queue_from_disk()' or
somesuch to avoid having to keep an explicit 'queue' pointer?
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:13:37
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the nvdimm-blk driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/blk.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:14:25
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the nvdimm-btt driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/btt.c | 24 +++++++-----------------
drivers/nvdimm/btt.h | 2 --
2 files changed, 7 insertions(+), 19 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:14:58
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the nvdimm-pmem driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/pmem.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:20:32
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
quoted hunk
Convert the nvme-multipath driver to use the blk_alloc_disk and
blk_cleanup_disk helpers to simplify gendisk and request_queue
allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvdimm/pmem.c | 1 -
drivers/nvme/host/multipath.c | 45 ++++++++++-------------------------
2 files changed, 13 insertions(+), 33 deletions(-)
@@ -443,33 +442,24 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)if(!(ctrl->subsys->cmic&NVME_CTRL_CMIC_MULTI_CTRL)||!multipath)return0;-q=blk_alloc_queue(ctrl->numa_node);-if(!q)-gotoout;-blk_queue_flag_set(QUEUE_FLAG_NONROT,q);-/* set to a default value for 512 until disk is validated */-blk_queue_logical_block_size(q,512);-blk_set_stacking_limits(&q->limits);--/* we need to propagate up the VMC settings */-if(ctrl->vwc&NVME_CTRL_VWC_PRESENT)-vwc=true;-blk_queue_write_cache(q,vwc,vwc);--head->disk=alloc_disk(0);+head->disk=blk_alloc_disk(ctrl->numa_node);if(!head->disk)-gotoout_cleanup_queue;+return-ENOMEM;head->disk->fops=&nvme_ns_head_ops;head->disk->private_data=head;-head->disk->queue=q;sprintf(head->disk->disk_name,"nvme%dn%d",ctrl->subsys->instance,head->instance);-return0;-out_cleanup_queue:-blk_cleanup_queue(q);-out:-return-ENOMEM;+blk_queue_flag_set(QUEUE_FLAG_NONROT,head->disk->queue);+/* set to a default value of 512 until the disk is validated */+blk_queue_logical_block_size(head->disk->queue,512);+blk_set_stacking_limits(&head->disk->queue->limits);++/* we need to propagate up the VMC settings */+if(ctrl->vwc&NVME_CTRL_VWC_PRESENT)+vwc=true;+blk_queue_write_cache(head->disk->queue,vwc,vwc);+return0;}staticvoidnvme_mpath_set_live(structnvme_ns*ns)
@@ -768,16 +758,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)/* make sure all pending bios are cleaned up */kblockd_schedule_work(&head->requeue_work);flush_work(&head->requeue_work);-blk_cleanup_queue(head->disk->queue);-if(!test_bit(NVME_NSHEAD_DISK_LIVE,&head->flags)){-/*-*ifdevice_add_diskwasn'tcalled,prevent-*diskreleasetoputabogusreferenceonthe-*requestqueue-*/-head->disk->queue=NULL;-}-put_disk(head->disk);+blk_cleanup_disk(head->disk);}voidnvme_mpath_init_ctrl(structnvme_ctrl*ctrl)
What about the check for GENHD_FL_UP a bit further up in line 766?
Can this still happen with the new allocation scheme, ie is there still
a difference in lifetime between ->disk and ->disk->queue?
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:21:12
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
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: Christoph Hellwig <hch@lst.de>
---
arch/m68k/emu/nfblock.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:22:06
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the simdisk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
arch/xtensa/platforms/iss/simdisk.c | 29 +++++++----------------------
1 file changed, 7 insertions(+), 22 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:22:42
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the n64cart driver to use the blk_alloc_disk helper to simplify
gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/n64cart.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:23:23
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the ps3vram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/ps3vram.c | 31 ++++++++-----------------------
1 file changed, 8 insertions(+), 23 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:24:00
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the dcssblk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/s390/block/dcssblk.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:24:40
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the xpram driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/s390/block/xpram.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:25:30
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
Convert the null_blk driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation. Note that the
blk-mq mode is left with its own allocations scheme, to be handled later.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/null_blk/main.c | 38 +++++++++++++++++------------------
1 file changed, 19 insertions(+), 19 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-23 08:26:05
On 5/21/21 7:51 AM, Christoph Hellwig wrote:
blk_alloc_queue is just an internal helper now, unexport it and remove
it from the public header.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-core.c | 1 -
block/blk.h | 2 ++
include/linux/blkdev.h | 1 -
3 files changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
On Fri, May 21, 2021 at 02:15:32PM +0800, Coly Li wrote:
quoted
The above 2 lines are added on purpose to prevent an refcount
underflow. It is from commit 86da9f736740 ("bcache: fix refcount
underflow in bcache_device_free()").
Maybe add a parameter to blk_cleanup_disk() or checking (disk->flags &
GENHD_FL_UP) inside blk_cleanup_disk() ?
Please take a look at patch 4 in the series.
Thanks for the hint. I will reply in your patch.
Coly Li
Convert the bcache driver to use the blk_alloc_disk and blk_cleanup_disk
helpers to simplify gendisk and request_queue allocation.
Signed-off-by: Christoph Hellwig <hch@lst.de>
@@ -379,9 +380,15 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,pdev->type=&part_type;pdev->parent=ddev;-err=blk_alloc_devt(bdev,&devt);-if(err)-gotoout_put;+/* in consecutive minor range? */+if(bdev->bd_partno<disk->minors){+devt=MKDEV(disk->major,disk->first_minor+bdev->bd_partno);+}else{+err=blk_alloc_ext_minor();+if(err<0)+gotoout_put;+devt=MKDEV(BLOCK_EXT_MAJOR,err);+}pdev->devt=devt;/* delay uevent until 'holders' subdir is created */
... and why we only add this here now.
For the genhd minors == 0 (aka GENHD_FL_EXT_DEVT) implies having to
allocate a dynamic dev_t, so it can be folded into another conditional.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-24 07:24:20
On Fri, May 21, 2021 at 05:44:07PM +0000, Luis Chamberlain wrote:
Its not obvious to me why using this new API requires you then to
set minors explicitly to 1, and yet here underneath we see the minors
argument passed is 0.
Nor is it clear from the documentation.
Basically for all new drivers no one should set minors at all, and the
dynamic dev_t mechanism does all the work. For converted old drivers
minors is set manually instead of being passed an an argument that
should be 0 for all new drivers.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-24 07:25:01
On Sun, May 23, 2021 at 09:58:48AM +0200, Hannes Reinecke wrote:
quoted
+ /*
+ * This is so fdisk will align partitions on 4k, because of
+ * direct_access API needing 4k alignment, returning a PFN
+ * (This is only a problem on very small devices <= 4M,
+ * otherwise fdisk will align on 1M. Regardless this call
+ * is harmless)
+ */
+ blk_queue_physical_block_size(disk->queue, PAGE_SIZE);
Maybe converting the comment to refer to 'PAGE_SIZE' instead of 4k while
you're at it ...
I really do not want to touch these kinds of unrelated things here.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-24 07:26:04
On Sun, May 23, 2021 at 10:10:34AM +0200, Hannes Reinecke wrote:
Can't these conditionals be merged into a single 'if (md->disk)'?
Eg like:
if (md->disk) {
spin_lock(&_minor_lock);
md->disk->private_data = NULL;
spin_unlock(&_minor_lock);
del_gendisk(md->disk);
dm_queue_destroy_keyslot_manager(md->queue);
blk_cleanup_disk(md->queue);
}
We're now always allocating 'md->disk' and 'md->queue' together,
so how can we end up in a situation where one is set without the other?
I guess we could do that, not sure it is worth the churn, though.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-24 07:26:47
On Sun, May 23, 2021 at 10:12:49AM +0200, Hannes Reinecke wrote:
quoted
+ blk_set_stacking_limits(&mddev->queue->limits);
blk_queue_write_cache(mddev->queue, true, true);
/* Allow extended partitions. This makes the
* 'mdp' device redundant, but we can't really
Wouldn't it make sense to introduce a helper 'blk_queue_from_disk()' or
somesuch to avoid having to keep an explicit 'queue' pointer?
My rought plan is that a few series from now bio based drivers will
never directly deal with the request_queue at all.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-24 07:29:57
On Sun, May 23, 2021 at 10:20:27AM +0200, Hannes Reinecke wrote:
What about the check for GENHD_FL_UP a bit further up in line 766?
Can this still happen with the new allocation scheme, ie is there still a
difference in lifetime between ->disk and ->disk->queue?
Yes, nvme_free_ns_head can still be called before device_add_disk was
called for an allocated nshead gendisk during error handling of the
setup path. There is still a difference in the lifetime in that they
are separately refcounted, but it does not matter to the driver.
From: Hannes Reinecke <hare@suse.de> Date: 2021-05-24 08:27:21
On 5/24/21 9:26 AM, Christoph Hellwig wrote:
On Sun, May 23, 2021 at 10:12:49AM +0200, Hannes Reinecke wrote:
quoted
quoted
+ blk_set_stacking_limits(&mddev->queue->limits);
blk_queue_write_cache(mddev->queue, true, true);
/* Allow extended partitions. This makes the
* 'mdp' device redundant, but we can't really
Wouldn't it make sense to introduce a helper 'blk_queue_from_disk()' or
somesuch to avoid having to keep an explicit 'queue' pointer?
My rought plan is that a few series from now bio based drivers will
never directly deal with the request_queue at all.
Go for it.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
On Fri, 21 May 2021 at 07:51, Christoph Hellwig [off-list ref] wrote:
Hi all,
this series is the first part of cleaning up lifetimes and allocation of
the gendisk and request_queue structure. It adds a new interface to
allocate the disk and queue together for bio based drivers, and a helper
for cleanup/free them when a driver is unloaded or a device is removed.
May I ask what else you have in the pipe for the next steps?
The reason why I ask is that I am looking into some issues related to
lifecycle problems of gendisk/mmc, typically triggered at SD/MMC card
removal.
From: Christoph Hellwig <hch@lst.de> Date: 2021-05-26 04:49:53
On Wed, May 26, 2021 at 12:41:37AM +0200, Ulf Hansson wrote:
On Fri, 21 May 2021 at 07:51, Christoph Hellwig [off-list ref] wrote:
quoted
Hi all,
this series is the first part of cleaning up lifetimes and allocation of
the gendisk and request_queue structure. It adds a new interface to
allocate the disk and queue together for bio based drivers, and a helper
for cleanup/free them when a driver is unloaded or a device is removed.
May I ask what else you have in the pipe for the next steps?
The reason why I ask is that I am looking into some issues related to
lifecycle problems of gendisk/mmc, typically triggered at SD/MMC card
removal.
In the short run not much more than superficial cleanups. Eventually
I want bio based drivers to not require a separate request_queue, leaving
that purely as a data structure for blk-mq based drivers. But it will
take a while until we get there, so it should not block any fixes.
For hot unplug handling it might be worth to take a look at nvme, as it
is tested a lot for that case.
On Wed, 26 May 2021 at 06:49, Christoph Hellwig [off-list ref] wrote:
On Wed, May 26, 2021 at 12:41:37AM +0200, Ulf Hansson wrote:
quoted
On Fri, 21 May 2021 at 07:51, Christoph Hellwig [off-list ref] wrote:
quoted
Hi all,
this series is the first part of cleaning up lifetimes and allocation of
the gendisk and request_queue structure. It adds a new interface to
allocate the disk and queue together for bio based drivers, and a helper
for cleanup/free them when a driver is unloaded or a device is removed.
May I ask what else you have in the pipe for the next steps?
The reason why I ask is that I am looking into some issues related to
lifecycle problems of gendisk/mmc, typically triggered at SD/MMC card
removal.
In the short run not much more than superficial cleanups. Eventually
I want bio based drivers to not require a separate request_queue, leaving
that purely as a data structure for blk-mq based drivers. But it will
take a while until we get there, so it should not block any fixes.
Alright, thanks for clarifying.
For hot unplug handling it might be worth to take a look at nvme, as it
is tested a lot for that case.
Hi all,
this series is the first part of cleaning up lifetimes and allocation of
the gendisk and request_queue structure. It adds a new interface to
allocate the disk and queue together for bio based drivers, and a helper
for cleanup/free them when a driver is unloaded or a device is removed.
Together this removes the need to treat the gendisk and request_queue
as separate entities for bio based drivers.