diff options
author | David Zeuthen <davidz@redhat.com> | 2010-05-03 08:08:59 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-05-21 12:37:30 -0400 |
commit | c3473c63542d53740f175f3a515257ae159e998b (patch) | |
tree | 20832b70ba6f89aacaa377d41b7427d74be647b1 | |
parent | 6245838fe4d2ce4aab52f543224f7d1212d9155c (diff) |
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 <davidz@redhat.com>
Acked-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/block/loop.c | 10 |
1 files changed, 9 insertions, 1 deletions
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, | |||
835 | 835 | ||
836 | set_capacity(lo->lo_disk, size); | 836 | set_capacity(lo->lo_disk, size); |
837 | bd_set_size(bdev, size << 9); | 837 | bd_set_size(bdev, size << 9); |
838 | /* let user-space know about the new size */ | ||
839 | kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); | ||
838 | 840 | ||
839 | set_blocksize(bdev, lo_blocksize); | 841 | set_blocksize(bdev, lo_blocksize); |
840 | 842 | ||
@@ -858,6 +860,7 @@ out_clr: | |||
858 | set_capacity(lo->lo_disk, 0); | 860 | set_capacity(lo->lo_disk, 0); |
859 | invalidate_bdev(bdev); | 861 | invalidate_bdev(bdev); |
860 | bd_set_size(bdev, 0); | 862 | bd_set_size(bdev, 0); |
863 | kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); | ||
861 | mapping_set_gfp_mask(mapping, lo->old_gfp_mask); | 864 | mapping_set_gfp_mask(mapping, lo->old_gfp_mask); |
862 | lo->lo_state = Lo_unbound; | 865 | lo->lo_state = Lo_unbound; |
863 | out_putf: | 866 | out_putf: |
@@ -944,8 +947,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) | |||
944 | if (bdev) | 947 | if (bdev) |
945 | invalidate_bdev(bdev); | 948 | invalidate_bdev(bdev); |
946 | set_capacity(lo->lo_disk, 0); | 949 | set_capacity(lo->lo_disk, 0); |
947 | if (bdev) | 950 | if (bdev) { |
948 | bd_set_size(bdev, 0); | 951 | bd_set_size(bdev, 0); |
952 | /* let user-space know about this change */ | ||
953 | kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); | ||
954 | } | ||
949 | mapping_set_gfp_mask(filp->f_mapping, gfp); | 955 | mapping_set_gfp_mask(filp->f_mapping, gfp); |
950 | lo->lo_state = Lo_unbound; | 956 | lo->lo_state = Lo_unbound; |
951 | /* This is safe: open() is still holding a reference. */ | 957 | /* 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) | |||
1189 | sz <<= 9; | 1195 | sz <<= 9; |
1190 | mutex_lock(&bdev->bd_mutex); | 1196 | mutex_lock(&bdev->bd_mutex); |
1191 | bd_set_size(bdev, sz); | 1197 | bd_set_size(bdev, sz); |
1198 | /* let user-space know about the new size */ | ||
1199 | kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); | ||
1192 | mutex_unlock(&bdev->bd_mutex); | 1200 | mutex_unlock(&bdev->bd_mutex); |
1193 | 1201 | ||
1194 | out: | 1202 | out: |