[libvirt] [PATCHv3 4/4] virsh: Use virNodeGetCPUMap if possible

Eric Blake eblake at redhat.com
Thu Nov 15 16:06:50 UTC 2012


On 11/13/2012 05:54 AM, Viktor Mihajlovski wrote:
> Modified the places where virNodeGetInfo was used for the purpose
> of obtaining the maximum node CPU number. Transparently falling
> back to virNodeGetInfo in case of failure.
> Wrote utility function vshNodeGetCPUCount to compute node CPU
> number.
> 
> Signed-off-by: Viktor Mihajlovski <mihajlov at linux.vnet.ibm.com>
> ---
> V2 Changes:
> Implemented Eric Blake's suggestion to remove code bloat 
> introduced by first patch version.
> New helper function vshNodeGetCPUCount is now used to calculate
> the number of node CPUs.
> 
> +static int
> +vshNodeGetCPUCount(virConnectPtr conn)
> +{
> +    int ret;
> +    virNodeInfo nodeinfo;
> +
> +    if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) {

Probably worth clearing out the error here, so that the rest of virsh
doesn't leak an error message that we ignored.

> +        /* fall back to nodeinfo */
> +        if (virNodeGetInfo(conn, &nodeinfo) == 0) {
> +            ret = VIR_NODEINFO_MAXCPUS(nodeinfo);
> +        }
> +    }
> +    return ret;
> +}
> +

ACK with that fixed, and pushed.

diff --git i/tools/virsh-domain.c w/tools/virsh-domain.c
index 183a598..d483f3f 100644
--- i/tools/virsh-domain.c
+++ w/tools/virsh-domain.c
@@ -138,6 +138,7 @@ vshNodeGetCPUCount(virConnectPtr conn)

     if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) {
         /* fall back to nodeinfo */
+        vshResetLibvirtError();
         if (virNodeGetInfo(conn, &nodeinfo) == 0) {
             ret = VIR_NODEINFO_MAXCPUS(nodeinfo);
         }

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121115/6ace0d26/attachment-0001.sig>


More information about the libvir-list mailing list