[libvirt] [PATCH 03/34] conf: Introduce virDomainStorageSourceFormatFull

Peter Krempa pkrempa at redhat.com
Mon Mar 18 15:54:52 UTC 2019


The new function formats a virStorageSource into an XML element which
already contains type and format for simpler handling.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/domain_conf.c   | 39 +++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  8 ++++++++
 src/libvirt_private.syms |  1 +
 3 files changed, 48 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4083839fc8..9f1f46c905 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23857,6 +23857,45 @@ virDomainStorageSourceFormat(virBufferPtr attrBuf,
 }


+/**
+ * virDomainStorageSourceFormatFull:
+ * @buf: output buffer
+ * @src: storage source to format
+ * @elemname: name of the top level element to use
+ * @status: output status-XML style private data
+ * @xmlopt: formatter callback data structure
+ *
+ * Formats @src into a XML element called @elemname. The element has both 'type'
+ * and 'format' attributes and thus is fully standalone.
+ */
+int
+virDomainStorageSourceFormatFull(virBufferPtr buf,
+                                 virStorageSourcePtr src,
+                                 const char *elemname,
+                                 bool status,
+                                 virDomainXMLOptionPtr xmlopt)
+{
+    VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+    VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+    unsigned int flags = 0;
+
+    if (status)
+        flags |= VIR_DOMAIN_DEF_FORMAT_STATUS;
+
+    virBufferSetChildIndent(&childBuf, buf);
+
+    virBufferAsprintf(&attrBuf, " type='%s' format='%s'",
+                      virStorageTypeToString(src->type),
+                      virStorageFileFormatTypeToString(src->format));
+
+    if (virDomainStorageSourceFormat(&attrBuf, &childBuf, src, flags,
+                                     true, true, 0, xmlopt) < 0)
+        return -1;
+
+    return virXMLFormatElement(buf, elemname, &attrBuf, &childBuf);
+}
+
+
 static int
 virDomainDiskSourceFormatInternal(virBufferPtr buf,
                                   virStorageSourcePtr src,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a6f8e13088..547ce8c5b9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3467,6 +3467,14 @@ int virDomainStorageSourceFormat(virBufferPtr attrBuf,
                                  virDomainXMLOptionPtr xmlopt)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

+int
+virDomainStorageSourceFormatFull(virBufferPtr buf,
+                                 virStorageSourcePtr src,
+                                 const char *elemname,
+                                 bool status,
+                                 virDomainXMLOptionPtr xmlopt)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
 int virDomainStorageSourceParse(xmlNodePtr node,
                                 xmlXPathContextPtr ctxt,
                                 virStorageSourcePtr src,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d9494a04bb..5b031ff877 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -564,6 +564,7 @@ virDomainStateTypeFromString;
 virDomainStateTypeToString;
 virDomainStorageNetworkParseHost;
 virDomainStorageSourceFormat;
+virDomainStorageSourceFormatFull;
 virDomainStorageSourceParse;
 virDomainTaintTypeFromString;
 virDomainTaintTypeToString;
-- 
2.20.1




More information about the libvir-list mailing list