The 'usb-redir' device has the following types according to QEMU for
properties we control:
chardev=<str> - ID of a chardev to use as a backend
filter=<str>
bootindex=<int32>
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 49 +++++++++++++++++++++++------------------
src/qemu/qemu_command.h | 6 ++---
src/qemu/qemu_hotplug.c | 6 ++---
3 files changed, 33 insertions(+), 28 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 810a4cc760..bab1da1c11 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9710,20 +9710,17 @@ qemuBuildConsoleCommandLine(virLogManager *logManager,
}
-char *
-qemuBuildRedirdevDevStr(const virDomainDef *def,
- virDomainRedirdevDef *dev,
- virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+virJSONValue *
+qemuBuildRedirdevDevProps(const virDomainDef *def,
+ virDomainRedirdevDef *dev)
{
- size_t i;
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_autoptr(virJSONValue) props = NULL;
virDomainRedirFilterDef *redirfilter = def->redirfilter;
+ g_autofree char *filter = NULL;
- virBufferAsprintf(&buf, "usb-redir,chardev=char%s,id=%s",
- dev->info.alias, dev->info.alias);
-
- if (redirfilter && redirfilter->nusbdevs) {
- virBufferAddLit(&buf, ",filter=");
+ if (redirfilter) {
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ size_t i;
for (i = 0; i < redirfilter->nusbdevs; i++) {
virDomainRedirFilterUSBDevDef *usbdev = redirfilter->usbdevs[i];
@@ -9747,19 +9744,26 @@ qemuBuildRedirdevDevStr(const virDomainDef *def,
else
virBufferAddLit(&buf, "-1:");
- virBufferAsprintf(&buf, "%u", usbdev->allow);
- if (i < redirfilter->nusbdevs -1)
- virBufferAddLit(&buf, "|");
+ virBufferAsprintf(&buf, "%u|", usbdev->allow);
}
+ virBufferTrim(&buf, "|");
+
+ filter = virBufferContentAndReset(&buf);
}
- if (dev->info.bootIndex)
- virBufferAsprintf(&buf, ",bootindex=%u", dev->info.bootIndex);
+ if (virJSONValueObjectCreate(&props,
+ "s:driver", "usb-redir",
+ "f:chardev",
g_strdup_printf("char%s", dev->info.alias),
+ "s:id", dev->info.alias,
+ "S:filter", filter,
+ "p:bootindex", dev->info.bootIndex,
+ 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);
}
@@ -9780,6 +9784,7 @@ qemuBuildRedirdevCommandLine(virLogManager *logManager,
for (i = 0; i < def->nredirdevs; i++) {
virDomainRedirdevDef *redirdev = def->redirdevs[i];
+ g_autoptr(virJSONValue) devprops = NULL;
char *devstr;
if (!(devstr = qemuBuildChrChardevStr(logManager, secManager,
@@ -9794,11 +9799,11 @@ qemuBuildRedirdevCommandLine(virLogManager *logManager,
virCommandAddArg(cmd, devstr);
VIR_FREE(devstr);
- virCommandAddArg(cmd, "-device");
- if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, qemuCaps)))
+ if (!(devprops = qemuBuildRedirdevDevProps(def, redirdev)))
+ return -1;
+
+ if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
return -1;
- virCommandAddArg(cmd, devstr);
- VIR_FREE(devstr);
}
return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 6995780f83..f965125277 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -204,9 +204,9 @@ virJSONValue *
qemuBuildHostdevMediatedDevProps(const virDomainDef *def,
virDomainHostdevDef *dev);
-char *qemuBuildRedirdevDevStr(const virDomainDef *def,
- virDomainRedirdevDef *dev,
- virQEMUCaps *qemuCaps);
+virJSONValue *
+qemuBuildRedirdevDevProps(const virDomainDef *def,
+ virDomainRedirdevDef *dev);
char *qemuBuildZPCIDevStr(virDomainDeviceInfo *dev);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e1db3d55f3..422ab267cf 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1961,7 +1961,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriver *driver,
qemuDomainObjPrivate *priv = vm->privateData;
virDomainDef *def = vm->def;
g_autofree char *charAlias = NULL;
- g_autofree char *devstr = NULL;
+ g_autoptr(virJSONValue) devprops = NULL;
bool chardevAdded = false;
g_autofree char *tlsAlias = NULL;
const char *secAlias = NULL;
@@ -1976,7 +1976,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriver *driver,
if ((virDomainUSBAddressEnsure(priv->usbaddrs, &redirdev->info)) < 0)
return -1;
- if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, priv->qemuCaps)))
+ if (!(devprops = qemuBuildRedirdevDevProps(def, redirdev)))
goto cleanup;
VIR_REALLOC_N(def->redirdevs, def->nredirdevs+1);
@@ -1994,7 +1994,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriver *driver,
goto exit_monitor;
chardevAdded = true;
- if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+ if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0)
goto exit_monitor;
if (qemuDomainObjExitMonitor(driver, vm) < 0)
--
2.31.1