From 3d24834d3cccccfe8e482ae3c86c10fa990d560f Mon Sep 17 00:00:00 2001
From: lutong <lutong14@huawei.com>
Date: Tue, 12 Aug 2025 15:26:52 +0800
Subject: [PATCH 6/6] conf: add support for memorytune XML processing for MB
priority
src/conf/domain_conf.c | 8 +++++++
src/conf/schemas/domaincommon.rng | 5 ++++
src/util/virresctrl.c | 40 +++++++++++++++++++++----------
3 files changed, 40 insertions(+), 13 deletions(-)
@@ -18238,6 +18238,7 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt,
unsigned int id;
unsigned int bandwidth;
unsigned int hard_limit = UINT_MAX;
+ unsigned int priority = UINT_MAX;
ctxt->node = node;
@@ -18258,6 +18259,13 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt,
virResctrlAllocSetMemoryBandwidth(alloc, VIR_MEMORY_TYPE_HARDLIMIT, id, hard_limit) < 0)
return -1;
+ if (virXMLPropUIntDefault(node, "priority", 10, 0, &priority, UINT_MAX) < 0)
+ return -1;
+
+ if (priority != UINT_MAX &&
+ virResctrlAllocSetMemoryBandwidth(alloc, VIR_MEMORY_TYPE_PRIORITY, id, priority) < 0)
+ return -1;
+
return 0;
}
@@ -1190,6 +1190,11 @@
<ref name="unsignedInt"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="priority">
+ <ref name="unsignedInt"/>
+ </attribute>
+ </optional>
</element>
<element name="monitor">
<attribute name="vcpus">
@@ -1400,20 +1400,34 @@ virResctrlAllocSetMemoryBandwidth(virResctrlAlloc *alloc,
virResctrlAllocMemBW *mem_bw = alloc->mem_bw;
virResctrlAllocMemPerType *a_type = NULL;
- if (type == VIR_MEMORY_TYPE_HARDLIMIT) {
- if (value > 1) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("Memory Bandwidth hard limit value just support 0 or 1."));
- return -1;
- }
- }
-
- if (type == VIR_MEMORY_TYPE_BANDWIDTH) {
- if (value > 100) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("Memory Bandwidth value exceeding 100 is invalid."));
+ switch (type) {
+ case VIR_MEMORY_TYPE_BANDWIDTH:
+ if (value > 100) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Memory Bandwidth value exceeding 100 is invalid."));
+ return -1;
+ }
+ break;
+ case VIR_MEMORY_TYPE_HARDLIMIT:
+ if (value > 1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Memory Bandwidth hard limit value just support 0 or 1."));
+ return -1;
+ }
+ break;
+ case VIR_MEMORY_TYPE_PRIORITY:
+ if (value > 7) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Memory Bandwidth priority value just support 0-7."));
+ return -1;
+ }
+ break;
+ case VIR_MEMORY_TYPE_MIN_BANDWIDTH:
+ case VIR_MEMORY_TYPE_LAST:
+ default:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Invalid memory bandwidth type."));
return -1;
- }
}
if (!mem_bw) {
--
2.33.0