qemuBuildWatchdogCommandLine: Generate via JSON

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>
This commit is contained in:
Peter Krempa 2021-09-27 14:37:48 +02:00
parent 8617d29abb
commit a4229c087e
3 changed files with 22 additions and 23 deletions

View File

@ -4157,21 +4157,22 @@ qemuBuildHostNetStr(virDomainNetDef *net,
} }
char * virJSONValue *
qemuBuildWatchdogDevStr(const virDomainDef *def, qemuBuildWatchdogDevProps(const virDomainDef *def,
virDomainWatchdogDef *dev, virDomainWatchdogDef *dev)
virQEMUCaps *qemuCaps G_GNUC_UNUSED)
{ {
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props = NULL;
virBufferAsprintf(&buf, "%s,id=%s", if (virJSONValueObjectCreate(&props,
virDomainWatchdogModelTypeToString(dev->model), "s:driver", virDomainWatchdogModelTypeToString(dev->model),
dev->info.alias); "s:id", dev->info.alias,
NULL) < 0)
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0)
return NULL; 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) virQEMUCaps *qemuCaps)
{ {
virDomainWatchdogDef *watchdog = def->watchdog; virDomainWatchdogDef *watchdog = def->watchdog;
g_autofree char *optstr = NULL; g_autoptr(virJSONValue) props = NULL;
const char *action; const char *action;
int actualAction; int actualAction;
@ -4191,13 +4192,11 @@ qemuBuildWatchdogCommandLine(virCommand *cmd,
if (qemuCommandAddExtDevice(cmd, &def->watchdog->info) < 0) if (qemuCommandAddExtDevice(cmd, &def->watchdog->info) < 0)
return -1; return -1;
virCommandAddArg(cmd, "-device"); if (!(props = qemuBuildWatchdogDevProps(def, watchdog)))
optstr = qemuBuildWatchdogDevStr(def, watchdog, qemuCaps);
if (!optstr)
return -1; 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 /* qemu doesn't have a 'dump' action; we tell qemu to 'pause', then
libvirt listens for the watchdog event, and we perform the dump libvirt listens for the watchdog event, and we perform the dump

View File

@ -234,9 +234,9 @@ char *qemuBuildShmemDevStr(virDomainDef *def,
virQEMUCaps *qemuCaps) virQEMUCaps *qemuCaps)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
char *qemuBuildWatchdogDevStr(const virDomainDef *def, virJSONValue *
virDomainWatchdogDef *dev, qemuBuildWatchdogDevProps(const virDomainDef *def,
virQEMUCaps *qemuCaps); virDomainWatchdogDef *dev);
int qemuBuildInputDevStr(char **devstr, int qemuBuildInputDevStr(char **devstr,
const virDomainDef *def, const virDomainDef *def,

View File

@ -3121,7 +3121,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
int ret = -1; int ret = -1;
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_WATCHDOG, { .watchdog = watchdog } }; virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_WATCHDOG, { .watchdog = watchdog } };
g_autofree char *watchdogstr = NULL; g_autoptr(virJSONValue) props = NULL;
bool releaseAddress = false; bool releaseAddress = false;
int rv; int rv;
@ -3145,7 +3145,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
goto cleanup; goto cleanup;
} }
if (!(watchdogstr = qemuBuildWatchdogDevStr(vm->def, watchdog, priv->qemuCaps))) if (!(props = qemuBuildWatchdogDevProps(vm->def, watchdog)))
goto cleanup; goto cleanup;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
@ -3203,7 +3203,7 @@ qemuDomainAttachWatchdog(virQEMUDriver *driver,
} }
if (rv >= 0) if (rv >= 0)
rv = qemuMonitorAddDevice(priv->mon, watchdogstr); rv = qemuMonitorAddDeviceProps(priv->mon, &props);
if (qemuDomainObjExitMonitor(driver, vm) < 0) { if (qemuDomainObjExitMonitor(driver, vm) < 0) {
releaseAddress = false; releaseAddress = false;