All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	Josef Bacik <josef@toxicpanda.com>,
	Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	"Darrick J . Wong" <djwong@kernel.org>,
	Ming Lei <ming.lei@redhat.com>,
	linux-block@vger.kernel.org, nbd@other.debian.org
Subject: Re: [PATCH 12/13] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release
Date: Thu, 24 Mar 2022 18:47:01 +0100	[thread overview]
Message-ID: <20220324174701.GA28583@lst.de> (raw)
In-Reply-To: <20220324171518.GC28007@lst.de>

On Thu, Mar 24, 2022 at 06:15:18PM +0100, Christoph Hellwig wrote:
> On Thu, Mar 24, 2022 at 03:13:21PM +0100, Jan Kara wrote:
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > 
> > Looks good but I still think we need something like attached preparatory
> > patch to not regress e.g. filesystem probing triggered by udev events. What
> > do you think?
> 
> Yes, I think it makes sense to add that.

Actually, looking at it in a little more detail: this misses the
explicit kobject_uevent calls for the capacity changes.  I think the
best idea might be something like this:

---
From db5ab8ab0fbcf07af769023a894fafc22b662cd9 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Thu, 24 Mar 2022 18:41:28 +0100
Subject: loop: suppress uevents while reconfiguring the device

Currently, udev change event is generated for a loop device before the
device is ready for IO. Due to serialization on lo->lo_mutex in
lo_open() this does not matter because anybody is able to open the
device and do IO only after the configuration is finished. However this
synchronization in lo_open() is going away so make sure userspace
reacting to the change event will see the new device state by generating
the event only when the device is setup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/loop.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index b3170e8cdbe95..bfd21af7aa38b 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -572,6 +572,10 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 
 	if (!file)
 		return -EBADF;
+
+	/* suppress uevents while reconfiguring the device */
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
+
 	is_loop = is_loop_device(file);
 	error = loop_global_lock_killable(lo, is_loop);
 	if (error)
@@ -626,13 +630,18 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 	fput(old_file);
 	if (partscan)
 		loop_reread_partitions(lo);
-	return 0;
+
+	error = 0;
+done:
+	/* enable and uncork uevent now that we are done */
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
+	return error;
 
 out_err:
 	loop_global_unlock(lo, is_loop);
 out_putf:
 	fput(file);
-	return error;
+	goto done;
 }
 
 /* loop sysfs attributes */
@@ -999,6 +1008,9 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 	/* This is safe, since we have a reference from open(). */
 	__module_get(THIS_MODULE);
 
+	/* suppress uevents while reconfiguring the device */
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
+
 	/*
 	 * If we don't hold exclusive handle for the device, upgrade to it
 	 * here to avoid changing device under exclusive owner.
@@ -1101,7 +1113,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 		loop_reread_partitions(lo);
 	if (!(mode & FMODE_EXCL))
 		bd_abort_claiming(bdev, loop_configure);
-	return 0;
+
+	error = 0;
+done:
+	/* enable and uncork uevent now that we are done */
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
+	return error;
 
 out_unlock:
 	loop_global_unlock(lo, is_loop);
@@ -1112,7 +1129,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 	fput(file);
 	/* This is safe: open() is still holding a reference. */
 	module_put(THIS_MODULE);
-	return error;
+	goto done;
 }
 
 static void __loop_clr_fd(struct loop_device *lo, bool release)
-- 
2.30.2


  reply	other threads:[~2022-03-24 17:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  7:51 yet another approach to fix the loop lock order inversions v4 Christoph Hellwig
2022-03-24  7:51 ` [PATCH 01/13] nbd: use the correct block_device in nbd_ioctl Christoph Hellwig
2022-03-24 12:20   ` Jan Kara
2022-03-24 13:23     ` Jan Kara
2022-03-24 17:11       ` Christoph Hellwig
2022-03-25  9:39         ` Jan Kara
2022-03-24  7:51 ` [PATCH 02/13] zram: cleanup reset_store Christoph Hellwig
2022-03-24 12:21   ` Jan Kara
2022-03-24  7:51 ` [PATCH 03/13] zram: cleanup zram_remove Christoph Hellwig
2022-03-24 13:15   ` Jan Kara
2022-03-24  7:51 ` [PATCH 04/13] block: add a disk_openers helper Christoph Hellwig
2022-03-24 13:24   ` Jan Kara
2022-03-24  7:51 ` [PATCH 05/13] block: turn bdev->bd_openers into an atomic_t Christoph Hellwig
2022-03-24 13:31   ` Jan Kara
2022-03-24 17:12     ` Christoph Hellwig
2022-03-24  7:51 ` [PATCH 06/13] loop: de-duplicate the idle worker freeing code Christoph Hellwig
2022-03-24  7:51 ` [PATCH 07/13] loop: initialize the worker tracking fields once Christoph Hellwig
2022-03-24  7:51 ` [PATCH 08/13] loop: remove the racy bd_inode->i_mapping->nrpages asserts Christoph Hellwig
2022-03-24  7:51 ` [PATCH 09/13] loop: don't freeze the queue in lo_release Christoph Hellwig
2022-03-24  7:51 ` [PATCH 10/13] loop: only freeze the queue in __loop_clr_fd when needed Christoph Hellwig
2022-03-24  7:51 ` [PATCH 11/13] loop: implement ->free_disk Christoph Hellwig
2022-03-24  7:51 ` [PATCH 12/13] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release Christoph Hellwig
2022-03-24 14:13   ` Jan Kara
2022-03-24 14:24     ` Tetsuo Handa
2022-03-24 17:23       ` Christoph Hellwig
2022-03-25 10:54         ` Tetsuo Handa
2022-03-25 16:23           ` Christoph Hellwig
2022-03-28  8:30             ` Jan Kara
2022-03-29  6:39               ` Christoph Hellwig
2022-03-29  9:42                 ` Jan Kara
2022-03-29  9:49                   ` Tetsuo Handa
2022-03-29 13:14                   ` Christoph Hellwig
2022-03-30  7:58                     ` Jan Kara
2022-03-24 17:15     ` Christoph Hellwig
2022-03-24 17:47       ` Christoph Hellwig [this message]
2022-03-25  9:34         ` Jan Kara
2022-03-24  7:51 ` [PATCH 13/13] loop: don't destroy lo->workqueue in __loop_clr_fd Christoph Hellwig
2022-03-24 14:14   ` Jan Kara

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=20220324174701.GA28583@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=djwong@kernel.org \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=ngupta@vflare.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.