[libvirt] [REPOST PATCH 0/8] Reorganize qemu_command.c in smaller piles (round 3)

Final pile of split. Rather than hope for a review of 25 patches or creating some remote place to place a branch - I'll repost the original: http://www.redhat.com/archives/libvir-list/2016-February/msg00975.html in smaller chunks. Differences in this set of patches vs. original series includes handling merge conflicts for logManager series plus a few minor edits/tweaks for better formatting/flow. This series was based off of git head commit 'ef2ab8fdc' which is the round 1 of the split: http://www.redhat.com/archives/libvir-list/2016-March/msg00288.html This is round 2 of the split based off of commit id '95ca4fe2': http://www.redhat.com/archives/libvir-list/2016-March/msg00491.html John Ferlan (8): qemu: Introduce qemuBuildSoundCommandLine qemu: Introduce qemuBuildWatchdogCommandLine qemu: Introduce qemuBuildRedirdevCommandLine qemu: Introduce qemuBuildHostdevCommandLine qemu: Introduce qemuBuildMemballoonCommandLine qemu: Introduce qemuBuildRNGCommandLine qemu: Introduce qemuBuildNVRAMCommandLine qemu: Introduce qemuBuildPanicCommandLine src/qemu/qemu_command.c | 1346 ++++++++++++++++++++++++++--------------------- src/qemu/qemu_command.h | 25 +- 2 files changed, 743 insertions(+), 628 deletions(-) -- 2.5.0

