render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From bd5cb5d5dfff79f092c843116876837d50b60250 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <bd5cb5d5dfff79f092c843116876837d50b60250@dist-git>
0a7476
From: Bing Niu <bing.niu@intel.com>
0a7476
Date: Mon, 15 Apr 2019 17:32:46 +0200
0a7476
Subject: [PATCH] util: Refactor virResctrlAllocFormat of virresctrl
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Refactor virResctrlAllocFormat so that it is easy to support other
0a7476
resource allocation technologies.
0a7476
0a7476
Signed-off-by: Bing Niu <bing.niu@intel.com>
0a7476
Reviewed-by: John Ferlan <jferlan@redhat.com>
0a7476
(cherry picked from commit 65bae2f18c27c4a30a8ea675b7c3767cdfbe4c70)
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: <18dd3a283af009213d718a81f66fe625f6335ece.1555342313.git.phrdina@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/util/virresctrl.c | 41 ++++++++++++++++++++++++++---------------
0a7476
 1 file changed, 26 insertions(+), 15 deletions(-)
0a7476
0a7476
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
0a7476
index 313f964f21..a38c9261b6 100644
0a7476
--- a/src/util/virresctrl.c
0a7476
+++ b/src/util/virresctrl.c
0a7476
@@ -849,17 +849,14 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc)
0a7476
 }
0a7476
 
0a7476
 
0a7476
-char *
0a7476
-virResctrlAllocFormat(virResctrlAllocPtr alloc)
0a7476
+static int
0a7476
+virResctrlAllocFormatCache(virResctrlAllocPtr alloc,
0a7476
+                           virBufferPtr buf)
0a7476
 {
0a7476
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
0a7476
     unsigned int level = 0;
0a7476
     unsigned int type = 0;
0a7476
     unsigned int cache = 0;
0a7476
 
0a7476
-    if (!alloc)
0a7476
-        return NULL;
0a7476
-
0a7476
     for (level = 0; level < alloc->nlevels; level++) {
0a7476
         virResctrlAllocPerLevelPtr a_level = alloc->levels[level];
0a7476
 
0a7476
@@ -872,7 +869,7 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc)
0a7476
             if (!a_type)
0a7476
                 continue;
0a7476
 
0a7476
-            virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToString(type));
0a7476
+            virBufferAsprintf(buf, "L%u%s:", level, virResctrlTypeToString(type));
0a7476
 
0a7476
             for (cache = 0; cache < a_type->nmasks; cache++) {
0a7476
                 virBitmapPtr mask = a_type->masks[cache];
0a7476
@@ -882,21 +879,35 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc)
0a7476
                     continue;
0a7476
 
0a7476
                 mask_str = virBitmapToString(mask, false, true);
0a7476
-                if (!mask_str) {
0a7476
-                    virBufferFreeAndReset(&buf;;
0a7476
-                    return NULL;
0a7476
-                }
0a7476
+                if (!mask_str)
0a7476
+                    return -1;
0a7476
 
0a7476
-                virBufferAsprintf(&buf, "%u=%s;", cache, mask_str);
0a7476
+                virBufferAsprintf(buf, "%u=%s;", cache, mask_str);
0a7476
                 VIR_FREE(mask_str);
0a7476
             }
0a7476
 
0a7476
-            virBufferTrim(&buf, ";", 1);
0a7476
-            virBufferAddChar(&buf, '\n');
0a7476
+            virBufferTrim(buf, ";", 1);
0a7476
+            virBufferAddChar(buf, '\n');
0a7476
         }
0a7476
     }
0a7476
 
0a7476
-    virBufferCheckError(&buf;;
0a7476
+    return virBufferCheckError(buf);
0a7476
+}
0a7476
+
0a7476
+
0a7476
+char *
0a7476
+virResctrlAllocFormat(virResctrlAllocPtr alloc)
0a7476
+{
0a7476
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
0a7476
+
0a7476
+    if (!alloc)
0a7476
+        return NULL;
0a7476
+
0a7476
+    if (virResctrlAllocFormatCache(alloc, &buf) < 0) {
0a7476
+        virBufferFreeAndReset(&buf;;
0a7476
+        return NULL;
0a7476
+    }
0a7476
+
0a7476
     return virBufferContentAndReset(&buf;;
0a7476
 }
0a7476
 
0a7476
-- 
0a7476
2.21.0
0a7476