dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions
@ 2021-08-23 20:29 Luis Chamberlain
  2021-08-23 20:29 ` [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk() Luis Chamberlain
                   ` (9 more replies)
  0 siblings, 10 replies; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

There's a total of 70 pending patches in my queue which transform
drivers over to use the new add_disk() error handling. Now that
Jens has merged the core components what is left are all the other
driver conversions. A bit of these changes are helpers to make that
easier to do.

I'm going to split the driver conversions into batches, and
this first batch are drivers which should be of high priority
to consider.

Should this get merged, I'll chug on with the next batch, and
so on with batches of 10 each, until we tackle last the wonderful
world of floppy drivers.

I've put together a git tree based on Jen's for-5.15/block branch
which holds all of my pending changes, in case anyone wants to
take a peak.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git/log/?h=20210823-for-axboe-add-disk-error-handling-next

Luis Chamberlain (10):
  scsi/sd: use blk_cleanup_queue() insted of put_disk()
  scsi/sd: add error handling support for add_disk()
  scsi/sr: use blk_cleanup_disk() instead of put_disk()
  scsi/sr: add error handling support for add_disk()
  nvme: add error handling support for add_disk()
  mmc/core/block: add error handling support for add_disk()
  md: add error handling support for add_disk()
  dm: add add_disk() error handling
  loop: add error handling support for add_disk()
  nbd: add error handling support for add_disk()

 drivers/block/loop.c     |  9 ++++++++-
 drivers/block/nbd.c      |  6 +++++-
 drivers/md/dm.c          | 16 +++++++++++-----
 drivers/md/md.c          |  7 ++++++-
 drivers/mmc/core/block.c |  4 +++-
 drivers/nvme/host/core.c | 10 +++++++++-
 drivers/scsi/sd.c        |  8 ++++++--
 drivers/scsi/sr.c        |  7 +++++--
 8 files changed, 53 insertions(+), 14 deletions(-)

-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  5:52   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk() Luis Chamberlain
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

The single put_disk() is useful if you know you're not doing
a cleanup after add_disk(), but since we want to add support
for that, just use the normal form of blk_cleanup_disk() to
cleanup the queue and put the disk.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 610ebba0d66e..7d5217905374 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3508,7 +3508,7 @@ static int sd_probe(struct device *dev)
  out_free_index:
 	ida_free(&sd_index_ida, index);
  out_put:
