]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fri Jul 6 16:00:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 6 Jul 2007 15:02:09 +0000 (15:02 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 6 Jul 2007 15:02:09 +0000 (15:02 +0000)
* src/hash.c, src/internal.h: Remove virGetDomainByID function
  as it is not used or exported.
* src/proxy_internal.c, src/qemu_driver.c, src/remote_internal.c,
  src/test.c, src/xend_internal.c, src/xs_internal.c: Fix
  all callers to virGetDomain and virGetNetwork functions -
  the callers do not need to set virterror since it is already
  set inside the functions.

ChangeLog
src/hash.c
src/internal.h
src/proxy_internal.c
src/qemu_driver.c
src/remote_internal.c
src/test.c
src/xend_internal.c
src/xs_internal.c

index d83b5d45a31bf03cf14c11beb080476779e02fb7..8c344ac799ebdaf564c5fe8f75f4d07ef5d310b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jul  6 16:00:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
+
+       * src/hash.c, src/internal.h: Remove virGetDomainByID function
+         as it is not used or exported.
+       * src/proxy_internal.c, src/qemu_driver.c, src/remote_internal.c,
+         src/test.c, src/xend_internal.c, src/xs_internal.c: Fix
+         all callers to virGetDomain and virGetNetwork functions -
+         the callers do not need to set virterror since it is already
+         set inside the functions.
+
 Fri Jul  6 15:54:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
 
        * include/libvirt/virterror.h, src/virterror.c, src/libvirt.c:
index 29cdfbf59e8bd84afe7b4b1cf28f08755ced522e..5da1accd5117f53bf43d14fcd09808ecbbe6e896 100644 (file)
@@ -863,51 +863,6 @@ done:
     return(ret);
 }
 
