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:
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 6e57425..0850b9b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2508,6 +2508,7 @@ static void virDomainObjDispose(void *obj)
virDomainObjPtr dom = obj;
VIR_DEBUG("obj=%p", dom);
+ virCondDestroy(&dom->cond);
virDomainDefFree(dom->def);
virDomainDefFree(dom->newDef);
@@ -2528,6 +2529,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;
@@ -2650,6 +2657,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 0fcf52e..1039f78 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2305,6 +2305,7 @@ typedef struct _virDomainObj virDomainObj;
typedef virDomainObj *virDomainObjPtr;
struct _virDomainObj {
virObjectLockable parent;
+ virCond cond;
pid_t pid;
virDomainStateReason state;
@@ -2424,6 +2425,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 6a95fb9..9076135 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -382,6 +382,7 @@ virDomainNetTypeToString;
virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
+virDomainObjBroadcast;
virDomainObjCopyPersistentDef;
virDomainObjEndAPI;
virDomainObjFormat;
@@ -409,7 +410,10 @@ virDomainObjParseNode;
virDomainObjSetDefTransient;
virDomainObjSetMetadata;
virDomainObjSetState;
+virDomainObjSignal;
virDomainObjTaint;
+virDomainObjWait;
+virDomainObjWaitUntil;
virDomainOSTypeFromString;
virDomainOSTypeToString;
virDomainParseMemory;
--
2.4.1