[PATCH v2 8/9] qemu: command: Move formatting of disk io error policy from -drive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That's a disk frontend attribute. Move the code to a separate function
since it's non-trivial and call it from the frontend attribute
formatter.
---
 src/qemu/qemu_command.c                            | 62 +++++++++++++---------
 ...uxml2argv-disk-drive-error-policy-enospace.args |  2 +-
 .../qemuxml2argv-disk-drive-error-policy-stop.args |  2 +-
 ...gv-disk-drive-error-policy-wreport-rignore.args |  2 +-
 4 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 92e3407632..ca4934b75c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1663,6 +1663,41 @@ qemuBuildDiskThrottling(virDomainDiskDefPtr disk,
 }


+static void
+qemuBuildDiskFrontendAttributeErrorPolicy(virDomainDiskDefPtr disk,
+                                          virQEMUCapsPtr qemuCaps,
+                                          virBufferPtr buf)
+{
+    const char *wpolicy = NULL;
+    const char *rpolicy = NULL;
+
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MONITOR_JSON))
+        return;
+
+    if (disk->error_policy)
+        wpolicy = virDomainDiskErrorPolicyTypeToString(disk->error_policy);
+
+    if (disk->rerror_policy)
+        rpolicy = virDomainDiskErrorPolicyTypeToString(disk->rerror_policy);
+
+    if (disk->error_policy == VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE) {
+        /* in the case of enospace, the option is spelled
+         * differently in qemu, and it's only valid for werror,
+         * not for rerror, so leave rerror NULL.
+         */
+        wpolicy = "enospc";
+    } else if (!rpolicy) {
+        /* for other policies, rpolicy can match wpolicy */
+        rpolicy = wpolicy;
+    }
+
+    if (wpolicy)
+        virBufferAsprintf(buf, ",werror=%s", wpolicy);
+    if (rpolicy)
+        virBufferAsprintf(buf, ",rerror=%s", rpolicy);
+}
+
+
 static void
 qemuBuildDiskFrontendAttributes(virDomainDiskDefPtr disk,
                                 virQEMUCapsPtr qemuCaps,
@@ -1687,6 +1722,8 @@ qemuBuildDiskFrontendAttributes(virDomainDiskDefPtr disk,
         virBufferAddLit(buf, ",serial=");
         virBufferEscape(buf, '\\', " ", "%s", disk->serial);
     }
+
+    qemuBuildDiskFrontendAttributeErrorPolicy(disk, qemuCaps, buf);
 }


@@ -1786,31 +1823,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
                           virDomainDiskDetectZeroesTypeToString(detect_zeroes));
     }

-    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MONITOR_JSON)) {
-        const char *wpolicy = NULL, *rpolicy = NULL;
-
-        if (disk->error_policy)
-            wpolicy = virDomainDiskErrorPolicyTypeToString(disk->error_policy);
-        if (disk->rerror_policy)
-            rpolicy = virDomainDiskErrorPolicyTypeToString(disk->rerror_policy);
-
-        if (disk->error_policy == VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE) {
-            /* in the case of enospace, the option is spelled
-             * differently in qemu, and it's only valid for werror,
-             * not for rerror, so leave rerror NULL.
-             */
-            wpolicy = "enospc";
-        } else if (!rpolicy) {
-            /* for other policies, rpolicy can match wpolicy */
-            rpolicy = wpolicy;
-        }
-
-        if (wpolicy)
-            virBufferAsprintf(&opt, ",werror=%s", wpolicy);
-        if (rpolicy)
-            virBufferAsprintf(&opt, ",rerror=%s", rpolicy);
-    }
-
     if (disk->iomode) {
         virBufferAsprintf(&opt, ",aio=%s",
                           virDomainDiskIoTypeToString(disk->iomode));
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args
index 704a571dd3..b019e44a24 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args
@@ -20,7 +20,7 @@ server,nowait \
 -boot c \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
-cache=none,werror=enospc \
+werror=enospc,cache=none \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
index 2e87d727fb..3bca32ac28 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
@@ -20,7 +20,7 @@ server,nowait \
 -boot c \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
-cache=none,werror=stop,rerror=stop \
+werror=stop,rerror=stop,cache=none \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args
index d3a9ec45eb..86d214fe7d 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args
@@ -20,7 +20,7 @@ server,nowait \
 -boot c \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
-cache=none,werror=report,rerror=ignore \
+werror=report,rerror=ignore,cache=none \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux