]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move common checks outside qemuBuildShmemDevLegacyStr
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 8 Aug 2016 11:44:38 +0000 (13:44 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 20 Sep 2016 13:42:43 +0000 (15:42 +0200)
Some checks will need to be performed for newer device types as well, so
let's not duplicate them.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_command.c

index 70c44c8ec94e6ddf241bfa77f0d650ade3b6651a..f288a3630bf2c2ef3f0454a9b5ab5bc5870530a2 100644 (file)
@@ -8514,29 +8514,12 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("ivshmem device is not supported "
                          "with this QEMU binary"));
-        goto error;
+        return NULL;
     }
 
     virBufferAddLit(&buf, "ivshmem");
-    if (shmem->size) {
-        /*
-         * Thanks to our parsing code, we have a guarantee that the
-         * size is power of two and is at least a mebibyte in size.
-         * But because it may change in the future, the checks are
-         * doubled in here.
-         */
-        if (shmem->size & (shmem->size - 1)) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("shmem size must be a power of two"));
-            goto error;
-        }
-        if (shmem->size < 1024 * 1024) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("shmem size must be at least 1 MiB (1024 KiB)"));
-            goto error;
-        }
+    if (shmem->size)
         virBufferAsprintf(&buf, ",size=%llum", shmem->size >> 20);
-    }
 
     if (!shmem->server.enabled) {
         virBufferAsprintf(&buf, ",shm=%s,id=%s", shmem->name, shmem->info.alias);
@@ -8552,13 +8535,6 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def,
         }
     }
 
-    if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("only 'pci' addresses are supported for the "
-                         "shared memory device"));
-        goto error;
-    }
-
     if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0)
         goto error;
 
@@ -8605,6 +8581,32 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
 {
     char *devstr = NULL;
 
+    if (shmem->size) {
+        /*
+         * Thanks to our parsing code, we have a guarantee that the
+         * size is power of two and is at least a mebibyte in size.
+         * But because it may change in the future, the checks are
+         * doubled in here.
+         */
+        if (shmem->size & (shmem->size - 1)) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("shmem size must be a power of two"));
+            return -1;
+        }
+        if (shmem->size < 1024 * 1024) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("shmem size must be at least 1 MiB (1024 KiB)"));
+            return -1;
+        }
+    }
+
+    if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("only 'pci' addresses are supported for the "
+                         "shared memory device"));
+        return -1;
+    }
+
     if (!(devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps)))
         return -1;
     virCommandAddArgList(cmd, "-device", devstr, NULL);