-	put_disk(gd);
+	blk_cleanup_disk(gd);
  out_free:
 	sd_zbc_release_disk(sdkp);
 	kfree(sdkp);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
  2021-08-23 20:29 ` [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk() Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  5:58   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk() Luis Chamberlain
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/scsi/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 7d5217905374..7df6f20f28ec 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3487,7 +3487,11 @@ static int sd_probe(struct device *dev)
 		pm_runtime_set_autosuspend_delay(dev,
 			sdp->host->hostt->rpm_autosuspend_delay);
 	}
-	device_add_disk(dev, gd, NULL);
+
+	error = device_add_disk(dev, gd, NULL);
+	if (error)
+		goto out_free_index;
+
 	if (sdkp->capacity)
 		sd_dif_config_host(sdkp);
 
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
  2021-08-23 20:29 ` [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk() Luis Chamberlain
  2021-08-23 20:29 ` [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:00   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk() Luis Chamberlain
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

The single put_disk() is useful if you know you're not doing
a cleanup after add_disk(), but since we want to add support
for that, just use the normal form of blk_cleanup_disk() to
cleanup the queue and put the disk.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/scsi/sr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index a0df27db4d61..dc78ad96e6f9 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -792,7 +792,7 @@ static int sr_probe(struct device *dev)
 	clear_bit(minor, sr_index_bits);
 	spin_unlock(&sr_index_lock);
 fail_put:
-	put_disk(disk);
+	blk_cleanup_disk(disk);
 	mutex_destroy(&cd->lock);
 fail_free:
 	kfree(cd);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (2 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk() Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:04   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 05/10] nvme: " Luis Chamberlain
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/scsi/sr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index dc78ad96e6f9..3e0c6f881521 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -779,7 +779,10 @@ static int sr_probe(struct device *dev)
 	dev_set_drvdata(dev, cd);
 	disk->flags |= GENHD_FL_REMOVABLE;
 	sr_revalidate_disk(cd);
-	device_add_disk(&sdev->sdev_gendev, disk, NULL);
+
+	error = device_add_disk(&sdev->sdev_gendev, disk, NULL);
+	if (error)
+		goto fail_minor;
 
 	sdev_printk(KERN_DEBUG, sdev,
 		    "Attached scsi CD-ROM %s\n", cd->cdi.name);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 05/10] nvme: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (3 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:09   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 06/10] mmc/core/block: " Luis Chamberlain
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/nvme/host/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 68acd33c3856..fe02e95173d8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3720,6 +3720,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
 	struct gendisk *disk;
 	struct nvme_id_ns *id;
 	int node = ctrl->numa_node;
+	int rc;
 
 	if (nvme_identify_ns(ctrl, nsid, ids, &id))
 		return;
@@ -3775,7 +3776,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
 
 	nvme_get_ctrl(ctrl);
 
-	device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
+	rc = device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
+	if (rc)
+		goto out_cleanup_ns_from_list;
+
 	if (!nvme_ns_head_multipath(ns->head))
 		nvme_add_ns_cdev(ns);
 
@@ -3785,6 +3789,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
 
 	return;
 
+ out_cleanup_ns_from_list:
+	down_write(&ctrl->namespaces_rwsem);
+	list_del_init(&ns->list);
+	up_write(&ctrl->namespaces_rwsem);
  out_unlink_ns:
 	mutex_lock(&ctrl->subsys->lock);
 	list_del_rcu(&ns->siblings);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 06/10] mmc/core/block: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (4 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 05/10] nvme: " Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:13   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 07/10] md: " Luis Chamberlain
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

The caller cleanups the disk already so all we need to do
is just pass along the return value.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/mmc/core/block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 4c11f171e56d..4f12c6d1e1b5 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2432,7 +2432,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	/* used in ->open, must be set before add_disk: */
 	if (area_type == MMC_BLK_DATA_AREA_MAIN)
 		dev_set_drvdata(&card->dev, md);
-	device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
+	ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
+	if (ret)
+		goto out;
 	return md;
 
  err_kfree:
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 07/10] md: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (5 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 06/10] mmc/core/block: " Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:15   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 08/10] dm: add add_disk() error handling Luis Chamberlain
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

We just do the unwinding of what was not done before, and are
sure to unlock prior to bailing.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/md/md.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ae8fe54ea358..5c0d3536d7c7 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5704,7 +5704,11 @@ static int md_alloc(dev_t dev, char *name)
 	 * through to md_open, so make sure it doesn't get too far
 	 */
 	mutex_lock(&mddev->open_mutex);
-	add_disk(disk);
+	error = add_disk(disk);
+	if (error) {
+		blk_cleanup_disk(disk);
+		goto abort_unlock;
+	}
 
 	error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
 	if (error) {
@@ -5718,6 +5722,7 @@ static int md_alloc(dev_t dev, char *name)
 	if (mddev->kobj.sd &&
 	    sysfs_create_group(&mddev->kobj, &md_bitmap_group))
 		pr_debug("pointless warning\n");
+ abort_unlock:
 	mutex_unlock(&mddev->open_mutex);
  abort:
 	mutex_unlock(&disks_mutex);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 08/10] dm: add add_disk() error handling
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (6 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 07/10] md: " Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:21   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk() Luis Chamberlain
  2021-08-23 20:29 ` [dm-devel] [PATCH 10/10] nbd: " Luis Chamberlain
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/md/dm.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 7981b7287628..cd26fde4ab56 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2077,15 +2077,21 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
 	if (r)
 		return r;
 
-	add_disk(md->disk);
+	r = add_disk(md->disk);
+	if (r)
+		goto out_cleanup_disk;
 
 	r = dm_sysfs_init(md);
-	if (r) {
-		del_gendisk(md->disk);
-		return r;
-	}
+	if (r)
+		goto out_del_gendisk;
 	md->type = type;
 	return 0;
+
+out_cleanup_disk:
+	blk_cleanup_disk(md->disk);
+out_del_gendisk:
+	del_gendisk(md->disk);
+	return r;
 }
 
 struct mapped_device *dm_get_md(dev_t dev)
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (7 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 08/10] dm: add add_disk() error handling Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:25   ` Christoph Hellwig
  2021-08-23 20:29 ` [dm-devel] [PATCH 10/10] nbd: " Luis Chamberlain
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Christoph Hellwig,
	Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/loop.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index fa1c298a8cfb..b8b9e2349e77 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2393,10 +2393,17 @@ static int loop_add(int i)
 	disk->events		= DISK_EVENT_MEDIA_CHANGE;
 	disk->event_flags	= DISK_EVENT_FLAG_UEVENT;
 	sprintf(disk->disk_name, "loop%d", i);