-/**
- * virGetDomainByID:
- * @conn: the hypervisor connection
- * @id: the ID number for the domain
- *
- * Lookup if the domain ID is already registered for that connection,
- * if yes return a new pointer to it, if no return NULL
- *
- * Returns a pointer to the domain, or NULL if not found
- */
-virDomainPtr
-virGetDomainByID(virConnectPtr conn, int id) {
-    virDomainPtr ret = NULL, cur;
-    virHashEntryPtr iter, next;
-    virHashTablePtr table;
-    int key;
-
-    if ((!VIR_IS_CONNECT(conn)) || (id < 0)) {
-        virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(NULL);
-    }
-    xmlMutexLock(conn->hashes_mux);
-
-    table = conn->domains;
-    if ((table == NULL) || (table->nbElems == 0))
-        goto done;
-    for (key = 0;key < table->size;key++) {
-        if (table->table[key].valid == 0)
-           continue;
-       iter = &(table->table[key]);
-       while (iter != NULL) {
-           next = iter->next;
-           cur = (virDomainPtr) iter->payload;
-           if ((cur != NULL) && (cur->id == id)) {
-               ret = cur;
-               goto done;
-           }
-           iter = next;
-       }
-    }
-done:
-    xmlMutexUnlock(conn->hashes_mux);
-    return(ret);
-}
-
 /**
  * virGetNetwork:
  * @conn: the hypervisor connection
index ee7b17e336a86a0b88357c39514e111ed7481662..a278596fdb3a314bc97cb0b468f583c24b78e0d0 100644 (file)
@@ -209,8 +209,6 @@ virDomainPtr        __virGetDomain  (virConnectPtr conn,
                                 const unsigned char *uuid);
 int            virFreeDomain   (virConnectPtr conn,
                                 virDomainPtr domain);
-virDomainPtr   virGetDomainByID(virConnectPtr conn,
-                                int id);
 virNetworkPtr  __virGetNetwork (virConnectPtr conn,
                                 const char *name,
                                 const unsigned char *uuid);
index eca93176d2cc6c7c961cfc77a80ec74b36342438..3d9403d229c2d889af81c85350339591eea092a2 100644 (file)
@@ -832,12 +832,7 @@ xenProxyLookupByID(virConnectPtr conn, int id)
     memcpy(uuid, &ans.extra.str[0], VIR_UUID_BUFLEN);
     name = &ans.extra.str[VIR_UUID_BUFLEN];
     res = virGetDomain(conn, name, uuid);
-
-    if (res == NULL)
-        virProxyError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-    else
-       res->id = id;
-    
+       if (res) res->id = id;
     return(res);
 }
 
@@ -879,12 +874,7 @@ xenProxyLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
     }
     name = &req.extra.str[0];
     res = virGetDomain(conn, name, uuid);
-
-    if (res == NULL)
-        virProxyError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-    else
-       res->id = req.data.arg;
-    
+       if (res) res->id = req.data.arg;
     return(res);
 }
 
@@ -930,12 +920,7 @@ xenProxyDomainLookupByName(virConnectPtr conn, const char *name)
        return(NULL);
     }
     res = virGetDomain(conn, name, (const unsigned char *)&req.extra.str[0]);
-
-    if (res == NULL)
-        virProxyError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-    else
-       res->id = req.data.arg;
-    
+       if (res) res->id = req.data.arg;
     return(res);
 }
 
index 6b0bcd23f706628f446135245f81a508ef87cb94..91cf920675962a10f15f501d5a5809a2f6241f9a 100644 (file)
@@ -1754,12 +1754,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
-    if (!dom) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virDomainPtr");
-        return NULL;
-    }
-
-    dom->id = vm->id;
+    if (dom) dom->id = vm->id;
     return dom;
 }
 static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
@@ -1774,12 +1769,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
-    if (!dom) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virDomainPtr");
-        return NULL;
-    }
-
-    dom->id = vm->id;
+    if (dom) dom->id = vm->id;
     return dom;
 }
 static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
@@ -1794,12 +1784,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
-    if (!dom) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virDomainPtr");
-        return NULL;
-    }
-
-    dom->id = vm->id;
+    if (dom) dom->id = vm->id;
     return dom;
 }
 
@@ -1850,12 +1835,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
-    if (!dom) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virDomainPtr");
-        return NULL;
-    }
-
-    dom->id = vm->id;
+    if (dom) dom->id = vm->id;
     return dom;
 }
 
@@ -2075,12 +2055,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
-    if (!dom) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virDomainPtr");
-        return NULL;
-    }
-
-    dom->id = vm->id;
+    if (dom) dom->id = vm->id;
     return dom;
 }
 
@@ -2185,10 +2160,6 @@ static virNetworkPtr qemudNetworkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSE
     }
 
     net = virGetNetwork(conn, network->def->name, network->def->uuid);
-    if (!net) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
-        return NULL;
-    }
     return net;
 }
 static virNetworkPtr qemudNetworkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -2203,10 +2174,6 @@ static virNetworkPtr qemudNetworkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSE
     }
 
     net = virGetNetwork(conn, network->def->name, network->def->uuid);
-    if (!net) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
-        return NULL;
-    }
     return net;
 }
 
@@ -2299,10 +2266,6 @@ static virNetworkPtr qemudNetworkCreate(virConnectPtr conn, const char *xml) {
     }
 
     net = virGetNetwork(conn, network->def->name, network->def->uuid);
-    if (!net) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
-        return NULL;
-    }
     return net;
 }
 
@@ -2326,10 +2289,6 @@ static virNetworkPtr qemudNetworkDefine(virConnectPtr conn, const char *xml) {
     }
 
     net = virGetNetwork(conn, network->def->name, network->def->uuid);
-    if (!net) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
-        return NULL;
-    }
     return net;
 }
 
index b48fa3116c676799bbdfbbcc0a3f1ad3c3c80377..a0663969e0432b246101a2cf7dc892c437f76c02 100644 (file)
@@ -1368,9 +1368,6 @@ remoteDomainCreateLinux (virConnectPtr conn,
         return NULL;
 
     dom = get_nonnull_domain (conn, ret.dom);
-    if (dom == NULL)
-        error (conn, VIR_ERR_RPC, "remoteDomainCreateLinux: domain not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_domain_create_linux_ret, (char *) &ret);
 
     return dom;
@@ -1393,9 +1390,6 @@ remoteDomainLookupByID (virConnectPtr conn, int id)
         return NULL;
 
     dom = get_nonnull_domain (conn, ret.dom);
-    if (dom == NULL)
-        error (conn, VIR_ERR_RPC, "remoteDomainLookupByID: domain not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_domain_lookup_by_id_ret, (char *) &ret);
 
     return dom;
@@ -1418,9 +1412,6 @@ remoteDomainLookupByUUID (virConnectPtr conn, const unsigned char *uuid)
         return NULL;
 
     dom = get_nonnull_domain (conn, ret.dom);
-    if (dom == NULL)
-        error (conn, VIR_ERR_RPC, "remoteDomainLookupByUUID: domain not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_domain_lookup_by_uuid_ret, (char *) &ret);
     return dom;
 }
@@ -1442,9 +1433,6 @@ remoteDomainLookupByName (virConnectPtr conn, const char *name)
         return NULL;
 
     dom = get_nonnull_domain (conn, ret.dom);
-    if (dom == NULL)
-        error (conn, VIR_ERR_RPC, "remoteDomainLookupByName: domain not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_domain_lookup_by_name_ret, (char *) &ret);
 
     return dom;
@@ -1905,9 +1893,6 @@ remoteDomainDefineXML (virConnectPtr conn, const char *xml)
         return NULL;
 
     dom = get_nonnull_domain (conn, ret.dom);
-    if (dom == NULL)
-        error (conn, VIR_ERR_RPC, "remoteDomainDefineXML: domain not found");
-
     xdr_free ((xdrproc_t) xdr_remote_domain_define_xml_ret, (char *) &ret);
 
     return dom;
@@ -2336,9 +2321,6 @@ remoteNetworkLookupByUUID (virConnectPtr conn,
         return NULL;
 
     net = get_nonnull_network (conn, ret.net);
-    if (net == NULL)
-        error (conn, VIR_ERR_RPC, "remoteNetworkLookupByUUID: network not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_network_lookup_by_uuid_ret, (char *) &ret);
 
     return net;
@@ -2362,9 +2344,6 @@ remoteNetworkLookupByName (virConnectPtr conn,
         return NULL;
 
     net = get_nonnull_network (conn, ret.net);
-    if (net == NULL)
-        error (conn, VIR_ERR_RPC, "remoteNetworkLookupByName: network not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_network_lookup_by_name_ret, (char *) &ret);
 
     return net;
@@ -2387,9 +2366,6 @@ remoteNetworkCreateXML (virConnectPtr conn, const char *xmlDesc)
         return NULL;
 
     net = get_nonnull_network (conn, ret.net);
-    if (net == NULL)
-        error (conn, VIR_ERR_RPC, "remoteNetworkCreateXML: network not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_network_create_xml_ret, (char *) &ret);
 
     return net;
@@ -2412,9 +2388,6 @@ remoteNetworkDefineXML (virConnectPtr conn, const char *xml)
         return NULL;
 
     net = get_nonnull_network (conn, ret.net);
-    if (net == NULL)
-        error (conn, VIR_ERR_RPC, "remoteNetworkDefineXML: network not found");
-
     xdr_free ((xdrproc_t) &xdr_remote_network_define_xml_ret, (char *) &ret);
 
     return net;
@@ -2843,9 +2816,7 @@ server_error (virConnectPtr conn, remote_error *err)
     virDomainPtr dom;
     virNetworkPtr net;
 
-    /* Get the domain and network, if set.  OK to ignore the return
-     * value of get_nonnull_* since these are informational.
-     */
+    /* Get the domain and network, if set. */
     dom = err->dom ? get_nonnull_domain (conn, *err->dom) : NULL;
     net = err->net ? get_nonnull_network (conn, *err->net) : NULL;
 
