[PATCH 09/13] src/storage: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/storage/storage_backend_disk.c    | 13 ++++---------
 src/storage/storage_backend_fs.c      |  5 +----
 src/storage/storage_backend_iscsi.c   |  5 +----
 src/storage/storage_backend_logical.c |  8 +++-----
 src/storage/storage_backend_mpath.c   |  4 +---
 src/storage/storage_backend_rbd.c     | 10 ++++------
 src/storage/storage_backend_scsi.c    |  4 +---
 7 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index a7a7d0e..b261773 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -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) {
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 4d69f74..bab02dd 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -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);
 
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 3d75215..ada6c48 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -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;
 }
 
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 15b86dc..1ac48e6 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -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;
 
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index 1e65a8d..5d0ed32 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -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;
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 22ed7de..bc52474 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -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",
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 1841816..4397257 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -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;
 
-- 
1.9.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]