-	add_disk(disk);
+
+	err = add_disk(disk);
+	if (err)
+		goto out_cleanup_disk;
+
 	mutex_unlock(&loop_ctl_mutex);
+
 	return i;
 
+out_cleanup_disk:
+	blk_cleanup_disk(disk);
 out_cleanup_tags:
 	blk_mq_free_tag_set(&lo->tag_set);
 out_free_idr:
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [dm-devel] [PATCH 10/10] nbd: add error handling support for add_disk()
  2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
                   ` (8 preceding siblings ...)
  2021-08-23 20:29 ` [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-23 20:29 ` Luis Chamberlain
  2021-08-24  6:27   ` Christoph Hellwig
  9 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-23 20:29 UTC (permalink / raw)
  To: axboe, martin.petersen, jejb, kbusch, sagi, adrian.hunter,
	beanhuo, ulf.hansson, avri.altman, swboyd, agk, snitzer, josef
  Cc: linux-block, bvanassche, linux-scsi, linux-mmc, linux-kernel,
	linux-nvme, ming.lei, hch, dm-devel, nbd, Christoph Hellwig,
	Luis Chamberlain

We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/nbd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c38317979f74..95f84c9b31f2 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1730,10 +1730,14 @@ static int nbd_dev_add(int index)
 	disk->fops = &nbd_fops;
 	disk->private_data = nbd;
 	sprintf(disk->disk_name, "nbd%d", index);
-	add_disk(disk);
+	err = add_disk(disk);
+	if (err)
+		goto out_err_disk;
 	nbd_total_devices++;
 	return index;
 
+out_err_disk:
+	blk_cleanup_disk(disk);
 out_free_idr:
 	idr_remove(&nbd_index_idr, index);
 out_free_tags:
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk() Luis Chamberlain
@ 2021-08-24  5:52   ` Christoph Hellwig
  2021-08-27 18:27     ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  5:52 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:21PM -0700, Luis Chamberlain wrote:
> The single put_disk() is useful if you know you're not doing
> a cleanup after add_disk(), but since we want to add support
> for that, just use the normal form of blk_cleanup_disk() to
> cleanup the queue and put the disk.

Hmm, I don't think this is correct.  The request_queue is owned by the
core SCSI code.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-24  5:58   ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  5:58 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:22PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk() Luis Chamberlain
@ 2021-08-24  6:00   ` Christoph Hellwig
  2021-08-27 18:28     ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:00 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:23PM -0700, Luis Chamberlain wrote:
> The single put_disk() is useful if you know you're not doing
> a cleanup after add_disk(), but since we want to add support
> for that, just use the normal form of blk_cleanup_disk() to
> cleanup the queue and put the disk.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

.. not needed as the cleanup is done by the core scsi code.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-24  6:04   ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:04 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:24PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 05/10] nvme: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 05/10] nvme: " Luis Chamberlain
@ 2021-08-24  6:09   ` Christoph Hellwig
  2021-08-27 18:32     ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:09 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:25PM -0700, Luis Chamberlain wrote:
> +	rc = device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
> +	if (rc)
> +		goto out_cleanup_ns_from_list;
> +

Nit: no real need for the rc variable here as we never use the actual
value.

>  	if (!nvme_ns_head_multipath(ns->head))
>  		nvme_add_ns_cdev(ns);
>  
> @@ -3785,6 +3789,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
>  
>  	return;
>  
> + out_cleanup_ns_from_list:
> +	down_write(&ctrl->namespaces_rwsem);
> +	list_del_init(&ns->list);
> +	up_write(&ctrl->namespaces_rwsem);

This also needs to do a nvme_put_ctrl.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 06/10] mmc/core/block: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 06/10] mmc/core/block: " Luis Chamberlain
@ 2021-08-24  6:13   ` Christoph Hellwig
  2021-08-27 18:42     ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:13 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:26PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> The caller cleanups the disk already so all we need to do