@@ -2867,9 +2838,8 @@ server_error (virConnectPtr conn, remote_error *err)
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
  * (name, uuid) pair into virDomainPtr or virNetworkPtr object.
- * virDomainPtr or virNetworkPtr cannot be NULL.
- *
- * NB. If these return NULL then the caller must return an error.
+ * These can return NULL if underlying memory allocations fail,
+ * but if they do then virterror has been set.
  */
 static virDomainPtr
 get_nonnull_domain (virConnectPtr conn, remote_nonnull_domain domain)
index be6d2f1b81a1a1a9f3a44a43f806599a43df2061..43e866adf11abfa4d2ebe08c4ae657043fab667f 100644 (file)
@@ -957,10 +957,7 @@ testDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
         }
     }
     dom = virGetDomain(conn, con->domains[handle].name, con->domains[handle].uuid);
-    if (dom == NULL) {
-        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        return (NULL);
-    }
+    if (dom == NULL) return NULL;
     con->numDomains++;
     return (dom);
 }
@@ -988,10 +985,7 @@ virDomainPtr testLookupDomainByID(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
-    if (dom == NULL) {
-        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        return(NULL);
-    }
+    if (dom == NULL) return NULL;
     dom->id = id;
     return (dom);
 }
@@ -1018,10 +1012,7 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
-    if (dom == NULL) {
-        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        return NULL;
-    }
+    if (dom == NULL) return NULL;
     dom->id = con->domains[idx].id;
 
     return dom;
