'qemu-nbd' explicit flush
Hello all,
I am using ‘qemu-nbd’ and ‘qemu-img’ from the command line to provide ‘qcow2’ loop filesystems. For performance, I have '--cache=writeback' set for the qemu-nbd device.
I am having trouble flushing all caches to disk at will; specifically before snapshotting the underlying filesystem that hold the ‘qcow2’ images.
Environment:
Qemu 1.2.0
Debian 6.0.5
Linux kernel 3.3.1 with Qemu patch to enable kernel flushing:
http://thread.gmane.org/gmane.linux.drivers.nbd.general/1108Usage example:
'qemu-nbd --cache=writeback -c /dev/nbd0 /images/my-qcow.img' 'mount /dev/nbd0 /my-mount-point'
Everything does flush correctly when I first unmount and then disconnect the device; however, in my case I am not able to unmount things before snapshotting.
I tried several approaches externally to flush the device. For example:
'mount -o remount,ro /dev/nbd0'
'blockdev --flushbufs /dev/nbd0'
I have been looking at the Qemu source code and in user space 'nbd.c' in routine 'nbd_trip' I see the case 'NBD_CMD_FLUSH' which looks to be called from the NBD socket interface. Here I see 'bdrv_co_flush(exp->bs)' which looks promising; however, I don't know how to setup the 'bs' pointer for the call.
Ideally, I would like to add a command line parm to 'qemu-nbd.c' to explicitely do the flush, but so far no luck.
I've been struggling with this for some time. Any guidance would be greatly appreciated.
Thank you,
Mark Trumpold
Quoted 2 lines · Mark Trumpold
Linux kernel 3.3.1 with Qemu patch to enable kernel flushing:
http://thread.gmane.org/gmane.linux.drivers.nbd.general/1108
Did you check that the kernel is sending NBD_FLUSH commands? You can use tcpdump and then check the captured network traffic.
Quoted 9 lines
Usage example:
'qemu-nbd --cache=writeback -c/dev/nbd0/images/my-qcow.img' 'mount/dev/nbd0/my-mount-point'Everything does flush correctly when I first unmount and then disconnect the device; however, in my case I am not able to unmount things before snapshotting.
I tried several approaches externally to flush the device. For example:
'mount -o remount,ro/dev/nbd0'
'blockdev --flushbufs/dev/nbd0'
Did you try plain old sync(1)?
Quoted 1 line
I have been looking at the Qemu source code and in user space '
nbd.c' in routine 'nbd_trip' I see the case 'NBD_CMD_FLUSH' which looks to be called from the NBD socket interface. Here I see 'bdrv_co_flush(exp->bs)' which looks promising; however, I don't know how to setup the 'bs' pointer for the call.
bs is the block device which was exported using:
exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags, nbd_export_closed);
in qemu-nbd.c:main().
Quoted 1 line
Ideally, I would like to add a command line parm to '
qemu-nbd.c' to explicitely do the flush, but so far no luck.
Doing that is a little tricky, I think there are two options:
1. Add a signal handler (like SIGHUP or SIGUSR1) to qemu-nbd which flushes all exports.
2. Instantiate a block/nbd.c client that connects to the running qemu-nbd server (make sure format=raw). Then call bdrv_flush() on the NBD client. You must use the qemu-nbd --shared=2 option.
Stefan
Il 22/05/2013 11:47, Stefan Hajnoczi ha scritto:
Quoted 11 lines · Mark Trumpold
Quoted 2 lines
Linux kernel 3.3.1 with Qemu patch to enable kernel flushing:
http://thread.gmane.org/gmane.linux.drivers.nbd.general/1108Did you check that the kernel is sending
NBD_FLUSHcommands? You can use tcpdump and then check the captured network traffic.Quoted 4 lines
Usage example:
'qemu-nbd --cache=writeback -c/dev/nbd0/images/my-qcow.img' 'mount/dev/nbd0/my-mount-point'
Quoted 7 lines
Quoted 5 lines
Everything does flush correctly when I first unmount and then disconnect the device; however, in my case I am not able to unmount things before snapshotting.
I tried several approaches externally to flush the device. For example:
'mount -o remount,ro/dev/nbd0'
'blockdev --flushbufs/dev/nbd0'Did you try plain old sync(1)?
This could also work:
dd if=/dev/zero of=dummy oflag=sync bs=512 count=1
Quoted 2 lines
1. Add a signal handler (like SIGHUP or SIGUSR1) to qemu-nbd which flushes all exports.
That would be a useful addition anyway.
Paolo