[libvirt] [PATCH 2/2] virsh: fix wrong NUMA nodes count getting

Eric Blake eblake at redhat.com
Thu Feb 17 22:11:29 UTC 2011


On 02/17/2011 06:39 AM, Michal Privoznik wrote:
> as written in docs, one must parse capabilities XML to get the right
> count of NUMA nodes.
> ---
>  tools/virsh.c |   27 ++++++++++++++++-----------
>  1 files changed, 16 insertions(+), 11 deletions(-)
> 

> -        if (!info.nodes) {
> -            vshError(ctl, "%s", _("no NUMA nodes present"));
> -            goto cleanup;
> -        }
> +        ret = xPathULong(node_xml,
> +                         (char*)"string(/capabilities/host/topology/cells/@num)",
> +                         &nodes_cnt);
> +
> +        if (ret)
> +            nodes_cnt = 1;

As Matthias pointed out, we already have a parse function.  If you ditch
patch 1/2, then squash this into 2/2, does it all work for you (only
compile-tested here)?

diff --git i/tools/virsh.c w/tools/virsh.c
index dd844ea..a2bff60 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -2287,7 +2287,8 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     unsigned long nodes_cnt;
     int all_given;
     char *node_xml;
-
+    xmlDocPtr xml = NULL;
+    xmlXPathContextPtr ctxt = NULL;

     if (!vshConnectionUsability(ctl, ctl->conn))
         return FALSE;
@@ -2308,12 +2309,24 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
             goto cleanup;
         }

-        ret = xPathULong(node_xml,
-
(char*)"string(/capabilities/host/topology/cells/@num)",
-                         &nodes_cnt);
+        xml = xmlReadDoc((const xmlChar *) node_xml,
"capabilities.xml", NULL,
+                         XML_PARSE_NOENT | XML_PARSE_NONET |
+                         XML_PARSE_NOWARNING);
+        if (!xml)
+            goto cleanup;
+
+        ctxt = xmlXPathNewContext(xml);
+        if (!ctxt)
+            goto cleanup;

-        if (ret)
+        ret =
virXPathULong("string(/capabilities/host/topology/cells/@num)",
+                                ctxt, &nodes_cnt);
+        if (ret == -1) {
             nodes_cnt = 1;
+        } else if (ret < 0) {
+            vshError(ctl, "%s", _("unable to determine number of nodes"));
+            goto cleanup;
+        }

         if (VIR_ALLOC_N(nodes, nodes_cnt) < 0) {
             vshError(ctl, "%s", _("could not allocate memory"));
@@ -2357,6 +2370,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
 cleanup:
     VIR_FREE(nodes);
     VIR_FREE(node_xml);
+    xmlXPathFreeContext(ctxt);
     return func_ret;
 }



-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list