[libvirt] [PATCH] virsh: use virConnectGetDomainCapabilities with maxvcpus

The following patch fixes the maxvcpus output on PPC64. Earlier I tried fixing this in kvmGetMaxVcpus() which was later decided to be document not use the virConnectGetMaxVcpus() instead use the virConnectGetDomainCapabilities api. I have not implemented the suggestedcpus as mentioned in my previous patches in this yet. Previous series fixing the virConnectGetDomainCapabilities can be found here. https://www.redhat.com/archives/libvir-list/2016-June/msg01873.html --- Shivaprasad G Bhat (1): virsh: use virConnectGetDomainCapabilities with maxvcpus tools/virsh-host.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) -- Signature

virsh maxvcpus --type kvm output is useless on PPC. Also, in commit e6806d79 we documented not rely on virConnectGetMaxVcpus output. Fix the maxvcpus to use virConnectGetDomainCapabilities now to make it useful. The call is made to use the default qemu binary and to check for the host machine and arch which is what the command intends to do anyway. Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- tools/virsh-host.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 57f0c0e..cf001c6 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -606,18 +606,43 @@ static bool cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) { const char *type = NULL; - int vcpus; + unsigned int vcpus; + char *caps = NULL; + const unsigned int flags = 0; /* No flags so far */ + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + bool ret = false; virshControlPtr priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; - if ((vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0) - return false; + caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type, flags); + if (!caps) { + vshError(ctl, "%s", _("failed to get domain capabilities")); + goto cleanup; + } + + xml = virXMLParseStringCtxt(caps, _("(domainCapabilities)"), &ctxt); + if (!xml) { + vshError(ctl, "%s", _("unable to parse domain capabilities")); + goto cleanup; + } + + if ((virXPathUInt("string(./vcpu[1]/@max)", ctxt, &vcpus)) < 0) { + vshError(ctl, "%s", _("unable to get maxvcpus")); + goto cleanup; + } vshPrint(ctl, "%d\n", vcpus); - return true; + ret = true; + cleanup: + VIR_FREE(caps); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + + return ret; } /*

On Wed, Jul 27, 2016 at 18:08:29 +0530, Shivaprasad G Bhat wrote:
virsh maxvcpus --type kvm output is useless on PPC. Also, in commit e6806d79 we documented not rely on virConnectGetMaxVcpus output. Fix the maxvcpus to use virConnectGetDomainCapabilities now to make it useful. The call is made to use the default qemu binary and to check for the host machine and arch which is what the command intends to do anyway.
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- tools/virsh-host.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 57f0c0e..cf001c6 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -606,18 +606,43 @@ static bool cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) { const char *type = NULL; - int vcpus; + unsigned int vcpus; + char *caps = NULL; + const unsigned int flags = 0; /* No flags so far */ + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + bool ret = false; virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false;
- if ((vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0) - return false; + caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type, flags); + if (!caps) { + vshError(ctl, "%s", _("failed to get domain capabilities")); + goto cleanup; + }
This will break compatibility when connecting to older versions of the daemon which don't support the virConnectGetDomainCapabilities. Peter
participants (2)
-
Peter Krempa
-
Shivaprasad G Bhat