The 'vfio-pci-nohotplug' device has the following property types
according to QEMU:
display=<OnOffAuto> - on/off/auto (default: "off")
sysfsdev=<str>
ramfb=<bool>
bootindex=<int32>
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 48 ++++++++++++++++++-----------------------
src/qemu/qemu_command.h | 7 +++---
src/qemu/qemu_hotplug.c | 7 +++---
3 files changed, 27 insertions(+), 35 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index b321c964ab..2f9e99068a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5338,40 +5338,34 @@
qemuBuildHostdevMdevModelTypeString(virDomainHostdevSubsysMediatedDev *mdev)
}
-char *
-qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
- virDomainHostdevDef *dev,
- virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+virJSONValue *
+qemuBuildHostdevMediatedDevProps(const virDomainDef *def,
+ virDomainHostdevDef *dev)
{
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_autoptr(virJSONValue) props = NULL;
virDomainHostdevSubsysMediatedDev *mdevsrc = &dev->source.subsys.u.mdev;
g_autofree char *mdevPath = NULL;
- const char *dev_str = NULL;
mdevPath = virMediatedDeviceGetSysfsPath(mdevsrc->uuidstr);
- dev_str = qemuBuildHostdevMdevModelTypeString(mdevsrc);
- if (!dev_str)
+ if (virJSONValueObjectCreate(&props,
+ "s:driver",
qemuBuildHostdevMdevModelTypeString(mdevsrc),
+ "s:id", dev->info->alias,
+ "s:sysfsdev", mdevPath,
+ "S:display",
qemuOnOffAuto(mdevsrc->display),
+ NULL) < 0)
return NULL;
- virBufferAdd(&buf, dev_str, -1);
- virBufferAsprintf(&buf, ",id=%s,sysfsdev=%s", dev->info->alias,
mdevPath);
-
- if (mdevsrc->display != VIR_TRISTATE_SWITCH_ABSENT)
- virBufferAsprintf(&buf, ",display=%s",
- virTristateSwitchTypeToString(mdevsrc->display));
-
- if (qemuBuildDeviceAddressStr(&buf, def, dev->info) < 0)
+ if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0)
return NULL;
- if (dev->info->bootIndex)
- virBufferAsprintf(&buf, ",bootindex=%u",
dev->info->bootIndex);
-
- if (mdevsrc->ramfb == VIR_TRISTATE_SWITCH_ON)
- virBufferAsprintf(&buf, ",ramfb=%s",
- virTristateSwitchTypeToString(mdevsrc->ramfb));
+ if (virJSONValueObjectAdd(props,
+ "T:ramfb", mdevsrc->ramfb,
+ "p:bootindex", dev->info->bootIndex,
+ NULL) < 0)
+ return NULL;
- return virBufferContentAndReset(&buf);
+ return g_steal_pointer(&props);
}
@@ -5502,6 +5496,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd,
virDomainHostdevSubsys *subsys = &hostdev->source.subsys;
virDomainHostdevSubsysMediatedDev *mdevsrc = &subsys->u.mdev;
g_autofree char *devstr = NULL;
+ g_autoptr(virJSONValue) devprops = NULL;
g_autofree char *vhostfdName = NULL;
int vhostfd = -1;
@@ -5581,12 +5576,11 @@ qemuBuildHostdevCommandLine(virCommand *cmd,
return -1;
}
- virCommandAddArg(cmd, "-device");
- if (!(devstr =
- qemuBuildHostdevMediatedDevStr(def, hostdev, qemuCaps)))
+ if (!(devprops = qemuBuildHostdevMediatedDevProps(def, hostdev)))
return -1;
- virCommandAddArg(cmd, devstr);
+ if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
+ return -1;
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 709b75c252..45a9cb0ac1 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -199,10 +199,9 @@ qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def,
virQEMUCaps *qemuCaps,
char *vhostfdName);
-char *
-qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
- virDomainHostdevDef *dev,
- virQEMUCaps *qemuCaps);
+virJSONValue *
+qemuBuildHostdevMediatedDevProps(const virDomainDef *def,
+ virDomainHostdevDef *dev);
char *qemuBuildRedirdevDevStr(const virDomainDef *def,
virDomainRedirdevDef *dev,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4230f6f70e..8250ca76a2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2855,7 +2855,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
virDomainHostdevDef *hostdev)
{
int ret = -1;
- g_autofree char *devstr = NULL;
+ g_autoptr(virJSONValue) devprops = NULL;
bool added = false;
bool teardowncgroup = false;
bool teardownlabel = false;
@@ -2901,8 +2901,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1)
< 0)
goto cleanup;
- if (!(devstr = qemuBuildHostdevMediatedDevStr(vm->def, hostdev,
- priv->qemuCaps)))
+ if (!(devprops = qemuBuildHostdevMediatedDevProps(vm->def, hostdev)))
goto cleanup;
VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1);
@@ -2912,7 +2911,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
teardownmemlock = true;
qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorAddDevice(priv->mon, devstr);
+ ret = qemuMonitorAddDeviceProps(priv->mon, &devprops);
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
ret = -1;
goto cleanup;
--
2.31.1