Introduce virDomainObjEndAPI

This is basically turning qemuDomObjEndAPI into a more general
function. Other drivers which gets a reference to domain objects may
benefit from this function too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-04-23 17:27:58 +02:00
parent fd65bee759
commit 79d14a9930
10 changed files with 174 additions and 170 deletions

View File

@ -2460,6 +2460,28 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
} }
/**
* virDomainObjEndAPI:
* @vm: domain object
*
* Finish working with a domain object in an API. This function
* clears whatever was left of a domain that was gathered using
* virDomainObjListFindByUUIDRef(). Currently that means only unlocking and
* decrementing the reference counter of that domain. And in order to
* make sure the caller does not access the domain, the pointer is
* cleared.
*/
void
virDomainObjEndAPI(virDomainObjPtr *vm)
{
if (!*vm)
return;
virObjectUnlock(*vm);
virObjectUnref(*vm);
*vm = NULL;
}
/* /*
* *

View File

@ -2397,6 +2397,8 @@ virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms, virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
const char *name); const char *name);
void virDomainObjEndAPI(virDomainObjPtr *vm);
bool virDomainObjTaint(virDomainObjPtr obj, bool virDomainObjTaint(virDomainObjPtr obj,
virDomainTaintFlags taint); virDomainTaintFlags taint);

View File

@ -374,6 +374,7 @@ virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString; virDomainNostateReasonTypeToString;
virDomainObjAssignDef; virDomainObjAssignDef;
virDomainObjCopyPersistentDef; virDomainObjCopyPersistentDef;
virDomainObjEndAPI;
virDomainObjFormat; virDomainObjFormat;
virDomainObjGetMetadata; virDomainObjGetMetadata;
virDomainObjGetPersistentDef; virDomainObjGetPersistentDef;

View File

@ -31,7 +31,7 @@ There are a number of locks on various objects
finds the domain in the domain list without blocking all other lookups. finds the domain in the domain list without blocking all other lookups.
When the domain is locked and the reference increased, the preferred way of When the domain is locked and the reference increased, the preferred way of
decrementing the reference counter and unlocking the domain is using the decrementing the reference counter and unlocking the domain is using the
qemuDomObjEndAPI() function. virDomainObjEndAPI() function.
Lock must be held when changing/reading any variable in the virDomainObjPtr Lock must be held when changing/reading any variable in the virDomainObjPtr
@ -206,7 +206,7 @@ Design patterns
...do work... ...do work...
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
* Updating something directly to do with a virDomainObjPtr * Updating something directly to do with a virDomainObjPtr
@ -221,7 +221,7 @@ Design patterns
qemuDomainObjEndJob(obj); qemuDomainObjEndJob(obj);
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
* Invoking a monitor command on a virDomainObjPtr * Invoking a monitor command on a virDomainObjPtr
@ -244,7 +244,7 @@ Design patterns
...do final work... ...do final work...
qemuDomainObjEndJob(obj); qemuDomainObjEndJob(obj);
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
* Running asynchronous job * Running asynchronous job
@ -284,7 +284,7 @@ Design patterns
...do final work... ...do final work...
qemuDomainObjEndAsyncJob(obj); qemuDomainObjEndAsyncJob(obj);
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
* Coordinating with a remote server for migration * Coordinating with a remote server for migration
@ -312,4 +312,4 @@ Design patterns
...do final work... ...do final work...
qemuDomainObjEndAsyncJob(obj); qemuDomainObjEndAsyncJob(obj);
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);

View File

@ -3393,7 +3393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
if (monpath) if (monpath)
ignore_value(unlink(monpath)); ignore_value(unlink(monpath));
VIR_FREE(monpath); VIR_FREE(monpath);
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
virObjectUnref(xmlopt); virObjectUnref(xmlopt);
if (pid != 0) { if (pid != 0) {

View File

@ -2977,25 +2977,6 @@ qemuDomainAgentAvailable(virDomainObjPtr vm,
return true; return true;
} }
/*
* Finish working with a domain object in an API. This function
* clears whatever was left of a domain that was gathered using
* qemuDomObjFromDomain(). Currently that means only unlocking and
* decrementing the reference counter of that domain. And in order to
* make sure the caller does not access the domain, the pointer is
* cleared.
*/
void
qemuDomObjEndAPI(virDomainObjPtr *vm)
{
if (!*vm)
return;
virObjectUnlock(*vm);
virObjectUnref(*vm);
*vm = NULL;
}
int int
qemuDomainAlignMemorySizes(virDomainDefPtr def) qemuDomainAlignMemorySizes(virDomainDefPtr def)

View File

@ -426,8 +426,6 @@ int qemuDomainSupportsBlockJobs(virDomainObjPtr vm, bool *modern)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk); bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
void qemuDomObjEndAPI(virDomainObjPtr *vm);
int qemuDomainAlignMemorySizes(virDomainDefPtr def); int qemuDomainAlignMemorySizes(virDomainDefPtr def);
void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem); void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);

File diff suppressed because it is too large Load Diff

View File

@ -2774,7 +2774,7 @@ qemuMigrationBegin(virConnectPtr conn,
} }
cleanup: cleanup:
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
return xml; return xml;
endjob: endjob:
@ -3141,7 +3141,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
priv->nbdPort = 0; priv->nbdPort = 0;
qemuDomainRemoveInactive(driver, vm); qemuDomainRemoveInactive(driver, vm);
} }
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
qemuMigrationCookieFree(mig); qemuMigrationCookieFree(mig);
@ -3538,7 +3538,7 @@ qemuMigrationConfirm(virConnectPtr conn,
} }
cleanup: cleanup:
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -4913,7 +4913,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
} }
cleanup: cleanup:
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
virObjectUnref(cfg); virObjectUnref(cfg);
@ -4979,7 +4979,7 @@ qemuMigrationPerformPhase(virQEMUDriverPtr driver,
qemuDomainRemoveInactive(driver, vm); qemuDomainRemoveInactive(driver, vm);
cleanup: cleanup:
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
return ret; return ret;
@ -5323,7 +5323,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
if (priv->mon) if (priv->mon)
qemuMonitorSetDomainLog(priv->mon, -1); qemuMonitorSetDomainLog(priv->mon, -1);
VIR_FREE(priv->origname); VIR_FREE(priv->origname);
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
qemuMigrationCookieFree(mig); qemuMigrationCookieFree(mig);

View File

@ -623,7 +623,7 @@ qemuProcessFakeReboot(void *opaque)
cleanup: cleanup:
if (ret == -1) if (ret == -1)
ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE)); ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE));
qemuDomObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
virObjectUnref(cfg); virObjectUnref(cfg);
@ -3845,7 +3845,7 @@ qemuProcessReconnect(void *opaque)
qemuDomainRemoveInactive(driver, obj); qemuDomainRemoveInactive(driver, obj);
cleanup: cleanup:
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
virObjectUnref(conn); virObjectUnref(conn);
virObjectUnref(cfg); virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates(); virNWFilterUnlockFilterUpdates();
@ -3889,7 +3889,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
if (!obj->persistent) if (!obj->persistent)
qemuDomainRemoveInactive(src->driver, obj); qemuDomainRemoveInactive(src->driver, obj);
qemuDomObjEndAPI(&obj); virDomainObjEndAPI(&obj);
virObjectUnref(data->conn); virObjectUnref(data->conn);
VIR_FREE(data); VIR_FREE(data);
return -1; return -1;