On 09/06/2016 05:56 PM, Peter Krempa wrote:
On Tue, Sep 06, 2016 at 16:59:09 +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 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(a)linux.vnet.ibm.com>
> ---
> tools/virsh-host.c | 28 +++++++++++++++++++++++++---
> 1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/tools/virsh-host.c b/tools/virsh-host.c
> index 57f0c0e..505cfbb 100644
> --- a/tools/virsh-host.c
> +++ b/tools/virsh-host.c
> @@ -607,16 +607,38 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
> {
> const char *type = NULL;
> int vcpus;
> + 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;
>
> - if ((vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0)
> - return false;
> + caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type,
flags);
> + if (caps) {
> + xml = virXMLParseStringCtxt(caps, _("(domainCapabilities)"),
&ctxt);
> + if (!xml) {
> + VIR_FREE(caps);
> + return false;
> + }
>
> - vshPrint(ctl, "%d\n", vcpus);
> + virXPathInt("string(./vcpu[1]/@max)", ctxt, &vcpus);
This doesn't handle the case when the capability XML does not contain
the required data. This still should fall back to the legacy approach.
Ah bhyve
doesn't report the vcpus in domcapabilities. Thanks. Fixed it
in next version I posted just now.
Regards,
Shivaprasad
Additionally virXPathInt does not initialize vcpus on failure and
since
it's not initialized when declared this would trigger a compiler
warning.
> + xmlXPathFreeContext(ctxt);
> + xmlFreeDoc(xml);
> + VIR_FREE(caps);