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

Peter Krempa posted 4 patches 4 years, 11 months ago
[PATCH 3/4] virStorageVolDefFormat: Extract formatting of source extents
Posted by Peter Krempa 4 years, 11 months ago
Move the extent formatting code into
virStorageVolDefFormatSourceExtents.

Signed-off-by: Peter Krempa <pkrempa@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

Re: [PATCH 3/4] virStorageVolDefFormat: Extract formatting of source extents
Posted by Michal Privoznik 4 years, 11 months ago
On 2/25/21 2:26 PM, Peter Krempa wrote:
> Move the extent formatting code into
> virStorageVolDefFormatSourceExtents.
> 
> Signed-off-by: Peter Krempa <pkrempa@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;

Insert an empty line here, please.

> +    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");
> +}
> +

Michal