Use parallelsGetDomain/'s in functions for domain lookup
and information obtaining.
Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
src/parallels/parallels_driver.c | 185 +++++++++++++++++++------------------
1 files changed, 95 insertions(+), 90 deletions(-)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 8b83a9d..de3d53f 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -786,12 +786,16 @@ static int
parallelsListDomains(virConnectPtr conn, int *ids, int maxids)
{
parallelsConnPtr privconn = conn->privateData;
- int n;
+ virDomainObjListPtr domains = NULL;
+ int n = -1;
- parallelsDriverLock(privconn);
- n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids);
- parallelsDriverUnlock(privconn);
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+ n = virDomainObjListGetActiveIDs(domains, ids, maxids);
+cleanup:
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return n;
}
@@ -799,12 +803,17 @@ static int
parallelsNumOfDomains(virConnectPtr conn)
{
parallelsConnPtr privconn = conn->privateData;
- int count;
+ virDomainObjListPtr domains = NULL;
+ int count = -1;
- parallelsDriverLock(privconn);
- count = virDomainObjListNumOfDomains(privconn->domains, 1);
- parallelsDriverUnlock(privconn);
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+
+ count = virDomainObjListNumOfDomains(domains, 1);
+cleanup:
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return count;
}
@@ -812,14 +821,18 @@ static int
parallelsListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
{
parallelsConnPtr privconn = conn->privateData;
- int n;
+ virDomainObjListPtr domains = NULL;
+ int n = -1;
+
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
- parallelsDriverLock(privconn);
memset(names, 0, sizeof(*names) * maxnames);
- n = virDomainObjListGetInactiveNames(privconn->domains, names,
- maxnames);
- parallelsDriverUnlock(privconn);
+ n = virDomainObjListGetInactiveNames(domains, names, maxnames);
+cleanup:
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return n;
}
@@ -827,28 +840,39 @@ static int
parallelsNumOfDefinedDomains(virConnectPtr conn)
{
parallelsConnPtr privconn = conn->privateData;
- int count;
+ virDomainObjListPtr domains = NULL;
+ int count = -1;
- parallelsDriverLock(privconn);
- count = virDomainObjListNumOfDomains(privconn->domains, 0);
- parallelsDriverUnlock(privconn);
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+ count = virDomainObjListNumOfDomains(domains, 0);
+
+cleanup:
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return count;
}
static int
parallelsListAllDomains(virConnectPtr conn,
- virDomainPtr **domains,
+ virDomainPtr **doms,
unsigned int flags)
{
parallelsConnPtr privconn = conn->privateData;
+ virDomainObjListPtr domains = NULL;
int ret = -1;
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
- parallelsDriverLock(privconn);
- ret = virDomainList(conn, privconn->domains->objs, domains, flags);
- parallelsDriverUnlock(privconn);
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+
+ ret = virDomainList(conn, domains->objs, doms, flags);
+
+cleanup:
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return ret;
}
@@ -857,11 +881,13 @@ parallelsLookupDomainByID(virConnectPtr conn, int id)
{
parallelsConnPtr privconn = conn->privateData;
virDomainPtr ret = NULL;
- virDomainObjPtr dom;
+ virDomainObjPtr dom = NULL;
+ virDomainObjListPtr domains = NULL;
- parallelsDriverLock(privconn);
- dom = virDomainFindByID(privconn->domains, id);
- parallelsDriverUnlock(privconn);
+ if (!(domains = parallelsGetDomains(privconn)))
+ goto cleanup;
+
+ dom = virDomainFindByID(domains, id);
if (dom == NULL) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
@@ -875,6 +901,8 @@ parallelsLookupDomainByID(virConnectPtr conn, int id)
cleanup:
if (dom)
virDomainObjUnlock(dom);
+ virDomainObjListDeinit(domains);
+ VIR_FREE(domains);
return ret;
}
@@ -883,15 +911,12 @@ parallelsLookupDomainByUUID(virConnectPtr conn, const unsigned char
*uuid)
{
parallelsConnPtr privconn = conn->privateData;
virDomainPtr ret = NULL;
- virDomainObjPtr dom;
+ virDomainObjPtr dom = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
- dom = virDomainFindByUUID(privconn->domains, uuid);
- parallelsDriverUnlock(privconn);
+ virUUIDFormat(uuid, uuidstr);
- if (dom == NULL) {
- char uuidstr[VIR_UUID_STRING_BUFLEN];
- virUUIDFormat(uuid, uuidstr);
+ if (!(dom = parallelsGetDomain(privconn, uuidstr))) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"),
uuidstr);
goto cleanup;
@@ -902,8 +927,7 @@ parallelsLookupDomainByUUID(virConnectPtr conn, const unsigned char
*uuid)
ret->id = dom->def->id;
cleanup:
- if (dom)
- virDomainObjUnlock(dom);
+ virObjectUnref(dom);
return ret;
}
@@ -912,13 +936,9 @@ parallelsLookupDomainByName(virConnectPtr conn, const char *name)
{
parallelsConnPtr privconn = conn->privateData;
virDomainPtr ret = NULL;
- virDomainObjPtr dom;
-
- parallelsDriverLock(privconn);
- dom = virDomainFindByName(privconn->domains, name);
- parallelsDriverUnlock(privconn);
+ virDomainObjPtr dom = NULL;
- if (dom == NULL) {
+ if (!(dom = parallelsGetDomain(privconn, name))) {
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching name '%s'"), name);
goto cleanup;
@@ -929,8 +949,7 @@ parallelsLookupDomainByName(virConnectPtr conn, const char *name)
ret->id = dom->def->id;
cleanup:
- if (dom)
- virDomainObjUnlock(dom);
+ virObjectUnref(dom);
return ret;
}
@@ -938,14 +957,13 @@ static int
parallelsGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainObjPtr privdom;
+ virDomainObjPtr privdom = NULL;
int ret = -1;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- parallelsDriverUnlock(privconn);
+ virUUIDFormat(domain->uuid, uuidstr);
- if (privdom == NULL) {
+ if (!(privdom == parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
@@ -958,8 +976,7 @@ parallelsGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
ret = 0;
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
+ virObjectUnref(privdom);
return ret;
}
@@ -967,13 +984,13 @@ static char *
parallelsGetOSType(virDomainPtr domain)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainObjPtr privdom;
-
+ virDomainObjPtr privdom = NULL;
char *ret = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- if (privdom == NULL) {
+ virUUIDFormat(domain->uuid, uuidstr);
+
+ if (!(privdom = parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
@@ -982,9 +999,7 @@ parallelsGetOSType(virDomainPtr domain)
virReportOOMError();
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
- parallelsDriverUnlock(privconn);
+ virObjectUnref(privdom);
return ret;
}
@@ -992,12 +1007,13 @@ static int
parallelsDomainIsPersistent(virDomainPtr domain)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainObjPtr privdom;
+ virDomainObjPtr privdom = NULL;
int ret = -1;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- if (privdom == NULL) {
+ virUUIDFormat(domain->uuid, uuidstr);
+
+ if (!(privdom = parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
@@ -1005,9 +1021,7 @@ parallelsDomainIsPersistent(virDomainPtr domain)
ret = 1;
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
- parallelsDriverUnlock(privconn);
+ virObjectUnref(privdom);
return ret;
}
@@ -1016,15 +1030,15 @@ parallelsDomainGetState(virDomainPtr domain,
int *state, int *reason, unsigned int flags)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainObjPtr privdom;
+ virDomainObjPtr privdom = NULL;
int ret = -1;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
virCheckFlags(0, -1);
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- parallelsDriverUnlock(privconn);
+ virUUIDFormat(domain->uuid, uuidstr);
- if (privdom == NULL) {
+ if (!(privdom = parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
@@ -1033,8 +1047,7 @@ parallelsDomainGetState(virDomainPtr domain,
ret = 0;
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
+ virObjectUnref(privdom);
return ret;
}
@@ -1042,29 +1055,23 @@ static char *
parallelsDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainDefPtr def;
- virDomainObjPtr privdom;
+ virDomainObjPtr privdom = NULL;
char *ret = NULL;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
/* Flags checked by virDomainDefFormat */
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- parallelsDriverUnlock(privconn);
+ virUUIDFormat(domain->uuid, uuidstr);
- if (privdom == NULL) {
+ if (!(privdom = parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
- def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
- privdom->newDef ? privdom->newDef : privdom->def;
-
- ret = virDomainDefFormat(def, flags);
+ ret = virDomainDefFormat(privdom->def, flags);
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
+ virObjectUnref(privdom);
return ret;
}
@@ -1072,14 +1079,13 @@ static int
parallelsDomainGetAutostart(virDomainPtr domain, int *autostart)
{
parallelsConnPtr privconn = domain->conn->privateData;
- virDomainObjPtr privdom;
+ virDomainObjPtr privdom = NULL;
int ret = -1;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
- parallelsDriverLock(privconn);
- privdom = virDomainFindByUUID(privconn->domains, domain->uuid);
- parallelsDriverUnlock(privconn);
+ virUUIDFormat(domain->uuid, uuidstr);
- if (privdom == NULL) {
+ if (!(privdom = parallelsGetDomain(privconn, uuidstr))) {
parallelsDomNotFoundError(domain);
goto cleanup;
}
@@ -1088,8 +1094,7 @@ parallelsDomainGetAutostart(virDomainPtr domain, int *autostart)
ret = 0;
cleanup:
- if (privdom)
- virDomainObjUnlock(privdom);
+ virObjectUnref(privdom);
return ret;
}
--
1.7.1