Due to confusing naming the pointer to the mask got copied which must not
happen, so use UpdateMask instead of SetMask.  That also means we can get
completely rid of SetMask.

Also don't clear the free bits since it is not used again (leftover from
previous versions).

Signed-off-by: Martin Kletzander <mklet...@redhat.com>
---
 src/util/virresctrl.c | 41 ++++++++++++++---------------------------
 1 file changed, 14 insertions(+), 27 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 2bdca5455783..14a3c459ffd3 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1255,22 +1255,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl 
ATTRIBUTE_UNUSED)
 
 #endif /* ! __linux__ */
 
-static int
-virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type,
-                       unsigned int cache,
-                       virBitmapPtr mask)
-{
-    if (a_type->nmasks <= cache &&
-        VIR_EXPAND_N(a_type->masks, a_type->nmasks,
-                     cache - a_type->nmasks + 1) < 0)
-        return -1;
-
-    virBitmapFree(a_type->masks[cache]);
-    a_type->masks[cache] = mask;
-
-    return 0;
-}
-
 
 /*
  * Given the information about requested allocation type `a_type`, the host
@@ -1278,16 +1262,19 @@ virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type,
  * this function tries to find the smallest free space in which the allocation
  * for cache id `cache` would fit.  We're looking for the smallest place in
  * order to minimize fragmentation and maximize the possibility of succeeding.
+ *
+ * Per-cache allocation for the @level, @type and @cache must already be
+ * allocated for @alloc (does not have to exist though).
  */
 static int
-virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
+virResctrlAllocFindUnused(virResctrlAllocPtr alloc,
                           virResctrlInfoPerTypePtr i_type,
                           virResctrlAllocPerTypePtr f_type,
                           unsigned int level,
                           unsigned int type,
                           unsigned int cache)
 {
-    unsigned long long *size = a_type->sizes[cache];
+    unsigned long long *size = alloc->levels[level]->types[type]->sizes[cache];
     virBitmapPtr a_mask = NULL;
     virBitmapPtr f_mask = NULL;
     unsigned long long need_bits;
@@ -1295,6 +1282,7 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr 
a_type,
     ssize_t pos = -1;
     ssize_t last_bits = 0;
     ssize_t last_pos = -1;
+    int ret = -1;
 
     if (!size)
         return 0;
@@ -1386,17 +1374,16 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr 
a_type,
     if (!a_mask)
         return -1;
 
-    for (i = last_pos; i < last_pos + need_bits; i++) {
+    for (i = last_pos; i < last_pos + need_bits; i++)
         ignore_value(virBitmapSetBit(a_mask, i));
-        ignore_value(virBitmapClearBit(f_mask, i));
-    }
 
-    if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) {
-        virBitmapFree(a_mask);
-        return -1;
-    }
+    if (virResctrlAllocUpdateMask(alloc, level, type, cache, a_mask) < 0)
+        goto cleanup;
 
-    return 0;
+    ret = 0;
+ cleanup:
+    virBitmapFree(a_mask);
+    return ret;
 }
 
 
@@ -1502,7 +1489,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
                 virResctrlInfoPerLevelPtr i_level = resctrl->levels[level];
                 virResctrlInfoPerTypePtr i_type = i_level->types[type];
 
-                if (virResctrlAllocFindUnused(a_type, i_type, f_type, level, 
type, cache) < 0)
+                if (virResctrlAllocFindUnused(alloc, i_type, f_type, level, 
type, cache) < 0)
                     goto cleanup;
             }
         }
-- 
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to