127bba
From 5a9b62b909200f231a70331d1848c983046f4fc7 Mon Sep 17 00:00:00 2001
127bba
Message-Id: <5a9b62b909200f231a70331d1848c983046f4fc7@dist-git>
127bba
From: Martin Kletzander <mkletzan@redhat.com>
127bba
Date: Fri, 4 Nov 2016 10:29:39 +0100
127bba
Subject: [PATCH] qemu: Move common checks outside qemuBuildShmemDevLegacyStr
127bba
127bba
Some checks will need to be performed for newer device types as well, so
127bba
let's not duplicate them.
127bba
127bba
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
127bba
(cherry picked from commit 9187cecc8170cbb5230d6d9787ad97edc8a07c06)
127bba
127bba
https://bugzilla.redhat.com/show_bug.cgi?id=1392031
127bba
127bba
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
127bba
---
127bba
 src/qemu/qemu_command.c | 54 +++++++++++++++++++++++++------------------------
127bba
 1 file changed, 28 insertions(+), 26 deletions(-)
127bba
127bba
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
127bba
index a3c9c7a..6eafa5e 100644
127bba
--- a/src/qemu/qemu_command.c
127bba
+++ b/src/qemu/qemu_command.c
127bba
@@ -8467,29 +8467,12 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def,
127bba
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
127bba
                        _("ivshmem device is not supported "
127bba
                          "with this QEMU binary"));
127bba
-        goto error;
127bba
+        return NULL;
127bba
     }
127bba
 
127bba
     virBufferAddLit(&buf, "ivshmem");
127bba
-    if (shmem->size) {
127bba
-        /*
127bba
-         * Thanks to our parsing code, we have a guarantee that the
127bba
-         * size is power of two and is at least a mebibyte in size.
127bba
-         * But because it may change in the future, the checks are
127bba
-         * doubled in here.
127bba
-         */
127bba
-        if (shmem->size & (shmem->size - 1)) {
127bba
-            virReportError(VIR_ERR_XML_ERROR, "%s",
127bba
-                           _("shmem size must be a power of two"));
127bba
-            goto error;
127bba
-        }
127bba
-        if (shmem->size < 1024 * 1024) {
127bba
-            virReportError(VIR_ERR_XML_ERROR, "%s",
127bba
-                           _("shmem size must be at least 1 MiB (1024 KiB)"));
127bba
-            goto error;
127bba
-        }
127bba
+    if (shmem->size)
127bba
         virBufferAsprintf(&buf, ",size=%llum", shmem->size >> 20);
127bba
-    }
127bba
 
127bba
     if (!shmem->server.enabled) {
127bba
         virBufferAsprintf(&buf, ",shm=%s,id=%s", shmem->name, shmem->info.alias);
127bba
@@ -8505,13 +8488,6 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def,
127bba
         }
127bba
     }
127bba
 
127bba
-    if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
127bba
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
127bba
-                       _("only 'pci' addresses are supported for the "
127bba
-                         "shared memory device"));
127bba
-        goto error;
127bba
-    }
127bba
-
127bba
     if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0)
127bba
         goto error;
127bba
 
127bba
@@ -8558,6 +8534,32 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
127bba
 {
127bba
     char *devstr = NULL;
127bba
 
127bba
+    if (shmem->size) {
127bba
+        /*
127bba
+         * Thanks to our parsing code, we have a guarantee that the
127bba
+         * size is power of two and is at least a mebibyte in size.
127bba
+         * But because it may change in the future, the checks are
127bba
+         * doubled in here.
127bba
+         */
127bba
+        if (shmem->size & (shmem->size - 1)) {
127bba
+            virReportError(VIR_ERR_XML_ERROR, "%s",
127bba
+                           _("shmem size must be a power of two"));
127bba
+            return -1;
127bba
+        }
127bba
+        if (shmem->size < 1024 * 1024) {
127bba
+            virReportError(VIR_ERR_XML_ERROR, "%s",
127bba
+                           _("shmem size must be at least 1 MiB (1024 KiB)"));
127bba
+            return -1;
127bba
+        }
127bba
+    }
127bba
+
127bba
+    if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
127bba
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
127bba
+                       _("only 'pci' addresses are supported for the "
127bba
+                         "shared memory device"));
127bba
+        return -1;
127bba
+    }
127bba
+
127bba
     if (!(devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps)))
127bba
         return -1;
127bba
     virCommandAddArgList(cmd, "-device", devstr, NULL);
127bba
-- 
127bba
2.10.2
127bba