Internally format the PCI controller properties into JSON, but convert
it back to a string as preparation for upcoming refactors.
The following types are declared for the properties we use by QEMU:
'nec-usb-xhci'
p2=<uint32> - (default: 4)
p3=<uint32> - (default: 4)
'ich9-usb-uhci6'
masterbus=<str>
firstport=<uint32> - (default: 0)
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 61 +++++++++++++++++++++++++++--------------
1 file changed, 41 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f7a2304d5c..2f1d4b846a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2828,37 +2828,48 @@ qemuBuildUSBControllerFindMasterAlias(const virDomainDef
*domainDef,
}
-static int
-qemuBuildUSBControllerDevStr(const virDomainDef *domainDef,
- virDomainControllerDef *def,
- virQEMUCaps *qemuCaps,
- virBuffer *buf)
+static virJSONValue *
+qemuBuildUSBControllerDevProps(const virDomainDef *domainDef,
+ virDomainControllerDef *def,
+ virQEMUCaps *qemuCaps)
{
- if (qemuValidateDomainDeviceDefControllerUSB(def, qemuCaps) < 0)
- return -1;
+ g_autoptr(virJSONValue) props = NULL;
- virBufferAsprintf(buf, "%s",
qemuControllerModelUSBTypeToString(def->model));
+ if (qemuValidateDomainDeviceDefControllerUSB(def, qemuCaps) < 0)
+ return NULL;
- if (def->opts.usbopts.ports != -1) {
- virBufferAsprintf(buf, ",p2=%d,p3=%d",
- def->opts.usbopts.ports, def->opts.usbopts.ports);
- }
+ if (virJSONValueObjectCreate(&props,
+ "s:driver",
qemuControllerModelUSBTypeToString(def->model),
+ "k:p2", def->opts.usbopts.ports,
+ "k:p3", def->opts.usbopts.ports,
+ NULL) < 0)
+ return NULL;
if (def->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) {
- const char *masterbus;
+ const char *alias;
- if (!(masterbus = qemuBuildUSBControllerFindMasterAlias(domainDef, def))) {
+ if (!(alias = qemuBuildUSBControllerFindMasterAlias(domainDef, def))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("masterbus not found"));
- return -1;
+ return NULL;
}
- virBufferAsprintf(buf, ",masterbus=%s.0,firstport=%d",
- masterbus, def->info.master.usb.startport);
+
+ if (virJSONValueObjectAdd(props,
+ "s:masterbus",
g_strdup_printf("%s.0", alias),
+ "i:firstport",
def->info.master.usb.startport,
+ NULL) < 0)
+ return NULL;
} else {
- virBufferAsprintf(buf, ",id=%s", def->info.alias);
+ if (virJSONValueObjectAdd(props,
+ "s:id", def->info.alias,
+ NULL) < 0)
+ return NULL;
}
- return 0;
+ if (qemuBuildDeviceAddressProps(props, domainDef, &def->info) < 0)
+ return NULL;
+
+ return g_steal_pointer(&props);
}
@@ -3125,9 +3136,19 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
break;
case VIR_DOMAIN_CONTROLLER_TYPE_USB:
- if (qemuBuildUSBControllerDevStr(domainDef, def, qemuCaps, &buf) == -1)
+ if (!(props = qemuBuildUSBControllerDevProps(domainDef, def, qemuCaps)))
return -1;
+ driver = virJSONValueObjectGetString(props, "driver");
+
+ virBufferAsprintf(&buf, "%s,", driver);
+
+ if (virQEMUBuildCommandLineJSON(props, &buf, "driver", NULL) <
0)
+ return -1;
+
+ *devstr = virBufferContentAndReset(&buf);
+
+ return 0;
break;
case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
--
2.31.1