Generate the 'zpci' device via JSON. Signed-off-by: Peter Krempa <pkre...@redhat.com> --- src/qemu/qemu_command.c | 81 +++++++++++++++++++---------------------- src/qemu/qemu_command.h | 3 +- src/qemu/qemu_hotplug.c | 27 +++++--------- 3 files changed, 49 insertions(+), 62 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9f593151ab..e8043f0055 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2232,48 +2232,43 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, return virBufferContentAndReset(&opt); } -char * -qemuBuildZPCIDevStr(virDomainDeviceInfo *dev) -{ - g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, - "zpci,uid=%u,fid=%u,target=%s,id=zpci%u", - dev->addr.pci.zpci.uid.value, - dev->addr.pci.zpci.fid.value, - dev->alias, - dev->addr.pci.zpci.uid.value); - - return virBufferContentAndReset(&buf); -} -static int -qemuCommandAddZPCIDevice(virCommand *cmd, - virDomainDeviceInfo *dev) +virJSONValue * +qemuBuildZPCIDevProps(virDomainDeviceInfo *dev) { - g_autofree char *devstr = NULL; + virJSONValue *props = NULL; - virCommandAddArg(cmd, "-device"); - - if (!(devstr = qemuBuildZPCIDevStr(dev))) - return -1; - - virCommandAddArg(cmd, devstr); + virJSONValueObjectCreate(&props, + "s:driver", "zpci", + "u:uid", dev->addr.pci.zpci.uid.value, + "u:fid", dev->addr.pci.zpci.fid.value, + "s:target", dev->alias, + "f:id", g_strdup_printf("zpci%u", dev->addr.pci.zpci.uid.value), + NULL); - return 0; + return props; } + static int qemuCommandAddExtDevice(virCommand *cmd, - virDomainDeviceInfo *dev) + virDomainDeviceInfo *dev, + virQEMUCaps *qemuCaps) { if (dev->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI || dev->addr.pci.extFlags == VIR_PCI_ADDRESS_EXTENSION_NONE) { return 0; } - if (dev->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) - return qemuCommandAddZPCIDevice(cmd, dev); + if (dev->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) { + g_autoptr(virJSONValue) devprops = NULL; + + if (!(devprops = qemuBuildZPCIDevProps(dev))) + return -1; + + if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0) + return -1; + } return 0; } @@ -2480,7 +2475,7 @@ qemuBuildDiskCommandLine(virCommand *cmd, !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) return 0; - if (qemuCommandAddExtDevice(cmd, &disk->info) < 0) + if (qemuCommandAddExtDevice(cmd, &disk->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -2588,7 +2583,7 @@ qemuBuildVHostUserFsCommandLine(virCommand *cmd, virCommandAddArg(cmd, "-chardev"); virCommandAddArg(cmd, chrdevstr); - if (qemuCommandAddExtDevice(cmd, &fs->info) < 0) + if (qemuCommandAddExtDevice(cmd, &fs->info, priv->qemuCaps) < 0) return -1; if (!(devstr = qemuBuildVHostUserFsDevStr(fs, def, chardev_alias, priv))) @@ -2686,7 +2681,7 @@ qemuBuildFSDevCommandLine(virCommand *cmd, return -1; virCommandAddArg(cmd, fsdevstr); - if (qemuCommandAddExtDevice(cmd, &fs->info) < 0) + if (qemuCommandAddExtDevice(cmd, &fs->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -3228,7 +3223,7 @@ qemuBuildControllersByTypeCommandLine(virCommand *cmd, return -1; if (devstr) { - if (qemuCommandAddExtDevice(cmd, &cont->info) < 0) + if (qemuCommandAddExtDevice(cmd, &cont->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -4177,7 +4172,7 @@ qemuBuildWatchdogCommandLine(virCommand *cmd, if (!def->watchdog) return 0; - if (qemuCommandAddExtDevice(cmd, &def->watchdog->info) < 0) + if (qemuCommandAddExtDevice(cmd, &def->watchdog->info, qemuCaps) < 0) return -1; if (!(props = qemuBuildWatchdogDevProps(def, watchdog))) @@ -4229,7 +4224,7 @@ qemuBuildMemballoonCommandLine(virCommand *cmd, if (qemuBuildDeviceAddressProps(props, def, &def->memballoon->info) < 0) return -1; - if (qemuCommandAddExtDevice(cmd, &def->memballoon->info) < 0) + if (qemuCommandAddExtDevice(cmd, &def->memballoon->info, qemuCaps) < 0) return -1; if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0) @@ -4376,7 +4371,7 @@ qemuBuildInputCommandLine(virCommand *cmd, for (i = 0; i < def->ninputs; i++) { virDomainInputDef *input = def->inputs[i]; - if (qemuCommandAddExtDevice(cmd, &input->info) < 0) + if (qemuCommandAddExtDevice(cmd, &input->info, qemuCaps) < 0) return -1; if (input->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) { @@ -4522,7 +4517,7 @@ qemuBuildSoundCommandLine(virCommand *cmd, if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) { virCommandAddArgList(cmd, "-soundhw", "pcspk", NULL); } else { - if (qemuCommandAddExtDevice(cmd, &sound->info) < 0) + if (qemuCommandAddExtDevice(cmd, &sound->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -4711,7 +4706,7 @@ qemuBuildVideoCommandLine(virCommand *cmd, if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE) continue; - if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info) < 0) + if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -5527,7 +5522,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd, if (hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED) continue; - if (qemuCommandAddExtDevice(cmd, hostdev->info) < 0) + if (qemuCommandAddExtDevice(cmd, hostdev->info, qemuCaps) < 0) return -1; virCommandAddArg(cmd, "-device"); @@ -5873,7 +5868,7 @@ qemuBuildRNGCommandLine(virLogManager *logManager, return -1; /* add the device */ - if (qemuCommandAddExtDevice(cmd, &rng->info) < 0) + if (qemuCommandAddExtDevice(cmd, &rng->info, qemuCaps) < 0) return -1; if (!(devprops = qemuBuildRNGDevProps(def, rng, qemuCaps))) @@ -8990,14 +8985,14 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver, * New way: -netdev type=tap,id=netdev1 -device e1000,id=netdev1 */ if (qemuDomainSupportsNicdev(def, net)) { - if (qemuCommandAddExtDevice(cmd, &net->info) < 0) + if (qemuCommandAddExtDevice(cmd, &net->info, qemuCaps) < 0) goto cleanup; if (!(nic = qemuBuildNicDevStr(def, net, net->driver.virtio.queues, qemuCaps))) goto cleanup; virCommandAddArgList(cmd, "-device", nic, NULL); } else if (!requireNicdev) { - if (qemuCommandAddExtDevice(cmd, &net->info) < 0) + if (qemuCommandAddExtDevice(cmd, &net->info, qemuCaps) < 0) goto cleanup; if (!(nic = qemuBuildLegacyNicStr(net))) @@ -9375,7 +9370,7 @@ qemuBuildShmemCommandLine(virLogManager *logManager, if (!devProps) return -1; - if (qemuCommandAddExtDevice(cmd, &shmem->info) < 0) + if (qemuCommandAddExtDevice(cmd, &shmem->info, qemuCaps) < 0) return -1; if (qemuBuildDeviceCommandlineFromJSON(cmd, devProps, qemuCaps) < 0) @@ -10520,7 +10515,7 @@ qemuBuildVsockCommandLine(virCommand *cmd, virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); priv->vhostfd = -1; - if (qemuCommandAddExtDevice(cmd, &vsock->info) < 0) + if (qemuCommandAddExtDevice(cmd, &vsock->info, qemuCaps) < 0) return -1; virCommandAddArgList(cmd, "-device", devstr, NULL); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index e8561c0a3c..81cdbed384 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -208,7 +208,8 @@ virJSONValue * qemuBuildRedirdevDevProps(const virDomainDef *def, virDomainRedirdevDef *dev); -char *qemuBuildZPCIDevStr(virDomainDeviceInfo *dev); +virJSONValue * +qemuBuildZPCIDevProps(virDomainDeviceInfo *dev); int qemuNetworkPrepareDevices(virDomainDef *def); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3c76e9be91..ea7028eae5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -138,22 +138,6 @@ qemuDomainDeleteDevice(virDomainObj *vm, } -static int -qemuDomainAttachZPCIDevice(qemuMonitor *mon, - virDomainDeviceInfo *info) -{ - g_autofree char *devstr_zpci = NULL; - - if (!(devstr_zpci = qemuBuildZPCIDevStr(info))) - return -1; - - if (qemuMonitorAddDevice(mon, devstr_zpci) < 0) - return -1; - - return 0; -} - - static int qemuDomainDetachZPCIDevice(qemuMonitor *mon, virDomainDeviceInfo *info) @@ -178,8 +162,15 @@ qemuDomainAttachExtensionDevice(qemuMonitor *mon, return 0; } - if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) - return qemuDomainAttachZPCIDevice(mon, info); + if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) { + g_autoptr(virJSONValue) devprops = NULL; + + if (!(devprops = qemuBuildZPCIDevProps(info))) + return -1; + + if (qemuMonitorAddDeviceProps(mon, &devprops) < 0) + return -1; + } return 0; } -- 2.31.1