qemu: command: Introduce helper for building JSON props of -device into commandline

The helper converts the JSON object to a string and adds it to the
current command as arguments of '-device'. The helper also prepares for
'-device' taking JSON directly.

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-25 09:08:05 +02:00
parent 89b5bc626a
commit feaeab09ea

View File

@ -221,6 +221,33 @@ qemuBuildNetdevCommandlineFromJSON(virCommand *cmd,
}
static G_GNUC_UNUSED int
qemuBuildDeviceCommandlineFromJSON(virCommand *cmd,
virJSONValue *props,
virQEMUCaps *qemuCaps)
{
g_autofree char *arg = NULL;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_JSON)) {
if (!(arg = virJSONValueToString(props, false)))
return -1;
} else {
const char *driver = virJSONValueObjectGetString(props, "driver");
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, "%s,", driver);
if (virQEMUBuildCommandLineJSON(props, &buf, "driver", NULL) < 0)
return -1;
arg = virBufferContentAndReset(&buf);
}
virCommandAddArgList(cmd, "-device", arg, NULL);
return 0;
}
/**
* qemuBuildMasterKeyCommandLine:
* @cmd: the command to modify