On 09/19/2013 10:48 AM, Paolo Bonzini wrote: > The following sequence happens:
> Hence, whenever the guest is reset, the cache mode of the disk should > be reset to whatever was specified in the "-drive" option. With this > change, the Linux virtio-blk driver finds that writeback caching is > enabled, and tells the block layer to send cache flush commands > appropriately. > > Reported-by: Rusty Russell <ru...@au1.ibm.com > Cc: qemu-sta...@nongnu.org > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > hw/block/virtio-blk.c | 8 ++++++-- > include/hw/virtio/virtio-blk.h | 1 + > 2 files changed, 7 insertions(+), 2 deletions(-) Reviewed-by: Eric Blake <ebl...@redhat.com> > > features = vdev->guest_features; > - bdrv_set_enable_write_cache(s->bs, !!(features & (1 << > VIRTIO_BLK_F_WCE))); > + if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) { > + bdrv_set_enable_write_cache(s->bs, > + !!(features & (1 << VIRTIO_BLK_F_WCE))); > + } > } > > static void virtio_blk_save(QEMUFile *f, void *opaque) > @@ -674,6 +678,7 @@ static int virtio_blk_device_init(VirtIODevice *vdev) > } > > blkconf_serial(&blk->conf, &blk->serial); > + s->original_wce = bdrv_enable_write_cache(blk->conf.bs); At first, I was worried that this does 'bool = int', and whether that was correct in all cases. But looking further, bdrv_enable_write_cache merely returns bs->enable_write_cache (also an int), but that all assignments to bs->enable_write_cache are careful to only assign 0 or 1. A followup patch that changes the types to bool might be in order, but doesn't invalidate this patch. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature