mirror of https://gitee.com/openkylin/libvirt.git
conf: domain: Add helper infrastructure for new connection close callbacks
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@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
e88593ba39
commit
2cb13113c2
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -699,6 +699,7 @@ virDomainXenPassthroughModeTypeToString;
|
|||
virDomainXMLOptionGetNamespace;
|
||||
virDomainXMLOptionGetSaveCookie;
|
||||
virDomainXMLOptionNew;
|
||||
virDomainXMLOptionSetCloseCallbackAlloc;
|
||||
virDomainXMLOptionSetMomentPostParse;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue