public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* loop uevent fix
@ 2020-11-12 16:50 Christoph Hellwig
  2020-11-12 16:50 ` [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-11-12 16:50 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Petr Vorel, Martijn Coenen, linux-block

Hi Peter and Jens,

this is how I'd slightly respin the patch from Petr on top of the
set_capacity_revalidate_and_notify I need for 5.11.  Let me know what
you think.

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

* [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify
  2020-11-12 16:50 loop uevent fix Christoph Hellwig
@ 2020-11-12 16:50 ` Christoph Hellwig
  2020-11-12 19:13   ` Petr Vorel
  2020-11-12 16:50 ` [PATCH 2/2] loop: Fix occasional uevent drop Christoph Hellwig
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2020-11-12 16:50 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Petr Vorel, Martijn Coenen, linux-block

Return if the function ended up sending an uevent or not.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c         | 5 ++++-
 include/linux/genhd.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 0a273211fec283..9387f050c248a7 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -49,7 +49,7 @@ static void disk_release_events(struct gendisk *disk);
  * Set disk capacity and notify if the size is not currently
  * zero and will not be set to zero
  */
-void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
 					bool update_bdev)
 {
 	sector_t capacity = get_capacity(disk);
@@ -62,7 +62,10 @@ void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
 		char *envp[] = { "RESIZE=1", NULL };
 
 		kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
+		return true;
 	}
+
+	return false;
 }
 
 EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 38f23d75701379..03da3f603d309c 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -315,7 +315,7 @@ static inline int get_disk_ro(struct gendisk *disk)
 extern void disk_block_events(struct gendisk *disk);
 extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
-void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
 		bool update_bdev);
 
 /* drivers/char/random.c */
-- 
2.28.0


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

* [PATCH 2/2] loop: Fix occasional uevent drop
  2020-11-12 16:50 loop uevent fix Christoph Hellwig
  2020-11-12 16:50 ` [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify Christoph Hellwig
@ 2020-11-12 16:50 ` Christoph Hellwig
  2020-11-12 19:25   ` Petr Vorel
  2020-11-12 19:31 ` loop uevent fix Petr Vorel
  2020-11-12 20:59 ` Jens Axboe
  3 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2020-11-12 16:50 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Petr Vorel, Martijn Coenen, linux-block, ltp

From: Petr Vorel <pvorel@suse.cz>

Commit 716ad0986cbd ("loop: Switch to set_capacity_revalidate_and_notify")
causes an occasional drop of loop device uevent, which are no longer
triggered in loop_set_size() but in a different part of code.

Bug is reproducible with LTP test uevent01 [1]:

i=0; while true; do
    i=$((i+1)); echo "== $i =="
    lsmod |grep -q loop && rmmod -f loop
    ./uevent01 || break
done

Put back triggering through code called in loop_set_size().

Fix required to add yet another parameter to
set_capacity_revalidate_and_notify().

[1] https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/uevents/uevent01.c

Fixes: 716ad0986cbd ("loop: Switch to set_capacity_revalidate_and_notify")
Reported-by: <ltp@lists.linux.it>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
[hch: rebased on a different change to the prototype of
 set_capacity_revalidate_and_notify]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index cb1191d6e945f2..a58084c2ed7ceb 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -255,7 +255,8 @@ static void loop_set_size(struct loop_device *lo, loff_t size)
 
 	bd_set_nr_sectors(bdev, size);
 
-	set_capacity_revalidate_and_notify(lo->lo_disk, size, false);
+	if (!set_capacity_revalidate_and_notify(lo->lo_disk, size, false))
+		kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
 }
 
 static inline int
-- 
2.28.0


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

* Re: [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify
  2020-11-12 16:50 ` [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify Christoph Hellwig
@ 2020-11-12 19:13   ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2020-11-12 19:13 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, Martijn Coenen, linux-block

Hi Christoph,

> Return if the function ended up sending an uevent or not.

> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
> ---
>  block/genhd.c         | 5 ++++-
>  include/linux/genhd.h | 2 +-
>  2 files changed, 5 insertions(+), 2 deletions(-)

> diff --git a/block/genhd.c b/block/genhd.c
> index 0a273211fec283..9387f050c248a7 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -49,7 +49,7 @@ static void disk_release_events(struct gendisk *disk);
>   * Set disk capacity and notify if the size is not currently
>   * zero and will not be set to zero
>   */
> -void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
> +bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
>  					bool update_bdev)
>  {
>  	sector_t capacity = get_capacity(disk);
> @@ -62,7 +62,10 @@ void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
>  		char *envp[] = { "RESIZE=1", NULL };

>  		kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
> +		return true;
>  	}
> +
> +	return false;
>  }