> is just pass along the return value.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>  drivers/mmc/core/block.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 4c11f171e56d..4f12c6d1e1b5 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -2432,7 +2432,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
>  	/* used in ->open, must be set before add_disk: */
>  	if (area_type == MMC_BLK_DATA_AREA_MAIN)
>  		dev_set_drvdata(&card->dev, md);
> -	device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> +	ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> +	if (ret)
> +		goto out;

This needs to do a blk_cleanup_queue and also te kfree of md.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 07/10] md: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 07/10] md: " Luis Chamberlain
@ 2021-08-24  6:15   ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:15 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:27PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> We just do the unwinding of what was not done before, and are
> sure to unlock prior to bailing.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 08/10] dm: add add_disk() error handling
  2021-08-23 20:29 ` [dm-devel] [PATCH 08/10] dm: add add_disk() error handling Luis Chamberlain
@ 2021-08-24  6:21   ` Christoph Hellwig
  2021-08-27 18:55     ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:21 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, hch, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:28PM -0700, Luis Chamberlain wrote:
> -	add_disk(md->disk);
> +	r = add_disk(md->disk);
> +	if (r)
> +		goto out_cleanup_disk;
>  
>  	r = dm_sysfs_init(md);
> -	if (r) {
> -		del_gendisk(md->disk);
> -		return r;
> -	}
> +	if (r)
> +		goto out_del_gendisk;
>  	md->type = type;
>  	return 0;
> +
> +out_cleanup_disk:
> +	blk_cleanup_disk(md->disk);
> +out_del_gendisk:
> +	del_gendisk(md->disk);
> +	return r;

I think the add_disk should just return r.  If you look at the
callers they eventualy end up in dm_table_destroy, which does
this cleanup.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk() Luis Chamberlain
@ 2021-08-24  6:25   ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:25 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel,
	Christoph Hellwig, agk, beanhuo, ming.lei, sagi, linux-scsi, hch,
	jejb, josef, nbd, linux-block, avri.altman, kbusch, swboyd,
	bvanassche, axboe, martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:29PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

and I think you can drop my signoff.  I added this when I planned
to send out with the original conversion, but dropped it for simpler
examples.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 10/10] nbd: add error handling support for add_disk()
  2021-08-23 20:29 ` [dm-devel] [PATCH 10/10] nbd: " Luis Chamberlain
@ 2021-08-24  6:27   ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-24  6:27 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel,
	Christoph Hellwig, agk, beanhuo, ming.lei, sagi, linux-scsi, hch,
	jejb, josef, nbd, linux-block, avri.altman, kbusch, swboyd,
	bvanassche, axboe, martin.petersen, linux-mmc, adrian.hunter

On Mon, Aug 23, 2021 at 01:29:30PM -0700, Luis Chamberlain wrote:
> We never checked for errors on add_disk() as this function
> returned void. Now that this is fixed, use the shiny new
> error handling.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Same comment on the signoff as for the previous one.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk()
  2021-08-24  5:52   ` Christoph Hellwig
@ 2021-08-27 18:27     ` Luis Chamberlain
  2021-08-28  7:26       ` Christoph Hellwig
  0 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-27 18:27 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Tue, Aug 24, 2021 at 06:52:53AM +0100, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 01:29:21PM -0700, Luis Chamberlain wrote:
> > The single put_disk() is useful if you know you're not doing
> > a cleanup after add_disk(), but since we want to add support
> > for that, just use the normal form of blk_cleanup_disk() to
> > cleanup the queue and put the disk.
> 
> Hmm, I don't think this is correct.  The request_queue is owned by the
> core SCSI code.

Alright, I'll drop this one. For the life of me I can't find the respective
probe call on the scsi layer.

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk()
  2021-08-24  6:00   ` Christoph Hellwig
@ 2021-08-27 18:28     ` Luis Chamberlain
  0 siblings, 0 replies; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-27 18:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Tue, Aug 24, 2021 at 07:00:27AM +0100, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 01:29:23PM -0700, Luis Chamberlain wrote:
