[libvirt] [PATCHv2 11/11] conf: Refactor and rename the function to validate a new resctrl monitor

Wang Huaqiang posted 11 patches 5 weeks ago

[libvirt] [PATCHv2 11/11] conf: Refactor and rename the function to validate a new resctrl monitor

Posted by Wang Huaqiang 5 weeks ago
A new algorithm for detecting the vcpus and monitor type conflicts
between new monitor an existing allocation and monitor groups.

After refactoring, since we are verifying both @vcpus and monitor
type @tag at the same time, the validating function name has been
renamed from virDomainResctrlMonValidateVcpus to
virDomainResctrlValidateMonitor.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
---
 src/conf/domain_conf.c | 62 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 676a2ac..2af81c0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19085,29 +19085,32 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
 }
 
 
-/* Checking if the monitor's vcpus is conflicted with existing allocation
- * and monitors.
+/* Checking if the monitor's vcpus and tag is conflicted with existing
+ * allocation and monitors.
  *
- * Returns 1 if @vcpus equals to @resctrl->vcpus, then the monitor will
- * share the underlying resctrl group with @resctrl->alloc. Returns - 1
- * if any conflict found. Returns 0 if no conflict and @vcpus is not equal
- * to @resctrl->vcpus.
+ * Returns 1 if @monitor->vcpus equals to @resctrl->vcpus, then the monitor
+ * will share the underlying resctrl group with @resctrl->alloc. Returns -1
+ * if any conflict found. Returns 0 if no conflict and @monitor->vcpus is
+ * not equal  to @resctrl->vcpus.
  */
 static int
-virDomainResctrlMonValidateVcpus(virDomainResctrlDefPtr resctrl,
-                                virBitmapPtr vcpus)
+virDomainResctrlValidateMonitor(virDomainResctrlDefPtr resctrl,
+                                virDomainResctrlMonDefPtr monitor)
 {
     size_t i = 0;
     int vcpu = -1;
-    size_t mons_same_alloc_vcpus = 0;
+    bool vcpus_overlap_any = false;
+    bool vcpus_equal_to_resctrl = false;
+    bool vcpus_overlap_no_resctrl = false;
+    bool default_alloc_monitor = virResctrlAllocIsEmpty(resctrl->alloc);
 
-    if (virBitmapIsAllClear(vcpus)) {
+    if (virBitmapIsAllClear(monitor->vcpus)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("vcpus is empty"));
         return -1;
     }
 
-    while ((vcpu = virBitmapNextSetBit(vcpus, vcpu)) >= 0) {
+    while ((vcpu = virBitmapNextSetBit(monitor->vcpus, vcpu)) >= 0) {
         if (!virBitmapIsBitSet(resctrl->vcpus, vcpu)) {
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("Monitor vcpus conflicts with allocation"));
@@ -19115,29 +19118,40 @@ virDomainResctrlMonValidateVcpus(virDomainResctrlDefPtr resctrl,
         }
     }
 
-    if (virBitmapEqual(vcpus, resctrl->vcpus))
-        return 1;
+    vcpus_equal_to_resctrl = virBitmapEqual(monitor->vcpus, resctrl->vcpus);
 
     for (i = 0; i < resctrl->nmonitors; i++) {
-        if (virBitmapEqual(resctrl->vcpus, resctrl->monitors[i]->vcpus)) {
-            mons_same_alloc_vcpus++;
-            continue;
+        if (virBitmapEqual(monitor->vcpus, resctrl->monitors[i]->vcpus)) {
+            if (monitor->tag != resctrl->monitors[i]->tag) {
+                continue;
+            } else {
+                virReportError(VIR_ERR_INVALID_ARG, "%s",
+                               _("Identical vcpus found in same type monitors"));
+                return -1;
+            }
         }
 
-        if (virBitmapOverlaps(vcpus, resctrl->monitors[i]->vcpus)) {
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("Monitor vcpus conflicts with monitors"));
+        if (virBitmapOverlaps(monitor->vcpus, resctrl->monitors[i]->vcpus))
+            vcpus_overlap_any = true;
 
-            return -1;
-        }
+        if (vcpus_equal_to_resctrl ||
+            virBitmapEqual(resctrl->monitors[i]->vcpus, resctrl->vcpus))
+            continue;
+
+        if (virBitmapOverlaps(monitor->vcpus, resctrl->monitors[i]->vcpus))
+            vcpus_overlap_no_resctrl = true;
     }
 
-    if (mons_same_alloc_vcpus > 1) {
+    if (vcpus_overlap_no_resctrl ||
+        (default_alloc_monitor && vcpus_overlap_any)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("Too many monitors have the same vcpu as allocation"));
+                       _("vcpus overlaps in resctrl groups"));
         return -1;
     }
 
+    if (vcpus_equal_to_resctrl && !default_alloc_monitor)
+        return 1;
+
     return 0;
 }
 
@@ -19211,7 +19225,7 @@ virDomainResctrlMonDefParse(virDomainDefPtr def,
         if (virDomainResctrlParseVcpus(def, nodes[i], &domresmon->vcpus) < 0)
             goto cleanup;
 
-        rv = virDomainResctrlMonValidateVcpus(resctrl, domresmon->vcpus);
+        rv = virDomainResctrlValidateMonitor(resctrl, domresmon);
         if (rv < 0)
             goto cleanup;
 
-- 
2.7.4

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