Add new function to manage adding the sound device options to the command line removing that task from the mainline qemuBuildCommandLine. Also since qemuBuildSoundDevStr was only local here, make it static as well as modifying the const virDomainDef. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 188 ++++++++++++++++++++++++++---------------------- src/qemu/qemu_command.h | 4 -- 2 files changed, 104 insertions(+), 88 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ba8c216..f010e48 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3583,8 +3583,8 @@ qemuBuildInputCommandLine(virCommandPtr cmd, } -char * -qemuBuildSoundDevStr(virDomainDefPtr def, +static char * +qemuBuildSoundDevStr(const virDomainDef *def, virDomainSoundDefPtr sound, virQEMUCapsPtr qemuCaps) { @@ -3689,6 +3689,105 @@ qemuBuildSoundCodecStr(virDomainSoundDefPtr sound, return NULL; } + +static int +qemuBuildSoundCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + size_t i, j; + + if (!def->nsounds) + return 0; + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + for (i = 0; i < def->nsounds; i++) { + virDomainSoundDefPtr sound = def->sounds[i]; + char *str = NULL; + + /* Sadly pcspk device doesn't use -device syntax. Fortunately + * we don't need to set any PCI address on it, so we don't + * mind too much */ + if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) { + virCommandAddArgList(cmd, "-soundhw", "pcspk", NULL); + } else { + virCommandAddArg(cmd, "-device"); + if (!(str = qemuBuildSoundDevStr(def, sound, qemuCaps))) + return -1; + + virCommandAddArg(cmd, str); + VIR_FREE(str); + if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 || + sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) { + char *codecstr = NULL; + + for (j = 0; j < sound->ncodecs; j++) { + virCommandAddArg(cmd, "-device"); + if (!(codecstr = + qemuBuildSoundCodecStr(sound, sound->codecs[j], + qemuCaps))) { + return -1; + + } + virCommandAddArg(cmd, codecstr); + VIR_FREE(codecstr); + } + if (j == 0) { + virDomainSoundCodecDef codec = { + VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX, + 0 + }; + virCommandAddArg(cmd, "-device"); + if (!(codecstr = + qemuBuildSoundCodecStr(sound, &codec, + qemuCaps))) { + return -1; + + } + virCommandAddArg(cmd, codecstr); + VIR_FREE(codecstr); + } + } + } + } + } else { + int size = 100; + char *modstr; + if (VIR_ALLOC_N(modstr, size+1) < 0) + return -1; + + for (i = 0; i < def->nsounds && size > 0; i++) { + virDomainSoundDefPtr sound = def->sounds[i]; + const char *model = virDomainSoundModelTypeToString(sound->model); + if (!model) { + VIR_FREE(modstr); + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("invalid sound model")); + return -1; + } + + if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 || + sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) { + VIR_FREE(modstr); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this QEMU binary lacks hda support")); + return -1; + } + + strncat(modstr, model, size); + size -= strlen(model); + if (i < (def->nsounds - 1)) + strncat(modstr, ",", size--); + } + virCommandAddArgList(cmd, "-soundhw", modstr, NULL); + VIR_FREE(modstr); + } + + return 0; +} + + + static char * qemuBuildDeviceVideoStr(const virDomainDef *def, virDomainVideoDefPtr video, @@ -8598,7 +8697,7 @@ qemuBuildCommandLine(virConnectPtr conn, const char *domainChannelTargetDir) { virErrorPtr originalError = NULL; - size_t i, j; + size_t i; char uuid[VIR_UUID_STRING_BUFLEN]; virCommandPtr cmd = NULL; bool emitBootindex = false; @@ -8759,87 +8858,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildVideoCommandLine(cmd, def, qemuCaps) < 0) goto error; - /* Add sound hardware */ - if (def->nsounds) { - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - for (i = 0; i < def->nsounds; i++) { - virDomainSoundDefPtr sound = def->sounds[i]; - char *str = NULL; - - /* Sadly pcspk device doesn't use -device syntax. Fortunately - * we don't need to set any PCI address on it, so we don't - * mind too much */ - if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) { - virCommandAddArgList(cmd, "-soundhw", "pcspk", NULL); - } else { - virCommandAddArg(cmd, "-device"); - if (!(str = qemuBuildSoundDevStr(def, sound, qemuCaps))) - goto error; - - virCommandAddArg(cmd, str); - VIR_FREE(str); - if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 || - sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) { - char *codecstr = NULL; - - for (j = 0; j < sound->ncodecs; j++) { - virCommandAddArg(cmd, "-device"); - if (!(codecstr = qemuBuildSoundCodecStr(sound, sound->codecs[j], qemuCaps))) { - goto error; - - } - virCommandAddArg(cmd, codecstr); - VIR_FREE(codecstr); - } - if (j == 0) { - virDomainSoundCodecDef codec = { - VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX, - 0 - }; - virCommandAddArg(cmd, "-device"); - if (!(codecstr = qemuBuildSoundCodecStr(sound, &codec, qemuCaps))) { - goto error; - - } - virCommandAddArg(cmd, codecstr); - VIR_FREE(codecstr); - } - } - } - } - } else { - int size = 100; - char *modstr; - if (VIR_ALLOC_N(modstr, size+1) < 0) - goto error; - - for (i = 0; i < def->nsounds && size > 0; i++) { - virDomainSoundDefPtr sound = def->sounds[i]; - const char *model = virDomainSoundModelTypeToString(sound->model); - if (!model) { - VIR_FREE(modstr); - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("invalid sound model")); - goto error; - } - - if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 || - sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) { - VIR_FREE(modstr); - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("this QEMU binary lacks hda support")); - goto error; - } - - strncat(modstr, model, size); - size -= strlen(model); - if (i < (def->nsounds - 1)) - strncat(modstr, ",", size--); - } - virCommandAddArgList(cmd, "-soundhw", modstr, NULL); - VIR_FREE(modstr); - } - } + if (qemuBuildSoundCommandLine(cmd, def, qemuCaps) < 0) + goto error; /* Add watchdog hardware */ if (def->watchdog) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index d3e676b..d7f1344 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -138,10 +138,6 @@ char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef, virDomainMemballoonDefPtr dev, virQEMUCapsPtr qemuCaps); -char *qemuBuildSoundDevStr(virDomainDefPtr domainDef, - virDomainSoundDefPtr sound, - virQEMUCapsPtr qemuCaps); - int qemuBuildMemoryBackendStr(unsigned long long size, unsigned long long pagesize, int guestNode, -- 2.5.0

Add new function to manage adding the watchdog device options to the command line removing that task from the mainline qemuBuildCommandLine. Also since qemuBuildWatchdogDevStr was only local here, make it static as well as modifying the const virDomainDef. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 93 ++++++++++++++++++++++++++++--------------------- src/qemu/qemu_command.h | 4 --- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f010e48..2cf9576 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3329,8 +3329,8 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, } -char * -qemuBuildWatchdogDevStr(virDomainDefPtr def, +static char * +qemuBuildWatchdogDevStr(const virDomainDef *def, virDomainWatchdogDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -3358,6 +3358,55 @@ qemuBuildWatchdogDevStr(virDomainDefPtr def, } +static int +qemuBuildWatchdogCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + virDomainWatchdogDefPtr watchdog = def->watchdog; + char *optstr; + const char *action; + + if (!def->watchdog) + return 0; + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + virCommandAddArg(cmd, "-device"); + + optstr = qemuBuildWatchdogDevStr(def, watchdog, qemuCaps); + if (!optstr) + return -1; + } else { + virCommandAddArg(cmd, "-watchdog"); + + const char *model = virDomainWatchdogModelTypeToString(watchdog->model); + if (!model) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing watchdog model")); + return -1; + } + + if (VIR_STRDUP(optstr, model) < 0) + return -1; + } + virCommandAddArg(cmd, optstr); + VIR_FREE(optstr); + + if (watchdog->action == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) + watchdog->action = VIR_DOMAIN_WATCHDOG_ACTION_PAUSE; + + action = virDomainWatchdogActionTypeToString(watchdog->action); + if (!action) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("invalid watchdog action")); + return -1; + } + virCommandAddArgList(cmd, "-watchdog-action", action, NULL); + + return 0; +} + + char * qemuBuildMemballoonDevStr(virDomainDefPtr def, virDomainMemballoonDefPtr dev, @@ -8861,44 +8910,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildSoundCommandLine(cmd, def, qemuCaps) < 0) goto error; - /* Add watchdog hardware */ - if (def->watchdog) { - virDomainWatchdogDefPtr watchdog = def->watchdog; - char *optstr; - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - virCommandAddArg(cmd, "-device"); - - optstr = qemuBuildWatchdogDevStr(def, watchdog, qemuCaps); - if (!optstr) - goto error; - } else { - virCommandAddArg(cmd, "-watchdog"); - - const char *model = virDomainWatchdogModelTypeToString(watchdog->model); - if (!model) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing watchdog model")); - goto error; - } - - if (VIR_STRDUP(optstr, model) < 0) - goto error; - } - virCommandAddArg(cmd, optstr); - VIR_FREE(optstr); - - int act = watchdog->action; - if (act == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) - act = VIR_DOMAIN_WATCHDOG_ACTION_PAUSE; - const char *action = virDomainWatchdogActionTypeToString(act); - if (!action) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("invalid watchdog action")); - goto error; - } - virCommandAddArgList(cmd, "-watchdog-action", action, NULL); - } + if (qemuBuildWatchdogCommandLine(cmd, def, qemuCaps) < 0) + goto error; /* Add redirected devices */ for (i = 0; i < def->nredirdevs; i++) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index d7f1344..e5b4445 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -130,10 +130,6 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef, virQEMUCapsPtr qemuCaps, int *nusbcontroller); -char *qemuBuildWatchdogDevStr(virDomainDefPtr domainDef, - virDomainWatchdogDefPtr dev, - virQEMUCapsPtr qemuCaps); - char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef, virDomainMemballoonDefPtr dev, virQEMUCapsPtr qemuCaps); -- 2.5.0

