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

[libvirt] [PATCH 4/5] node conf: Make parsing routines consistent with other drivers



Add virNodeDeviceParseFile, and make virNodeDeviceParseNode non-static. These
will be used by the test driver.

Signed-off-by: Cole Robinson <crobinso redhat com>
---
 src/conf/node_device_conf.c |   47 ++++++++++++++++++++++++++++++++++++------
 src/conf/node_device_conf.h |    9 ++++++++
 2 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index a810940..f09f814 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1097,8 +1097,11 @@ virNodeDeviceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt, int create
     return NULL;
 }
 
-static virNodeDeviceDefPtr
-virNodeDeviceDefParseNode(virConnectPtr conn, xmlDocPtr xml, xmlNodePtr root, int create)
+virNodeDeviceDefPtr
+virNodeDeviceDefParseNode(virConnectPtr conn,
+                          xmlDocPtr xml,
+                          xmlNodePtr root,
+                          int create)
 {
     xmlXPathContextPtr ctxt = NULL;
     virNodeDeviceDefPtr def = NULL;
@@ -1143,8 +1146,13 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
     }
 }
 
-virNodeDeviceDefPtr
-virNodeDeviceDefParseString(virConnectPtr conn, const char *str, int create)
+
+
+static virNodeDeviceDefPtr
+virNodeDeviceDefParse(virConnectPtr conn,
+                      const char *str,
+                      const char *filename,
+                      int create)
 {
     xmlParserCtxtPtr pctxt;
     xmlDocPtr xml = NULL;
@@ -1159,9 +1167,17 @@ virNodeDeviceDefParseString(virConnectPtr conn, const char *str, int create)
     pctxt->_private = conn;
 
     if (conn) virResetError (&conn->err);
-    xml = xmlCtxtReadDoc(pctxt, BAD_CAST str, "device.xml", NULL,
-                         XML_PARSE_NOENT | XML_PARSE_NONET |
-                         XML_PARSE_NOWARNING);
+    if (filename) {
+        xml = xmlCtxtReadFile (pctxt, filename, NULL,
+                               XML_PARSE_NOENT | XML_PARSE_NONET |
+                               XML_PARSE_NOWARNING);
+    } else {
+        xml = xmlCtxtReadDoc (pctxt, BAD_CAST str,
+                              "device.xml", NULL,
+                              XML_PARSE_NOENT | XML_PARSE_NONET |
+                              XML_PARSE_NOWARNING);
+    }
+
     if (!xml) {
         if (conn && conn->err.code == VIR_ERR_NONE)
               virNodeDeviceReportError(conn, VIR_ERR_XML_ERROR,
@@ -1183,6 +1199,23 @@ cleanup:
     return def;
 }
 
+virNodeDeviceDefPtr
+virNodeDeviceDefParseString(virConnectPtr conn,
+                            const char *str,
+                            int create)
+{
+    return virNodeDeviceDefParse(conn, str, NULL, create);
+}
+
+virNodeDeviceDefPtr
+virNodeDeviceDefParseFile(virConnectPtr conn,
+                          const char *filename,
+                          int create)
+{
+    return virNodeDeviceDefParse(conn, NULL, filename, create);
+}
+
+
 void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
 {
     union _virNodeDevCapData *data = &caps->data;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 9fa9127..29a4d43 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -28,6 +28,8 @@
 #include "util.h"
 #include "threads.h"
 
+#include <libxml/tree.h>
+
 #define CREATE_DEVICE 1
 #define EXISTING_DEVICE 0
 
@@ -211,6 +213,13 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
 virNodeDeviceDefPtr virNodeDeviceDefParseString(virConnectPtr conn,
                                                 const char *str,
                                                 int create);
+virNodeDeviceDefPtr virNodeDeviceDefParseFile(virConnectPtr conn,
+                                              const char *filename,
+                                              int create);
+virNodeDeviceDefPtr virNodeDeviceDefParseNode(virConnectPtr conn,
+                                              xmlDocPtr xml,
+                                              xmlNodePtr root,
+                                              int create);
 
 void virNodeDeviceDefFree(virNodeDeviceDefPtr def);
 
-- 
1.6.5.rc2


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