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

Peter Krempa pkrempa at redhat.com
Thu Feb 25 13:26:16 UTC 2021


Move the extent formatting code into
virStorageVolDefFormatSourceExtents.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 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




More information about the libvir-list mailing list