]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Validate watchdog action compatibility per-device
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 19 Apr 2023 12:07:26 +0000 (14:07 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Thu, 20 Apr 2023 08:17:35 +0000 (10:17 +0200)
This makes it also work during attach.  Also add a test for attaching a
watchdog with incompatible action.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2187278
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_validate.c
tests/qemuhotplugtest.c
tests/qemuhotplugtestdevices/qemuhotplug-watchdog-reset.xml [new file with mode: 0644]
tests/qemuhotplugtestdomains/qemuhotplug-base-live+watchdog+watchdog-reset.xml [new symlink]

index a03f7056b191473c190161ebc2da67bc38386390..b2c3fd1785bc99b87b4a0770b052d56defef98c0 100644 (file)
@@ -1114,16 +1114,6 @@ qemuValidateDomainDefWatchdogs(const virDomainDef *def)
     size_t i = 0;
 
     for (i = 0; i < def->nwatchdogs; i++) {
-        /* We could theoretically support different watchdogs having dump and
-         * pause, but let's be honest, we support multiple watchdogs only
-         * because we need to be able to add a second, implicit one, not because
-         * it is a brilliant idea to have multiple watchdogs. */
-        if (def->watchdogs[i]->action != def->watchdogs[0]->action) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("watchdogs with different actions are not supported "
-                             "with this QEMU binary"));
-            return -1;
-        }
 
         if (def->watchdogs[i]->model == VIR_DOMAIN_WATCHDOG_MODEL_ITCO) {
             if (found_itco) {
@@ -2308,6 +2298,18 @@ static int
 qemuValidateDomainWatchdogDef(const virDomainWatchdogDef *dev,
                               const virDomainDef *def)
 {
+    /* We could theoretically support different watchdogs having dump and
+     * pause, but let's be honest, we support multiple watchdogs only
+     * because we need to be able to add a second, implicit one, not because
+     * it is a brilliant idea to have multiple watchdogs. */
+    if (def->nwatchdogs &&
+        def->watchdogs[0]->action != dev->action) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("watchdogs with different actions are not supported "
+                         "with this QEMU binary"));
+        return -1;
+    }
+
     switch ((virDomainWatchdogModel) dev->model) {
     case VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB:
         if (dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
index 63a6833cfde72bbd44a4d5decf6c057bba59aaa8..6aaccce55b391618bc2c5f94b293e06cca3260a7 100644 (file)
@@ -908,6 +908,9 @@ mymain(void)
     DO_TEST_DETACH("x86_64", "base-live", "watchdog-user-alias-full", false, false,
                    "device_del", QMP_DEVICE_DELETED("ua-UserWatchdog") QMP_OK);
 
+    /* attaching a watchdog with different action should fail */
+    DO_TEST_ATTACH("x86_64", "base-live+watchdog", "watchdog-reset", true, false, NULL);
+
     DO_TEST_ATTACH("x86_64", "base-live", "guestfwd", false, true,
                    "getfd", QMP_OK,
                    "chardev-add", QMP_OK,
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-watchdog-reset.xml b/tests/qemuhotplugtestdevices/qemuhotplug-watchdog-reset.xml
new file mode 100644 (file)
index 0000000..cb1c072
--- /dev/null
@@ -0,0 +1 @@
+<watchdog model='i6300esb' action='reset'/>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+watchdog+watchdog-reset.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+watchdog+watchdog-reset.xml
new file mode 120000 (symlink)
index 0000000..d3d1764
--- /dev/null
@@ -0,0 +1 @@
+qemuhotplug-base-live+watchdog.xml
\ No newline at end of file