Add new function to manage adding the redirdev device options to the command line removing that task from the mainline qemuBuildCommandLine. Also move the qemuBuildRedirdevDevStr closer to the new function and modify to use the const virDomainDef instead of virDomainDefPtr Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 246 +++++++++++++++++++++++++----------------------- src/qemu/qemu_command.h | 2 +- 2 files changed, 131 insertions(+), 117 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2cf9576..b04578a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4237,93 +4237,6 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, char * -qemuBuildRedirdevDevStr(virDomainDefPtr def, - virDomainRedirdevDefPtr dev, - virQEMUCapsPtr qemuCaps) -{ - size_t i; - virBuffer buf = VIR_BUFFER_INITIALIZER; - virDomainRedirFilterDefPtr redirfilter = def->redirfilter; - - if (dev->bus != VIR_DOMAIN_REDIRDEV_BUS_USB) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Redirection bus %s is not supported by QEMU"), - virDomainRedirdevBusTypeToString(dev->bus)); - goto error; - } - - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB redirection is not supported " - "by this version of QEMU")); - goto error; - } - - virBufferAsprintf(&buf, "usb-redir,chardev=char%s,id=%s", - dev->info.alias, dev->info.alias); - - if (redirfilter && redirfilter->nusbdevs) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR_FILTER)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB redirection filter is not " - "supported by this version of QEMU")); - goto error; - } - - virBufferAddLit(&buf, ",filter="); - - for (i = 0; i < redirfilter->nusbdevs; i++) { - virDomainRedirFilterUSBDevDefPtr usbdev = redirfilter->usbdevs[i]; - if (usbdev->usbClass >= 0) - virBufferAsprintf(&buf, "0x%02X:", usbdev->usbClass); - else - virBufferAddLit(&buf, "-1:"); - - if (usbdev->vendor >= 0) - virBufferAsprintf(&buf, "0x%04X:", usbdev->vendor); - else - virBufferAddLit(&buf, "-1:"); - - if (usbdev->product >= 0) - virBufferAsprintf(&buf, "0x%04X:", usbdev->product); - else - virBufferAddLit(&buf, "-1:"); - - if (usbdev->version >= 0) - virBufferAsprintf(&buf, "0x%04X:", usbdev->version); - else - virBufferAddLit(&buf, "-1:"); - - virBufferAsprintf(&buf, "%u", usbdev->allow); - if (i < redirfilter->nusbdevs -1) - virBufferAddLit(&buf, "|"); - } - } - - if (dev->info.bootIndex) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR_BOOTINDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("USB redirection booting is not " - "supported by this version of QEMU")); - goto error; - } - virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex); - } - - if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) - goto error; - - if (virBufferCheckError(&buf) < 0) - goto error; - - return virBufferContentAndReset(&buf); - - error: - virBufferFreeAndReset(&buf); - return NULL; -} - -char * qemuBuildUSBHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) @@ -8383,6 +8296,134 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager, } +char * +qemuBuildRedirdevDevStr(const virDomainDef *def, + virDomainRedirdevDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ + size_t i; + virBuffer buf = VIR_BUFFER_INITIALIZER; + virDomainRedirFilterDefPtr redirfilter = def->redirfilter; + + if (dev->bus != VIR_DOMAIN_REDIRDEV_BUS_USB) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Redirection bus %s is not supported by QEMU"), + virDomainRedirdevBusTypeToString(dev->bus)); + goto error; + } + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("USB redirection is not supported " + "by this version of QEMU")); + goto error; + } + + virBufferAsprintf(&buf, "usb-redir,chardev=char%s,id=%s", + dev->info.alias, dev->info.alias); + + if (redirfilter && redirfilter->nusbdevs) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR_FILTER)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("USB redirection filter is not " + "supported by this version of QEMU")); + goto error; + } + + virBufferAddLit(&buf, ",filter="); + + for (i = 0; i < redirfilter->nusbdevs; i++) { + virDomainRedirFilterUSBDevDefPtr usbdev = redirfilter->usbdevs[i]; + if (usbdev->usbClass >= 0) + virBufferAsprintf(&buf, "0x%02X:", usbdev->usbClass); + else + virBufferAddLit(&buf, "-1:"); + + if (usbdev->vendor >= 0) + virBufferAsprintf(&buf, "0x%04X:", usbdev->vendor); + else + virBufferAddLit(&buf, "-1:"); + + if (usbdev->product >= 0) + virBufferAsprintf(&buf, "0x%04X:", usbdev->product); + else + virBufferAddLit(&buf, "-1:"); + + if (usbdev->version >= 0) + virBufferAsprintf(&buf, "0x%04X:", usbdev->version); + else + virBufferAddLit(&buf, "-1:"); + + virBufferAsprintf(&buf, "%u", usbdev->allow); + if (i < redirfilter->nusbdevs -1) + virBufferAddLit(&buf, "|"); + } + } + + if (dev->info.bootIndex) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_REDIR_BOOTINDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("USB redirection booting is not " + "supported by this version of QEMU")); + goto error; + } + virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex); + } + + if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) + goto error; + + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; +} + + +static int +qemuBuildRedirdevCommandLine(virLogManagerPtr logManager, + virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + size_t i; + + for (i = 0; i < def->nredirdevs; i++) { + virDomainRedirdevDefPtr redirdev = def->redirdevs[i]; + char *devstr; + + virCommandAddArg(cmd, "-chardev"); + if (!(devstr = qemuBuildChrChardevStr(logManager, cmd, def, + &redirdev->source.chr, + redirdev->info.alias, + qemuCaps))) { + return -1; + } + + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("redirected devices are not supported by this QEMU")); + return -1; + } + + virCommandAddArg(cmd, "-device"); + if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, qemuCaps))) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } + + return 0; +} + + static int qemuBuildDomainLoaderCommandLine(virCommandPtr cmd, virDomainDefPtr def, @@ -8913,35 +8954,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildWatchdogCommandLine(cmd, def, qemuCaps) < 0) goto error; - /* Add redirected devices */ - for (i = 0; i < def->nredirdevs; i++) { - virDomainRedirdevDefPtr redirdev = def->redirdevs[i]; - char *devstr; - - if (!(devstr = qemuBuildChrChardevStr(logManager, cmd, def, - &redirdev->source.chr, - redirdev->info.alias, - qemuCaps))) { - goto error; - } - - virCommandAddArg(cmd, "-chardev"); - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("redirected devices are not supported by this QEMU")); - goto error; - } - - - virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, qemuCaps))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } + if (qemuBuildRedirdevCommandLine(logManager, cmd, def, qemuCaps) < 0) + goto error; /* Add host passthrough hardware */ for (i = 0; i < def->nhostdevs; i++) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index e5b4445..841208f 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -194,7 +194,7 @@ char *qemuBuildSCSIHostdevDevStr(virDomainDefPtr def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps); -char *qemuBuildRedirdevDevStr(virDomainDefPtr def, +char *qemuBuildRedirdevDevStr(const virDomainDef *def, virDomainRedirdevDefPtr dev, virQEMUCapsPtr qemuCaps); -- 2.5.0

Add new function to manage adding the host device options to the command line removing that task from the mainline qemuBuildCommandLine. Also modify qemuBuildPCIHostdevDevStr, qemuBuildUSBHostdevDevStr, and qemuBuildSCSIHostdevDevStr to use const virDomainDef instead of virDomainDefPtr. Make qemuBuildPCIHostdevPCIDevStr and qemuBuildUSBHostdevUSBDevStr static to the qemu_command.c. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 343 ++++++++++++++++++++++++++---------------------- src/qemu/qemu_command.h | 11 +- 2 files changed, 186 insertions(+), 168 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b04578a..69026f9 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4144,7 +4144,7 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev) } char * -qemuBuildPCIHostdevDevStr(virDomainDefPtr def, +qemuBuildPCIHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, int bootIndex, /* used iff dev->info->bootIndex == 0 */ const char *configfd, @@ -4208,7 +4208,7 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def, } -char * +static char * qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -4237,7 +4237,7 @@ qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, char * -qemuBuildUSBHostdevDevStr(virDomainDefPtr def, +qemuBuildUSBHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -4331,7 +4331,7 @@ qemuBuildHubCommandLine(virCommandPtr cmd, } -char * +static char * qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev) { char *ret = NULL; @@ -4456,7 +4456,7 @@ qemuBuildSCSIHostdevDrvStr(virConnectPtr conn, } char * -qemuBuildSCSIHostdevDevStr(virDomainDefPtr def, +qemuBuildSCSIHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -4717,6 +4717,181 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager, } +static int +qemuBuildHostdevCommandLine(virCommandPtr cmd, + virConnectPtr conn, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps, + qemuBuildCommandLineCallbacksPtr callbacks, + int *bootHostdevNet) +{ + size_t i; + + for (i = 0; i < def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev = def->hostdevs[i]; + virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys; + char *devstr; + + if (hostdev->info->bootIndex) { + if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && + subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("booting from assigned devices is only " + "supported for PCI, USB and SCSI devices")); + return -1; + } else { + if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { + if (subsys->u.pci.backend == + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { + if (!virQEMUCapsGet(qemuCaps, + QEMU_CAPS_VFIO_PCI_BOOTINDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("booting from PCI devices assigned with VFIO " + "is not supported with this version of qemu")); + return -1; + } + } else { + if (!virQEMUCapsGet(qemuCaps, + QEMU_CAPS_PCI_BOOTINDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("booting from assigned PCI devices is not " + "supported with this version of qemu")); + return -1; + } + } + } + if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_HOST_BOOTINDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("booting from assigned USB devices is not " + "supported with this version of qemu")); + return -1; + } + if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && + !virQEMUCapsGet(qemuCaps, + QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("booting from assigned SCSI devices is not" + " supported with this version of qemu")); + return -1; + } + } + } + + /* USB */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + virCommandAddArg(cmd, "-device"); + if (!(devstr = + qemuBuildUSBHostdevDevStr(def, hostdev, qemuCaps))) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else { + virCommandAddArg(cmd, "-usbdevice"); + if (!(devstr = qemuBuildUSBHostdevUSBDevStr(hostdev))) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } + } + + /* PCI */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { + int backend = subsys->u.pci.backend; + + if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("VFIO PCI device assignment is not " + "supported by this version of qemu")); + return -1; + } + } + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + char *configfd_name = NULL; + int bootIndex = hostdev->info->bootIndex; + + /* bootNet will be non-0 if boot order was set and no other + * net devices were encountered + */ + if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && + bootIndex == 0) { + bootIndex = *bootHostdevNet; + *bootHostdevNet = 0; + } + if ((backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) { + int configfd = qemuOpenPCIConfig(hostdev); + + if (configfd >= 0) { + if (virAsprintf(&configfd_name, "%d", configfd) < 0) { + VIR_FORCE_CLOSE(configfd); + return -1; + } + + virCommandPassFD(cmd, configfd, + VIR_COMMAND_PASS_FD_CLOSE_PARENT); + } + } + virCommandAddArg(cmd, "-device"); + devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex, + configfd_name, qemuCaps); + VIR_FREE(configfd_name); + if (!devstr) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCIDEVICE)) { + virCommandAddArg(cmd, "-pcidevice"); + if (!(devstr = qemuBuildPCIHostdevPCIDevStr(hostdev, qemuCaps))) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("PCI device assignment is not supported by this version of qemu")); + return -1; + } + } + + /* SCSI */ + if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) { + char *drvstr; + + virCommandAddArg(cmd, "-drive"); + if (!(drvstr = qemuBuildSCSIHostdevDrvStr(conn, hostdev, + qemuCaps, callbacks))) + return -1; + virCommandAddArg(cmd, drvstr); + VIR_FREE(drvstr); + + virCommandAddArg(cmd, "-device"); + if (!(devstr = qemuBuildSCSIHostdevDevStr(def, hostdev, + qemuCaps))) + return -1; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("SCSI passthrough is not supported by this version of qemu")); + return -1; + } + } + } + + return 0; +} + static char * qemuBuildChrArgStr(const virDomainChrSourceDef *dev, const char *prefix) @@ -8957,161 +9132,9 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildRedirdevCommandLine(logManager, cmd, def, qemuCaps) < 0) goto error; - /* Add host passthrough hardware */ - for (i = 0; i < def->nhostdevs; i++) { - virDomainHostdevDefPtr hostdev = def->hostdevs[i]; - char *devstr; - - if (hostdev->info->bootIndex) { - if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || - (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && - hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && - hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("booting from assigned devices is only " - "supported for PCI, USB and SCSI devices")); - goto error; - } else { - if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { - if (hostdev->source.subsys.u.pci.backend - == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_PCI_BOOTINDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("booting from PCI devices assigned with VFIO " - "is not supported with this version of qemu")); - goto error; - } - } else { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_BOOTINDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("booting from assigned PCI devices is not " - "supported with this version of qemu")); - goto error; - } - } - } - if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_HOST_BOOTINDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("booting from assigned USB devices is not " - "supported with this version of qemu")); - goto error; - } - if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("booting from assigned SCSI devices is not" - " supported with this version of qemu")); - goto error; - } - } - } - - /* USB */ - if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildUSBHostdevDevStr(def, hostdev, qemuCaps))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } else { - virCommandAddArg(cmd, "-usbdevice"); - if (!(devstr = qemuBuildUSBHostdevUSBDevStr(hostdev))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } - } - - /* PCI */ - if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { - int backend = hostdev->source.subsys.u.pci.backend; - - if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("VFIO PCI device assignment is not " - "supported by this version of qemu")); - goto error; - } - } - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - char *configfd_name = NULL; - int bootIndex = hostdev->info->bootIndex; - - /* bootNet will be non-0 if boot order was set and no other - * net devices were encountered - */ - if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET && - bootIndex == 0) { - bootIndex = bootHostdevNet; - bootHostdevNet = 0; - } - if ((backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) { - int configfd = qemuOpenPCIConfig(hostdev); - - if (configfd >= 0) { - if (virAsprintf(&configfd_name, "%d", configfd) < 0) { - VIR_FORCE_CLOSE(configfd); - goto error; - } - - virCommandPassFD(cmd, configfd, - VIR_COMMAND_PASS_FD_CLOSE_PARENT); - } - } - virCommandAddArg(cmd, "-device"); - devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex, - configfd_name, qemuCaps); - VIR_FREE(configfd_name); - if (!devstr) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCIDEVICE)) { - virCommandAddArg(cmd, "-pcidevice"); - if (!(devstr = qemuBuildPCIHostdevPCIDevStr(hostdev, qemuCaps))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("PCI device assignment is not supported by this version of qemu")); - goto error; - } - } - - /* SCSI */ - if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) { - char *drvstr; - - virCommandAddArg(cmd, "-drive"); - if (!(drvstr = qemuBuildSCSIHostdevDrvStr(conn, hostdev, qemuCaps, callbacks))) - goto error; - virCommandAddArg(cmd, drvstr); - VIR_FREE(drvstr); - - virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildSCSIHostdevDevStr(def, hostdev, qemuCaps))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("SCSI passthrough is not supported by this version of qemu")); - goto error; - } - } - } + if (qemuBuildHostdevCommandLine(cmd, conn, def, qemuCaps, callbacks, + &bootHostdevNet) < 0) + goto error; if (migrateURI) virCommandAddArgList(cmd, "-incoming", migrateURI, NULL); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 841208f..4e22421 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -148,11 +148,8 @@ int qemuBuildMemoryBackendStr(unsigned long long size, char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem); -/* Legacy, pre device support */ -char *qemuBuildPCIHostdevPCIDevStr(virDomainHostdevDefPtr dev, - virQEMUCapsPtr qemuCaps); /* Current, best practice */ -char *qemuBuildPCIHostdevDevStr(virDomainDefPtr def, +char *qemuBuildPCIHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, int bootIndex, const char *configfd, @@ -178,10 +175,8 @@ char *qemuBuildShmemBackendStr(virLogManagerPtr logManager, int qemuOpenPCIConfig(virDomainHostdevDefPtr dev); -/* Legacy, pre device support */ -char *qemuBuildUSBHostdevUSBDevStr(virDomainHostdevDefPtr dev); /* Current, best practice */ -char *qemuBuildUSBHostdevDevStr(virDomainDefPtr def, +char *qemuBuildUSBHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps); @@ -190,7 +185,7 @@ char *qemuBuildSCSIHostdevDrvStr(virConnectPtr conn, virQEMUCapsPtr qemuCaps, qemuBuildCommandLineCallbacksPtr callbacks) ATTRIBUTE_NONNULL(4); -char *qemuBuildSCSIHostdevDevStr(virDomainDefPtr def, +char *qemuBuildSCSIHostdevDevStr(const virDomainDef *def, virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps); -- 2.5.0

Add new function to manage adding the memballoon device options to the command line removing that task from the mainline qemuBuildCommandLine. Also modify the qemuBuildMemballoonDevStr to use const virDomainDef instead of virDomainDefPtr. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 76 ++++++++++++++++++++++++++++--------------------- src/qemu/qemu_command.h | 2 +- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 69026f9..0f9fe60 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3408,7 +3408,7 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd, char * -qemuBuildMemballoonDevStr(virDomainDefPtr def, +qemuBuildMemballoonDevStr(const virDomainDef *def, virDomainMemballoonDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -3456,6 +3456,47 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def, return NULL; } + +static int +qemuBuildMemballoonCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + /* QEMU changed its default behavior to not include the virtio balloon + * device. Explicitly request it to ensure it will be present. + * + * NB: Earlier we declared that VirtIO balloon will always be in + * slot 0x3 on bus 0x0 + */ + if (STREQLEN(def->os.machine, "s390-virtio", 10) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) + def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE; + + if (def->memballoon && + def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE) { + if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Memory balloon device type '%s' is not supported by this version of qemu"), + virDomainMemballoonModelTypeToString(def->memballoon->model)); + return -1; + } + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + char *optstr; + virCommandAddArg(cmd, "-device"); + + optstr = qemuBuildMemballoonDevStr(def, def->memballoon, qemuCaps); + if (!optstr) + return -1; + virCommandAddArg(cmd, optstr); + VIR_FREE(optstr); + } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BALLOON)) { + virCommandAddArgList(cmd, "-balloon", "virtio", NULL); + } + } + return 0; +} + + static char * qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) { @@ -9139,37 +9180,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (migrateURI) virCommandAddArgList(cmd, "-incoming", migrateURI, NULL); - /* QEMU changed its default behavior to not include the virtio balloon - * device. Explicitly request it to ensure it will be present. - * - * NB: Earlier we declared that VirtIO balloon will always be in - * slot 0x3 on bus 0x0 - */ - if (STREQLEN(def->os.machine, "s390-virtio", 10) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) - def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE; - - if (def->memballoon && - def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE) { - if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Memory balloon device type '%s' is not supported by this version of qemu"), - virDomainMemballoonModelTypeToString(def->memballoon->model)); - goto error; - } - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { - char *optstr; - virCommandAddArg(cmd, "-device"); - - optstr = qemuBuildMemballoonDevStr(def, def->memballoon, qemuCaps); - if (!optstr) - goto error; - virCommandAddArg(cmd, optstr); - VIR_FREE(optstr); - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BALLOON)) { - virCommandAddArgList(cmd, "-balloon", "virtio", NULL); - } - } + if (qemuBuildMemballoonCommandLine(cmd, def, qemuCaps) < 0) + goto error; for (i = 0; i < def->nrngs; i++) { virDomainRNGDefPtr rng = def->rngs[i]; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 4e22421..25de1abd 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -130,7 +130,7 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef, virQEMUCapsPtr qemuCaps, int *nusbcontroller); -char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef, +char *qemuBuildMemballoonDevStr(const virDomainDef *domainDef, virDomainMemballoonDefPtr dev, virQEMUCapsPtr qemuCaps); -- 2.5.0