>  EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
> diff --git a/include/linux/genhd.h b/include/linux/genhd.h
> index 38f23d75701379..03da3f603d309c 100644
> --- a/include/linux/genhd.h
> +++ b/include/linux/genhd.h
> @@ -315,7 +315,7 @@ static inline int get_disk_ro(struct gendisk *disk)
>  extern void disk_block_events(struct gendisk *disk);
>  extern void disk_unblock_events(struct gendisk *disk);
>  extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
> -void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
> +bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
>  		bool update_bdev);

>  /* drivers/char/random.c */

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

* Re: [PATCH 2/2] loop: Fix occasional uevent drop
  2020-11-12 16:50 ` [PATCH 2/2] loop: Fix occasional uevent drop Christoph Hellwig
@ 2020-11-12 19:25   ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2020-11-12 19:25 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, Martijn Coenen, linux-block, ltp

Hi Christoph,

> From: Petr Vorel <pvorel@suse.cz>
Thanks for rebasing my code. Using loop.c specific code in the file instead of
the function is indeed much better.

I also like your cleanup for 5.11 (remove the update_bdev parameter from
set_capacity_revalidate_and_notify).

> Commit 716ad0986cbd ("loop: Switch to set_capacity_revalidate_and_notify")
> causes an occasional drop of loop device uevent, which are no longer
> triggered in loop_set_size() but in a different part of code.

> Bug is reproducible with LTP test uevent01 [1]:

> i=0; while true; do
>     i=$((i+1)); echo "== $i =="
>     lsmod |grep -q loop && rmmod -f loop
>     ./uevent01 || break
> done

> Put back triggering through code called in loop_set_size().

> Fix required to add yet another parameter to
> set_capacity_revalidate_and_notify().
This ^ is no longer true and should be removed.

Kind regards,
Petr

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

* Re: loop uevent fix
  2020-11-12 16:50 loop uevent fix Christoph Hellwig
  2020-11-12 16:50 ` [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify Christoph Hellwig
  2020-11-12 16:50 ` [PATCH 2/2] loop: Fix occasional uevent drop Christoph Hellwig
@ 2020-11-12 19:31 ` Petr Vorel
  2020-11-12 20:59 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2020-11-12 19:31 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, Martijn Coenen, linux-block

Hi Jens, Christoph,

> Hi Peter and Jens,

> this is how I'd slightly respin the patch from Petr on top of the
> set_capacity_revalidate_and_notify I need for 5.11.  Let me know what
> you think.

+1, thanks.

From your discussion on my original patch I understand that these 2 fixes will
make it to v5.10-rc4. Will they go also to v5.9 stable tree? (it affects also
v5.8, but that version is EOL).

Kind regards,
Petr

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

* Re: loop uevent fix
  2020-11-12 16:50 loop uevent fix Christoph Hellwig
                   ` (2 preceding siblings ...)
  2020-11-12 19:31 ` loop uevent fix Petr Vorel
@ 2020-11-12 20:59 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2020-11-12 20:59 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Petr Vorel, Martijn Coenen, linux-block

On 11/12/20 9:50 AM, Christoph Hellwig wrote:
> Hi Peter and Jens,
> 
> this is how I'd slightly respin the patch from Petr on top of the
> set_capacity_revalidate_and_notify I need for 5.11.  Let me know what
> you think.

LGTM - I've added it for 5.10, marked for 5.9 backport.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-11-12 20:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-12 16:50 loop uevent fix Christoph Hellwig
2020-11-12 16:50 ` [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify Christoph Hellwig
2020-11-12 19:13   ` Petr Vorel
2020-11-12 16:50 ` [PATCH 2/2] loop: Fix occasional uevent drop Christoph Hellwig
2020-11-12 19:25   ` Petr Vorel
2020-11-12 19:31 ` loop uevent fix Petr Vorel
2020-11-12 20:59 ` Jens Axboe

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