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.
This commit is contained in:
Richard W.M. Jones 2007-07-06 15:02:09 +00:00
parent b26376750e
commit 16eae80edf
9 changed files with 33 additions and 177 deletions

View File

@ -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:

View 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

View 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);

View 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);
}

View 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;
}

View 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)

View 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;

View 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);

View File

@ -650,9 +650,7 @@ 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);
if (path != NULL) free(path);
goto done;
}
ret->id = id;