From 657451fe2a5e8b55adbae643ac818b496c9cbc0c Mon Sep 17 00:00:00 2001 Message-Id: <657451fe2a5e8b55adbae643ac818b496c9cbc0c@dist-git> From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 16 May 2017 10:44:51 +0200 Subject: [PATCH] qemu: refactor qemuBuildIOMMUCommandLine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a separate buffer for options and use a helper variable for def->iommu. (cherry picked from commit b595cc05e83288b743d48904964e4dcb547a2d26) Signed-off-by: Ján Tomko https://bugzilla.redhat.com/show_bug.cgi?id=1427005 Signed-off-by: Jiri Denemark --- src/qemu/qemu_command.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4d3a3d8ca..b27b9f8ad 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6664,33 +6664,42 @@ qemuBuildIOMMUCommandLine(virCommandPtr cmd, const virDomainDef *def, virQEMUCapsPtr qemuCaps) { - if (!def->iommu) + virBuffer opts = VIR_BUFFER_INITIALIZER; + const virDomainIOMMUDef *iommu = def->iommu; + int ret = -1; + + if (!iommu) return 0; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU)) return 0; /* Already handled via -machine */ - switch (def->iommu->model) { + switch (iommu->model) { case VIR_DOMAIN_IOMMU_MODEL_INTEL: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("IOMMU device: '%s' is not supported with " "this QEMU binary"), - virDomainIOMMUModelTypeToString(def->iommu->model)); + virDomainIOMMUModelTypeToString(iommu->model)); return -1; } if (!qemuDomainIsQ35(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("IOMMU device: '%s' is only supported with " "Q35 machines"), - virDomainIOMMUModelTypeToString(def->iommu->model)); + virDomainIOMMUModelTypeToString(iommu->model)); return -1; } - virCommandAddArgList(cmd, "-device", "intel-iommu", NULL); + virBufferAddLit(&opts, "intel-iommu"); case VIR_DOMAIN_IOMMU_MODEL_LAST: break; } - return 0; + virCommandAddArg(cmd, "-device"); + virCommandAddArgBuffer(cmd, &opts); + + ret = 0; + virBufferFreeAndReset(&opts); + return ret; } -- 2.13.0