All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Martijn Coenen <maco@android.com>,
	Alyssa Ross <hi@alyssa.is>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH] loop: LOOP_CONFIGURE: send uevents for partitions
Date: Tue, 21 Feb 2023 22:28:51 +0000	[thread overview]
Message-ID: <20230221222847.607096-1-hi@alyssa.is> (raw)

LOOP_CONFIGURE is, as I understand it, supposed to be a way to combine
LOOP_SET_FD and LOOP_SET_STATUS64 into a single syscall.  When using
LOOP_SET_FD+LOOP_SET_STATUS64, a single uevent would be sent for each
partition found on the loop device during LOOP_SET_STATUS64, but when
using LOOP_CONFIGURE, no such uevent was being sent.

In the old setup, uevents are disabled for LOOP_SET_FD, but not for
LOOP_SET_STATUS64.  This makes sense, as it prevents uevents being
sent for a partially configured device during LOOP_SET_FD — they're
only sent at the end of LOOP_SET_STATUS64.  But for LOOP_CONFIGURE,
uevents were disabled for the entire operation, so that final
notification was never issued.  To fix this, I've moved the
loop_reread_partitions() call, which causes the uevents to be issued,
to after uevents are re-enabled, matching the behaviour of the
LOOP_SET_FD+LOOP_SET_STATUS64 combination.

I noticed this because Busybox's losetup program recently changed from
using LOOP_SET_FD+LOOP_SET_STATUS64 to LOOP_CONFIGURE, and this broke
my setup, for which I want a notification from the kernel any time a
new partition becomes available.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl")
---

I've marked this as an RFC because there's still a problem with this
patch that I'd be grateful for advice on how to solve: this change
accidentally makes LOOP_SET_FD emit uevents as well if max_part is
configured.  There are a few ways I could imagine resolving this:

 - Have loop_configure distinguish between LOOP_SET_FD and
   LOOP_CONFIGURE somehow.

 - Have loop_configure take a bool argument specifying whether uevents
   should be reenabled before or after the loop_reread_partitions()
   call.

 - Move re-enabling the uevent and calling loop_reread_partitions()
   out of loop_configure().

All of these have drawbacks for the understandability of the code
though, so I wanted to ask what the best way to proceed would be.

 drivers/block/loop.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 5f04235e4ff7..d8063dbf5ec1 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1110,15 +1110,19 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 		clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
 
 	loop_global_unlock(lo, is_loop);
-	if (partscan)
-		loop_reread_partitions(lo);
 	if (!(mode & FMODE_EXCL))
 		bd_abort_claiming(bdev, loop_configure);
 
+	/*
+	 * Now that we are done, reread the partitions with uevent
+	 * re-enabled to let userspace know about the changes.
+	 */
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
+	if (partscan)
+		loop_reread_partitions(lo);
+
 	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:
@@ -1130,6 +1134,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);
+	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
 	goto done;
 }
 
-- 
2.37.1


                 reply	other threads:[~2023-02-21 22:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230221222847.607096-1-hi@alyssa.is \
    --to=hi@alyssa.is \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.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 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.