render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
0a7476
From c00106d41b74d86ee7357ed62399ea7ffb9cd393 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <c00106d41b74d86ee7357ed62399ea7ffb9cd393@dist-git>
0a7476
From: Bing Niu <bing.niu@intel.com>
0a7476
Date: Mon, 15 Apr 2019 17:32:56 +0200
0a7476
Subject: [PATCH] conf: Factor out vcpus overlapping from
0a7476
 virDomainCachetuneDefParse
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Factor out vcpus overlapping detecting part from
0a7476
virDomainCachetuneDefParse and introduce virDomainResctrlVcpuMatch.
0a7476
Instead of allocating virResctrlAllocPtr by default, allocating
0a7476
virResctrlAllocPtr after confirm vcpus not overlap with existing ones.
0a7476
And virDomainResctrlVcpuMatch can be reused by other resource control
0a7476
technologies. virDomainResctrlVcpuMatch can clarify old vcpus overlap
0a7476
error whether an overlap or a redefinition.
0a7476
0a7476
Signed-off-by: Bing Niu <bing.niu@intel.com>
0a7476
Reviewed-by: John Ferlan <jferlan@redhat.com>
0a7476
(cherry picked from commit e5cc7c0a0258530000aa9fd930c649b525b6f801)
0a7476
0a7476
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1468650
0a7476
0a7476
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
0a7476
Message-Id: <ee62ff896868ef147f9d7e6c67a5c151e0c4695b.1555342313.git.phrdina@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/conf/domain_conf.c | 51 ++++++++++++++++++++++++++++++++----------
0a7476
 1 file changed, 39 insertions(+), 12 deletions(-)
0a7476
0a7476
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
0a7476
index 07d21f8026..fb5adbcd10 100644
0a7476
--- a/src/conf/domain_conf.c
0a7476
+++ b/src/conf/domain_conf.c
0a7476
@@ -19077,6 +19077,31 @@ virDomainResctrlParseVcpus(virDomainDefPtr def,
0a7476
 }
0a7476
 
0a7476
 
0a7476
+static int
0a7476
+virDomainResctrlVcpuMatch(virDomainDefPtr def,
0a7476
+                          virBitmapPtr vcpus,
0a7476
+                          virResctrlAllocPtr *alloc)
0a7476
+{
0a7476
+    ssize_t i = 0;
0a7476
+
0a7476
+    for (i = 0; i < def->nresctrls; i++) {
0a7476
+        /* vcpus group has been created, directly use the existing one.
0a7476
+         * Just updating memory allocation information of that group
0a7476
+         */
0a7476
+        if (virBitmapEqual(def->resctrls[i]->vcpus, vcpus)) {
0a7476
+            *alloc = def->resctrls[i]->alloc;
0a7476
+            break;
0a7476
+        }
0a7476
+        if (virBitmapOverlaps(def->resctrls[i]->vcpus, vcpus)) {
0a7476
+            virReportError(VIR_ERR_XML_ERROR, "%s",
0a7476
+                           _("Overlapping vcpus in resctrls"));
0a7476
+            return -1;
0a7476
+        }
0a7476
+    }
0a7476
+    return 0;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 static int
0a7476
 virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
0a7476
                                 xmlNodePtr node,
0a7476
@@ -19160,7 +19185,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
     xmlNodePtr oldnode = ctxt->node;
0a7476
     xmlNodePtr *nodes = NULL;
0a7476
     virBitmapPtr vcpus = NULL;
0a7476
-    virResctrlAllocPtr alloc = virResctrlAllocNew();
0a7476
+    virResctrlAllocPtr alloc = NULL;
0a7476
     virDomainResctrlDefPtr tmp_resctrl = NULL;
0a7476
     char *tmp = NULL;
0a7476
     char *vcpus_str = NULL;
0a7476
@@ -19171,9 +19196,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
 
0a7476
     ctxt->node = node;
0a7476
 
0a7476
-    if (!alloc)
0a7476
-        goto cleanup;
0a7476
-
0a7476
     if (VIR_ALLOC(tmp_resctrl) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
@@ -19191,6 +19213,19 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
         goto cleanup;
0a7476
     }
0a7476
 
0a7476
+    if (virDomainResctrlVcpuMatch(def, vcpus, &alloc) < 0)
0a7476
+        goto cleanup;
0a7476
+
0a7476
+    if (!alloc) {
0a7476
+        alloc = virResctrlAllocNew();
0a7476
+        if (!alloc)
0a7476
+            goto cleanup;
0a7476
+    } else {
0a7476
+        virReportError(VIR_ERR_XML_ERROR, "%s",
0a7476
+                       _("Identical vcpus in cachetunes found"));
0a7476
+        goto cleanup;
0a7476
+    }
0a7476
+
0a7476
     for (i = 0; i < n; i++) {
0a7476
         if (virDomainCachetuneDefParseCache(ctxt, nodes[i], alloc) < 0)
0a7476
             goto cleanup;
0a7476
@@ -19201,14 +19236,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
         goto cleanup;
0a7476
     }
0a7476
 
0a7476
-    for (i = 0; i < def->nresctrls; i++) {
0a7476
-        if (virBitmapOverlaps(def->resctrls[i]->vcpus, vcpus)) {
0a7476
-            virReportError(VIR_ERR_XML_ERROR, "%s",
0a7476
-                           _("Overlapping vcpus in cachetunes"));
0a7476
-            goto cleanup;
0a7476
-        }
0a7476
-    }
0a7476
-
0a7476
     /* We need to format it back because we need to be consistent in the naming
0a7476
      * even when users specify some "sub-optimal" string there. */
0a7476
     VIR_FREE(vcpus_str);
0a7476
-- 
0a7476
2.21.0
0a7476