Re: [Qemu-devel] Online resize of virtio-blk device does not emit udev event

2013-02-22 Thread Milos Vyletel
- Original Message -
 On Wed, Feb 20, 2013 at 09:34:45PM +0100, Milos Vyletel wrote:
  It looks like none of the block drivers handle this.
 
 drivers/md/dm*.c is a block driver and you showed that LVM
 (device-mapper) does raise a uevent when the device is resized.  That
 would be the place to look.
 

Thanks. That's where I was looking. Device mapper likes to use
uevents and they are all over place. However I found drivers/md/md.c
that uses uevents in same way as my proof of concept patch. I've
posted my patch to LKML to see what they think about it. In case
anyone is interested here's the link

https://patchwork.kernel.org/patch/2172791/

Milos



Re: [Qemu-devel] Online resize of virtio-blk device does not emit udev event

2013-02-21 Thread Stefan Hajnoczi
On Wed, Feb 20, 2013 at 09:34:45PM +0100, Milos Vyletel wrote:
 It looks like none of the block drivers handle this.

drivers/md/dm*.c is a block driver and you showed that LVM
(device-mapper) does raise a uevent when the device is resized.  That
would be the place to look.

Stefan



Re: [Qemu-devel] Online resize of virtio-blk device does not emit udev event

2013-02-20 Thread Stefan Hajnoczi
On Tue, Feb 19, 2013 at 10:15:32PM +0100, Milos Vyletel wrote:
 I was looking at the virtblk_config_changed_work function in RHEL6.3 kernel's
 drivers/block/virtio_blk.c which I believe is the function handling 
 blockresize
 and it does not look like it tries to emit any kobject uevent.
 
 Before I jump into patching kernel my question is whether it makes sense to 
 have
 such uevent? I surely can use a way how to detect capacity change from 
 userspace.

I suggest checking how other block drivers (including the device-mapper
and scsi layers) handle resize.  Perhaps virtio_blk.c can follow an
existing approach.

Stefan



Re: [Qemu-devel] Online resize of virtio-blk device does not emit udev event

2013-02-20 Thread Milos Vyletel
Stefan,

that's essentially what I was trying to do. I wanted to get an opinion from
someone more familiar with the virtio-blk and kernel in general firs though.

It looks like none of the block drivers handle this. It may be good idea to
add some function to block/genhd.c where similar stuff already exists
(media_change_notify_thread() for example). 

In the meantime I've done some proof of concept work directly in virtio-blk
driver where I'm emitting uevent when disk is resized.

What I'm trying to do is basically automatically handle resizing of filesystem
on guest in case host resizes block device for guest. This kernel patch along
with simple udev rules takes care of it.

--- drivers/block/virtio_blk.c.orig 2013-02-20 11:14:54.0 -0500
+++ drivers/block/virtio_blk.c  2013-02-20 13:34:15.0 -0500
@@ -294,6 +294,8 @@ static void virtblk_config_changed_work(
struct virtio_device *vdev = vblk-vdev;
struct request_queue *q = vblk-disk-queue;
char cap_str_2[10], cap_str_10[10];
+   char event[] = RESIZE=1;
+   char *envp[] = { event, NULL };
u64 capacity, size;

mutex_lock(vblk-config_lock);
@@ -323,6 +325,7 @@ static void virtblk_config_changed_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);
 }

# cat /etc/udev/rules.d/98-virtio-resize.rules
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

Milos

- Original Message -
From: Stefan Hajnoczi stefa...@gmail.com
To: Milos Vyletel milos.vyle...@sde.cz
Cc: qemu-devel@nongnu.org
Sent: Wednesday, February 20, 2013 4:47:34 AM
Subject: Re: [Qemu-devel] Online resize of virtio-blk device does not emit udev 
event

On Tue, Feb 19, 2013 at 10:15:32PM +0100, Milos Vyletel wrote:
 I was looking at the virtblk_config_changed_work function in RHEL6.3 kernel's
 drivers/block/virtio_blk.c which I believe is the function handling 
 blockresize
 and it does not look like it tries to emit any kobject uevent.
 
 Before I jump into patching kernel my question is whether it makes sense to 
 have
 such uevent? I surely can use a way how to detect capacity change from 
 userspace.

I suggest checking how other block drivers (including the device-mapper
and scsi layers) handle resize.  Perhaps virtio_blk.c can follow an
existing approach.

Stefan



[Qemu-devel] Online resize of virtio-blk device does not emit udev event

2013-02-19 Thread Milos Vyletel
Hi,

This list seem to be most appropriate place to ask this question since it's 
QEMU related and virtio-blk maintainers are here as well.

I'm doing some work with online resizing of guest's block device on LVM. What I
do is call lvresize to expand logical volume itself and virsh blockresize to
notify guest about this change. Besides the fact that I needed to patch kernel
to get this working on mounted partitions(BZ 906050) everything works just fine.

Now that I've had this part successfully tested I wanted to make a script that
will be triggered by udev whenever particular device is changed. I assumed that
after capacity change virtio_blk driver would emit udev event but that's not the
case. I'm able to see one on host but not on guest.

[root@host ~]# lvresize -f -L +100M /dev/vgguests/evd2  \
 virsh blockresize resize vdb 1
  Rounding size to boundary between physical extents: 128.00 MiB
  Extending logical volume evd2 to 15.00 GiB
  Logical volume evd2 successfully resized
Block device 'vdb' is resized

[root@host ~]# udevadm monitor
...
KERNEL[1361292279.619233] change   /devices/virtual/block/dm-9 (block)
UDEV  [1361292279.736012] change   /devices/virtual/block/dm-9 (block)
...

I was looking at the virtblk_config_changed_work function in RHEL6.3 kernel's
drivers/block/virtio_blk.c which I believe is the function handling blockresize
and it does not look like it tries to emit any kobject uevent.

Before I jump into patching kernel my question is whether it makes sense to have
such uevent? I surely can use a way how to detect capacity change from 
userspace.

Thanks,
Milos