@@ -1049,10 +1040,7 @@ virDomainPtr testLookupDomainByName(virConnectPtr conn,
     }
 
     dom = virGetDomain(conn, con->domains[idx].name, con->domains[idx].uuid);
-    if (dom == NULL) {
-        testError(conn, NULL, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        return NULL;
-    }
+    if (dom == NULL) return NULL;
     dom->id = con->domains[idx].id;
 
     return dom;
index 8c157bdfe65daf20e63da74f2623fbefa6eb1ce6..03b489c54c9e231032e2311a92c5208f05e1fd61 100644 (file)
@@ -1889,10 +1889,8 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
         goto error;
 
     ret = virGetDomain(conn, name, (const unsigned char *) &uuid[0]);
-    if (ret == NULL) {
-        virXendError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        return(NULL);
-    }
+    if (ret == NULL) return NULL;
+
     tmp = sexpr_node(root, "domain/domid");
     /* New 3.0.4 XenD will not report a domid for inactive domains,
      * so only error out for old XenD
@@ -2740,10 +2738,8 @@ xenDaemonLookupByID(virConnectPtr conn, int id) {
     }
 
     ret = virGetDomain(conn, name, uuid);
-    if (ret == NULL) {
-        virXendError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        goto error;
-    }
+    if (ret == NULL) return NULL;
+
     ret->id = id;
     free(name);
     return (ret);
@@ -2989,11 +2985,8 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
         return (NULL);
 
     ret = virGetDomain(conn, name, uuid);
-    if (ret == NULL) {
-        virXendError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-        free(name);
-        return (NULL);
-    }
+    if (ret == NULL) return NULL;
+
     ret->id = id;
     free(name);
     return (ret);
index 264959cb13a85a1cc537567026b2408d16ac0bae..cce182b826e113cc16c875d8cfb3d76a3f44d708 100644 (file)
@@ -650,10 +650,8 @@ xenStoreDomainLookupByName(virConnectPtr conn, const char *name)
 
     ret = virGetDomain(conn, name, NULL);
     if (ret == NULL) {
-        virXenStoreError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
-       if (path != NULL)
-           free(path);
-       goto done;
+        if (path != NULL) free(path);
+        goto done;
     }
     ret->id = id;