]> xenbits.xensource.com Git - libvirt.git/commitdiff
src/storage: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Mar 2014 08:33:31 +0000 (09:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Mar 2014 12:45:10 +0000 (13:45 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_backend_disk.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_iscsi.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_rbd.c
src/storage/storage_backend_scsi.c

index a7a7d0ec0d1450f3cb634d2fe67684d88479d27b..b2617734507b7f6571da0601d34e60a5d5769721 100644 (file)
@@ -52,20 +52,15 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
     if (vol == NULL) {
         if (VIR_ALLOC(vol) < 0)
             return -1;
-
-        if (VIR_REALLOC_N(pool->volumes.objs,
-                          pool->volumes.count+1) < 0) {
-            virStorageVolDefFree(vol);
-            return -1;
-        }
-        pool->volumes.objs[pool->volumes.count++] = vol;
-
         /* Prepended path will be same for all partitions, so we can
          * strip the path to form a reasonable pool-unique name
          */
         tmp = strrchr(groups[0], '/');
-        if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0)
+        if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0 ||
+            VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
+            virStorageVolDefFree(vol);
             return -1;
+        }
     }
 
     if (vol->target.path == NULL) {
index 4d69f74a998a27b7c1352c70fbce2d3a24438688..bab02dd1ee0cc1f27cadc91ac29d1079b84a8767 100644 (file)
@@ -905,11 +905,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         }
 
 
-        if (VIR_REALLOC_N(pool->volumes.objs,
-                          pool->volumes.count+1) < 0)
+        if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
             goto cleanup;
-        pool->volumes.objs[pool->volumes.count++] = vol;
-        vol = NULL;
     }
     closedir(dir);
 
index 3d75215c3fc4a50e31a7dfae88bd592c7bbca068..ada6c48e61f81f9f9f86f60b9639f9a7c568f59c 100644 (file)
@@ -447,14 +447,11 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
     if (VIR_STRDUP(target, groups[1]) < 0)
         return -1;
 
-    if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) {
+    if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) {
         VIR_FREE(target);
         return -1;
     }
 
-    list->targets[list->ntargets] = target;
-    list->ntargets++;
-
     return 0;
 }
 
index 15b86dc8a21a9c8c871609c4a4723dd8cec1670d..1ac48e61108a4466b56dbfb25e0faa7b95068916 100644 (file)
@@ -115,9 +115,6 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
         if (VIR_STRDUP(vol->name, groups[0]) < 0)
             goto cleanup;
 
-        if (VIR_REALLOC_N(pool->volumes.objs,
-                          pool->volumes.count + 1))
-            goto cleanup;
     }
 
     if (vol->target.path == NULL) {
@@ -251,8 +248,9 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
         vol->source.nextent++;
     }
 
-    if (is_new_vol)
-        pool->volumes.objs[pool->volumes.count++] = vol;
+    if (is_new_vol &&
+        VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
+        goto cleanup;
 
     ret = 0;
 
index 1e65a8d3cbbd7f2dc32fd090b0c762638791e100..5d0ed320b2df4bd8e34b7d8d61232e3ce0920891 100644 (file)
@@ -99,10 +99,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
     if (VIR_STRDUP(vol->key, vol->target.path) < 0)
         goto cleanup;
 
-    if (VIR_REALLOC_N(pool->volumes.objs,
-                      pool->volumes.count + 1) < 0)
+    if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, vol) < 0)
         goto cleanup;
-    pool->volumes.objs[pool->volumes.count++] = vol;
     pool->def->capacity += vol->capacity;
     pool->def->allocation += vol->allocation;
     ret = 0;
index 22ed7dea214ce7eb4690c0d7008068e3c1191182..bc52474b26d302c2254f7f77a02f4c66e7082f58 100644 (file)
@@ -382,11 +382,6 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
     for (name = names; name < names + max_size;) {
         virStorageVolDefPtr vol;
 
-        if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) {
-            virStoragePoolObjClearVols(pool);
-            goto cleanup;
-        }
-
         if (STREQ(name, ""))
             break;
 
@@ -405,7 +400,10 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
             goto cleanup;
         }
 
-        pool->volumes.objs[pool->volumes.count++] = vol;
+        if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
+            virStoragePoolObjClearVols(pool);
+            goto cleanup;
+        }
     }
 
     VIR_DEBUG("Found %zu images in RBD pool %s",
index 1841816db50255db6ddcf6df22ac017cacc60817..43972578eed149834ff55834e1a43955e89c5adb 100644 (file)
@@ -249,12 +249,10 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
     pool->def->capacity += vol->capacity;
     pool->def->allocation += vol->allocation;
 
-    if (VIR_REALLOC_N(pool->volumes.objs,
-                      pool->volumes.count + 1) < 0) {
+    if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0) {
         retval = -1;
         goto free_vol;
     }
-    pool->volumes.objs[pool->volumes.count++] = vol;
 
     goto out;