[PATCH v3 1/4] logical: Use VIR_APPEND_ELEMENT instead of VIR_REALLOC_N

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

 



Rather than preallocating a set number of elements, then walking through
the extents and adjusting the specific element in place, use the APPEND
macros to handle that chore.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/storage_conf.h               |  2 +-
 src/storage/storage_backend_logical.c | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index f1dc62b..31b45be 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -50,7 +50,7 @@ struct _virStorageVolSourceExtent {
 typedef struct _virStorageVolSource virStorageVolSource;
 typedef virStorageVolSource *virStorageVolSourcePtr;
 struct _virStorageVolSource {
-    int nextent;
+    size_t nextent;
     virStorageVolSourceExtentPtr extents;
 
     int partType; /* virStorageVolTypeDisk, only used by disk
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 7c05b6a..bb02d8a 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -84,6 +84,9 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
     size_t i;
     int err, nvars;
     unsigned long long offset, size, length;
+    virStorageVolSourceExtent extent;
+
+    memset(&extent, 0, sizeof(extent));
 
     nextents = 1;
     if (STREQ(groups[4], VIR_STORAGE_VOL_LOGICAL_SEGTYPE_STRIPED)) {
@@ -94,11 +97,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
         }
     }
 
-    /* Allocate and fill in extents information */
-    if (VIR_REALLOC_N(vol->source.extents,
-                      vol->source.nextent + nextents) < 0)
-        goto cleanup;
-
     if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("malformed volume extent length value"));
@@ -162,7 +160,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
         len = vars[j].rm_eo - vars[j].rm_so;
         p[vars[j].rm_eo] = '\0';
 
-        if (VIR_STRNDUP(vol->source.extents[vol->source.nextent].path,
+        if (VIR_STRNDUP(extent.path,
                         p + vars[j].rm_so, len) < 0)
             goto cleanup;
 
@@ -176,12 +174,13 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
             VIR_FREE(offset_str);
             goto cleanup;
         }
-
         VIR_FREE(offset_str);
+        extent.start = offset * size;
+        extent.end = (offset * size) + length;
 
-        vol->source.extents[vol->source.nextent].start = offset * size;
-        vol->source.extents[vol->source.nextent].end = (offset * size) + length;
-        vol->source.nextent++;
+        if (VIR_APPEND_ELEMENT(vol->source.extents, vol->source.nextent,
+                               extent) < 0)
+            goto cleanup;
     }
 
     ret = 0;
@@ -190,6 +189,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
     VIR_FREE(regex);
     VIR_FREE(reg);
     VIR_FREE(vars);
+    VIR_FREE(extent.path);
     return ret;
 }
 
-- 
2.5.0

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