]> xenbits.xensource.com Git - libvirt.git/commitdiff
logical: Use VIR_APPEND_ELEMENT instead of VIR_REALLOC_N
authorJohn Ferlan <jferlan@redhat.com>
Mon, 1 Feb 2016 14:39:00 +0000 (09:39 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 2 Feb 2016 18:12:57 +0000 (13:12 -0500)
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@redhat.com>
src/conf/storage_conf.h
src/storage/storage_backend_logical.c

index f1dc62b11548f4352d9ebea7bbc56b74679cd967..31b45be04f9acbadd233accea17ade75552b317e 100644 (file)
@@ -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
index 7c05b6ad7d501d8399b00a74dd8c877a7b2050ce..bb02d8af4b104e17db28475ab4827f6d3c3767e7 100644 (file)
@@ -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;
 }