Add new function to manage adding the RNG device options to the command line removing that task from the mainline qemuBuildCommandLine. Also modify the qemuBuildRNGDevStr to use const virDomainDef instead of virDomainDefPtr. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 85 +++++++++++++++++++++++++++++-------------------- src/qemu/qemu_command.h | 2 +- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0f9fe60..d6f7651 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5195,7 +5195,7 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev) static int qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager, virCommandPtr cmd, - virDomainDefPtr def, + const virDomainDef *def, virDomainRNGDefPtr rng, virQEMUCapsPtr qemuCaps, char **chr) @@ -5302,7 +5302,7 @@ qemuBuildRNGBackendStr(virDomainRNGDefPtr rng, char * -qemuBuildRNGDevStr(virDomainDefPtr def, +qemuBuildRNGDevStr(const virDomainDef *def, virDomainRNGDefPtr dev, virQEMUCapsPtr qemuCaps) { @@ -5354,6 +5354,52 @@ qemuBuildRNGDevStr(virDomainDefPtr def, } +static int +qemuBuildRNGCommandLine(virLogManagerPtr logManager, + virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + size_t i; + + for (i = 0; i < def->nrngs; i++) { + virDomainRNGDefPtr rng = def->rngs[i]; + char *tmp; + + if (!rng->info.alias) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("RNG device is missing alias")); + return -1; + } + + /* possibly add character device for backend */ + if (qemuBuildRNGBackendChrdevStr(logManager, cmd, def, + rng, qemuCaps, &tmp) < 0) + return -1; + + if (tmp) { + virCommandAddArgList(cmd, "-chardev", tmp, NULL); + VIR_FREE(tmp); + } + + /* add the RNG source backend */ + if (!(tmp = qemuBuildRNGBackendStr(rng, qemuCaps))) + return -1; + + virCommandAddArgList(cmd, "-object", tmp, NULL); + VIR_FREE(tmp); + + /* add the device */ + if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps))) + return -1; + virCommandAddArgList(cmd, "-device", tmp, NULL); + VIR_FREE(tmp); + } + + return 0; +} + + static char *qemuBuildSmbiosBiosStr(virSysinfoBIOSDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -9183,39 +9229,8 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildMemballoonCommandLine(cmd, def, qemuCaps) < 0) goto error; - for (i = 0; i < def->nrngs; i++) { - virDomainRNGDefPtr rng = def->rngs[i]; - char *tmp; - - if (!rng->info.alias) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("RNG device is missing alias")); - goto error; - } - - /* possibly add character device for backend */ - if (qemuBuildRNGBackendChrdevStr(logManager, cmd, def, - rng, qemuCaps, &tmp) < 0) - goto error; - - if (tmp) { - virCommandAddArgList(cmd, "-chardev", tmp, NULL); - VIR_FREE(tmp); - } - - /* add the RNG source backend */ - if (!(tmp = qemuBuildRNGBackendStr(rng, qemuCaps))) - goto error; - - virCommandAddArgList(cmd, "-object", tmp, NULL); - VIR_FREE(tmp); - - /* add the device */ - if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps))) - goto error; - virCommandAddArgList(cmd, "-device", tmp, NULL); - VIR_FREE(tmp); - } + if (qemuBuildRNGCommandLine(logManager, cmd, def, qemuCaps) < 0) + goto error; if (def->nvram) { if (ARCH_IS_PPC64(def->os.arch) && diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 25de1abd..7c13d45 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -155,7 +155,7 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def, const char *configfd, virQEMUCapsPtr qemuCaps); -char *qemuBuildRNGDevStr(virDomainDefPtr def, +char *qemuBuildRNGDevStr(const virDomainDef *def, virDomainRNGDefPtr dev, virQEMUCapsPtr qemuCaps); int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, -- 2.5.0

Add new function to manage adding the NVRAM device options to the command line removing that task from the mainline qemuBuildCommandLine. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 61 ++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d6f7651..c63e97f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3522,6 +3522,42 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) return NULL; } + +static int +qemuBuildNVRAMCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + if (!def->nvram) + return 0; + + if (ARCH_IS_PPC64(def->os.arch) && + STRPREFIX(def->os.machine, "pseries")) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVRAM)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("nvram device is not supported by " + "this QEMU binary")); + return -1; + } + + char *optstr; + virCommandAddArg(cmd, "-global"); + optstr = qemuBuildNVRAMDevStr(def->nvram); + if (!optstr) + return -1; + if (optstr) + virCommandAddArg(cmd, optstr); + VIR_FREE(optstr); + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("nvram device is only supported for PPC64")); + return -1; + } + + return 0; +} + + static char * qemuBuildVirtioInputDevStr(const virDomainDef *def, virDomainInputDefPtr dev, @@ -9232,30 +9268,9 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildRNGCommandLine(logManager, cmd, def, qemuCaps) < 0) goto error; - if (def->nvram) { - if (ARCH_IS_PPC64(def->os.arch) && - STRPREFIX(def->os.machine, "pseries")) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVRAM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("nvram device is not supported by " - "this QEMU binary")); - goto error; - } + if (qemuBuildNVRAMCommandLine(cmd, def, qemuCaps) < 0) + goto error; - char *optstr; - virCommandAddArg(cmd, "-global"); - optstr = qemuBuildNVRAMDevStr(def->nvram); - if (!optstr) - goto error; - if (optstr) - virCommandAddArg(cmd, optstr); - VIR_FREE(optstr); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("nvram device is only supported for PPC64")); - goto error; - } - } if (snapshot) virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL); -- 2.5.0

