[PATCHv4 17/17] util: use VIR_(APPEND|DELETE)_ELEMENT for lock owners lists

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

 



---
 src/util/virlockspace.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 99b6182..dc156f8 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -223,11 +223,9 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
     }
     res->lockHeld = true;
 
-    if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0)
+    if (VIR_APPEND_ELEMENT(res->owners, res->nOwners, owner) < 0)
         goto no_memory;
 
-    res->owners[res->nOwners-1] = owner;
-
     return res;
 
 no_memory:
@@ -643,12 +641,10 @@ int virLockSpaceAcquireResource(virLockSpacePtr lockspace,
         if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) &&
             (flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) {
 
-            if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) {
+            if (VIR_APPEND_ELEMENT(res->owners, res->nOwners, owner) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
-            res->owners[res->nOwners-1] = owner;
-
             goto done;
         }
         virReportError(VIR_ERR_RESOURCE_BUSY,
@@ -707,11 +703,7 @@ int virLockSpaceReleaseResource(virLockSpacePtr lockspace,
         goto cleanup;
     }
 
-    if (i < (res->nOwners - 1))
-        memmove(res->owners + i,
-                res->owners + i + 1,
-                (res->nOwners - i - 1) * sizeof(res->owners[0]));
-    VIR_SHRINK_N(res->owners, res->nOwners, 1);
+    VIR_DELETE_ELEMENT(res->owners, i, res->nOwners);
 
     if ((res->nOwners == 0) &&
         virHashRemoveEntry(lockspace->resources, resname) < 0)
@@ -753,11 +745,7 @@ virLockSpaceRemoveResourcesForOwner(const void *payload,
 
     data->count++;
 
-    if (i < (res->nOwners - 1))
-        memmove(res->owners + i,
-                res->owners + i + 1,
-                (res->nOwners - i - 1) * sizeof(res->owners[0]));
-    VIR_SHRINK_N(res->owners, res->nOwners, 1);
+    VIR_DELETE_ELEMENT(res->owners, i, res->nOwners);
 
     if (res->nOwners) {
         VIR_DEBUG("Other shared owners remain");
-- 
1.7.11.7

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