linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	linux-block@vger.kernel.org
Subject: [PATCH 03/11] block: call bdev_add later in device_add_disk
Date: Wed, 18 Aug 2021 16:45:34 +0200	[thread overview]
Message-ID: <20210818144542.19305-4-hch@lst.de> (raw)
In-Reply-To: <20210818144542.19305-1-hch@lst.de>

Once bdev_add is called userspace can open the block device.  Ensure
that the struct device, which is used for refcounting of the disk
besides various other things, is fully setup at that point.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index ec4be5889fbf..ab455f110be2 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -466,29 +466,14 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
 
 	disk_alloc_events(disk);
 
-	if (disk->flags & GENHD_FL_HIDDEN) {
-		/*
-		 * Don't let hidden disks show up in /proc/partitions,
-		 * and don't bother scanning for partitions either.
-		 */
-		disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
-		disk->flags |= GENHD_FL_NO_PART_SCAN;
-	} else {
-		/* Register BDI before referencing it from bdev */
-		ddev->devt = MKDEV(disk->major, disk->first_minor);
-		ret = bdi_register(disk->bdi, "%u:%u",
-				   disk->major, disk->first_minor);
-		WARN_ON(ret);
-		bdi_set_owner(disk->bdi, ddev);
-		bdev_add(disk->part0, ddev->devt);
-	}
-
 	/* delay uevents, until we scanned partition table */
 	dev_set_uevent_suppress(ddev, 1);
 
 	ddev->parent = parent;
 	ddev->groups = groups;
 	dev_set_name(ddev, "%s", disk->disk_name);
+	if (!(disk->flags & GENHD_FL_HIDDEN))
+		ddev->devt = MKDEV(disk->major, disk->first_minor);
 	if (device_add(ddev))
 		return;
 	if (!sysfs_deprecated) {
@@ -521,12 +506,25 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
 		disk->slave_dir = NULL;
 	}
 
-	if (!(disk->flags & GENHD_FL_HIDDEN)) {
+	if (disk->flags & GENHD_FL_HIDDEN) {
+		/*
+		 * Don't let hidden disks show up in /proc/partitions,
+		 * and don't bother scanning for partitions either.
+		 */
+		disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
+		disk->flags |= GENHD_FL_NO_PART_SCAN;
+	} else {
+		ret = bdi_register(disk->bdi, "%u:%u",
+				   disk->major, disk->first_minor);
+		WARN_ON(ret);
+		bdi_set_owner(disk->bdi, ddev);
+		bdev_add(disk->part0, ddev->devt);
+
 		disk_scan_partitions(disk);
 
 		/*
 		 * Announce the disk and partitions after all partitions are
-		 * created.
+		 * created. (for hidden disks uevents remain suppressed forever)
 		 */
 		dev_set_uevent_suppress(ddev, 0);
 		disk_uevent(disk, KOBJ_ADD);
-- 
2.30.2


  parent reply	other threads:[~2021-08-18 14:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-18 14:45 add error handling to add_disk / device_add_disk Christoph Hellwig
2021-08-18 14:45 ` [PATCH 01/11] block: add a sanity check for a live disk in del_gendisk Christoph Hellwig
2021-08-19 10:41   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 02/11] block: fold register_disk into device_add_disk Christoph Hellwig
2021-08-19 10:48   ` Hannes Reinecke
2021-08-18 14:45 ` Christoph Hellwig [this message]
2021-08-20  6:06   ` [PATCH 03/11] block: call bdev_add later in device_add_disk Hannes Reinecke
2021-08-18 14:45 ` [PATCH 04/11] block: create the bdi link earlier " Christoph Hellwig
2021-08-20  6:08   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 05/11] block: call blk_integrity_add " Christoph Hellwig
2021-08-20  6:08   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 06/11] block: call blk_register_queue " Christoph Hellwig
2021-08-20  6:09   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 07/11] block: return errors from blk_integrity_add Christoph Hellwig
2021-08-20  6:10   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 08/11] block: return errors from disk_alloc_events Christoph Hellwig
2021-08-20  6:10   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 09/11] block: add error handling for device_add_disk / add_disk Christoph Hellwig
2021-08-20  6:12   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 10/11] virtio_blk: add error handling support for add_disk() Christoph Hellwig
2021-08-20  6:12   ` Hannes Reinecke
2021-08-18 14:45 ` [PATCH 11/11] null_blk: " Christoph Hellwig
2021-08-20  6:13   ` Hannes Reinecke
2021-08-23 18:57 ` add error handling to add_disk / device_add_disk Jens Axboe
2021-08-23 19:44   ` Luis Chamberlain
2021-08-23 19:50     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210818144542.19305-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=jasowang@redhat.com \
    --cc=linux-block@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mcgrof@kernel.org \
    --cc=mst@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).