]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Introduce virResctrlAllocSetMemoryBandwidth
authorBing Niu <bing.niu@intel.com>
Mon, 30 Jul 2018 03:12:34 +0000 (11:12 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 13 Aug 2018 18:19:41 +0000 (14:19 -0400)
Introduce an API to allow setting of the MBA from domain XML.

Signed-off-by: Bing Niu <bing.niu@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/libvirt_private.syms
src/util/virresctrl.c
src/util/virresctrl.h

index 971b12c383d67a49a7648fe2be5186fb4e220595..ca4a192a4a22266064977ab15a28714a5b0ab876 100644 (file)
@@ -2656,6 +2656,7 @@ virResctrlAllocNew;
 virResctrlAllocRemove;
 virResctrlAllocSetCacheSize;
 virResctrlAllocSetID;
+virResctrlAllocSetMemoryBandwidth;
 virResctrlInfoGetCache;
 virResctrlInfoNew;
 
index 45fc6fc84791807bede18aa5d0d09960b039f357..adf36a7c0a728e949e41baee63bb1afdfa987856 100644 (file)
@@ -965,6 +965,54 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
 }
 
 
+/* virResctrlAllocSetMemoryBandwidth
+ * @alloc: Pointer to an active allocation
+ * @id: node id of MBA to be set
+ * @memory_bandwidth: new memory bandwidth value
+ *
+ * Set the @memory_bandwidth for the node @id entry in the @alloc.
+ *
+ * Returns 0 on success, -1 on failure with error message set.
+ */
+int
+virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
+                                  unsigned int id,
+                                  unsigned int memory_bandwidth)
+{
+    virResctrlAllocMemBWPtr mem_bw = alloc->mem_bw;
+
+    if (memory_bandwidth > 100) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Memory Bandwidth value exceeding 100 is invalid."));
+        return -1;
+    }
+
+    if (!mem_bw) {
+        if (VIR_ALLOC(mem_bw) < 0)
+            return -1;
+        alloc->mem_bw = mem_bw;
+    }
+
+    if (mem_bw->nbandwidths <= id &&
+        VIR_EXPAND_N(mem_bw->bandwidths, mem_bw->nbandwidths,
+                     id - mem_bw->nbandwidths + 1) < 0)
+        return -1;
+
+    if (mem_bw->bandwidths[id]) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Memory Bandwidth already defined for node %u"),
+                       id);
+        return -1;
+    }
+
+    if (VIR_ALLOC(mem_bw->bandwidths[id]) < 0)
+        return -1;
+
+    *(mem_bw->bandwidths[id]) = memory_bandwidth;
+    return 0;
+}
+
+
 /* virResctrlAllocForeachMemory
  * @alloc: Pointer to an active allocation
  * @cb: Callback function
index 5ea5b27d3bccf3b5840c60d0fa560324ee997f9f..8d62517aa175338fbb5d68334bc13fb332bc730d 100644 (file)
@@ -95,6 +95,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
                             virResctrlAllocForeachCacheCallback cb,
                             void *opaque);
 
+int
+virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
+                                  unsigned int id,
+                                  unsigned int memory_bandwidth);
+
 int
 virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl,
                              virResctrlAllocForeachMemoryCallback cb,