[libvirt] [PATCH v2] virsh: use virConnectGetDomainCapabilities with maxvcpus
John Ferlan
jferlan at redhat.com
Thu Sep 1 14:20:08 UTC 2016
On 07/29/2016 09:49 AM, 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 emulator
> binary and to check for the host machine and arch which is what the
> command intends to show anyway.
>
> Signed-off-by: Shivaprasad G Bhat <sbhat at linux.vnet.ibm.com>
> ---
> tools/virsh-host.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/tools/virsh-host.c b/tools/virsh-host.c
> index 57f0c0e..dd6ff4e 100644
> --- a/tools/virsh-host.c
> +++ b/tools/virsh-host.c
> @@ -606,15 +606,37 @@ static bool
> cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
> {
> const char *type = NULL;
> - int vcpus;
> + int vcpus = -1;
> + char *caps = NULL;
> + const unsigned int flags = 0; /* No flags so far */
> + xmlDocPtr xml = NULL;
> + xmlXPathContextPtr ctxt = NULL;
> virshControlPtr priv = ctl->privData;
>
> if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
> return false;
>
> + caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type, flags);
> + if (!caps)
I think perhaps a bit of code like virshGetDomainDescription,
cmdDomblkstat, cmdDominfo, virshDomainListCollect, etc. where last_error
is checked for VIR_ERR_NO_SUPPORT, vshResetLibvirtError is called before
falling back...
John
> + goto fallback;
> +
> + xml = virXMLParseStringCtxt(caps, _("(domainCapabilities)"), &ctxt);
> + if (!xml) {
> + VIR_FREE(caps);
> + goto fallback;
> + }
> +
> + virXPathInt("string(./vcpu[1]/@max)", ctxt, &vcpus);
> +
> + xmlXPathFreeContext(ctxt);
> + xmlFreeDoc(xml);
> + if (vcpus > 0)
> + goto exit;
> +
> + fallback:
> if ((vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0)
> return false;
> -
> + exit:
> vshPrint(ctl, "%d\n", vcpus);
>
> return true;
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>
More information about the libvir-list
mailing list