+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:
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
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);
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);
}
}
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);
}
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);
}
}
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,
}
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,
}
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;
}
}
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;
}
}
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;
}
}
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,
}
net = virGetNetwork(conn, network->def->name, network->def->uuid);
- if (!net) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
- return NULL;
- }
return net;
}
}
net = virGetNetwork(conn, network->def->name, network->def->uuid);
- if (!net) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
- return NULL;
- }
return net;
}
}
net = virGetNetwork(conn, network->def->name, network->def->uuid);
- if (!net) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "virNetworkPtr");
- return NULL;
- }
return net;
}
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;
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;
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;
}
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;
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;
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;
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;
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;
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;
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;
/* 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)
}
}
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);
}
}
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);
}
}
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;
}
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;
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
}
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);
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);
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;