[PATCH 22/23] virStorageBackendLogicalParseVolExtents: Move 'extents' inside the loop

Peter Krempa pkrempa at redhat.com
Wed Aug 4 11:02:42 UTC 2021


It's used only inside the loop filling the extents, move it there and
restructure the code so that 'extent.path' doesn't have to be freed.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/storage/storage_backend_logical.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index cffa2c8849..90e7c9e41d 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -128,11 +128,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
     unsigned long long offset;
     unsigned long long size;
     unsigned long long length;
-    virStorageVolSourceExtent extent;
     g_autofree char *regex = NULL;

-    memset(&extent, 0, sizeof(extent));
-
     /* Assume 1 extent (the regex for 'devices' is "(\\S+)") and only
      * check the 'stripes' field if we have a striped, mirror, or one of
      * the raid (raid1, raid4, raid5*, raid6*, or raid10) segtypes in which
@@ -189,11 +186,12 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
      * is the whole matched string.
      */
     for (i = 0; i < nextents; i++) {
-        size_t j;
         g_autofree char *offset_str = NULL;
+        virStorageVolSourceExtent extent;
+        size_t j = (i * 2) + 1;
+
+        memset(&extent, 0, sizeof(extent));

-        j = (i * 2) + 1;
-        extent.path = g_match_info_fetch(info, j);
         offset_str = g_match_info_fetch(info, j + 1);

         if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
@@ -201,6 +199,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
                            _("malformed volume extent offset value"));
             goto cleanup;
         }
+
+        extent.path = g_match_info_fetch(info, j);
         extent.start = offset * size;
         extent.end = (offset * size) + length;

@@ -210,7 +210,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
     ret = 0;

  cleanup:
-    VIR_FREE(extent.path);
     return ret;
 }

-- 
2.31.1




More information about the libvir-list mailing list