The qemuBuildMachineCommandLine() function is needlessly long. Separate out parts that generate arguments based on domainDef->features[] into qemuAppendDomainFeaturesMachineParam(). Unfortunately, expected outputs for some qemuxml2argvdata cases needed to be updated because the order in which features are generated is changed. But there's no functional change. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_command.c | 154 ++++++++++-------- ...-auto-efi-enrolled-keys.x86_64-latest.args | 2 +- ...-auto-efi-loader-secure.x86_64-latest.args | 2 +- ...firmware-auto-efi-nvram.x86_64-latest.args | 2 +- ...rmware-auto-efi-secboot.x86_64-latest.args | 2 +- .../firmware-auto-efi.x86_64-latest.args | 2 +- .../firmware-manual-efi-secure.args | 2 +- .../machine-smm-off.x86_64-latest.args | 2 +- .../machine-smm-on.x86_64-latest.args | 2 +- .../qemuxml2argvdata/machine-vmport-opt.args | 2 +- .../q35-virt-manager-basic.args | 2 +- .../tseg-explicit-size.x86_64-latest.args | 2 +- 12 files changed, 95 insertions(+), 81 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 77f5644b1c..b5f1d7de0a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6956,48 +6956,21 @@ qemuBuildNameCommandLine(virCommand *cmd, return 0; } + static int -qemuBuildMachineCommandLine(virCommand *cmd, - virQEMUDriverConfig *cfg, - const virDomainDef *def, - virQEMUCaps *qemuCaps, - qemuDomainObjPrivate *priv) +qemuAppendDomainFeaturesMachineParam(virBuffer *buf, + const virDomainDef *def, + virQEMUCaps *qemuCaps) { virTristateSwitch vmport = def->features[VIR_DOMAIN_FEATURE_VMPORT]; virTristateSwitch smm = def->features[VIR_DOMAIN_FEATURE_SMM]; - virCPUDef *cpu = def->cpu; - g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - size_t i; - - virCommandAddArg(cmd, "-machine"); - virBufferAdd(&buf, def->os.machine, -1); - - /* To avoid the collision of creating USB controllers when calling - * machine->init in QEMU, it needs to set usb=off - */ - virBufferAddLit(&buf, ",usb=off"); if (vmport != VIR_TRISTATE_SWITCH_ABSENT) - virBufferAsprintf(&buf, ",vmport=%s", + virBufferAsprintf(buf, ",vmport=%s", virTristateSwitchTypeToString(vmport)); - if (smm) - virBufferAsprintf(&buf, ",smm=%s", virTristateSwitchTypeToString(smm)); - - if (def->mem.dump_core) { - virBufferAsprintf(&buf, ",dump-guest-core=%s", - virTristateSwitchTypeToString(def->mem.dump_core)); - } else { - virBufferAsprintf(&buf, ",dump-guest-core=%s", - cfg->dumpGuestCore ? "on" : "off"); - } - - if (def->mem.nosharepages) - virBufferAddLit(&buf, ",mem-merge=off"); - - if (def->keywrap && - !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap)) - return -1; + if (smm != VIR_TRISTATE_SWITCH_ABSENT) + virBufferAsprintf(buf, ",smm=%s", virTristateSwitchTypeToString(smm)); if (def->features[VIR_DOMAIN_FEATURE_GIC] == VIR_TRISTATE_SWITCH_ON) { bool hasGICVersionOption = virQEMUCapsGet(qemuCaps, @@ -7025,7 +6998,7 @@ qemuBuildMachineCommandLine(virCommand *cmd, return -1; } - virBufferAsprintf(&buf, ",gic-version=%s", + virBufferAsprintf(buf, ",gic-version=%s", virGICVersionTypeToString(def->gic_version)); break; @@ -7036,38 +7009,13 @@ qemuBuildMachineCommandLine(virCommand *cmd, } } - if (def->iommu) { - switch (def->iommu->model) { - case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: - virBufferAddLit(&buf, ",iommu=smmuv3"); - break; - - case VIR_DOMAIN_IOMMU_MODEL_INTEL: - case VIR_DOMAIN_IOMMU_MODEL_VIRTIO: - /* These IOMMUs are formatted in qemuBuildIOMMUCommandLine */ - break; - - case VIR_DOMAIN_IOMMU_MODEL_LAST: - default: - virReportEnumRangeError(virDomainIOMMUModel, def->iommu->model); - return -1; - } - } - - for (i = 0; i < def->nmems; i++) { - if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { - virBufferAddLit(&buf, ",nvdimm=on"); - break; - } - } - if (def->features[VIR_DOMAIN_FEATURE_IOAPIC] != VIR_DOMAIN_IOAPIC_NONE) { switch ((virDomainIOAPIC) def->features[VIR_DOMAIN_FEATURE_IOAPIC]) { case VIR_DOMAIN_IOAPIC_QEMU: - virBufferAddLit(&buf, ",kernel_irqchip=split"); + virBufferAddLit(buf, ",kernel_irqchip=split"); break; case VIR_DOMAIN_IOAPIC_KVM: - virBufferAddLit(&buf, ",kernel_irqchip=on"); + virBufferAddLit(buf, ",kernel_irqchip=on"); break; case VIR_DOMAIN_IOAPIC_NONE: case VIR_DOMAIN_IOAPIC_LAST: @@ -7078,12 +7026,12 @@ qemuBuildMachineCommandLine(virCommand *cmd, if (def->features[VIR_DOMAIN_FEATURE_HPT] == VIR_TRISTATE_SWITCH_ON) { if (def->hpt_resizing != VIR_DOMAIN_HPT_RESIZING_NONE) { - virBufferAsprintf(&buf, ",resize-hpt=%s", + virBufferAsprintf(buf, ",resize-hpt=%s", virDomainHPTResizingTypeToString(def->hpt_resizing)); } if (def->hpt_maxpagesize > 0) { - virBufferAsprintf(&buf, ",cap-hpt-max-page-size=%lluk", + virBufferAsprintf(buf, ",cap-hpt-max-page-size=%lluk", def->hpt_maxpagesize); } } @@ -7091,34 +7039,100 @@ qemuBuildMachineCommandLine(virCommand *cmd, if (def->features[VIR_DOMAIN_FEATURE_HTM] != VIR_TRISTATE_SWITCH_ABSENT) { const char *str; str = virTristateSwitchTypeToString(def->features[VIR_DOMAIN_FEATURE_HTM]); - virBufferAsprintf(&buf, ",cap-htm=%s", str); + virBufferAsprintf(buf, ",cap-htm=%s", str); } if (def->features[VIR_DOMAIN_FEATURE_NESTED_HV] != VIR_TRISTATE_SWITCH_ABSENT) { const char *str; str = virTristateSwitchTypeToString(def->features[VIR_DOMAIN_FEATURE_NESTED_HV]); - virBufferAsprintf(&buf, ",cap-nested-hv=%s", str); + virBufferAsprintf(buf, ",cap-nested-hv=%s", str); } if (def->features[VIR_DOMAIN_FEATURE_CCF_ASSIST] != VIR_TRISTATE_SWITCH_ABSENT) { const char *str; str = virTristateSwitchTypeToString(def->features[VIR_DOMAIN_FEATURE_CCF_ASSIST]); - virBufferAsprintf(&buf, ",cap-ccf-assist=%s", str); + virBufferAsprintf(buf, ",cap-ccf-assist=%s", str); } if (def->features[VIR_DOMAIN_FEATURE_CFPC] != VIR_DOMAIN_CFPC_NONE) { const char *str = virDomainCFPCTypeToString(def->features[VIR_DOMAIN_FEATURE_CFPC]); - virBufferAsprintf(&buf, ",cap-cfpc=%s", str); + virBufferAsprintf(buf, ",cap-cfpc=%s", str); } if (def->features[VIR_DOMAIN_FEATURE_SBBC] != VIR_DOMAIN_SBBC_NONE) { const char *str = virDomainSBBCTypeToString(def->features[VIR_DOMAIN_FEATURE_SBBC]); - virBufferAsprintf(&buf, ",cap-sbbc=%s", str); + virBufferAsprintf(buf, ",cap-sbbc=%s", str); } if (def->features[VIR_DOMAIN_FEATURE_IBS] != VIR_DOMAIN_IBS_NONE) { const char *str = virDomainIBSTypeToString(def->features[VIR_DOMAIN_FEATURE_IBS]); - virBufferAsprintf(&buf, ",cap-ibs=%s", str); + virBufferAsprintf(buf, ",cap-ibs=%s", str); + } + + return 0; +} + + +static int +qemuBuildMachineCommandLine(virCommand *cmd, + virQEMUDriverConfig *cfg, + const virDomainDef *def, + virQEMUCaps *qemuCaps, + qemuDomainObjPrivate *priv) +{ + virCPUDef *cpu = def->cpu; + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + size_t i; + + virCommandAddArg(cmd, "-machine"); + virBufferAdd(&buf, def->os.machine, -1); + + /* To avoid the collision of creating USB controllers when calling + * machine->init in QEMU, it needs to set usb=off + */ + virBufferAddLit(&buf, ",usb=off"); + + if (def->mem.dump_core) { + virBufferAsprintf(&buf, ",dump-guest-core=%s", + virTristateSwitchTypeToString(def->mem.dump_core)); + } else { + virBufferAsprintf(&buf, ",dump-guest-core=%s", + cfg->dumpGuestCore ? "on" : "off"); + } + + if (def->mem.nosharepages) + virBufferAddLit(&buf, ",mem-merge=off"); + + if (def->keywrap && + !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap)) + return -1; + + if (qemuAppendDomainFeaturesMachineParam(&buf, def, qemuCaps) < 0) + return -1; + + if (def->iommu) { + switch (def->iommu->model) { + case VIR_DOMAIN_IOMMU_MODEL_SMMUV3: + virBufferAddLit(&buf, ",iommu=smmuv3"); + break; + + case VIR_DOMAIN_IOMMU_MODEL_INTEL: + case VIR_DOMAIN_IOMMU_MODEL_VIRTIO: + /* These IOMMUs are formatted in qemuBuildIOMMUCommandLine */ + break; + + case VIR_DOMAIN_IOMMU_MODEL_LAST: + default: + virReportEnumRangeError(virDomainIOMMUModel, def->iommu->model); + return -1; + } + } + + for (i = 0; i < def->nmems; i++) { + if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + virBufferAddLit(&buf, ",nvdimm=on"); + break; + } } if (cpu && cpu->model && diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-enrolled-keys.x86_64-latest.args b/tests/qemuxml2argvdata/firmware-auto-efi-enrolled-keys.x86_64-latest.args index 7479b05af4..a9391d7921 100644 --- a/tests/qemuxml2argvdata/firmware-auto-efi-enrolled-keys.x86_64-latest.args +++ b/tests/qemuxml2argvdata/firmware-auto-efi-enrolled-keys.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/fedora_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ --machine pc-q35-4.0,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ +-machine pc-q35-4.0,usb=off,dump-guest-core=off,smm=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-loader-secure.x86_64-latest.args b/tests/qemuxml2argvdata/firmware-auto-efi-loader-secure.x86_64-latest.args index 7479b05af4..a9391d7921 100644 --- a/tests/qemuxml2argvdata/firmware-auto-efi-loader-secure.x86_64-latest.args +++ b/tests/qemuxml2argvdata/firmware-auto-efi-loader-secure.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/fedora_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ --machine pc-q35-4.0,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ +-machine pc-q35-4.0,usb=off,dump-guest-core=off,smm=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-nvram.x86_64-latest.args b/tests/qemuxml2argvdata/firmware-auto-efi-nvram.x86_64-latest.args index 1061e93554..9795dedc7c 100644 --- a/tests/qemuxml2argvdata/firmware-auto-efi-nvram.x86_64-latest.args +++ b/tests/qemuxml2argvdata/firmware-auto-efi-nvram.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ -blockdev '{"driver":"file","filename":"/path/to/fedora_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ --machine pc-q35-4.0,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ +-machine pc-q35-4.0,usb=off,dump-guest-core=off,smm=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-secboot.x86_64-latest.args b/tests/qemuxml2argvdata/firmware-auto-efi-secboot.x86_64-latest.args index 7479b05af4..a9391d7921 100644 --- a/tests/qemuxml2argvdata/firmware-auto-efi-secboot.x86_64-latest.args +++ b/tests/qemuxml2argvdata/firmware-auto-efi-secboot.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/fedora_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ --machine pc-q35-4.0,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ +-machine pc-q35-4.0,usb=off,dump-guest-core=off,smm=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxml2argvdata/firmware-auto-efi.x86_64-latest.args b/tests/qemuxml2argvdata/firmware-auto-efi.x86_64-latest.args index 7479b05af4..a9391d7921 100644 --- a/tests/qemuxml2argvdata/firmware-auto-efi.x86_64-latest.args +++ b/tests/qemuxml2argvdata/firmware-auto-efi.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-fedora/.config \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/fedora_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \ --machine pc-q35-4.0,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ +-machine pc-q35-4.0,usb=off,dump-guest-core=off,smm=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxml2argvdata/firmware-manual-efi-secure.args b/tests/qemuxml2argvdata/firmware-manual-efi-secure.args index fe0f78599b..1a5f83e489 100644 --- a/tests/qemuxml2argvdata/firmware-manual-efi-secure.args +++ b/tests/qemuxml2argvdata/firmware-manual-efi-secure.args @@ -11,7 +11,7 @@ QEMU_AUDIO_DRV=none \ -name guest=test-bios,debug-threads=on \ -S \ -object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-test-bios/master-key.aes \ --machine q35,usb=off,smm=on,dump-guest-core=off \ +-machine q35,usb=off,dump-guest-core=off,smm=on \ -accel tcg \ -global driver=cfi.pflash01,property=secure,value=on \ -drive file=/usr/share/OVMF/OVMF_CODE.secboot.fd,if=pflash,format=raw,unit=0,readonly=on \ diff --git a/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args index 46f6a4a70c..83462bec68 100644 --- a/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args +++ b/tests/qemuxml2argvdata/machine-smm-off.x86_64-latest.args @@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -name guest=QEMUGuest1,debug-threads=on \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ --machine q35,usb=off,smm=off,dump-guest-core=off,memory-backend=pc.ram \ +-machine q35,usb=off,dump-guest-core=off,smm=off,memory-backend=pc.ram \ -accel tcg \ -cpu qemu64 \ -m 214 \ diff --git a/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args b/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args index 6fde375523..53a03124b4 100644 --- a/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args +++ b/tests/qemuxml2argvdata/machine-smm-on.x86_64-latest.args @@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -name guest=QEMUGuest1,debug-threads=on \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ --machine q35,usb=off,smm=on,dump-guest-core=off,memory-backend=pc.ram \ +-machine q35,usb=off,dump-guest-core=off,smm=on,memory-backend=pc.ram \ -accel tcg \ -cpu qemu64 \ -m 214 \ diff --git a/tests/qemuxml2argvdata/machine-vmport-opt.args b/tests/qemuxml2argvdata/machine-vmport-opt.args index c95c972803..769f3d67e5 100644 --- a/tests/qemuxml2argvdata/machine-vmport-opt.args +++ b/tests/qemuxml2argvdata/machine-vmport-opt.args @@ -11,7 +11,7 @@ QEMU_AUDIO_DRV=none \ -name guest=QEMUGuest1,debug-threads=on \ -S \ -object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ --machine pc,usb=off,vmport=off,dump-guest-core=off \ +-machine pc,usb=off,dump-guest-core=off,vmport=off \ -accel tcg \ -m 214 \ -overcommit mem-lock=off \ diff --git a/tests/qemuxml2argvdata/q35-virt-manager-basic.args b/tests/qemuxml2argvdata/q35-virt-manager-basic.args index 32875f291c..b4c9715717 100644 --- a/tests/qemuxml2argvdata/q35-virt-manager-basic.args +++ b/tests/qemuxml2argvdata/q35-virt-manager-basic.args @@ -11,7 +11,7 @@ QEMU_AUDIO_DRV=spice \ -name guest=virt-manager-basic,debug-threads=on \ -S \ -object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-virt-manager-basic/master-key.aes \ --machine q35,usb=off,vmport=off,dump-guest-core=off \ +-machine q35,usb=off,dump-guest-core=off,vmport=off \ -accel kvm \ -m 4096 \ -overcommit mem-lock=off \ diff --git a/tests/qemuxml2argvdata/tseg-explicit-size.x86_64-latest.args b/tests/qemuxml2argvdata/tseg-explicit-size.x86_64-latest.args index 3371199be5..e05f295c4f 100644 --- a/tests/qemuxml2argvdata/tseg-explicit-size.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tseg-explicit-size.x86_64-latest.args @@ -10,7 +10,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -name guest=QEMUGuest1,debug-threads=on \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ --machine pc-q35-2.10,usb=off,smm=on,dump-guest-core=off,memory-backend=pc.ram \ +-machine pc-q35-2.10,usb=off,dump-guest-core=off,smm=on,memory-backend=pc.ram \ -accel tcg \ -global mch.extended-tseg-mbytes=48 \ -cpu qemu64 \ -- 2.35.1