[libvirt] [PATCH 2/8] util: Use default group's mask for unspecified resctrl allocations

Martin Kletzander mkletzan at redhat.com
Wed Jan 31 09:41:40 UTC 2018


Introduce virResctrlAllocCopyMasks() and use that to initially copy the default
group schemata to the allocation before reserving any parts of the cache.  The
reason for this is that when new group is created the schemata will have unknown
data in it.  If there was previously group with the same CLoS ID, it will have
the previous valies, if not it will have all bits set.  And we need to set all
unspecified (in the XML) allocations to the same one as the default group.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1289368

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 src/util/virresctrl.c | 64 ++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index fa7c28e9b45e..2bdca5455783 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1296,23 +1296,8 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
     ssize_t last_bits = 0;
     ssize_t last_pos = -1;
 
-    /* If there is no reservation requested we need to set all bits.  That's due
-     * to weird interface of the resctrl sysfs.  It's also the reason why we
-     * cannot reserve the whole cache in one allocation. */
-    if (!size) {
-        a_mask = virBitmapNew(i_type->bits);
-        if (!a_mask)
-            return -1;
-
-        virBitmapSetAll(a_mask);
-
-        if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) {
-            virBitmapFree(a_mask);
-            return -1;
-        }
-
+    if (!size)
         return 0;
-    }
 
     if (cache >= f_type->nmasks) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -1415,6 +1400,44 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
 }
 
 
+static int
+virResctrlAllocCopyMasks(virResctrlAllocPtr dst,
+                         virResctrlAllocPtr src)
+{
+    unsigned int level = 0;
+
+    for (level = 0; level < src->nlevels; level++) {
+        virResctrlAllocPerLevelPtr s_level = src->levels[level];
+        unsigned int type = 0;
+
+        if (!s_level)
+            continue;
+
+        for (type = 0; type < VIR_CACHE_TYPE_LAST; type++) {
+            virResctrlAllocPerTypePtr s_type = s_level->types[type];
+            virResctrlAllocPerTypePtr d_type = NULL;
+            unsigned int cache = 0;
+
+            if (!s_type)
+                continue;
+
+            d_type = virResctrlAllocGetType(dst, level, type);
+            if (!d_type)
+                return -1;
+
+            for (cache = 0; cache < s_type->nmasks; cache++) {
+                virBitmapPtr mask = s_type->masks[cache];
+
+                if (mask && virResctrlAllocUpdateMask(dst, level, type, cache, mask) < 0)
+                    return -1;
+            }
+        }
+    }
+
+    return 0;
+}
+
+
 /*
  * This function is called when creating an allocation in the system.  What it
  * does is that it gets all the unused bits using virResctrlAllocGetUnused() and
@@ -1428,11 +1451,19 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
     int ret = -1;
     unsigned int level = 0;
     virResctrlAllocPtr alloc_free = NULL;
+    virResctrlAllocPtr alloc_default = NULL;
 
     alloc_free = virResctrlAllocGetUnused(resctrl);
     if (!alloc_free)
         return -1;
 
+    alloc_default = virResctrlAllocGetDefault(resctrl);
+    if (!alloc_default)
+        return -1;
+
+    if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0)
+        return -1;
+
     for (level = 0; level < alloc->nlevels; level++) {
         virResctrlAllocPerLevelPtr a_level = alloc->levels[level];
         virResctrlAllocPerLevelPtr f_level = NULL;
@@ -1480,6 +1511,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
     ret = 0;
  cleanup:
     virObjectUnref(alloc_free);
+    virObjectUnref(alloc_default);
     return ret;
 }
 
-- 
2.16.1




More information about the libvir-list mailing list