diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index ec540f8c27..f5b51d20ad 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1023,14 +1023,21 @@ - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 50d9230239..cfec86a24d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19711,10 +19711,14 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, { VIR_XPATH_NODE_AUTORESTORE(ctxt); virDomainResctrlDefPtr resctrl = NULL; + virDomainResctrlDefPtr newresctrl = NULL; g_autoptr(virBitmap) vcpus = NULL; g_autofree xmlNodePtr *nodes = NULL; g_autoptr(virResctrlAlloc) alloc = NULL; ssize_t i = 0; + size_t nmons = 0; + size_t ret = -1; + int n; ctxt->node = node; @@ -19741,29 +19745,44 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, return -1; } + /* First, parse element if any element exists */ for (i = 0; i < n; i++) { if (virDomainMemorytuneDefParseMemory(ctxt, nodes[i], alloc) < 0) return -1; } - if (n == 0) - return 0; - /* * If this is a new allocation, format ID and append to resctrl, otherwise * just update the existing alloc information, which is done in above * virDomainMemorytuneDefParseMemory */ if (!resctrl) { - if (!(resctrl = virDomainResctrlNew(node, alloc, vcpus, flags))) + if (!(newresctrl = virDomainResctrlNew(node, alloc, vcpus, flags))) return -1; - if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, resctrl) < 0) { - virDomainResctrlDefFree(resctrl); - return -1; - } + resctrl = newresctrl; } - return 0; + /* Next, parse element */ + nmons = resctrl->nmonitors; + if (virDomainResctrlMonDefParse(def, ctxt, node, + VIR_RESCTRL_MONITOR_TYPE_MEMBW, + resctrl) < 0) + goto cleanup; + + nmons = resctrl->nmonitors - nmons; + /* Now @nmons contains the new element number found in current + * element, and @n holds the number of new element, + * only append the new @newresctrl object to domain if any of them is + * not zero. */ + if (newresctrl && (nmons || n)) { + if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, newresctrl) < 0) + goto cleanup; + } + + ret = 0; + cleanup: + virDomainResctrlDefFree(newresctrl); + return ret; } @@ -27630,12 +27649,19 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, { g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); g_autofree char *vcpus = NULL; + size_t i = 0; if (virResctrlAllocForeachMemory(resctrl->alloc, virDomainMemorytuneDefFormatHelper, &childrenBuf) < 0) return -1; + for (i = 0; i< resctrl->nmonitors; i++) { + if (virDomainResctrlMonDefFormatHelper(resctrl->monitors[i], + VIR_RESCTRL_MONITOR_TYPE_MEMBW, + &childrenBuf) < 0) + return -1; + } if (!virBufferUse(&childrenBuf)) return 0; diff --git a/tests/genericxml2xmlindata/memorytune.xml b/tests/genericxml2xmlindata/memorytune.xml index 187409e525..6fdf5341f1 100644 --- a/tests/genericxml2xmlindata/memorytune.xml +++ b/tests/genericxml2xmlindata/memorytune.xml @@ -10,12 +10,17 @@ + + + + + hvm diff --git a/tests/genericxml2xmloutdata/memorytune.xml b/tests/genericxml2xmloutdata/memorytune.xml new file mode 100644 index 0000000000..f996435a6e --- /dev/null +++ b/tests/genericxml2xmloutdata/memorytune.xml @@ -0,0 +1,42 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 4 + + + + + + + + + + + + + + + + + + + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index e5d2bca947..501bcdb0a1 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -173,7 +173,7 @@ mymain(void) TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_FULL("cachetune-colliding-monitor", false, true, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); - DO_TEST("memorytune"); + DO_TEST_DIFFERENT("memorytune"); DO_TEST_FULL("memorytune-colliding-allocs", false, true, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); DO_TEST_FULL("memorytune-colliding-cachetune", false, true,