]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use a separate buffer for <filesystem><driver>
authorJán Tomko <jtomko@redhat.com>
Mon, 22 Aug 2016 15:45:18 +0000 (17:45 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 26 Apr 2017 14:29:38 +0000 (16:29 +0200)
Format the attributes in a separate buffer and only
print the element if it's not empty.

src/conf/domain_conf.c

index 97f00da9d38dd0ff0383c93e71d5c26d513b5f19..61006dea7d6fffd8a6a16006ca57fba2de9e8b5e 100644 (file)
@@ -21388,6 +21388,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,
@@ -21407,16 +21408,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");
     }