[PATCH 3/4] virStorageVolDefFormat: Extract formatting of source extents

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

 



Move the extent formatting code into
virStorageVolDefFormatSourceExtents.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/storage_conf.c | 53 +++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 0f515c7cbb..1bc27ff194 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1643,6 +1643,34 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
 }


+static void
+virStorageVolDefFormatSourceExtents(virBufferPtr buf,
+                                    virStorageVolDefPtr def)
+{
+    size_t i;
+    const char *thispath = NULL;
+    for (i = 0; i < def->source.nextent; i++) {
+        if (thispath == NULL ||
+            STRNEQ(thispath, def->source.extents[i].path)) {
+            if (thispath != NULL)
+                virBufferAddLit(buf, "</device>\n");
+
+            virBufferEscapeString(buf, "<device path='%s'>\n",
+                                  def->source.extents[i].path);
+        }
+
+        virBufferAdjustIndent(buf, 2);
+        virBufferAsprintf(buf, "<extent start='%llu' end='%llu'/>\n",
+                          def->source.extents[i].start,
+                          def->source.extents[i].end);
+        virBufferAdjustIndent(buf, -2);
+        thispath = def->source.extents[i].path;
+    }
+    if (thispath != NULL)
+        virBufferAddLit(buf, "</device>\n");
+}
+
+
 char *
 virStorageVolDefFormat(virStoragePoolDefPtr pool,
                        virStorageVolDefPtr def)
@@ -1663,29 +1691,8 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
     virBufferAddLit(&buf, "<source>\n");
     virBufferAdjustIndent(&buf, 2);

-    if (def->source.nextent) {
-        size_t i;
-        const char *thispath = NULL;
-        for (i = 0; i < def->source.nextent; i++) {
-            if (thispath == NULL ||
-                STRNEQ(thispath, def->source.extents[i].path)) {
-                if (thispath != NULL)
-                    virBufferAddLit(&buf, "</device>\n");
-
-                virBufferEscapeString(&buf, "<device path='%s'>\n",
-                                      def->source.extents[i].path);
-            }
-
-            virBufferAdjustIndent(&buf, 2);
-            virBufferAsprintf(&buf, "<extent start='%llu' end='%llu'/>\n",
-                              def->source.extents[i].start,
-                              def->source.extents[i].end);
-            virBufferAdjustIndent(&buf, -2);
-            thispath = def->source.extents[i].path;
-        }
-        if (thispath != NULL)
-            virBufferAddLit(&buf, "</device>\n");
-    }
+    if (def->source.nextent)
+        virStorageVolDefFormatSourceExtents(&buf, def);

     virBufferAdjustIndent(&buf, -2);
     virBufferAddLit(&buf, "</source>\n");
-- 
2.29.2




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

  Powered by Linux