提交 e0713c4b 编写于 作者: J Jiri Denemark

conf: Introduce per-domain condition variable

Complex jobs, such as migration, need to monitor several events at once,
which is impossible when each of the event uses its own condition
variable. This patch adds a single condition variable to each domain
object. This variable can be used instead of the other event specific
conditions.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 355d8f47
......@@ -2509,6 +2509,7 @@ static void virDomainObjDispose(void *obj)
virDomainObjPtr dom = obj;
VIR_DEBUG("obj=%p", dom);
virCondDestroy(&dom->cond);
virDomainDefFree(dom->def);
virDomainDefFree(dom->newDef);
......@@ -2529,6 +2530,12 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt)
if (!(domain = virObjectLockableNew(virDomainObjClass)))
return NULL;
if (virCondInit(&domain->cond) < 0) {
virReportSystemError(errno, "%s",
_("failed to initialize domain condition"));
goto error;
}
if (xmlopt->privateData.alloc) {
if (!(domain->privateData = (xmlopt->privateData.alloc)()))
goto error;
......@@ -2651,6 +2658,46 @@ virDomainObjEndAPI(virDomainObjPtr *vm)
}
void
virDomainObjSignal(virDomainObjPtr vm)
{
virCondSignal(&vm->cond);
}
void
virDomainObjBroadcast(virDomainObjPtr vm)
{
virCondBroadcast(&vm->cond);
}
int
virDomainObjWait(virDomainObjPtr vm)
{
if (virCondWait(&vm->cond, &vm->parent.lock) < 0) {
virReportSystemError(errno, "%s",
_("failed to wait for domain condition"));
return -1;
}
return 0;
}
int
virDomainObjWaitUntil(virDomainObjPtr vm,
unsigned long long whenms)
{
if (virCondWaitUntil(&vm->cond, &vm->parent.lock, whenms) < 0 &&
errno != ETIMEDOUT) {
virReportSystemError(errno, "%s",
_("failed to wait for domain condition"));
return -1;
}
return 0;
}
/*
*
* If flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE then
......
......@@ -2318,6 +2318,7 @@ typedef struct _virDomainObj virDomainObj;
typedef virDomainObj *virDomainObjPtr;
struct _virDomainObj {
virObjectLockable parent;
virCond cond;
pid_t pid;
virDomainStateReason state;
......@@ -2437,6 +2438,11 @@ void virDomainObjEndAPI(virDomainObjPtr *vm);
bool virDomainObjTaint(virDomainObjPtr obj,
virDomainTaintFlags taint);
void virDomainObjSignal(virDomainObjPtr vm);
void virDomainObjBroadcast(virDomainObjPtr vm);
int virDomainObjWait(virDomainObjPtr vm);
int virDomainObjWaitUntil(virDomainObjPtr vm,
unsigned long long whenms);
int virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def);
int virDomainDeviceDefCheckUnsupportedMemoryDevice(virDomainDeviceDefPtr dev);
......
......@@ -380,6 +380,7 @@ virDomainNetTypeToString;
virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
virDomainObjBroadcast;
virDomainObjCopyPersistentDef;
virDomainObjEndAPI;
virDomainObjFormat;
......@@ -409,8 +410,11 @@ virDomainObjParseNode;
virDomainObjSetDefTransient;
virDomainObjSetMetadata;
virDomainObjSetState;
virDomainObjSignal;
virDomainObjTaint;
virDomainObjUpdateModificationImpact;
virDomainObjWait;
virDomainObjWaitUntil;
virDomainOSTypeFromString;
virDomainOSTypeToString;
virDomainParseMemory;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册