parallels_driver: Utilize parallelsDomObjFromDomain()

Instead of each API copying the same lines of code, lets use the
generic function designed just for that purpose. At the same time,
drop useless connection object locking in some functions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-04-22 18:23:38 +02:00
parent 3236da8bb7
commit d2256fb552

View File

@ -534,18 +534,11 @@ parallelsDomainLookupByName(virConnectPtr conn, const char *name)
static int static int
parallelsDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) parallelsDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
int ret = -1; int ret = -1;
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
parallelsDriverUnlock(privconn);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
info->state = virDomainObjGetState(privdom, NULL); info->state = virDomainObjGetState(privdom, NULL);
info->memory = privdom->def->mem.cur_balloon; info->memory = privdom->def->mem.cur_balloon;
@ -563,47 +556,35 @@ parallelsDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
static char * static char *
parallelsDomainGetOSType(virDomainPtr domain) parallelsDomainGetOSType(virDomainPtr domain)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
char *ret = NULL; char *ret = NULL;
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(privdom->def->os.type))); ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(privdom->def->os.type)));
cleanup: cleanup:
if (privdom) if (privdom)
virObjectUnlock(privdom); virObjectUnlock(privdom);
parallelsDriverUnlock(privconn);
return ret; return ret;
} }
static int static int
parallelsDomainIsPersistent(virDomainPtr domain) parallelsDomainIsPersistent(virDomainPtr domain)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
int ret = -1; int ret = -1;
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
ret = 1; ret = 1;
cleanup: cleanup:
if (privdom) if (privdom)
virObjectUnlock(privdom); virObjectUnlock(privdom);
parallelsDriverUnlock(privconn);
return ret; return ret;
} }
@ -611,19 +592,12 @@ static int
parallelsDomainGetState(virDomainPtr domain, parallelsDomainGetState(virDomainPtr domain,
int *state, int *reason, unsigned int flags) int *state, int *reason, unsigned int flags)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
int ret = -1; int ret = -1;
virCheckFlags(0, -1); virCheckFlags(0, -1);
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
parallelsDriverUnlock(privconn);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
*state = virDomainObjGetState(privdom, reason); *state = virDomainObjGetState(privdom, reason);
ret = 0; ret = 0;
@ -637,21 +611,14 @@ parallelsDomainGetState(virDomainPtr domain,
static char * static char *
parallelsDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) parallelsDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainDefPtr def; virDomainDefPtr def;
virDomainObjPtr privdom; virDomainObjPtr privdom;
char *ret = NULL; char *ret = NULL;
/* Flags checked by virDomainDefFormat */ /* Flags checked by virDomainDefFormat */
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
parallelsDriverUnlock(privconn);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
def = (flags & VIR_DOMAIN_XML_INACTIVE) && def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
privdom->newDef ? privdom->newDef : privdom->def; privdom->newDef ? privdom->newDef : privdom->def;
@ -667,18 +634,11 @@ parallelsDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
static int static int
parallelsDomainGetAutostart(virDomainPtr domain, int *autostart) parallelsDomainGetAutostart(virDomainPtr domain, int *autostart)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
int ret = -1; int ret = -1;
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
parallelsDriverUnlock(privconn);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
*autostart = privdom->autostart; *autostart = privdom->autostart;
ret = 0; ret = 0;
@ -822,20 +782,13 @@ parallelsDomainGetVcpus(virDomainPtr domain,
unsigned char *cpumaps, unsigned char *cpumaps,
int maplen) int maplen)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom = NULL; virDomainObjPtr privdom = NULL;
size_t i; size_t i;
int v, maxcpu, hostcpus; int v, maxcpu, hostcpus;
int ret = -1; int ret = -1;
parallelsDriverLock(privconn); if (!(privdom = parallelsDomObjFromDomain(domain)))
privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
parallelsDriverUnlock(privconn);
if (privdom == NULL) {
parallelsDomNotFoundError(domain);
goto cleanup; goto cleanup;
}
if (!virDomainObjIsActive(privdom)) { if (!virDomainObjIsActive(privdom)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
@ -956,15 +909,11 @@ static int parallelsDomainShutdown(virDomainPtr domain)
static int parallelsDomainIsActive(virDomainPtr domain) static int parallelsDomainIsActive(virDomainPtr domain)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
int ret = -1; int ret = -1;
dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!(dom = parallelsDomObjFromDomain(domain)))
if (dom == NULL) {
parallelsDomNotFoundError(domain);
return -1; return -1;
}
ret = virDomainObjIsActive(dom); ret = virDomainObjIsActive(dom);
virObjectUnlock(dom); virObjectUnlock(dom);
@ -991,11 +940,8 @@ parallelsDomainUndefineFlags(virDomainPtr domain,
virCheckFlags(0, -1); virCheckFlags(0, -1);
dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!(dom = parallelsDomObjFromDomain(domain)))
if (dom == NULL) {
parallelsDomNotFoundError(domain);
return -1; return -1;
}
ret = prlsdkUnregisterDomain(privconn, dom); ret = prlsdkUnregisterDomain(privconn, dom);
if (ret) if (ret)
@ -1013,18 +959,14 @@ parallelsDomainUndefine(virDomainPtr domain)
static int static int
parallelsDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags) parallelsDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
{ {
parallelsConnPtr privconn = domain->conn->privateData;
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
int state, reason; int state, reason;
int ret = 0; int ret = 0;
virCheckFlags(0, -1); virCheckFlags(0, -1);
dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!(dom = parallelsDomObjFromDomain(domain)))
if (dom == NULL) {
parallelsDomNotFoundError(domain);
return -1; return -1;
}
state = virDomainObjGetState(dom, &reason); state = virDomainObjGetState(dom, &reason);
if (state == VIR_DOMAIN_SHUTOFF && reason == VIR_DOMAIN_SHUTOFF_SAVED) if (state == VIR_DOMAIN_SHUTOFF && reason == VIR_DOMAIN_SHUTOFF_SAVED)
@ -1045,11 +987,8 @@ parallelsDomainManagedSave(virDomainPtr domain, unsigned int flags)
virCheckFlags(VIR_DOMAIN_SAVE_RUNNING | virCheckFlags(VIR_DOMAIN_SAVE_RUNNING |
VIR_DOMAIN_SAVE_PAUSED, -1); VIR_DOMAIN_SAVE_PAUSED, -1);
dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!(dom = parallelsDomObjFromDomain(domain)))
if (dom == NULL) {
parallelsDomNotFoundError(domain);
return -1; return -1;
}
state = virDomainObjGetState(dom, &reason); state = virDomainObjGetState(dom, &reason);
@ -1076,11 +1015,8 @@ parallelsDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags)
virCheckFlags(0, -1); virCheckFlags(0, -1);
dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid); if (!(dom = parallelsDomObjFromDomain(domain)))
if (dom == NULL) {
parallelsDomNotFoundError(domain);
return -1; return -1;
}
state = virDomainObjGetState(dom, &reason); state = virDomainObjGetState(dom, &reason);
@ -1106,11 +1042,8 @@ static int parallelsDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
privdom = virDomainObjListFindByUUID(privconn->domains, dom->uuid); if (!(privdom = parallelsDomObjFromDomain(dom)))
if (privdom == NULL) {
parallelsDomNotFoundError(dom);
return -1; return -1;
}
if (!(flags & VIR_DOMAIN_AFFECT_CONFIG)) { if (!(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",