]> xenbits.xensource.com Git - libvirt.git/commitdiff
phyp: Make generic domain listing functions return -1 in case of error
authorMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 6 Nov 2009 01:15:19 +0000 (02:15 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 6 Nov 2009 20:28:49 +0000 (21:28 +0100)
phypNumDomainsGeneric() and phypListDomainsGeneric() return 0 in case
of an error. This makes it impossible to distinguish between an actual
error and no domains being defined on the hypervisor. It also turn the
no domains situation into an error. Return -1 in case of an error to
fix this problem.

src/phyp/phyp_driver.c

index b94d0faa067af1209c57ff12e101726db15ce651..8d54ae7edd88784fa1dcaa0bb716999c95f5c8e1 100644 (file)
@@ -980,7 +980,7 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
   err:
     VIR_FREE(cmd);
     VIR_FREE(ret);
-    return 0;
+    return -1;
 }
 
 static int
@@ -1065,7 +1065,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids,
   err:
     VIR_FREE(cmd);
     VIR_FREE(ret);
-    return 0;
+    return -1;
 }
 
 static int
@@ -1130,7 +1130,7 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
         VIR_FREE(names[i]);
     VIR_FREE(cmd);
     VIR_FREE(ret);
-    return 0;
+    return -1;
 }
 
 static virDomainPtr
@@ -1843,17 +1843,34 @@ phypUUIDTable_Init(virConnectPtr conn)
     int *ids = NULL;
     unsigned int i = 0;
 
-    if ((nids = phypNumDomainsGeneric(conn, 2)) == 0)
+    if ((nids = phypNumDomainsGeneric(conn, 2)) < 0)
         goto err;
 
+    /* exit early if there are no domains */
+    if (nids == 0)
+        return 0;
+
     if (VIR_ALLOC_N(ids, nids) < 0) {
         virReportOOMError(conn);
         goto err;
     }
 
-    if (phypListDomainsGeneric(conn, ids, nids, 1) == 0)
+    if ((nids = phypListDomainsGeneric(conn, ids, nids, 1)) < 0)
         goto err;
 
+    /* exit early if there are no domains */
+    /* FIXME: phypNumDomainsGeneric() returned > 0 but phypListDomainsGeneric()
+     *        returned 0. indicates this an error condition?
+     *        an even stricter check would be to treat
+     *
+     *          phypNumDomainsGeneric() != phypListDomainsGeneric()
+     *
+     *        as an error */
+    if (nids == 0) {
+        VIR_FREE(ids);
+        return 0;
+    }
+
     phyp_driver = conn->privateData;
     uuid_table = phyp_driver->uuid_table;
     uuid_table->nlpars = nids;