[libvirt] [PATCH 14/14] qemu: domain: Move initialization of disk cachemode for <shareable> disks

Peter Krempa pkrempa at redhat.com
Thu Mar 29 11:51:11 UTC 2018


The qemu command line generator code set disk caching of shareable disks
to 'none' when formatting the command line silently. Move this code to a
common place when preparing the domain definition for startup so that it
does not have to be duplicated.

The new test case shows that the actual cache mode will now be recorded
in the live XML definition.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_command.c                               |  2 --
 src/qemu/qemu_domain.c                                | 11 +++++++++++
 tests/qemuxml2startupxmloutdata/disk-drive-shared.xml |  2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c1225591b3..9e74ec64e9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1804,8 +1804,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
     if (disk->cachemode) {
         virBufferAsprintf(&opt, ",cache=%s",
                           qemuDiskCacheV2TypeToString(disk->cachemode));
-    } else if (disk->src->shared && !disk->src->readonly) {
-        virBufferAddLit(&opt, ",cache=none");
     }

     if (disk->copy_on_read) {
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cbad7d0f4c..d78a3cb255 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11891,11 +11891,22 @@ qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
 }


+static void
+qemuDomainPrepareDiskCachemode(virDomainDiskDefPtr disk)
+{
+    if (disk->cachemode == VIR_DOMAIN_DISK_CACHE_DEFAULT &&
+        disk->src->shared && !disk->src->readonly)
+        disk->cachemode = VIR_DOMAIN_DISK_CACHE_DISABLE;
+}
+
+
 int
 qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
                             qemuDomainObjPrivatePtr priv,
                             virQEMUDriverConfigPtr cfg)
 {
+    qemuDomainPrepareDiskCachemode(disk);
+
     if (qemuDomainPrepareDiskSourceTLS(disk->src, cfg) < 0)
         return -1;

diff --git a/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml b/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml
index f4d2871ae7..60b7eca788 100644
--- a/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml
+++ b/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml
@@ -15,7 +15,7 @@
   <devices>
     <emulator>/usr/bin/qemu-system-i686</emulator>
     <disk type='block' device='disk'>
-      <driver name='qemu' type='raw'/>
+      <driver name='qemu' type='raw' cache='none'/>
       <source dev='/dev/HostVG/QEMUGuest1'/>
       <target dev='hda' bus='ide'/>
       <shareable/>
-- 
2.16.2




More information about the libvir-list mailing list