[libvirt] [PATCH] ppc64: get the maxvcpus from the qemu caps instead of /dev/kvm

On PPC64, the KVM_MAX_VCPUS is defined to be 1024 where as qemu has MAX_CPUMASK_BITS defined at 255 in include/sysemu/sysemu.h. virsh domacapabilities and virsh maxvcpus --type kvm return different maxvcpus values and is confusing as to know what actually works. Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- src/qemu/qemu_driver.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3d0c7c8..d84fc47 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1255,10 +1255,34 @@ static int qemuConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED) static int -kvmGetMaxVCPUs(void) +kvmGetMaxVCPUs(virConnectPtr conn) { int fd; int ret; + virArch arch = virArchFromHost(); + virQEMUCapsPtr qemuCaps = NULL; + virQEMUDriverPtr driver = conn->privateData; + + const char *machine; + + if (ARCH_IS_PPC64(arch)) { + if (!(qemuCaps = virQEMUCapsCacheLookupByArch(driver->qemuCapsCache, + arch))) { + virReportError(VIR_ERR_INVALID_ARG, + _("unable to find any emulator to serve '%s' " + "architecture"), virArchToString(arch)); + return -1; + } + + if (!(machine = virQEMUCapsGetDefaultMachine(qemuCaps))) { + virObjectUnref(qemuCaps); + return -1; + } + + ret = virQEMUCapsGetMachineMaxCpus(qemuCaps, machine); + virObjectUnref(qemuCaps); + return ret; + } if ((fd = open(KVM_DEVICE, O_RDONLY)) < 0) { virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE); @@ -1323,7 +1347,7 @@ qemuConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) return 16; if (STRCASEEQ(type, "kvm")) - return kvmGetMaxVCPUs(); + return kvmGetMaxVCPUs(conn); if (STRCASEEQ(type, "kqemu")) return 1;

On 05/02/2016 09:14 AM, Shivaprasad G Bhat wrote:
On PPC64, the KVM_MAX_VCPUS is defined to be 1024 where as qemu has MAX_CPUMASK_BITS defined at 255 in include/sysemu/sysemu.h.
virsh domacapabilities and virsh maxvcpus --type kvm return different maxvcpus values and is confusing as to know what actually works.
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- src/qemu/qemu_driver.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3d0c7c8..d84fc47 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1255,10 +1255,34 @@ static int qemuConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
static int -kvmGetMaxVCPUs(void) +kvmGetMaxVCPUs(virConnectPtr conn) { int fd; int ret; + virArch arch = virArchFromHost(); + virQEMUCapsPtr qemuCaps = NULL; + virQEMUDriverPtr driver = conn->privateData; + + const char *machine; + + if (ARCH_IS_PPC64(arch)) { + if (!(qemuCaps = virQEMUCapsCacheLookupByArch(driver->qemuCapsCache, + arch))) { + virReportError(VIR_ERR_INVALID_ARG, + _("unable to find any emulator to serve '%s' " + "architecture"), virArchToString(arch)); + return -1; + } + + if (!(machine = virQEMUCapsGetDefaultMachine(qemuCaps))) { + virObjectUnref(qemuCaps); + return -1; + } + + ret = virQEMUCapsGetMachineMaxCpus(qemuCaps, machine); + virObjectUnref(qemuCaps); + return ret; + }
I don't really like this. The MaxVCPUs API sucks: it doesn't take enough parameters to give an accurate picture of what the max VCPUs supported for your desired config is. And that's basically unfixable. Hacking in a one off fix for PPC64 here doesn't seem like a good idea. If you really want to 'fix' this I'd suggest one or more of: - Reflect /dev/kvm maxvcpus in the capabilities XML somehow - Extend 'virsh maxvcpus' to take os_type+virt_type+emulator+machine_type, look up the capabilities XML, correlate that with maxvcpus output/new capabilities XML, and give a real value for the desired config - Change the maxvcpus API to consistently to return capabilities output, or cap the return value to the largest reported in capabilities output, and do it consistently for all architectures - Cole
if ((fd = open(KVM_DEVICE, O_RDONLY)) < 0) { virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE); @@ -1323,7 +1347,7 @@ qemuConnectGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) return 16;
if (STRCASEEQ(type, "kvm")) - return kvmGetMaxVCPUs(); + return kvmGetMaxVCPUs(conn);
if (STRCASEEQ(type, "kqemu")) return 1;
participants (2)
-
Cole Robinson
-
Shivaprasad G Bhat