[PATCHv5 04/13] Use a separate buffer for <filesystem><driver>

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

 



Format the attributes in a separate buffer and only
print the element if it's not empty.
---
 src/conf/domain_conf.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index af1c12e..1e694fd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20252,6 +20252,7 @@ virDomainFSDefFormat(virBufferPtr buf,
     const char *fsdriver = virDomainFSDriverTypeToString(def->fsdriver);
     const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
     const char *src = def->src->path;
+    virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -20271,16 +20272,21 @@ virDomainFSDefFormat(virBufferPtr buf,
                       type, accessmode);
     virBufferAdjustIndent(buf, 2);
     if (def->fsdriver) {
-        virBufferAsprintf(buf, "<driver type='%s'", fsdriver);
+        virBufferAsprintf(&driverBuf, " type='%s'", fsdriver);
 
         if (def->format)
-            virBufferAsprintf(buf, " format='%s'",
+            virBufferAsprintf(&driverBuf, " format='%s'",
                               virStorageFileFormatTypeToString(def->format));
 
         /* Don't generate anything if wrpolicy is set to default */
         if (def->wrpolicy)
-            virBufferAsprintf(buf, " wrpolicy='%s'", wrpolicy);
+            virBufferAsprintf(&driverBuf, " wrpolicy='%s'", wrpolicy);
+
+    }
 
+    if (virBufferUse(&driverBuf)) {
+        virBufferAddLit(buf, "<driver");
+        virBufferAddBuffer(buf, &driverBuf);
         virBufferAddLit(buf, "/>\n");
     }
 
-- 
2.7.3

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