[PATCHv3 01/27] virCaps: conf: start splitting out irrelevat data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---

Notes:
    Version 3:
    - Changed comment at the capabilities structure
    - virDomainXMLConfGetNamespace now returns a pointer instead of struct
    - use virDomainXMLPrivateDataCallbacks instead of separate pointers
    - even more fallout fixed in driver's I wasn't compiling originaly
    Version 2:
    - complete rewrite

 src/conf/capabilities.h |  8 ++----
 src/conf/domain_conf.c  | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h  | 27 +++++++++++++++++++
 3 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 6c67fb3..a70896a 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -160,19 +160,15 @@ struct _virCaps {
     size_t nguests;
     size_t nguests_max;
     virCapsGuestPtr *guests;
+
+    /* Move to virDomainXMLConf 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 717fc20..5bec673 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -736,6 +736,77 @@ 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 */
+    virDomainXMLPrivateDataCallbacks privateData;
+
+    /* 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->privateData = *priv;
+
+    if (xmlns)
+        xmlconf->ns = *xmlns;
+
+    return xmlconf;
+}
+
+/**
+ * virDomainXMLConfGetNamespace:
+ *
+ * @xmlconf: XML parser configuration object
+ *
+ * Returns a pointer to the stored namespace structure.
+ * The lifetime of the pointer is equal to @xmlconf;
+ */
+virDomainXMLNamespacePtr
+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..da72981 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);
+
+virDomainXMLNamespacePtr
+virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf);
+
 static inline bool
 virDomainObjIsActive(virDomainObjPtr dom)
 {
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]