> > The single put_disk() is useful if you know you're not doing
> > a cleanup after add_disk(), but since we want to add support
> > for that, just use the normal form of blk_cleanup_disk() to
> > cleanup the queue and put the disk.
> > 
> > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> 
> .. not needed as the cleanup is done by the core scsi code.

Dropped.

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 05/10] nvme: add error handling support for add_disk()
  2021-08-24  6:09   ` Christoph Hellwig
@ 2021-08-27 18:32     ` Luis Chamberlain
  0 siblings, 0 replies; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-27 18:32 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Tue, Aug 24, 2021 at 07:09:37AM +0100, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 01:29:25PM -0700, Luis Chamberlain wrote:
> > +	rc = device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
> > +	if (rc)
> > +		goto out_cleanup_ns_from_list;
> > +
> 
> Nit: no real need for the rc variable here as we never use the actual
> value.

Alrighty.

> >  	if (!nvme_ns_head_multipath(ns->head))
> >  		nvme_add_ns_cdev(ns);
> >  
> > @@ -3785,6 +3789,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
> >  
> >  	return;
> >  
> > + out_cleanup_ns_from_list:
> > +	down_write(&ctrl->namespaces_rwsem);
> > +	list_del_init(&ns->list);
> > +	up_write(&ctrl->namespaces_rwsem);
> 
> This also needs to do a nvme_put_ctrl.

Fixed.

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 06/10] mmc/core/block: add error handling support for add_disk()
  2021-08-24  6:13   ` Christoph Hellwig
@ 2021-08-27 18:42     ` Luis Chamberlain
  2021-08-28  7:32       ` Christoph Hellwig
  0 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-27 18:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Tue, Aug 24, 2021 at 07:13:13AM +0100, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 01:29:26PM -0700, Luis Chamberlain wrote:
> > We never checked for errors on add_disk() as this function
> > returned void. Now that this is fixed, use the shiny new
> > error handling.
> > 
> > The caller cleanups the disk already so all we need to do
> > is just pass along the return value.
> > 
> > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> > ---
> >  drivers/mmc/core/block.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> > index 4c11f171e56d..4f12c6d1e1b5 100644
> > --- a/drivers/mmc/core/block.c
> > +++ b/drivers/mmc/core/block.c
> > @@ -2432,7 +2432,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
> >  	/* used in ->open, must be set before add_disk: */
> >  	if (area_type == MMC_BLK_DATA_AREA_MAIN)
> >  		dev_set_drvdata(&card->dev, md);
> > -	device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > +	ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > +	if (ret)
> > +		goto out;
> 
> This needs to do a blk_cleanup_queue and also te kfree of md.

If mmc_blk_alloc_parts() fails mmc_blk_remove_req() is called which
does both for us?

 Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 08/10] dm: add add_disk() error handling
  2021-08-24  6:21   ` Christoph Hellwig
@ 2021-08-27 18:55     ` Luis Chamberlain
  2021-08-28  7:35       ` Christoph Hellwig
  0 siblings, 1 reply; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-27 18:55 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Tue, Aug 24, 2021 at 07:21:30AM +0100, Christoph Hellwig wrote:
> On Mon, Aug 23, 2021 at 01:29:28PM -0700, Luis Chamberlain wrote:
> > -	add_disk(md->disk);
> > +	r = add_disk(md->disk);
> > +	if (r)
> > +		goto out_cleanup_disk;
> >  
> >  	r = dm_sysfs_init(md);
> > -	if (r) {
> > -		del_gendisk(md->disk);
> > -		return r;
> > -	}
> > +	if (r)
> > +		goto out_del_gendisk;
> >  	md->type = type;
> >  	return 0;
> > +
> > +out_cleanup_disk:
> > +	blk_cleanup_disk(md->disk);
> > +out_del_gendisk:
> > +	del_gendisk(md->disk);
> > +	return r;
> 
> I think the add_disk should just return r.  If you look at the
> callers they eventualy end up in dm_table_destroy, which does
> this cleanup.

I don't see it. What part of dm_table_destroy() does this?

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk()
  2021-08-27 18:27     ` Luis Chamberlain
@ 2021-08-28  7:26       ` Christoph Hellwig
  0 siblings, 0 replies; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-28  7:26 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, Christoph Hellwig, jejb,
	josef, nbd, linux-block, avri.altman, kbusch, swboyd, bvanassche,
	axboe, martin.petersen, linux-mmc, adrian.hunter

