* [PATCH] btrfs: Notify udev when removing device
@ 2012-12-06 19:25 Lukas Czerner
2012-12-07 17:12 ` Anand Jain
0 siblings, 1 reply; 2+ messages in thread
From: Lukas Czerner @ 2012-12-06 19:25 UTC (permalink / raw)
To: linux-btrfs; +Cc: chris.mason, Lukas Czerner
Currently udev does not know about the device being removed from the
file system. This may result in the situation where we're unable to
mount the file system by UUID or by LABEL because the by-uuid and
by-label links may still point to the device which is no longer part of
the btrfs file system and hence does not have any btrfs super block.
It can be easily reproduced by the following:
mkfs.btrfs -L bugfs /dev/loop[0-6]
mount /dev/loop0 /mnt/test
btrfs device delete /dev/loop0 /mnt/test
umount /mnt/test
mount LABEL=bugfs /mnt/test <---- this fails
then see:
ls -l /dev/disk/by-label/bugfs
which will still point to the /dev/loop0
We did not noticed this before because libblkid would send the udev
event for us when it notice that the link does not fit the reality,
however it does not do that anymore and completely relies on udev
information.
Fix this by sending the KOBJ_CHANGE event to the bdev kobject after
successful device removal.
Note that this does not affect device addition, because we will open the
device prior the addition from userspace and udev will notice that and
reread the device afterwards.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
fs/btrfs/volumes.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0f5ebb7..95c6f7d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -71,6 +71,19 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
kfree(fs_devices);
}
+static void btrfs_kobject_uevent(struct block_device *bdev,
+ enum kobject_action action)
+{
+ int ret;
+
+ ret = kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, action);
+ if (ret)
+ pr_warn("Sending event '%d' to kobject: '%s' (%p): failed\n",
+ action,
+ kobject_name(&disk_to_dev(bdev->bd_disk)->kobj),
+ &disk_to_dev(bdev->bd_disk)->kobj);
+}
+
void btrfs_cleanup_fs_uuids(void)
{
struct btrfs_fs_devices *fs_devices;
@@ -1493,6 +1506,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
ret = 0;
+ /* Notify udev that device has changed */
+ btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
+
error_brelse:
brelse(bh);
error_close:
--
1.7.7.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: Notify udev when removing device
2012-12-06 19:25 [PATCH] btrfs: Notify udev when removing device Lukas Czerner
@ 2012-12-07 17:12 ` Anand Jain
0 siblings, 0 replies; 2+ messages in thread
From: Anand Jain @ 2012-12-07 17:12 UTC (permalink / raw)
To: Lukas Czerner; +Cc: linux-btrfs
It works. Nice fix.
Thanks
Anand
On 12/07/2012 03:25 AM, Lukas Czerner wrote:
> Currently udev does not know about the device being removed from the
> file system. This may result in the situation where we're unable to
> mount the file system by UUID or by LABEL because the by-uuid and
> by-label links may still point to the device which is no longer part of
> the btrfs file system and hence does not have any btrfs super block.
>
> It can be easily reproduced by the following:
>
> mkfs.btrfs -L bugfs /dev/loop[0-6]
> mount /dev/loop0 /mnt/test
> btrfs device delete /dev/loop0 /mnt/test
> umount /mnt/test
>
> mount LABEL=bugfs /mnt/test <---- this fails
>
> then see:
>
> ls -l /dev/disk/by-label/bugfs
>
> which will still point to the /dev/loop0
>
> We did not noticed this before because libblkid would send the udev
> event for us when it notice that the link does not fit the reality,
> however it does not do that anymore and completely relies on udev
> information.
>
> Fix this by sending the KOBJ_CHANGE event to the bdev kobject after
> successful device removal.
>
> Note that this does not affect device addition, because we will open the
> device prior the addition from userspace and udev will notice that and
> reread the device afterwards.
>
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> fs/btrfs/volumes.c | 16 ++++++++++++++++
> 1 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 0f5ebb7..95c6f7d 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -71,6 +71,19 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
> kfree(fs_devices);
> }
>
> +static void btrfs_kobject_uevent(struct block_device *bdev,
> + enum kobject_action action)
> +{
> + int ret;
> +
> + ret = kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, action);
> + if (ret)
> + pr_warn("Sending event '%d' to kobject: '%s' (%p): failed\n",
> + action,
> + kobject_name(&disk_to_dev(bdev->bd_disk)->kobj),
> + &disk_to_dev(bdev->bd_disk)->kobj);
> +}
> +
> void btrfs_cleanup_fs_uuids(void)
> {
> struct btrfs_fs_devices *fs_devices;
> @@ -1493,6 +1506,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
>
> ret = 0;
>
> + /* Notify udev that device has changed */
> + btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
> +
> error_brelse:
> brelse(bh);
> error_close:
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-12-07 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-06 19:25 [PATCH] btrfs: Notify udev when removing device Lukas Czerner
2012-12-07 17:12 ` Anand Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).