[PATCH v1 20/24] qemu_command.c: move 'panic' validation to qemu_validate.c

Daniel Henrique Barboza danielhb413 at gmail.com
Wed Oct 14 20:43:03 UTC 2020


Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/qemu/qemu_command.c                       | 78 +--------------
 src/qemu/qemu_validate.c                      | 96 +++++++++++++++++++
 .../pseries-panic-address.err                 |  2 +-
 tests/qemuxml2argvtest.c                      | 10 +-
 tests/qemuxml2xmltest.c                       |  8 +-
 5 files changed, 111 insertions(+), 83 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 16bb8dbdbe..ed14e1d01f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9325,78 +9325,13 @@ qemuBuildVMCoreInfoCommandLine(virCommandPtr cmd,
 
 static int
 qemuBuildPanicCommandLine(virCommandPtr cmd,
-                          const virDomainDef *def,
-                          virQEMUCapsPtr qemuCaps)
+                          const virDomainDef *def)
 {
     size_t i;
 
     for (i = 0; i < def->npanics; i++) {
         switch ((virDomainPanicModel) def->panics[i]->model) {
-        case VIR_DOMAIN_PANIC_MODEL_S390:
-            /* For s390 guests, the hardware provides the same
-             * functionality as the pvpanic device. The address
-             * cannot be configured by the user */
-            if (!ARCH_IS_S390(def->os.arch)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("only S390 guests support "
-                                 "panic device of model 's390'"));
-                return -1;
-            }
-            if (def->panics[i]->info.type !=
-                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("setting the panic device address is not "
-                                 "supported for model 's390'"));
-                return -1;
-            }
-            break;
-
-        case VIR_DOMAIN_PANIC_MODEL_HYPERV:
-            /* Panic with model 'hyperv' is not a device, it should
-             * be configured in cpu commandline. The address
-             * cannot be configured by the user */
-            if (!ARCH_IS_X86(def->os.arch)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("only i686 and x86_64 guests support "
-                                 "panic device of model 'hyperv'"));
-                return -1;
-            }
-            if (def->panics[i]->info.type !=
-                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("setting the panic device address is not "
-                                 "supported for model 'hyperv'"));
-                return -1;
-            }
-            break;
-
-        case VIR_DOMAIN_PANIC_MODEL_PSERIES:
-            /* For pSeries guests, the firmware provides the same
-             * functionality as the pvpanic device. The address
-             * cannot be configured by the user */
-            if (!qemuDomainIsPSeries(def)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("only pSeries guests support panic device "
-                                 "of model 'pseries'"));
-                return -1;
-            }
-            if (def->panics[i]->info.type !=
-                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("setting the panic device address is not "
-                                 "supported for model 'pseries'"));
-                return -1;
-            }
-            break;
-
         case VIR_DOMAIN_PANIC_MODEL_ISA:
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PANIC)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("the QEMU binary does not support the "
-                                 "ISA panic device"));
-                return -1;
-            }
-
             switch (def->panics[i]->info.type) {
             case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
                 virCommandAddArg(cmd, "-device");
@@ -9407,14 +9342,11 @@ qemuBuildPanicCommandLine(virCommandPtr cmd,
             case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
                 virCommandAddArgList(cmd, "-device", "pvpanic", NULL);
                 break;
-
-            default:
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("panic is supported only "
-                                 "with ISA address type"));
-                return -1;
             }
 
+        case VIR_DOMAIN_PANIC_MODEL_S390:
+        case VIR_DOMAIN_PANIC_MODEL_HYPERV:
+        case VIR_DOMAIN_PANIC_MODEL_PSERIES:
         /* default model value was changed before in post parse */
         case VIR_DOMAIN_PANIC_MODEL_DEFAULT:
         case VIR_DOMAIN_PANIC_MODEL_LAST:
@@ -10017,7 +9949,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     if (qemuBuildSeccompSandboxCommandLine(cmd, cfg, qemuCaps) < 0)
         return NULL;
 
