The new connect close callbacks for domains will be represented by a
virObject associated with the domain object itself.
To simplify handling the pointer to the close callback data will be done
by an immutable pointer allocated directly when allocating the
corresponding virDomainObj struct.
This patch adds the 'closecallbacks' field to virDomainObj and a
corresponding callback to allocate it into virDomainXMLOption.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 13 +++++++++++++
src/conf/domain_conf.h | 25 +++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
3 files changed, 39 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6c088ff295..66189277fd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1722,6 +1722,14 @@ virDomainXMLOptionGetSaveCookie(virDomainXMLOption *xmlopt)
}
+void
+virDomainXMLOptionSetCloseCallbackAlloc(virDomainXMLOption *xmlopt,
+ virDomainCloseCallbackDataAlloc cb)
+{
+ xmlopt->closecallbackAlloc = cb;
+}
+
+
void
virDomainXMLOptionSetMomentPostParse(virDomainXMLOption *xmlopt,
virDomainMomentPostParseCallback cb)
@@ -3906,6 +3914,7 @@ static void virDomainObjDispose(void *obj)
virDomainSnapshotObjListFree(dom->snapshots);
virDomainCheckpointObjListFree(dom->checkpoints);
virDomainJobObjFree(dom->job);
+ virObjectUnref(dom->closecallbacks);
}
virDomainObj *
@@ -3932,6 +3941,10 @@ virDomainObjNew(virDomainXMLOption *xmlopt)
domain->privateDataFreeFunc = xmlopt->privateData.free;
}
+ if (xmlopt->closecallbackAlloc) {
+ domain->closecallbacks = (xmlopt->closecallbackAlloc)();
+ }
+
if (!(domain->snapshots = virDomainSnapshotObjListNew()))
goto error;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1404c55053..33c4ff69dd 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3126,6 +3126,23 @@ struct _virDomainObj {
void *privateData;
void (*privateDataFreeFunc)(void *);
+ /* Connection close callbacks helper data
+ *
+ * Immutable pointer sharing lifetime of the virDomainObj. May be NULL, if
+ * the hypervisor driver doesn't use close callbacks.
+ *
+ * The closecallbacks helper data may be accessed without holding the
+ * virDomainObj lock to check whether a connection being closed has a
+ * registered close callback.
+ *
+ * Otherwise virDomainObj must be held and acquired before the lock on the
+ * closecallbacks data.
+ *
+ * The above rules ensure minimal lock contention when closing the
+ * connection while also allowing correct handling.
+ */
+ virObject *closecallbacks;
+
int taint;
size_t ndeprecations;
char **deprecations;
@@ -3304,6 +3321,11 @@ struct _virDomainJobObjConfig {
unsigned int maxQueuedJobs;
};
+
+typedef virObject *(*virDomainCloseCallbackDataAlloc)(void);
+void virDomainXMLOptionSetCloseCallbackAlloc(virDomainXMLOption *xmlopt,
+ virDomainCloseCallbackDataAlloc cb);
+
virDomainXMLOption *virDomainXMLOptionNew(virDomainDefParserConfig *config,
virDomainXMLPrivateDataCallbacks *priv,
virXMLNamespace *xmlns,
@@ -3352,6 +3374,9 @@ struct _virDomainXMLOption {
/* virDomainJobObj callbacks, private data callbacks and defaults */
virDomainJobObjConfig jobObjConfig;
+
+ /* closecallback allocation callback */
+ virDomainCloseCallbackDataAlloc closecallbackAlloc;
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainXMLOption, virObjectUnref);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 54a3859604..8f50f9fa1e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -699,6 +699,7 @@ virDomainXenPassthroughModeTypeToString;
virDomainXMLOptionGetNamespace;
virDomainXMLOptionGetSaveCookie;
virDomainXMLOptionNew;
+virDomainXMLOptionSetCloseCallbackAlloc;
virDomainXMLOptionSetMomentPostParse;
--
2.38.1