Add a helper that parses a storage source XML node into a new
virStorageSource object. Since there are multiple approaches to store
the 'type' and 'format' attributes, they need to be parsed manually
prior to calling the function.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/conf/domain_conf.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  6 +++++
 src/libvirt_private.syms |  1 +
 3 files changed, 67 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 86fc275116..0b25c6316f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8650,6 +8650,66 @@ virDomainStorageSourceParse(xmlNodePtr node,
 }


+/**
+ * virDomainStorageSourceParseNew:
+ * @node: XML node object to parse
+ * @ctxt: XML XPath context
+ * @flags: virDomainDefParseFlags
+ *
+ * Parses the XML @node and returns a virStorageSource object with the parsed
+ * data. Note that 'format' and 'type' attributes need to be members of the 
same
+ * object and need to be provided.
+ */
+virStorageSourcePtr
+virDomainStorageSourceParseNew(xmlNodePtr node,
+                               xmlXPathContextPtr ctxt,
+                               unsigned int flags)
+{
+    virStorageSourcePtr src = NULL;
+    virStorageSourcePtr ret = NULL;
+    char *format = NULL;
+    char *type = NULL;
+
+    if (VIR_ALLOC(src) < 0)
+        return NULL;
+
+    if (!(type = virXMLPropString(node, "type"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing storage source type"));
+        goto cleanup;
+    }
+
+    if (!(format = virXMLPropString(node, "format"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       ("missing storage source format"));
+        goto cleanup;
+    }
+
+    if ((src->type = virStorageTypeFromString(type)) <= 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown storage source type '%s'"), type);
+        goto cleanup;
+    }
+
+    if ((src->format = virStorageFileFormatTypeFromString(format)) <= 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown storage source format '%s'"), format);
+        goto cleanup;
+    }
+
+    if (virDomainStorageSourceParse(node, ctxt, src, flags) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, src);
+
+ cleanup:
+    virStorageSourceFree(src);
+    VIR_FREE(format);
+    VIR_FREE(type);
+    return ret;
+}
+
+
 int
 virDomainDiskSourceParse(xmlNodePtr node,
                          xmlXPathContextPtr ctxt,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 61379e50fe..c82a23d220 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3434,6 +3434,12 @@ int virDomainStorageSourceFormat(virBufferPtr attrBuf,
                                  bool skipSeclabels)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

+virStorageSourcePtr
+virDomainStorageSourceParseNew(xmlNodePtr node,
+                               xmlXPathContextPtr ctxt,
+                               unsigned int flags)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
                                      int maplen,
                                      int ncpumaps,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c67bce7389..4dfcbb4230 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -543,6 +543,7 @@ virDomainStateReasonToString;
 virDomainStateTypeFromString;
 virDomainStateTypeToString;
 virDomainStorageSourceFormat;
+virDomainStorageSourceParseNew;
 virDomainTaintTypeFromString;
 virDomainTaintTypeToString;
 virDomainTimerModeTypeFromString;
-- 
2.16.2

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

Reply via email to