}
+int qemuCapsAddCPUDefinition(qemuCapsPtr caps,
+ const char *name)
+{
+ char *tmp = strdup(name);
+ if (!tmp) {
+ virReportOOMError();
+ return -1;
+ }
+ if (VIR_EXPAND_N(caps->cpuDefinitions, caps->ncpuDefinitions, 1) < 0) {
+ VIR_FREE(tmp);
+ virReportOOMError();
+ return -1;
+ }
+ caps->cpuDefinitions[caps->ncpuDefinitions-1] = tmp;
+ return 0;
+}
+
+
size_t qemuCapsGetCPUDefinitions(qemuCapsPtr caps,
char ***names)
{
const char *qemuCapsGetArch(qemuCapsPtr caps);
unsigned int qemuCapsGetVersion(qemuCapsPtr caps);
unsigned int qemuCapsGetKVMVersion(qemuCapsPtr caps);
+int qemuCapsAddCPUDefinition(qemuCapsPtr caps,
+ const char *name);
size_t qemuCapsGetCPUDefinitions(qemuCapsPtr caps,
char ***names);
size_t qemuCapsGetMachineTypes(qemuCapsPtr caps,
virCPUDefPtr guest = NULL;
virCPUDefPtr cpu = NULL;
size_t ncpus = 0;
- const char **cpus = NULL;
+ char **cpus = NULL;
const char *default_model;
union cpuData *data = NULL;
bool have_cpu = false;
const char *preferred;
int hasSVM;
- if (host &&
- qemuCapsProbeCPUModels(emulator, caps, host->arch,
- &ncpus, &cpus) < 0)
- goto cleanup;
-
- if (!ncpus || !host) {
+ if (!host ||
+ (ncpus = qemuCapsGetCPUDefinitions(caps, &cpus)) == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("CPU specification not supported by hypervisor"));
goto cleanup;
guest->type = VIR_CPU_TYPE_GUEST;
guest->fallback = cpu->fallback;
- if (cpuDecode(guest, data, cpus, ncpus, preferred) < 0)
+ if (cpuDecode(guest, data, (const char **)cpus, ncpus, preferred) < 0)
goto cleanup;
virBufferAdd(&buf, guest->model, -1);
virCPUDefFree(guest);
virCPUDefFree(cpu);
- if (cpus) {
- for (i = 0; i < ncpus; i++)
- VIR_FREE(cpus[i]);
- VIR_FREE(cpus);
- }
-
return ret;
no_memory:
+++ /dev/null
-candidates="/usr/bin/qemu-kvm
- /usr/libexec/qemu-kvm
- /usr/bin/qemu-system-x86_64
- /usr/bin/qemu"
-qemu=
-for candidate in $candidates; do
- if test -x $candidate; then
- qemu=$candidate
- break
- fi
-done
-
-real_qemu()
-{
- if test x$qemu != x; then
- exec $qemu "$@"
- else
- return 1
- fi
-}
-
-faked_machine()
-{
- echo "pc"
-}
-
-faked_cpu()
-{
- cat <<EOF
-x86 Opteron_G3
-x86 Opteron_G2
-x86 Opteron_G1
-x86 Nehalem
-x86 Penryn
-x86 Conroe
-x86 [n270]
-x86 [athlon]
-x86 [pentium3]
-x86 [pentium2]
-x86 [pentium]
-x86 [486]
-x86 [coreduo]
-x86 [qemu32]
-x86 [kvm64]
-x86 [core2duo]
-x86 [phenom]
-x86 [qemu64]
-x86 [host]
-EOF
-}
+++ /dev/null
-#! /bin/sh
-
-. ${0%/*}/qemu-lib.sh
-
-case $* in
-"-M ?")
- faked_machine
- ;;
-"-cpu ?")
- faked_cpu | grep -Fv '['
- ;;
-*)
- real_qemu "$@"
- ;;
-esac
+++ /dev/null
-#! /bin/sh
-
-. ${0%/*}/qemu-lib.sh
-
-case $* in
-"-M ?")
- faked_machine
- ;;
-"-cpu ?")
- faked_cpu
- ;;
-*)
- real_qemu "$@"
- ;;
-esac
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu qemu32,-kvm_pv_eoi -m 214 -smp 6 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -boot n -net none -serial none \
-parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu qemu32,+kvm_pv_eoi -m 214 -smp 6 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -boot n -net none -serial none \
-parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu qemu64,-svm,-lm,-nx,-syscall,-clflush,-pse36,-mca -m 214 -smp 6 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+ds_cpl,+tm,+ht,+ds,-nx -m 214 -smp 6 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+ds_cpl,+tm,+ht,+ds,-nx -m 214 -smp 6 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
HOME=/home/test \
USER=test \
LOGNAME=test \
-./qemu.sh \
+/usr/bin/qemu \
-S \
-M pc \
-cpu Penryn,-sse4.1 \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu host,-kvmclock -enable-kvm -m 214 -smp 6 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
HOME=/home/test \
USER=test \
LOGNAME=test \
-./qemu-supported-cpus.sh \
+/usr/bin/qemu \
-S \
-M pc \
-cpu Penryn,+xtpr,+tm2,+est,+vmx,+ds_cpl,+monitor,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme,-sse4.1 \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu-supported-cpus.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu-supported-cpus.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
HOME=/home/test \
USER=test \
LOGNAME=test \
-./qemu.sh \
+/usr/bin/qemu \
-S \
-M pc \
-cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
HOME=/home/test \
USER=test \
LOGNAME=test \
-./qemu.sh \
+/usr/bin/qemu \
-S \
-M pc \
-cpu host \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,-kvmclock -enable-kvm -m 214 -smp 6 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \
none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,\
+acpi,+ds -m 214 -smp 6 -nographic -monitor unix:/tmp/test-monitor,server,\
nowait -no-acpi -boot n -net none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,\
+acpi,+ds,-lm,-nx,-syscall -m 214 -smp 6 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-m 214 -smp 16 -numa node,nodeid=0,cpus=0-7,mem=107 \
-numa node,nodeid=1,cpus=8-15,mem=107 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-m 214 -smp 16,sockets=2,cores=4,threads=2 \
-numa node,nodeid=0,cpus=0-7,mem=107 \
-numa node,nodeid=1,cpus=8-15,mem=107 -nographic -monitor \
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+est,+vmx,+ds_cpl,+tm,+ht,+acpi,+ds,-nx \
-m 214 -smp 6 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot n -net none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-m 214 -smp 6,sockets=3,cores=2,threads=1 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \
-parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu core2duo -m 214 -smp 6,sockets=1,cores=2,threads=3 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net none -serial none \
-parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-m 214 -smp 6 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot n -net none -serial none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
</devices>
</domain>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu qemu32,-kvm_pv_eoi -m 214 -smp 6 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -boot n -net none -serial \
none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc \
-cpu qemu32,+kvm_pv_eoi -m 214 -smp 6 -nographic -monitor \
unix:/tmp/test-monitor,server,nowait -boot n -net none -serial \
none -parallel none -usb
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
</devices>
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice \
-./qemu.sh -S -M pc -cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,\
+/usr/bin/qemu -S -M pc -cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,\
+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds \
-m 1024 -smp 2 -nodefaults -monitor unix:/tmp/test-monitor,server,nowait \
-boot dc -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/f14.img'/>
goto out;
}
- /*
- * For test purposes, we may want to fake emulator's output by providing
- * our own script instead of a real emulator. For this to work we need to
- * specify a relative path in <emulator/> element, which, however, is not
- * allowed by RelaxNG schema for domain XML. To work around it we add an
- * extra '/' at the beginning of relative emulator path so that it looks
- * like, e.g., "/./qemu.sh" or "/../emulator/qemu.sh" instead of
- * "./qemu.sh" or "../emulator/qemu.sh" respectively. The following code
- * detects such paths, strips the extra '/' and makes the path absolute.
- */
- if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
- if (!(emulator = strdup(vmdef->emulator + 1)))
- goto out;
- VIR_FREE(vmdef->emulator);
- vmdef->emulator = NULL;
- if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
- abs_srcdir, emulator) < 0)
- goto out;
- }
-
if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID))
vmdef->id = 6;
else
}
+static int
+testAddCPUModels(qemuCapsPtr caps, bool skipLegacy)
+{
+ const char *newModels[] = {
+ "Opteron_G3", "Opteron_G2", "Opteron_G1",
+ "Nehalem", "Penryn", "Conroe",
+ };
+ const char *legacyModels[] = {
+ "n270", "athlon", "pentium3", "pentium2", "pentium",
+ "486", "coreduo", "kvm32", "qemu32", "kvm64",
+ "core2duo", "phenom", "qemu64",
+ };
+ size_t i;
+
+ for (i = 0 ; i < ARRAY_CARDINALITY(newModels) ; i++) {
+ if (qemuCapsAddCPUDefinition(caps, newModels[i]) < 0)
+ return -1;
+ }
+ if (skipLegacy)
+ return 0;
+ for (i = 0 ; i < ARRAY_CARDINALITY(legacyModels) ; i++) {
+ if (qemuCapsAddCPUDefinition(caps, legacyModels[i]) < 0)
+ return -1;
+ }
+ return 0;
+}
+
static int
mymain(void)
{
int ret = 0;
char *map = NULL;
+ bool skipLegacyCPUs = false;
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
}; \
if (!(info.extraFlags = qemuCapsNew())) \
return EXIT_FAILURE; \
+ if (testAddCPUModels(info.extraFlags, skipLegacyCPUs) < 0) \
+ return EXIT_FAILURE; \
qemuCapsSetList(info.extraFlags, __VA_ARGS__, QEMU_CAPS_LAST); \
if (virtTestRun("QEMU XML-2-ARGV " name, \
1, testCompareXMLToArgvHelper, &info) < 0) \
DO_TEST("cpu-numa1", NONE);
DO_TEST("cpu-numa2", QEMU_CAPS_SMP_TOPOLOGY);
DO_TEST("cpu-host-model", NONE);
+ skipLegacyCPUs = true;
DO_TEST("cpu-host-model-fallback", NONE);
DO_TEST_FAILURE("cpu-host-model-nofallback", NONE);
+ skipLegacyCPUs = false;
DO_TEST("cpu-host-passthrough", QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST);
DO_TEST_FAILURE("cpu-host-passthrough", NONE);
DO_TEST_FAILURE("cpu-qemu-host-passthrough",
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
- <emulator>/./qemu.sh</emulator>
+ <emulator>/usr/bin/qemu</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/f14.img'/>