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

[libvirt] [PATCH 09/12] qemu: command: Move formatting of disk io error policy from -drive



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 |  5 +-
 .../qemuxml2argv-disk-drive-error-policy-stop.args |  5 +-
 ...gv-disk-drive-error-policy-wreport-rignore.args |  5 +-
 4 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6ae738020d..03a2e6855a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1649,6 +1649,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,
@@ -1673,6 +1708,8 @@ qemuBuildDiskFrontendAttributes(virDomainDiskDefPtr disk,
         virBufferAddLit(buf, ",serial=");
         virBufferEscape(buf, '\\', " ", "%s", disk->serial);
     }
+
+    qemuBuildDiskFrontendAttributeErrorPolicy(disk, qemuCaps, buf);
 }


@@ -1771,31 +1808,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..80422a8c88 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-enospace.args
@@ -20,8 +20,9 @@ server,nowait \
 -boot c \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
-cache=none,werror=enospc \
--device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+cache=none \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
+werror=enospc \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
index 2e87d727fb..bcac9f2a8e 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-stop.args
@@ -20,8 +20,9 @@ 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 \
--device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+cache=none \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
+werror=stop,rerror=stop \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
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..f558477230 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-policy-wreport-rignore.args
@@ -20,8 +20,9 @@ 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 \
--device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+cache=none \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
+werror=report,rerror=ignore \
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
 media=cdrom,readonly=on \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
-- 
2.14.3


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