[PATCH 6/8] conf: split out snapshot disk XML formatting

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

 



Just to reduce the indentation levels. Remove the unneeded
NULL check for disk->file, as virBufferEscapeString doesn't
print anything with NULL arguments.
---
 src/conf/snapshot_conf.c | 53 ++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 5b54a28..324b07f 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -552,6 +552,33 @@ cleanup:
     return ret;
 }
 
+static void
+virDomainSnapshotDiskDefFormat(virBufferPtr buf,
+                               virDomainSnapshotDiskDefPtr disk)
+{
+    if (!disk->name)
+        return;
+
+    virBufferEscapeString(buf, "    <disk name='%s'", disk->name);
+    if (disk->snapshot > 0)
+        virBufferAsprintf(buf, " snapshot='%s'",
+                          virDomainSnapshotLocationTypeToString(disk->snapshot));
+    if (!disk->file && disk->format == 0) {
+        virBufferAddLit(buf, "/>\n");
+        return;
+    }
+
+    virBufferAddLit(buf, ">\n");
+
+    virBufferAdjustIndent(buf, 6);
+    if (disk->format > 0)
+        virBufferEscapeString(buf, "<driver type='%s'/>\n",
+                              virStorageFileFormatTypeToString(disk->format));
+    virBufferEscapeString(buf, "<source file='%s'/>\n", disk->file);
+    virBufferAdjustIndent(buf, -6);
+    virBufferAddLit(buf, "    </disk>\n");
+}
+
 char *virDomainSnapshotDefFormat(const char *domain_uuid,
                                  virDomainSnapshotDefPtr def,
                                  unsigned int flags,
@@ -587,30 +614,8 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
     }
     if (def->ndisks) {
         virBufferAddLit(&buf, "  <disks>\n");
-        for (i = 0; i < def->ndisks; i++) {
-            virDomainSnapshotDiskDefPtr disk = &def->disks[i];
-
-            if (!disk->name)
-                continue;
-
-            virBufferEscapeString(&buf, "    <disk name='%s'", disk->name);
-            if (disk->snapshot)
-                virBufferAsprintf(&buf, " snapshot='%s'",
-                                  virDomainSnapshotLocationTypeToString(disk->snapshot));
-            if (disk->file || disk->format > 0) {
-                virBufferAddLit(&buf, ">\n");
-                if (disk->format > 0)
-                    virBufferEscapeString(&buf, "      <driver type='%s'/>\n",
-                                          virStorageFileFormatTypeToString(
-                                              disk->format));
-                if (disk->file)
-                    virBufferEscapeString(&buf, "      <source file='%s'/>\n",
-                                          disk->file);
-                virBufferAddLit(&buf, "    </disk>\n");
-            } else {
-                virBufferAddLit(&buf, "/>\n");
-            }
-        }
+        for (i = 0; i < def->ndisks; i++)
+            virDomainSnapshotDiskDefFormat(&buf, &def->disks[i]);
         virBufferAddLit(&buf, "  </disks>\n");
     }
     if (def->dom) {
-- 
1.8.1.5

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