Skip to content

Commit 498ef5c

Browse files
Christoph Hellwigaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent d2c7f56 commit 498ef5c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

drivers/block/loop.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
569569

570570
if (!file)
571571
return -EBADF;
572+
573+
/* suppress uevents while reconfiguring the device */
574+
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
575+
572576
is_loop = is_loop_device(file);
573577
error = loop_global_lock_killable(lo, is_loop);
574578
if (error)
@@ -623,13 +627,18 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
623627
fput(old_file);
624628
if (partscan)
625629
loop_reread_partitions(lo);
626-
return 0;
630+
631+
error = 0;
632+
done:
633+
/* enable and uncork uevent now that we are done */
634+
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
635+
return error;
627636

628637
out_err:
629638
loop_global_unlock(lo, is_loop);
630639
out_putf:
631640
fput(file);
632-
return error;
641+
goto done;
633642
}
634643

635644
/* loop sysfs attributes */
@@ -994,6 +1003,9 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
9941003
/* This is safe, since we have a reference from open(). */
9951004
__module_get(THIS_MODULE);
9961005

1006+
/* suppress uevents while reconfiguring the device */
1007+
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
1008+
9971009
/*
9981010
* If we don't hold exclusive handle for the device, upgrade to it
9991011
* here to avoid changing device under exclusive owner.
@@ -1096,7 +1108,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
10961108
loop_reread_partitions(lo);
10971109
if (!(mode & FMODE_EXCL))
10981110
bd_abort_claiming(bdev, loop_configure);
1099-
return 0;
1111+
1112+
error = 0;
1113+
done:
1114+
/* enable and uncork uevent now that we are done */
1115+
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
1116+
return error;
11001117

11011118
out_unlock:
11021119
loop_global_unlock(lo, is_loop);
@@ -1107,7 +1124,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
11071124
fput(file);
11081125
/* This is safe: open() is still holding a reference. */
11091126
module_put(THIS_MODULE);
1110-
return error;
1127+
goto done;
11111128
}
11121129

11131130
static void __loop_clr_fd(struct loop_device *lo, bool release)

0 commit comments

Comments
 (0)