virtio-blk: emit udev event when device is resized
authorMilos Vyletel <milos.vyletel@sde.cz>
Tue, 12 Mar 2013 05:04:40 +0000 (15:34 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 12 Mar 2013 05:14:55 +0000 (15:44 +1030)
When virtio-blk device is resized from host (using block_resize from QEMU) emit
KOBJ_CHANGE uevent to notify guest about such change. This allows user to have
custom udev rules which would take whatever action if such event occurs. As a
proof of concept I've created simple udev rule that automatically resize
filesystem on virtio-blk device.

ACTION=="change", KERNEL=="vd*", \
        ENV{RESIZE}=="1", \
        ENV{ID_FS_TYPE}=="ext[3-4]", \
        RUN+="/sbin/resize2fs /dev/%k"
ACTION=="change", KERNEL=="vd*", \
        ENV{RESIZE}=="1", \
        ENV{ID_FS_TYPE}=="LVM2_member", \
        RUN+="/sbin/pvresize /dev/%k"

Signed-off-by: Milos Vyletel <milos.vyletel@sde.cz>
Tested-by: Asias He <asias@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (minor simplification)
drivers/block/virtio_blk.c

index 8ad21a25bc0d92cc80f48f69f4556bdcc6ef6fa2..922bcb97e23afa2cba11c9965d4d376a4b10a01d 100644 (file)
@@ -539,6 +539,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
        struct virtio_device *vdev = vblk->vdev;
        struct request_queue *q = vblk->disk->queue;
        char cap_str_2[10], cap_str_10[10];
+       char *envp[] = { "RESIZE=1", NULL };
        u64 capacity, size;
 
        mutex_lock(&vblk->config_lock);
@@ -568,6 +569,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
 
        set_capacity(vblk->disk, capacity);
        revalidate_disk(vblk->disk);
+       kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp);
 done:
        mutex_unlock(&vblk->config_lock);
 }