From a4229c087e0c86f12a28ab4adf0a8c920bf1987c Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 27 Sep 2021 14:37:48 +0200 Subject: [PATCH] qemuBuildWatchdogCommandLine: Generate via JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The watchdog doesn't have any special properties. Convert the command line generator and hotplug code. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 33 ++++++++++++++++----------------- src/qemu/qemu_command.h | 6 +++--- src/qemu/qemu_hotplug.c | 6 +++--- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ee882da9e7..38a6109c92 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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 (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0) + if (virJSONValueObjectCreate(&props, + "s:driver", virDomainWatchdogModelTypeToString(dev->model), + "s:id", dev->info.alias, + NULL) < 0) return NULL; - return virBufferContentAndReset(&buf); + if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0) + return NULL; + + 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 diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index d59a55e8aa..6ce151d8d9 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -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, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d5f6722d5a..f833a619a7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -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;