From c3473c63542d53740f175f3a515257ae159e998b Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 3 May 2010 14:08:59 +0200 Subject: generate "change" uevent for loop device Recent udev versions probe loop devices for filesystems meaning that the /dev/disk hierarchy may contain useful entries such as $ ls -l /dev/disk/by-label/Fedora-12-x86_64-Live lrwxrwxrwx 1 root root 11 Mar 11 13:41 /dev/disk/by-label/Fedora-12-x86_64-Live -> ../../loop0 Unfortunately, no "change" uevent is generated when the loop device is detached so the symlink persists. Additionally, no "change" uevent is guaranteed to be generated when attaching an fd or changing capacity. For example, user space could open the loop device O_RDONLY (in fact, recent util-linux-ng does this) so udev's OPTIONS+="watch" machinery may not trigger the "change" uevent. This patch ensures that the "change" uevent is generated in all of these cases. As a result, the /dev/disk hierarchy works as expected for loop devices. Signed-off-by: David Zeuthen Acked-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 8546d123b9a7..a90e83c9be96 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -835,6 +835,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, set_capacity(lo->lo_disk, size); bd_set_size(bdev, size << 9); + /* let user-space know about the new size */ + kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); set_blocksize(bdev, lo_blocksize); @@ -858,6 +860,7 @@ out_clr: set_capacity(lo->lo_disk, 0); invalidate_bdev(bdev); bd_set_size(bdev, 0); + kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); mapping_set_gfp_mask(mapping, lo->old_gfp_mask); lo->lo_state = Lo_unbound; out_putf: @@ -944,8 +947,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) if (bdev) invalidate_bdev(bdev); set_capacity(lo->lo_disk, 0); - if (bdev) + if (bdev) { bd_set_size(bdev, 0); + /* let user-space know about this change */ + kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); + } mapping_set_gfp_mask(filp->f_mapping, gfp); lo->lo_state = Lo_unbound; /* This is safe: open() is still holding a reference. */ @@ -1189,6 +1195,8 @@ static int loop_set_capacity(struct loop_device *lo, struct block_device *bdev) sz <<= 9; mutex_lock(&bdev->bd_mutex); bd_set_size(bdev, sz); + /* let user-space know about the new size */ + kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); mutex_unlock(&bdev->bd_mutex); out: -- cgit v1.2.2