mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
qemu_command: Separate domain features building into a helper
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@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
f7baee531a
commit
b185abe9d9
@ -6956,48 +6956,21 @@ qemuBuildNameCommandLine(virCommand *cmd,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuBuildMachineCommandLine(virCommand *cmd,
|
||||
virQEMUDriverConfig *cfg,
|
||||
qemuAppendDomainFeaturesMachineParam(virBuffer *buf,
|
||||
const virDomainDef *def,
|
||||
virQEMUCaps *qemuCaps,
|
||||
qemuDomainObjPrivate *priv)
|
||||
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,6 +7009,107 @@ qemuBuildMachineCommandLine(virCommand *cmd,
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
break;
|
||||
case VIR_DOMAIN_IOAPIC_KVM:
|
||||
virBufferAddLit(buf, ",kernel_irqchip=on");
|
||||
break;
|
||||
case VIR_DOMAIN_IOAPIC_NONE:
|
||||
case VIR_DOMAIN_IOAPIC_LAST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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",
|
||||
virDomainHPTResizingTypeToString(def->hpt_resizing));
|
||||
}
|
||||
|
||||
if (def->hpt_maxpagesize > 0) {
|
||||
virBufferAsprintf(buf, ",cap-hpt-max-page-size=%lluk",
|
||||
def->hpt_maxpagesize);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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:
|
||||
@ -7061,66 +7135,6 @@ qemuBuildMachineCommandLine(virCommand *cmd,
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
break;
|
||||
case VIR_DOMAIN_IOAPIC_KVM:
|
||||
virBufferAddLit(&buf, ",kernel_irqchip=on");
|
||||
break;
|
||||
case VIR_DOMAIN_IOAPIC_NONE:
|
||||
case VIR_DOMAIN_IOAPIC_LAST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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",
|
||||
virDomainHPTResizingTypeToString(def->hpt_resizing));
|
||||
}
|
||||
|
||||
if (def->hpt_maxpagesize > 0) {
|
||||
virBufferAsprintf(&buf, ",cap-hpt-max-page-size=%lluk",
|
||||
def->hpt_maxpagesize);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (cpu && cpu->model &&
|
||||
cpu->mode == VIR_CPU_MODE_HOST_MODEL &&
|
||||
qemuDomainIsPSeries(def)) {
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
Loading…
x
Reference in New Issue
Block a user