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: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
ACKed in version 2
Version 3:
- rebased (context conflict in libvirt_private.syms)
Version 2:
- new patch which replaces thread queues and conditions (patch 1
and 2 in version 1)
src/conf/domain_conf.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 6 ++++++
src/libvirt_private.syms | 4 ++++
3 files changed, 57 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 36de844..433183f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ba17a8d..ac29ce5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 55a5e19..62a4b4c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -380,6 +380,7 @@ virDomainNetTypeToString;
virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
+virDomainObjBroadcast;
virDomainObjCopyPersistentDef;
virDomainObjEndAPI;
virDomainObjFormat;
@@ -408,8 +409,11 @@ virDomainObjParseNode;
virDomainObjSetDefTransient;
virDomainObjSetMetadata;
virDomainObjSetState;
+virDomainObjSignal;
virDomainObjTaint;
virDomainObjUpdateModificationImpact;
+virDomainObjWait;
+virDomainObjWaitUntil;
virDomainOSTypeFromString;
virDomainOSTypeToString;
virDomainParseMemory;
--
2.4.3