On Fri, Aug 27, 2021 at 11:27:36AM -0700, Luis Chamberlain wrote:
> On Tue, Aug 24, 2021 at 06:52:53AM +0100, Christoph Hellwig wrote:
> > On Mon, Aug 23, 2021 at 01:29:21PM -0700, Luis Chamberlain wrote:
> > > The single put_disk() is useful if you know you're not doing
> > > a cleanup after add_disk(), but since we want to add support
> > > for that, just use the normal form of blk_cleanup_disk() to
> > > cleanup the queue and put the disk.
> > 
> > Hmm, I don't think this is correct.  The request_queue is owned by the
> > core SCSI code.
> 
> Alright, I'll drop this one. For the life of me I can't find the respective
> probe call on the scsi layer.

What probe call?  SCSI allocates the request_queue using the normal
blk_mq_init_queue function in scsi_alloc_sdev.  It it then used to
send SCSI passthrough commands for probing before eventually binding
an upper level driver using the driver model (or something not binding
one at all if there is none for the device type).

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 06/10] mmc/core/block: add error handling support for add_disk()
  2021-08-27 18:42     ` Luis Chamberlain
@ 2021-08-28  7:32       ` Christoph Hellwig
  2021-08-30 20:42         ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-28  7:32 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, Christoph Hellwig, jejb,
	josef, nbd, linux-block, avri.altman, kbusch, swboyd, bvanassche,
	axboe, martin.petersen, linux-mmc, adrian.hunter

On Fri, Aug 27, 2021 at 11:42:36AM -0700, Luis Chamberlain wrote:
> > >  	if (area_type == MMC_BLK_DATA_AREA_MAIN)
> > >  		dev_set_drvdata(&card->dev, md);
> > > -	device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > > +	ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > > +	if (ret)
> > > +		goto out;
> > 
> > This needs to do a blk_cleanup_queue and also te kfree of md.
> 
> If mmc_blk_alloc_parts() fails mmc_blk_remove_req() is called which
> does both for us?

Yes, but only for the main gendisk, and those parts already added to
the list which happens after device_add_disk succeeded.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 08/10] dm: add add_disk() error handling
  2021-08-27 18:55     ` Luis Chamberlain
@ 2021-08-28  7:35       ` Christoph Hellwig
  2021-08-30 21:00         ` Luis Chamberlain
  0 siblings, 1 reply; 31+ messages in thread
From: Christoph Hellwig @ 2021-08-28  7:35 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, Christoph Hellwig, jejb,
	josef, nbd, linux-block, avri.altman, kbusch, swboyd, bvanassche,
	axboe, martin.petersen, linux-mmc, adrian.hunter

On Fri, Aug 27, 2021 at 11:55:14AM -0700, Luis Chamberlain wrote:
> > I think the add_disk should just return r.  If you look at the
> > callers they eventualy end up in dm_table_destroy, which does
> > this cleanup.
> 
> I don't see it. What part of dm_table_destroy() does this?

Sorry, dm_destroy, not dm_table_destroy.  For dm_early_create it's
trivial as that calls both dm_table_destroy and dm_destroy in the error
path.  The normal table_load case is a separate ioctl, but if that
fails userspace needs to call the DM_DEV_REMOVE_CMD to cleanup
the state - similar to any other failure.

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 06/10] mmc/core/block: add error handling support for add_disk()
  2021-08-28  7:32       ` Christoph Hellwig
@ 2021-08-30 20:42         ` Luis Chamberlain
  0 siblings, 0 replies; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-30 20:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Sat, Aug 28, 2021 at 08:32:11AM +0100, Christoph Hellwig wrote:
> On Fri, Aug 27, 2021 at 11:42:36AM -0700, Luis Chamberlain wrote:
> > > >  	if (area_type == MMC_BLK_DATA_AREA_MAIN)
> > > >  		dev_set_drvdata(&card->dev, md);
> > > > -	device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > > > +	ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
> > > > +	if (ret)
> > > > +		goto out;
> > > 
> > > This needs to do a blk_cleanup_queue and also te kfree of md.
> > 
> > If mmc_blk_alloc_parts() fails mmc_blk_remove_req() is called which
> > does both for us?
> 
> Yes, but only for the main gendisk, and those parts already added to
> the list which happens after device_add_disk succeeded.

Ah yes I see that now. Will fix up. The tag also needs to be cleaned up.

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dm-devel] [PATCH 08/10] dm: add add_disk() error handling
  2021-08-28  7:35       ` Christoph Hellwig
