[PATCH] Fix callers to virGetDomain and virGetNetwork

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

 



(1) Removes virGetDomainByID.  This function was neither used nor exported.

(2) virGetDomain sets a virterror connection error whenever anything bad happens (realistically malloc failure is the only thing that can go wrong). Therefore callers do not need to set virterror if the function returns NULL. The patch fixes these callers.

(3) Same as (2), for virGetNetwork.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
? qemud/libvirtd.init
Index: src/hash.c
===================================================================
RCS file: /data/cvs/libvirt/src/hash.c,v
retrieving revision 1.22
diff -u -p -r1.22 hash.c
--- src/hash.c	8 May 2007 10:53:27 -0000	1.22
+++ src/hash.c	4 Jul 2007 10:27:04 -0000
@@ -864,51 +864,6 @@ done:
 }
 
 /**
- * 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
  * @name: pointer to the network name
Index: src/internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/internal.h,v
retrieving revision 1.45
diff -u -p -r1.45 internal.h
--- src/internal.h	26 Jun 2007 22:56:14 -0000	1.45
+++ src/internal.h	4 Jul 2007 10:27:04 -0000
@@ -209,8 +209,6 @@ virDomainPtr	__virGetDomain	(virConnectP
 				 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: src/proxy_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/proxy_internal.c,v
retrieving revision 1.31
diff -u -p -r1.31 proxy_internal.c
--- src/proxy_internal.c	26 Jun 2007 11:42:46 -0000	1.31
+++ src/proxy_internal.c	4 Jul 2007 10:27:05 -0000
@@ -832,12 +832,7 @@ xenProxyLookupByID(virConnectPtr conn, i
     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,
     }
     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
 	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: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.3
diff -u -p -r1.3 qemu_driver.c
--- src/qemu_driver.c	4 Jul 2007 03:59:13 -0000	1.3
+++ src/qemu_driver.c	4 Jul 2007 10:27:07 -0000
@@ -1754,12 +1754,7 @@ static virDomainPtr qemudDomainLookupByI
     }
 
     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 qemudDomainLookupByU
     }
 
     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 qemudDomainLookupByN
     }
 
     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(vi
     }
 
     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(vi
     }
 
     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 qemudNetworkLookupB
     }
 
     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 qemudNetworkLookupB
     }
 
     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(
     }
 
     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(
     }
 
     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: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.12
diff -u -p -r1.12 remote_internal.c
--- src/remote_internal.c	4 Jul 2007 03:59:13 -0000	1.12
+++ src/remote_internal.c	4 Jul 2007 10:27:09 -0000
@@ -1368,9 +1368,6 @@ remoteDomainCreateLinux (virConnectPtr c
         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 co
         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 
         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 
         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 con
         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;
@@ -2337,9 +2322,6 @@ remoteNetworkLookupByUUID (virConnectPtr
         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;
@@ -2363,9 +2345,6 @@ remoteNetworkLookupByName (virConnectPtr
         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;
@@ -2388,9 +2367,6 @@ remoteNetworkCreateXML (virConnectPtr co
         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;
@@ -2413,9 +2389,6 @@ remoteNetworkDefineXML (virConnectPtr co
         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;
@@ -2844,9 +2817,7 @@ server_error (virConnectPtr conn, remote
     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;
 
@@ -2868,9 +2839,8 @@ server_error (virConnectPtr conn, remote
 
 /* 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: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.39
diff -u -p -r1.39 test.c
--- src/test.c	4 Jul 2007 09:16:23 -0000	1.39
+++ src/test.c	4 Jul 2007 10:27:09 -0000
@@ -957,10 +957,7 @@ testDomainCreateLinux(virConnectPtr conn
         }
     }
     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);
 }
@@ -987,10 +984,7 @@ virDomainPtr testLookupDomainByID(virCon
     }
 
     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);
 }
@@ -1011,10 +1005,7 @@ virDomainPtr testLookupDomainByUUID(virC
     }
     if (idx >= 0) {
         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);
@@ -1036,10 +1027,7 @@ virDomainPtr testLookupDomainByName(virC
     }
     if (idx >= 0) {
         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: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.125
diff -u -p -r1.125 xend_internal.c
--- src/xend_internal.c	26 Jun 2007 22:33:22 -0000	1.125
+++ src/xend_internal.c	4 Jul 2007 10:27:12 -0000
@@ -1889,10 +1889,8 @@ sexpr_to_domain(virConnectPtr conn, stru
         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, 
     }
 
     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
         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: src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.44
diff -u -p -r1.44 xs_internal.c
--- src/xs_internal.c	26 Jun 2007 11:42:46 -0000	1.44
+++ src/xs_internal.c	4 Jul 2007 10:27:12 -0000
@@ -650,10 +650,8 @@ xenStoreDomainLookupByName(virConnectPtr
 
     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;
 

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

--
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]