Skip to contentSkip to conversation

'qemu-nbd' explicit flush

Qemu-devel Mark Trumpold 2 participants 2 messages May 23, 2013 – May 24, 2013

lore
Share & tools
lore
#0 lore raw

I had one question I forgot to ask..

Is it possible to switch from '--cache=writeback' functionality to '--cache=writethrough' (and visa versa) while qemu-nbd is connected to the '/dev/nbd<x>' device?

Thank you,
Mark T.

-----Original Message-----
From: Mark Trumpold [mailto:[email protected]]
Sent: Thursday, May 23, 2013 02:58 PM
To: 'Paolo Bonzini', 'Stefan Hajnoczi'
Cc: 'Mark Trumpold', [email protected], [email protected]
Subject: Re: 'qemu-nbd' explicit flush

I have a working configuration using the signal approach suggested by Stefan.

'qemu-nbd.c' is patched as follows:

    do {
        main_loop_wait(false);
+       if (sighup_reported) {
+           sighup_reported = false;
+           bdrv_drain_all();
+           bdrv_flush_all();
        }
    } while (!sigterm_reported && (persistent || !nbd_started || nb_fds > 0));

The driving script was patched as follows:

mount -o remount,ro /dev/nbd0
blockdev --flushbufs /dev/nbd0
+ kill -HUP <qemu-nbd process id>

I needed to retain 'blockdev --flushbufs' for things to work. Seems the 'bdrv_flush_all' is flushing what is being missed by the blockdev flush. I did not go back an retest with 'fsync' or other approaches I had tried before.

Thanks again Paolo and Stefan for your help!!
Regards,
Mark T.

-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]]
Sent: Wednesday, May 22, 2013 04:07 AM
To: 'Stefan Hajnoczi'
Cc: 'Mark Trumpold', [email protected], [email protected]
Subject: Re: 'qemu-nbd' explicit flush

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/1108

Did you check that the kernel is sending NBD_FLUSH commands? 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

#1 lore raw
Quoted 5 lines · Mark Trumpold

I had one question I forgot to ask..

Is it possible to switch from '--cache=writeback' functionality to '--cache=writethrough' (and visa versa) while qemu-nbd is connected to the '/dev/nbd<x>' device?

No. The block layer APIs to do that are available in QEMU but qemu-nbd doesn't have run-time cache mode changing.

Stefan