Skip to contentSkip to conversation

loop uevent fix

PATCH In review Christoph Hellwig 3 participants 7 messages Nov 12, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

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 lore raw

PATCH 1/2 block: add a return value to set_capacity_revalidate_and_notify

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

---
 block/genhd.c         | 5 ++++-
 include/linux/genhd.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
block/genhd.c +4 -1
index 0a273211fec283..9387f050c248a7 100644
@@ -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);
include/linux/genhd.h +1 -1
index 38f23d75701379..03da3f603d309c 100644
@@ -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 */
Signature · 1 line
2.28.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] block: add a return value to set_capacity_revalidate_and_notify

Hi Christoph,

Quoted 3 lines

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

Kind regards,
Petr

Quoted 42 lines
---
 block/genhd.c         | 5 ++++-
 include/linux/genhd.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
block/genhd.c +4 -1
index 0a273211fec283..9387f050c248a7 100644
@@ -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);
include/linux/genhd.h +1 -1
index 38f23d75701379..03da3f603d309c 100644
@@ -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 */
#3 lore raw

PATCH 2/2 loop: Fix occasional uevent drop

In reply to Christoph Hellwig

From: Petr Vorel <[email protected]>

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")

[hch: rebased on a different change to the prototype of
set_capacity_revalidate_and_notify]

---
 drivers/block/loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/loop.c +2 -1
index cb1191d6e945f2..a58084c2ed7ceb 100644
@@ -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
Signature · 1 line
2.28.0
#4 lore raw

Re: [PATCH 2/2] loop: Fix occasional uevent drop

Hi Christoph,

Quoted 1 line

From: Petr Vorel <[email protected]>

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).

Quoted 10 lines

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
Quoted 6 lines

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

#5 lore raw
In reply to Christoph Hellwig

Hi Jens, Christoph,

Quoted 5 lines

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

maintainer
#6 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

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.

Signature · 1 line
Jens Axboe