-    if (qemuBuildPanicCommandLine(cmd, def, qemuCaps) < 0)
+    if (qemuBuildPanicCommandLine(cmd, def) < 0)
         return NULL;
 
     for (i = 0; i < def->nshmems; i++) {
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 7969571b4a..a5e3849ae5 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -878,6 +878,99 @@ qemuValidateDomainDefSysinfo(const virSysinfoDef *def,
 }
 
 
+static int
+qemuValidateDomainDefPanic(const virDomainDef *def,
+                           virQEMUCapsPtr qemuCaps)
+{
+    size_t i;
+
+    for (i = 0; i < def->npanics; i++) {
+        switch ((virDomainPanicModel) def->panics[i]->model) {
+        case VIR_DOMAIN_PANIC_MODEL_S390:
+            /* For s390 guests, the hardware provides the same
+             * functionality as the pvpanic device. The address
+             * cannot be configured by the user */
+            if (!ARCH_IS_S390(def->os.arch)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("only S390 guests support "
+                                 "panic device of model 's390'"));
+                return -1;
+            }
+            if (def->panics[i]->info.type !=
+                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("setting the panic device address is not "
+                                 "supported for model 's390'"));
+                return -1;
+            }
+            break;
+
+        case VIR_DOMAIN_PANIC_MODEL_HYPERV:
+            /* Panic with model 'hyperv' is not a device, it should
+             * be configured in cpu commandline. The address
+             * cannot be configured by the user */
+            if (!ARCH_IS_X86(def->os.arch)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("only i686 and x86_64 guests support "
+                                 "panic device of model 'hyperv'"));
+                return -1;
+            }
+            if (def->panics[i]->info.type !=
+                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("setting the panic device address is not "
+                                 "supported for model 'hyperv'"));
+                return -1;
+            }
+            break;
+
+        case VIR_DOMAIN_PANIC_MODEL_PSERIES:
+            /* For pSeries guests, the firmware provides the same
+             * functionality as the pvpanic device. The address
+             * cannot be configured by the user */
+            if (!qemuDomainIsPSeries(def)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("only pSeries guests support panic device "
+                                 "of model 'pseries'"));
+                return -1;
+            }
+            if (def->panics[i]->info.type !=
+                VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("setting the panic device address is not "
+                                 "supported for model 'pseries'"));
+                return -1;
+            }
+            break;
+
+        case VIR_DOMAIN_PANIC_MODEL_ISA:
+            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PANIC)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("the QEMU binary does not support the "
+                                 "ISA panic device"));
+                return -1;
+            }
+
+            if (def->panics[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+                def->panics[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("panic is supported only "
+                                 "with ISA address type"));
+                return -1;
+            }
+            break;
+
+        /* default model value was changed before in post parse */
+        case VIR_DOMAIN_PANIC_MODEL_DEFAULT:
+        case VIR_DOMAIN_PANIC_MODEL_LAST:
+            break;
+        }
+    }
+
+    return 0;
+}
+
+
 int
 qemuValidateDomainDef(const virDomainDef *def,
                       void *opaque)
@@ -1112,6 +1205,9 @@ qemuValidateDomainDef(const virDomainDef *def,
             return -1;
     }
 
+    if (qemuValidateDomainDefPanic(def, qemuCaps) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/pseries-panic-address.err b/tests/qemuxml2argvdata/pseries-panic-address.err
index c7a512c51e..63afb4ff00 100644
--- a/tests/qemuxml2argvdata/pseries-panic-address.err
+++ b/tests/qemuxml2argvdata/pseries-panic-address.err
@@ -1 +1 @@
-unsupported configuration: 'spapr-vty' is not supported in this QEMU binary
+unsupported configuration: setting the panic device address is not supported for model 'pseries'
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index fdcfadf4c8..73e3a91282 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2064,8 +2064,8 @@ mymain(void)
     DO_TEST("pseries-panic-no-address",
             QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
             QEMU_CAPS_DEVICE_SPAPR_VTY);
-    DO_TEST_FAILURE("pseries-panic-address",
-                    QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
+    DO_TEST_PARSE_ERROR("pseries-panic-address",
+                        QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
 
     DO_TEST("pseries-phb-simple",
             QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
@@ -2377,9 +2377,9 @@ mymain(void)
     DO_TEST("s390-panic-no-address",
             QEMU_CAPS_CCW,
             QEMU_CAPS_VIRTIO_S390);
-    DO_TEST_FAILURE("s390-panic-address",
-            QEMU_CAPS_CCW,
-            QEMU_CAPS_VIRTIO_S390);
+    DO_TEST_PARSE_ERROR("s390-panic-address",
+                        QEMU_CAPS_CCW,
+                        QEMU_CAPS_VIRTIO_S390);
     DO_TEST("s390-panic-missing",
             QEMU_CAPS_CCW,
             QEMU_CAPS_VIRTIO_S390);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 7160653471..1cd57c6bc1 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -1116,12 +1116,12 @@ mymain(void)
             QEMU_CAPS_DEVICE_QXL,
             QEMU_CAPS_Q35_PCI_HOLE64_SIZE);
 
-    DO_TEST("panic", NONE);
-    DO_TEST("panic-isa", NONE);
+    DO_TEST("panic", QEMU_CAPS_DEVICE_PANIC);
+    DO_TEST("panic-isa", QEMU_CAPS_DEVICE_PANIC);
     DO_TEST("panic-pseries",
             QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
-    DO_TEST("panic-double", NONE);
-    DO_TEST("panic-no-address", NONE);
+    DO_TEST("panic-double", QEMU_CAPS_DEVICE_PANIC);
+    DO_TEST("panic-no-address", QEMU_CAPS_DEVICE_PANIC);
 
     DO_TEST("disk-backing-chains", NONE);
     DO_TEST("disk-backing-chains-index", NONE);
-- 
2.26.2




More information about the libvir-list mailing list