[libvirt] [PATCH 2/2] Make sure that output from xenStore*Domains is correct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* src/xend_internal.c: xenDaemonDomainLookupByID said to accept that
    uuid == NULL, but would gladly dereference it without checking
    this.

* src/xs_internal.c: xenStoreNumOfDomains and xenStoreListDomains now
    make sure that the domains that are reported as existing also
    exist in xend. xenStoreDoListDomains needed to be modified to
    handle the virConnectPtr to be able to call
    xenDaemonDomainLookupByID.
---
 src/xend_internal.c |    5 +++--
 src/xs_internal.c   |   36 ++++++++++++++++++++++++++----------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/xend_internal.c b/src/xend_internal.c
index 867f85f..fad5e60 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -1042,7 +1042,8 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
     const char *name = NULL;
     struct sexpr *root;
 
-    memset(uuid, 0, VIR_UUID_BUFLEN);
+    if (uuid != NULL)
+        memset(uuid, 0, VIR_UUID_BUFLEN);
 
     root = sexpr_get(xend, "/xend/domain/%d?detail=1", id);
     if (root == NULL)
@@ -1057,7 +1058,7 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
     if (domname)
       *domname = strdup(name);
 
-    if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
+    if (uuid != NULL && sexpr_uuid(uuid, root, "domain/uuid") < 0) {
       virXendError(xend, VIR_ERR_INTERNAL_ERROR,
                    "%s", _("domain information incomplete, missing uuid"));
       goto error;
diff --git a/src/xs_internal.c b/src/xs_internal.c
index 1f54b1f..8a7516e 100644
--- a/src/xs_internal.c
+++ b/src/xs_internal.c
@@ -36,6 +36,7 @@
 #include "xen_unified.h"
 #include "xs_internal.h"
 #include "xen_internal.h"
+#include "xend_internal.h"
 
 #define VIR_FROM_THIS VIR_FROM_XEN
 
@@ -543,8 +544,9 @@ int
 xenStoreNumOfDomains(virConnectPtr conn)
 {
     unsigned int num;
-    char **idlist;
-    int ret = -1;
+    char **idlist = NULL, *endptr;
+    int i, r, ret = -1, realnum = 0;
+    long id;
     xenUnifiedPrivatePtr priv;
 
     if (conn == NULL) {
@@ -557,10 +559,21 @@ xenStoreNumOfDomains(virConnectPtr conn)
         virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(-1);
     }
+
     idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
     if (idlist) {
-        free(idlist);
-        ret = num;
+        for (i = 0; i < num; i++) {
+            id = strtol(idlist[i], &endptr, 10);
+            if ((endptr == idlist[i]) || (*endptr != 0))
+                goto out;
+
+            r = xenDaemonDomainLookupByID(conn, (int) id, NULL, NULL);
+            if (r == 0)
+                realnum++;
+        }
+out:
+        VIR_FREE (idlist);
+        ret = realnum;
     }
     return(ret);
 }
@@ -577,11 +590,11 @@ xenStoreNumOfDomains(virConnectPtr conn)
  * Returns the number of domain found or -1 in case of error
  */
 static int
-xenStoreDoListDomains(xenUnifiedPrivatePtr priv, int *ids, int maxids)
+xenStoreDoListDomains(virConnectPtr conn, xenUnifiedPrivatePtr priv, int *ids, int maxids)
 {
     char **idlist = NULL, *endptr;
     unsigned int num, i;
-    int ret = -1;
+    int r, ret = -1;
     long id;
 
     if (priv->xshandle == NULL)
@@ -595,7 +608,10 @@ xenStoreDoListDomains(xenUnifiedPrivatePtr priv, int *ids, int maxids)
         id = strtol(idlist[i], &endptr, 10);
         if ((endptr == idlist[i]) || (*endptr != 0))
             goto out;
-        ids[ret++] = (int) id;
+
+        r = xenDaemonDomainLookupByID(conn, (int) id, NULL, NULL);
+        if (r == 0)
+            ids[ret++] = (int) id;
     }
 
 out:
@@ -627,7 +643,7 @@ xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
     priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     xenUnifiedLock(priv);
-    ret = xenStoreDoListDomains(priv, ids, maxids);
+    ret = xenStoreDoListDomains(conn, priv, ids, maxids);
     xenUnifiedUnlock(priv);
 
     return(ret);
@@ -1276,7 +1292,7 @@ retry:
         virReportOOMError(NULL);
         return -1;
     }
-    nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt);
+    nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
     if (nread != new_domain_cnt) {
         // mismatch. retry this read
         VIR_FREE(new_domids);
@@ -1357,7 +1373,7 @@ retry:
         virReportOOMError(NULL);
         return -1;
     }
-    nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt);
+    nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
     if (nread != new_domain_cnt) {
         // mismatch. retry this read
         VIR_FREE(new_domids);
-- 
1.6.2

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]