[pve-devel] Fwd: Re: recommanded cache setting for rbd image

Alexandre DERUMIER aderumier at odiso.com
Wed Nov 7 08:09:23 CET 2012


>> But why does a guest do not support flushes? What kind of guest is that? 
Some old kernels, or old filesystems version without barrier support.

Also virtio driver:

 some virtio driver drivers versions doesn't support flushed

http://git.qemu-project.org/?p=qemu.git;a=commit;h=9315cbfd8d7074eca44fbc5f93902e97b27d5240
"
virtio-blk: disable write cache if not negotiated

If the guest does not support flushes, we should run in writethrough mode.
The setting is temporary until the next reset, so that for example the
BIOS will run in writethrough mode while Linux will run with a writeback
cache.
"

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 97bb4bd..fd8fa90 100644 (file)
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -543,6 +543,19 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
     return features;
 }
 
+static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
+{
+    VirtIOBlock *s = to_virtio_blk(vdev);
+    uint32_t features;
+
+    if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+        return;
+    }
+
+    features = vdev->guest_features;
+    bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
+}
+
 static void virtio_blk_save(QEMUFile *f, void *opaque)
 {
     VirtIOBlock *s = opaque;
@@ -623,6 +636,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     s->vdev.get_config = virtio_blk_update_config;
     s->vdev.set_config = virtio_blk_set_config;
     s->vdev.get_features = virtio_blk_get_features;
+    s->vdev.set_status = virtio_blk_set_status;
     s->vdev.reset = virtio_blk_reset;
     s->bs = blk->conf.bs;
     s->conf = &blk->conf;



also 

http://www.mail-archive.com/kvm@vger.kernel.org/msg74629.html
virtio-blk spec: writeback cache enable improvements

This patch introduces two improvements to writeback cache handling
in the virtio-blk spec.

1) The VIRTIO_BLK_F_FLUSH feature is renamed to VIRTIO_BLK_F_WCE, and
QEMU's behavior is documented explicitly as part of the spec: the host
negotiates the feature only if its cache is writeback.  The obvious dual
requirement is imposed on the guest: it should negotiate the feature
only if it is able to send flushes.  And in order to protect against
data loss, the spec now mandates that the host operates in writethrough
mode if the guest does not negotiate VIRTIO_BLK_F_WCE (this behavior
was already _allowed_ by the spec so far).  This can change with every
reset of course; typically the BIOS will run as writethrough, while the
"main" OS will run in writeback mode.  This is a backwards-compatible
refinement geared towards old or limited guests, so there is no need
for a new feature bit.

2) a second feature is added, VIRTIO_BLK_F_CONFIG_WCE, that provides
the same information in the configuration.  This will enable the driver
to modify the write-cache setting at runtime (via sysfs for Linux, via
MODE SELECT for Windows).



-->So seem that if we put cache=writeback, and that virtio doesn't support flushes, it'll use writetrough, great :)


----- Mail original ----- 

De: "Dietmar Maurer" <dietmar at proxmox.com> 
À: "Alexandre DERUMIER" <aderumier at odiso.com> 
Cc: pve-devel at pve.proxmox.com 
Envoyé: Mercredi 7 Novembre 2012 06:29:56 
Objet: RE: [pve-devel] Fwd: Re: recommanded cache setting for rbd image 

> >>block: default cache mode is now writeback 
> >> 
> >>so it is already 'writeback'? 
> I think we need to read the qemu code. I don't know if writeback is writeback 
> mode in guest or writeback in host. 
> cache=none : writeback is guest 
> cache=writeback : writeback is guest,writeback in host 

So far, we only talk about cache mode in the host. I do not care what the guest it doing ;-) 

> One another interesting thing in qemu 1.2 changelog: 
> 
> "Emulated IDE and SCSI as well as virtio-blk devices can now switch the cache 
> mode between writethrough and writeback. virtio-blk automatically switches 
> to writethrough if the guest driver doesn't support flushes. " 
> 
> So maybe if we set cache=none and that guest doesn't support flushes 
> (drivers,kernel,?), it become writethrough in guest, so it's safe ? 

No, default cache is 'writeback'. But this is unsafe when the guest doesn't support flushes. 
That is why it is changed to writethrough to be safe. 

But why does a guest do not support flushes? What kind of guest is that? 



More information about the pve-devel mailing list