]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildWatchdogCommandLine: Generate via JSON
authorPeter Krempa <pkrempa@redhat.com>
Mon, 27 Sep 2021 12:37:48 +0000 (14:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:26:03 +0000 (10:26 +0200)
The watchdog doesn't have any special properties.

Convert the command line generator and hotplug code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_hotplug.c

index ee882da9e708c0a26c4057804296f7939aa470a7..38a6109c926bbcee3c7f11adcb671b1e5c87b429 100644 (file)
@@ -4157,21 +4157,22 @@ qemuBuildHostNetStr(virDomainNetDef *net,
 }
 
 
-char *
-qemuBuildWatchdogDevStr(const virDomainDef *def,
-                        virDomainWatchdogDef *dev,
-                        virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+virJSONValue *
+qemuBuildWatchdogDevProps(const virDomainDef *def,
+                          virDomainWatchdogDef *dev)
 {
-    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autoptr(virJSONValue) props = NULL;
 
-    virBufferAsprintf(&buf, "%s,id=%s",
-                      virDomainWatchdogModelTypeToString(dev->model),
-                      dev->info.alias);
+    if (virJSONValueObjectCreate(&props,
+                                 "s:driver", virDomainWatchdogModelTypeToString(dev->model),
+                                 "s:id", dev->info.alias,
+                                 NULL) < 0)
+        return NULL;
 
-    if (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0)
+    if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0)
         return NULL;
 
-    return virBufferContentAndReset(&buf);
+    return g_steal_pointer(&props);
 }
 
 
@@ -4181,7 +4182,7 @@ qemuBuildWatchdogCommandLine(virCommand *cmd,
                              virQEMUCaps *qemuCaps)
 {
     virDomainWatchdogDef *watchdog = def->watchdog;
-    g_autofree char *optstr = NULL;
+    g_autoptr(virJSONValue) props = NULL;
     const char *action;
     int actualAction;
 
@@ -4191,13 +4192,11 @@ qemuBuildWatchdogCommandLine(virCommand *cmd,
     if (qemuCommandAddExtDevice(cmd, &def->watchdog->info) < 0)
         return -1;
 
-    virCommandAddArg(cmd, "-device");
-
-    optstr = qemuBuildWatchdogDevStr(def, watchdog, qemuCaps);
-    if (!optstr)
+    if (!(props = qemuBuildWatchdogDevProps(def, watchdog)))
         return -1;
 
-    virCommandAddArg(cmd, optstr);
+    if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps))
+        return -1;
 
     /* qemu doesn't have a 'dump' action; we tell qemu to 'pause', then
        libvirt listens for the watchdog event, and we perform the dump
index d59a55e8aa93b0ec717f7a3a108087e84509ab02..6ce151d8d9245cb4a686d6cc09fdea935af53040 100644 (file)
@@ -234,9 +234,9 @@ char *qemuBuildShmemDevStr(virDomainDef *def,
                            virQEMUCaps *qemuCaps)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
-char *qemuBuildWatchdogDevStr(const virDomainDef *def,
-                              virDomainWatchdogDef *dev,
-                              virQEMUCaps *qemuCaps);
+virJSONValue *
+qemuBuildWatchdogDevProps(const virDomainDef *def,
+                          virDomainWatchdogDef *dev);
 
 int qemuBuildInputDevStr(char **devstr,
                          const virDomainDef *def,
index d5f6722d5aee50162f83441e46f97f2e079ca171..f833a619a7cbc533272fc6946a382beb6dca17d1 100644 (file)
@@ -3121,7 +3121,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
     int ret = -1;
     qemuDomainObjPrivate *priv = vm->privateData;
     virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_WATCHDOG, { .watchdog = watchdog } };
-    g_autofree char *watchdogstr = NULL;
+    g_autoptr(virJSONValue) props = NULL;
     bool releaseAddress = false;
     int rv;
 
@@ -3145,7 +3145,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
         goto cleanup;
     }
 
-    if (!(watchdogstr = qemuBuildWatchdogDevStr(vm->def, watchdog, priv->qemuCaps)))
+    if (!(props = qemuBuildWatchdogDevProps(vm->def, watchdog)))
         goto cleanup;
 
     qemuDomainObjEnterMonitor(driver, vm);
@@ -3203,7 +3203,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
     }
 
     if (rv >= 0)
-        rv = qemuMonitorAddDevice(priv->mon, watchdogstr);
+        rv = qemuMonitorAddDeviceProps(priv->mon, &props);
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
         releaseAddress = false;