提交 79d14a99 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
上级 fd65bee7
......@@ -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;
}
/*
*
......
......@@ -2397,6 +2397,8 @@ virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
const char *name);
void virDomainObjEndAPI(virDomainObjPtr *vm);
bool virDomainObjTaint(virDomainObjPtr obj,
virDomainTaintFlags taint);
......
......@@ -374,6 +374,7 @@ virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
virDomainObjCopyPersistentDef;
virDomainObjEndAPI;
virDomainObjFormat;
virDomainObjGetMetadata;
virDomainObjGetPersistentDef;
......
......@@ -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.
When the domain is locked and the reference increased, the preferred way of
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
......@@ -206,7 +206,7 @@ Design patterns
...do work...
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
* Updating something directly to do with a virDomainObjPtr
......@@ -221,7 +221,7 @@ Design patterns
qemuDomainObjEndJob(obj);
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
* Invoking a monitor command on a virDomainObjPtr
......@@ -244,7 +244,7 @@ Design patterns
...do final work...
qemuDomainObjEndJob(obj);
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
* Running asynchronous job
......@@ -284,7 +284,7 @@ Design patterns
...do final work...
qemuDomainObjEndAsyncJob(obj);
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
* Coordinating with a remote server for migration
......@@ -312,4 +312,4 @@ Design patterns
...do final work...
qemuDomainObjEndAsyncJob(obj);
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
......@@ -3393,7 +3393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
if (monpath)
ignore_value(unlink(monpath));
VIR_FREE(monpath);
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
virObjectUnref(xmlopt);
if (pid != 0) {
......
......@@ -2977,25 +2977,6 @@ qemuDomainAgentAvailable(virDomainObjPtr vm,
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
qemuDomainAlignMemorySizes(virDomainDefPtr def)
......
......@@ -426,8 +426,6 @@ int qemuDomainSupportsBlockJobs(virDomainObjPtr vm, bool *modern)
ATTRIBUTE_NONNULL(1);
bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
void qemuDomObjEndAPI(virDomainObjPtr *vm);
int qemuDomainAlignMemorySizes(virDomainDefPtr def);
void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem);
......
此差异已折叠。
......@@ -2774,7 +2774,7 @@ qemuMigrationBegin(virConnectPtr conn,
}
cleanup:
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
return xml;
endjob:
......@@ -3141,7 +3141,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
priv->nbdPort = 0;
qemuDomainRemoveInactive(driver, vm);
}
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
if (event)
qemuDomainEventQueue(driver, event);
qemuMigrationCookieFree(mig);
......@@ -3538,7 +3538,7 @@ qemuMigrationConfirm(virConnectPtr conn,
}
cleanup:
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
virObjectUnref(cfg);
return ret;
}
......@@ -4913,7 +4913,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
}
cleanup:
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
if (event)
qemuDomainEventQueue(driver, event);
virObjectUnref(cfg);
......@@ -4979,7 +4979,7 @@ qemuMigrationPerformPhase(virQEMUDriverPtr driver,
qemuDomainRemoveInactive(driver, vm);
cleanup:
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
if (event)
qemuDomainEventQueue(driver, event);
return ret;
......@@ -5323,7 +5323,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
if (priv->mon)
qemuMonitorSetDomainLog(priv->mon, -1);
VIR_FREE(priv->origname);
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
if (event)
qemuDomainEventQueue(driver, event);
qemuMigrationCookieFree(mig);
......
......@@ -623,7 +623,7 @@ qemuProcessFakeReboot(void *opaque)
cleanup:
if (ret == -1)
ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE));
qemuDomObjEndAPI(&vm);
virDomainObjEndAPI(&vm);
if (event)
qemuDomainEventQueue(driver, event);
virObjectUnref(cfg);
......@@ -3845,7 +3845,7 @@ qemuProcessReconnect(void *opaque)
qemuDomainRemoveInactive(driver, obj);
cleanup:
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
virObjectUnref(conn);
virObjectUnref(cfg);
virNWFilterUnlockFilterUpdates();
......@@ -3889,7 +3889,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
if (!obj->persistent)
qemuDomainRemoveInactive(src->driver, obj);
qemuDomObjEndAPI(&obj);
virDomainObjEndAPI(&obj);
virObjectUnref(data->conn);
VIR_FREE(data);
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册