diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index a81094005669482ebfde6b1c713cdda77c9e9b56..f09f81496733e02bd5c9ea7daa380dfdac610636 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 9fa9127e604f93796b1eeeec7c93241736f80f9b..29a4d43000d2d80ef2f42838392727a04196846b 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 + #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);