The virCaps structure gathered a ton of irrelevant data over time that. The original reason is that it was propagated to the XML parser functions. This patch aims to create a new data structure virDomainXMLConf that will contain immutable data that are used by the XML parser. This will allow two things we need: 1) Get rid of the stuff from virCaps 2) Allow us to add callbacks to check and add driver specific stuff after domain XML is parsed. This first attempt removes pointers to private data allocation functions to this new structure and update all callers and function that require them. --- src/conf/capabilities.h | 8 ++---- src/conf/domain_conf.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 27 +++++++++++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index cc01765..bf64296 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -159,19 +159,15 @@ struct _virCaps { size_t nguests; size_t nguests_max; virCapsGuestPtr *guests; + + /* deal with these later */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned int emulatorRequired : 1; const char *defaultDiskDriverName; int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); - void *(*privateDataAllocFunc)(void); - void (*privateDataFreeFunc)(void *); - int (*privateDataXMLFormat)(virBufferPtr, void *); - int (*privateDataXMLParse)(xmlXPathContextPtr, void *); bool hasWideScsiBus; const char *defaultInitPath; - - virDomainXMLNamespace ns; }; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f7c8af1..2b54aec 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -736,6 +736,76 @@ static int virDomainObjOnceInit(void) VIR_ONCE_GLOBAL_INIT(virDomainObj) + +/* This structure holds various callbacks and data needed + * while parsing and creating domain XMLs */ +struct _virDomainXMLConf { + virObject parent; + + /* domain private data management callbacks */ + virDomainXMLPrivateDataAllocFunc privateDataAllocFunc; + virDomainXMLPrivateDataFreeFunc privateDataFreeFunc; + virDomainXMLPrivateDataFormatFunc privateDataXMLFormat; + virDomainXMLPrivateDataParseFunc privateDataXMLParse; + + /* XML namespace callbacks */ + virDomainXMLNamespace ns; + }; + + + +static virClassPtr virDomainXMLConfClass; + +static int virDomainXMLConfOnceInit(void) +{ + if (!(virDomainXMLConfClass = virClassNew(virClassForObject(), + "virDomainXMLConf", + sizeof(virDomainXMLConf), + NULL))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virDomainXMLConf) + +/** + * virDomainXMLConfNew: + * + * Allocate a new domain XML configuration + */ +virDomainXMLConfPtr +virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainXMLNamespacePtr xmlns) +{ + virDomainXMLConfPtr xmlconf; + + if (virDomainXMLConfInitialize() < 0) + return NULL; + + if (!(xmlconf = virObjectNew(virDomainXMLConfClass))) + return NULL; + + if (priv) { + xmlconf->privateDataAllocFunc = priv->alloc; + xmlconf->privateDataFreeFunc = priv->free; + xmlconf->privateDataXMLFormat = priv->format; + xmlconf->privateDataXMLParse = priv->parse; + } + + if (xmlns) + xmlconf->ns = *xmlns; + + return xmlconf; +} + +virDomainXMLNamespace +virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf) +{ + return xmlconf->ns; +} + + void virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights, int ndevices) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2509193..db14504 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1926,6 +1926,33 @@ struct _virDomainObj { typedef struct _virDomainObjList virDomainObjList; typedef virDomainObjList *virDomainObjListPtr; + +/* This structure holds various callbacks and data needed + * while parsing and creating domain XMLs */ +typedef struct _virDomainXMLConf virDomainXMLConf; +typedef virDomainXMLConf *virDomainXMLConfPtr; + +typedef void *(*virDomainXMLPrivateDataAllocFunc)(void); +typedef void (*virDomainXMLPrivateDataFreeFunc)(void *); +typedef int (*virDomainXMLPrivateDataFormatFunc)(virBufferPtr, void *); +typedef int (*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr, void *); + +typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks; +typedef virDomainXMLPrivateDataCallbacks *virDomainXMLPrivateDataCallbacksPtr; +struct _virDomainXMLPrivateDataCallbacks { + virDomainXMLPrivateDataAllocFunc alloc; + virDomainXMLPrivateDataFreeFunc free; + virDomainXMLPrivateDataFormatFunc format; + virDomainXMLPrivateDataParseFunc parse; +}; + +virDomainXMLConfPtr +virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainXMLNamespacePtr xmlns); + +virDomainXMLNamespace +virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf); + static inline bool virDomainObjIsActive(virDomainObjPtr dom) { -- 1.8.1.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list