Add new function to manage adding the panic device options to the command line removing that task from the mainline qemuBuildCommandLine. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.c | 158 ++++++++++++++++++++++++++---------------------- 1 file changed, 87 insertions(+), 71 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c63e97f..ac099de 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8960,6 +8960,91 @@ qemuBuildTPMCommandLine(virCommandPtr cmd, } +static int +qemuBuildPanicCommandLine(virCommandPtr cmd, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + size_t i; + + for (i = 0; i < def->npanics; i++) { + switch ((virDomainPanicModel) def->panics[i]->model) { + case VIR_DOMAIN_PANIC_MODEL_HYPERV: + /* Panic with model 'hyperv' is not a device, it should + * be configured in cpu commandline. The address + * cannot be configured by the user */ + if (!ARCH_IS_X86(def->os.arch)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only i686 and x86_64 guests support " + "panic device of model 'hyperv'")); + return -1; + } + if (def->panics[i]->info.type != + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting the panic device address is not " + "supported for model 'hyperv'")); + return -1; + } + break; + + case VIR_DOMAIN_PANIC_MODEL_PSERIES: + /* For pSeries guests, the firmware provides the same + * functionality as the pvpanic device. The address + * cannot be configured by the user */ + if (!ARCH_IS_PPC64(def->os.arch) || + !STRPREFIX(def->os.machine, "pseries")) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only pSeries guests support panic device " + "of model 'pseries'")); + return -1; + } + if (def->panics[i]->info.type != + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting the panic device address is not " + "supported for model 'pseries'")); + return -1; + } + break; + + case VIR_DOMAIN_PANIC_MODEL_ISA: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PANIC)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("the QEMU binary does not support the " + "panic device")); + return -1; + } + + switch (def->panics[i]->info.type) { + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: + virCommandAddArg(cmd, "-device"); + virCommandAddArgFormat(cmd, "pvpanic,ioport=%d", + def->panics[i]->info.addr.isa.iobase); + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + virCommandAddArgList(cmd, "-device", "pvpanic", NULL); + break; + + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("panic is supported only " + "with ISA address type")); + return -1; + } + + /* default model value was changed before in post parse */ + case VIR_DOMAIN_PANIC_MODEL_DEFAULT: + case VIR_DOMAIN_PANIC_MODEL_LAST: + break; + } + } + + return 0; +} + + /** * qemuBuildCommandLineValidate: * @@ -9297,77 +9382,8 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } - for (i = 0; i < def->npanics; i++) { - switch ((virDomainPanicModel) def->panics[i]->model) { - case VIR_DOMAIN_PANIC_MODEL_HYPERV: - /* Panic with model 'hyperv' is not a device, it should - * be configured in cpu commandline. The address - * cannot be configured by the user */ - if (!ARCH_IS_X86(def->os.arch)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only i686 and x86_64 guests support " - "panic device of model 'hyperv'")); - goto error; - } - if (def->panics[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("setting the panic device address is not " - "supported for model 'hyperv'")); - goto error; - } - break; - - case VIR_DOMAIN_PANIC_MODEL_PSERIES: - /* For pSeries guests, the firmware provides the same - * functionality as the pvpanic device. The address - * cannot be configured by the user */ - if (!ARCH_IS_PPC64(def->os.arch) || - !STRPREFIX(def->os.machine, "pseries")) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only pSeries guests support panic device " - "of model 'pseries'")); - goto error; - } - if (def->panics[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("setting the panic device address is not " - "supported for model 'pseries'")); - goto error; - } - break; - - case VIR_DOMAIN_PANIC_MODEL_ISA: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PANIC)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("the QEMU binary does not support the " - "panic device")); - goto error; - } - - switch (def->panics[i]->info.type) { - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: - virCommandAddArg(cmd, "-device"); - virCommandAddArgFormat(cmd, "pvpanic,ioport=%d", - def->panics[i]->info.addr.isa.iobase); - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: - virCommandAddArgList(cmd, "-device", "pvpanic", NULL); - break; - - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("panic is supported only " - "with ISA address type")); - goto error; - } - - /* default model value was changed before in post parse */ - case VIR_DOMAIN_PANIC_MODEL_DEFAULT: - case VIR_DOMAIN_PANIC_MODEL_LAST: - break; - } - } + if (qemuBuildPanicCommandLine(cmd, def, qemuCaps) < 0) + goto error; for (i = 0; i < def->nshmems; i++) { if (qemuBuildShmemCommandLine(logManager, cmd, -- 2.5.0

On Fri, Mar 11, 2016 at 07:36:21PM -0500, John Ferlan wrote:
Final pile of split.
Rather than hope for a review of 25 patches or creating some remote place to place a branch - I'll repost the original:
http://www.redhat.com/archives/libvir-list/2016-February/msg00975.html
in smaller chunks. Differences in this set of patches vs. original series includes handling merge conflicts for logManager series plus a few minor edits/tweaks for better formatting/flow. This series was based off of git head commit 'ef2ab8fdc' which is the round 1 of the split:
http://www.redhat.com/archives/libvir-list/2016-March/msg00288.html
This is round 2 of the split based off of commit id '95ca4fe2':
http://www.redhat.com/archives/libvir-list/2016-March/msg00491.html
John Ferlan (8): qemu: Introduce qemuBuildSoundCommandLine qemu: Introduce qemuBuildWatchdogCommandLine qemu: Introduce qemuBuildRedirdevCommandLine qemu: Introduce qemuBuildHostdevCommandLine qemu: Introduce qemuBuildMemballoonCommandLine qemu: Introduce qemuBuildRNGCommandLine qemu: Introduce qemuBuildNVRAMCommandLine qemu: Introduce qemuBuildPanicCommandLine
src/qemu/qemu_command.c | 1346 ++++++++++++++++++++++++++--------------------- src/qemu/qemu_command.h | 25 +- 2 files changed, 743 insertions(+), 628 deletions(-)
ACK series. However the static function changes could be one separate patch and the const virDomainDef could be in another one. Jan
participants (2)
-
John Ferlan
-
Ján Tomko