@ 2021-08-30 21:00         ` Luis Chamberlain
  0 siblings, 0 replies; 31+ messages in thread
From: Luis Chamberlain @ 2021-08-30 21:00 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: ulf.hansson, snitzer, linux-nvme, linux-kernel, dm-devel, agk,
	beanhuo, ming.lei, sagi, linux-scsi, jejb, josef, nbd,
	linux-block, avri.altman, kbusch, swboyd, bvanassche, axboe,
	martin.petersen, linux-mmc, adrian.hunter

On Sat, Aug 28, 2021 at 08:35:57AM +0100, Christoph Hellwig wrote:
> On Fri, Aug 27, 2021 at 11:55:14AM -0700, Luis Chamberlain wrote:
> > > I think the add_disk should just return r.  If you look at the
> > > callers they eventualy end up in dm_table_destroy, which does
> > > this cleanup.
> > 
> > I don't see it. What part of dm_table_destroy() does this?
> 
> Sorry, dm_destroy, not dm_table_destroy.  For dm_early_create it's
> trivial as that calls both dm_table_destroy and dm_destroy in the error
> path.  The normal table_load case is a separate ioctl, but if that
> fails userspace needs to call the DM_DEV_REMOVE_CMD to cleanup
> the state - similar to any other failure.

I see, ok sure I'll document this on the commit log as its not so
obvious.

  Luis

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-08-30 21:01 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 20:29 [dm-devel] [PATCH 00/10] block: first batch of add_disk() error handling conversions Luis Chamberlain
2021-08-23 20:29 ` [dm-devel] [PATCH 01/10] scsi/sd: use blk_cleanup_queue() insted of put_disk() Luis Chamberlain
2021-08-24  5:52   ` Christoph Hellwig
2021-08-27 18:27     ` Luis Chamberlain
2021-08-28  7:26       ` Christoph Hellwig
2021-08-23 20:29 ` [dm-devel] [PATCH 02/10] scsi/sd: add error handling support for add_disk() Luis Chamberlain
2021-08-24  5:58   ` Christoph Hellwig
2021-08-23 20:29 ` [dm-devel] [PATCH 03/10] scsi/sr: use blk_cleanup_disk() instead of put_disk() Luis Chamberlain
2021-08-24  6:00   ` Christoph Hellwig
2021-08-27 18:28     ` Luis Chamberlain
2021-08-23 20:29 ` [dm-devel] [PATCH 04/10] scsi/sr: add error handling support for add_disk() Luis Chamberlain
2021-08-24  6:04   ` Christoph Hellwig
2021-08-23 20:29 ` [dm-devel] [PATCH 05/10] nvme: " Luis Chamberlain
2021-08-24  6:09   ` Christoph Hellwig
2021-08-27 18:32     ` Luis Chamberlain
2021-08-23 20:29 ` [dm-devel] [PATCH 06/10] mmc/core/block: " Luis Chamberlain
2021-08-24  6:13   ` Christoph Hellwig
2021-08-27 18:42     ` Luis Chamberlain
2021-08-28  7:32       ` Christoph Hellwig
2021-08-30 20:42         ` Luis Chamberlain
2021-08-23 20:29 ` [dm-devel] [PATCH 07/10] md: " Luis Chamberlain
2021-08-24  6:15   ` Christoph Hellwig
2021-08-23 20:29 ` [dm-devel] [PATCH 08/10] dm: add add_disk() error handling Luis Chamberlain
2021-08-24  6:21   ` Christoph Hellwig
2021-08-27 18:55     ` Luis Chamberlain
2021-08-28  7:35       ` Christoph Hellwig
2021-08-30 21:00         ` Luis Chamberlain
2021-08-23 20:29 ` [dm-devel] [PATCH 09/10] loop: add error handling support for add_disk() Luis Chamberlain
2021-08-24  6:25   ` Christoph Hellwig
2021-08-23 20:29 ` [dm-devel] [PATCH 10/10] nbd: " Luis Chamberlain
2021-08-24  6:27   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).