Linux block layer
 help / color / mirror / Atom feed
* [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
@ 2025-04-15  8:51 Thomas Weißschuh
  2025-04-15 10:18 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2025-04-15  8:51 UTC (permalink / raw)
  To: Jens Axboe, Martijn Coenen, Alyssa Ross, Christoph Hellwig,
	Greg KH, Jan Kara
  Cc: John Ogness, linux-block, linux-kernel, stable,
	Thomas Weißschuh

The original commit message and the wording "uncork" in the code comment
indicate that it is expected that the suppressed event instances are
automatically sent after unsuppressing.
This is not the case, instead they are discarded.
In effect this means that no "changed" events are emitted on the device
itself by default.
While each discovered partition does trigger a changed event on the
device, devices without partitions don't have any event emitted.

This makes udev miss the device creation and prompted workarounds in
userspace. See the linked util-linux/losetup bug.

Explicitly emit the events and drop the confusingly worded comments.

Link: https://github.com/util-linux/util-linux/issues/2434
Fixes: 498ef5c777d9 ("loop: suppress uevents while reconfiguring the device")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Changes in v2:
- Use correct Fixes tag
- Rework commit message slightly
- Rebase onto v6.15-rc1
- Link to v1: https://lore.kernel.org/r/20250317-loop-uevent-changed-v1-1-cb29cb91b62d@linutronix.de
---
 drivers/block/loop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 674527d770dc669e982a2b441af1171559aa427c..09a725710a21171e0adf5888f929ccaf94e98992 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -667,8 +667,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 
 	error = 0;
 done:
-	/* enable and uncork uevent now that we are done */
 	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
+	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
 	return error;
 
 out_err:
@@ -1129,8 +1129,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 	if (partscan)
 		clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
 
-	/* enable and uncork uevent now that we are done */
 	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
+	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
 
 	loop_global_unlock(lo, is_loop);
 	if (partscan)

---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250307-loop-uevent-changed-aa3690f43e03

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>


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

* Re: [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
  2025-04-15  8:51 [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device Thomas Weißschuh
@ 2025-04-15 10:18 ` Greg KH
  2025-04-15 10:24 ` Jan Kara
  2025-04-15 13:48 ` Jens Axboe
  2 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2025-04-15 10:18 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Jens Axboe, Martijn Coenen, Alyssa Ross, Christoph Hellwig,
	Jan Kara, John Ogness, linux-block, linux-kernel, stable

On Tue, Apr 15, 2025 at 10:51:47AM +0200, Thomas Weißschuh wrote:
> The original commit message and the wording "uncork" in the code comment
> indicate that it is expected that the suppressed event instances are
> automatically sent after unsuppressing.
> This is not the case, instead they are discarded.
> In effect this means that no "changed" events are emitted on the device
> itself by default.
> While each discovered partition does trigger a changed event on the
> device, devices without partitions don't have any event emitted.
> 
> This makes udev miss the device creation and prompted workarounds in
> userspace. See the linked util-linux/losetup bug.
> 
> Explicitly emit the events and drop the confusingly worded comments.
> 
> Link: https://github.com/util-linux/util-linux/issues/2434
> Fixes: 498ef5c777d9 ("loop: suppress uevents while reconfiguring the device")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Changes in v2:
> - Use correct Fixes tag
> - Rework commit message slightly
> - Rebase onto v6.15-rc1
> - Link to v1: https://lore.kernel.org/r/20250317-loop-uevent-changed-v1-1-cb29cb91b62d@linutronix.de
> ---
>  drivers/block/loop.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 674527d770dc669e982a2b441af1171559aa427c..09a725710a21171e0adf5888f929ccaf94e98992 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -667,8 +667,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
>  
>  	error = 0;
>  done:
> -	/* enable and uncork uevent now that we are done */
>  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
>  	return error;
>  
>  out_err:
> @@ -1129,8 +1129,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
>  	if (partscan)
>  		clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
>  
> -	/* enable and uncork uevent now that we are done */
>  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
>  
>  	loop_global_unlock(lo, is_loop);
>  	if (partscan)
> 
> ---
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> change-id: 20250307-loop-uevent-changed-aa3690f43e03
> 
> Best regards,
> -- 
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* Re: [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
  2025-04-15  8:51 [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device Thomas Weißschuh
  2025-04-15 10:18 ` Greg KH
@ 2025-04-15 10:24 ` Jan Kara
  2025-04-15 11:07   ` Thomas Weißschuh
  2025-04-15 13:48 ` Jens Axboe
  2 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2025-04-15 10:24 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Jens Axboe, Martijn Coenen, Alyssa Ross, Christoph Hellwig,
	Greg KH, Jan Kara, John Ogness, linux-block, linux-kernel, stable

On Tue 15-04-25 10:51:47, Thomas Weißschuh wrote:
> The original commit message and the wording "uncork" in the code comment
> indicate that it is expected that the suppressed event instances are
> automatically sent after unsuppressing.
> This is not the case, instead they are discarded.
> In effect this means that no "changed" events are emitted on the device
> itself by default.
> While each discovered partition does trigger a changed event on the
> device, devices without partitions don't have any event emitted.
> 
> This makes udev miss the device creation and prompted workarounds in
> userspace. See the linked util-linux/losetup bug.
> 
> Explicitly emit the events and drop the confusingly worded comments.
> 
> Link: https://github.com/util-linux/util-linux/issues/2434
> Fixes: 498ef5c777d9 ("loop: suppress uevents while reconfiguring the device")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Thanks for the fix! When reading the code, I'm a bit curious: What is
actually generating events for partitions with loop_change_fd() call?
Because there loop_reread_partitions() still happens with uevents
supressed... I suspect event supressing there should be shorter.

								Honza

> ---
> Changes in v2:
> - Use correct Fixes tag
> - Rework commit message slightly
> - Rebase onto v6.15-rc1
> - Link to v1: https://lore.kernel.org/r/20250317-loop-uevent-changed-v1-1-cb29cb91b62d@linutronix.de
> ---
>  drivers/block/loop.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 674527d770dc669e982a2b441af1171559aa427c..09a725710a21171e0adf5888f929ccaf94e98992 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -667,8 +667,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
>  
>  	error = 0;
>  done:
> -	/* enable and uncork uevent now that we are done */
>  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
>  	return error;
>  
>  out_err:
> @@ -1129,8 +1129,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
>  	if (partscan)
>  		clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
>  
> -	/* enable and uncork uevent now that we are done */
>  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
>  
>  	loop_global_unlock(lo, is_loop);
>  	if (partscan)
> 
> ---
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> change-id: 20250307-loop-uevent-changed-aa3690f43e03
> 
> Best regards,
> -- 
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
  2025-04-15 10:24 ` Jan Kara
@ 2025-04-15 11:07   ` Thomas Weißschuh
  2025-04-15 16:33     ` Jan Kara
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2025-04-15 11:07 UTC (permalink / raw)
  To: Jan Kara
  Cc: Jens Axboe, Martijn Coenen, Alyssa Ross, Christoph Hellwig,
	Greg KH, John Ogness, linux-block, linux-kernel, stable

On Tue, Apr 15, 2025 at 12:24:55PM +0200, Jan Kara wrote:
> On Tue 15-04-25 10:51:47, Thomas Weißschuh wrote:
> > The original commit message and the wording "uncork" in the code comment
> > indicate that it is expected that the suppressed event instances are
> > automatically sent after unsuppressing.
> > This is not the case, instead they are discarded.
> > In effect this means that no "changed" events are emitted on the device
> > itself by default.
> > While each discovered partition does trigger a changed event on the
> > device, devices without partitions don't have any event emitted.
> > 
> > This makes udev miss the device creation and prompted workarounds in
> > userspace. See the linked util-linux/losetup bug.
> > 
> > Explicitly emit the events and drop the confusingly worded comments.
> > 
> > Link: https://github.com/util-linux/util-linux/issues/2434
> > Fixes: 498ef5c777d9 ("loop: suppress uevents while reconfiguring the device")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 
> Thanks for the fix! When reading the code, I'm a bit curious: What is
> actually generating events for partitions with loop_change_fd() call?
> Because there loop_reread_partitions() still happens with uevents
> supressed... I suspect event supressing there should be shorter.

Makes sense.
For loop_configure() this was fixed in
commit bb430b694226 ("loop: LOOP_CONFIGURE: send uevents for partitions").
I guess we need the same for loop_change_fd().

I'm not entirely sure on how to order the commits or if they should be
folded together.
My current preference is to first have the current patch under discussion and
then the fix for loop_change_fd().


Thomas

> > ---
> > Changes in v2:
> > - Use correct Fixes tag
> > - Rework commit message slightly
> > - Rebase onto v6.15-rc1
> > - Link to v1: https://lore.kernel.org/r/20250317-loop-uevent-changed-v1-1-cb29cb91b62d@linutronix.de
> > ---
> >  drivers/block/loop.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> > index 674527d770dc669e982a2b441af1171559aa427c..09a725710a21171e0adf5888f929ccaf94e98992 100644
> > --- a/drivers/block/loop.c
> > +++ b/drivers/block/loop.c
> > @@ -667,8 +667,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
> >  
> >  	error = 0;
> >  done:
> > -	/* enable and uncork uevent now that we are done */
> >  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> > +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
> >  	return error;
> >  
> >  out_err:
> > @@ -1129,8 +1129,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> >  	if (partscan)
> >  		clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
> >  
> > -	/* enable and uncork uevent now that we are done */
> >  	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> > +	kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
> >  
> >  	loop_global_unlock(lo, is_loop);
> >  	if (partscan)
> > 
> > ---
> > base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> > change-id: 20250307-loop-uevent-changed-aa3690f43e03
> > 
> > Best regards,
> > -- 
> > Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > 
> -- 
> Jan Kara <jack@suse.com>
> SUSE Labs, CR

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

* Re: [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
  2025-04-15  8:51 [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device Thomas Weißschuh
  2025-04-15 10:18 ` Greg KH
  2025-04-15 10:24 ` Jan Kara
@ 2025-04-15 13:48 ` Jens Axboe
  2 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2025-04-15 13:48 UTC (permalink / raw)
  To: Martijn Coenen, Alyssa Ross, Christoph Hellwig, Greg KH, Jan Kara,
	Thomas Weißschuh
  Cc: John Ogness, linux-block, linux-kernel, stable


On Tue, 15 Apr 2025 10:51:47 +0200, Thomas Weißschuh wrote:
> The original commit message and the wording "uncork" in the code comment
> indicate that it is expected that the suppressed event instances are
> automatically sent after unsuppressing.
> This is not the case, instead they are discarded.
> In effect this means that no "changed" events are emitted on the device
> itself by default.
> While each discovered partition does trigger a changed event on the
> device, devices without partitions don't have any event emitted.
> 
> [...]

Applied, thanks!

[1/1] loop: properly send KOBJ_CHANGED uevent for disk device
      commit: 7ed2a771b5fb3edee9c4608181235c30b40bb042

Best regards,
-- 
Jens Axboe




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

* Re: [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device
  2025-04-15 11:07   ` Thomas Weißschuh
@ 2025-04-15 16:33     ` Jan Kara
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Kara @ 2025-04-15 16:33 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Jan Kara, Jens Axboe, Martijn Coenen, Alyssa Ross,
	Christoph Hellwig, Greg KH, John Ogness, linux-block,
	linux-kernel, stable

On Tue 15-04-25 13:07:48, Thomas Weißschuh wrote:
> On Tue, Apr 15, 2025 at 12:24:55PM +0200, Jan Kara wrote:
> > On Tue 15-04-25 10:51:47, Thomas Weißschuh wrote:
> > > The original commit message and the wording "uncork" in the code comment
> > > indicate that it is expected that the suppressed event instances are
> > > automatically sent after unsuppressing.
> > > This is not the case, instead they are discarded.
> > > In effect this means that no "changed" events are emitted on the device
> > > itself by default.
> > > While each discovered partition does trigger a changed event on the
> > > device, devices without partitions don't have any event emitted.
> > > 
> > > This makes udev miss the device creation and prompted workarounds in
> > > userspace. See the linked util-linux/losetup bug.
> > > 
> > > Explicitly emit the events and drop the confusingly worded comments.
> > > 
> > > Link: https://github.com/util-linux/util-linux/issues/2434
> > > Fixes: 498ef5c777d9 ("loop: suppress uevents while reconfiguring the device")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > 
> > Thanks for the fix! When reading the code, I'm a bit curious: What is
> > actually generating events for partitions with loop_change_fd() call?
> > Because there loop_reread_partitions() still happens with uevents
> > supressed... I suspect event supressing there should be shorter.
> 
> Makes sense.
> For loop_configure() this was fixed in
> commit bb430b694226 ("loop: LOOP_CONFIGURE: send uevents for partitions").
> I guess we need the same for loop_change_fd().
> 
> I'm not entirely sure on how to order the commits or if they should be
> folded together.
> My current preference is to first have the current patch under discussion and
> then the fix for loop_change_fd().

Yeah, whatever. I was asking mainly to make sure my understanding of the
current code is correct :). With this one feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2025-04-15 16:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15  8:51 [PATCH v2] loop: properly send KOBJ_CHANGED uevent for disk device Thomas Weißschuh
2025-04-15 10:18 ` Greg KH
2025-04-15 10:24 ` Jan Kara
2025-04-15 11:07   ` Thomas Weißschuh
2025-04-15 16:33     ` Jan Kara
2025-04-15 13:48 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox