提交 8795adf7 编写于 作者: P Peter Krempa

qemu: command: Refactor NUMA backend object formatting to use JSON objs

With the new JSON to argv formatter we are now able to represent the
memory backend definitions in the JSON object format that is reusable
for monitor use (hotplug) and then convert it into the shell string.
This will avoid having two separate instances of the same code that
would create the different formats.

Previous refactors now allow to make this step without changes to the
test suite.
上级 b50b4ef3
...@@ -4533,12 +4533,10 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -4533,12 +4533,10 @@ qemuBuildMemoryBackendStr(unsigned long long size,
virDomainDefPtr def, virDomainDefPtr def,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virQEMUDriverConfigPtr cfg, virQEMUDriverConfigPtr cfg,
const char *aliasPrefix, const char **backendType,
size_t id, virJSONValuePtr *backendProps,
char **backendStr,
bool force) bool force)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainHugePagePtr master_hugepage = NULL; virDomainHugePagePtr master_hugepage = NULL;
virDomainHugePagePtr hugepage = NULL; virDomainHugePagePtr hugepage = NULL;
virDomainNumatuneMemMode mode; virDomainNumatuneMemMode mode;
...@@ -4546,11 +4544,15 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -4546,11 +4544,15 @@ qemuBuildMemoryBackendStr(unsigned long long size,
virMemAccess memAccess = def->cpu->cells[guestNode].memAccess; virMemAccess memAccess = def->cpu->cells[guestNode].memAccess;
size_t i; size_t i;
char *mem_path = NULL; char *mem_path = NULL;
char *nodemask = NULL; virBitmapPtr nodemask = NULL;
char *tmpmask = NULL, *next = NULL;
int ret = -1; int ret = -1;
virJSONValuePtr props = NULL;
*backendStr = NULL; *backendProps = NULL;
*backendType = NULL;
if (!(props = virJSONValueNewObject()))
return -1;
mode = virDomainNumatuneGetMode(def->numatune, guestNode); mode = virDomainNumatuneGetMode(def->numatune, guestNode);
...@@ -4623,16 +4625,23 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -4623,16 +4625,23 @@ qemuBuildMemoryBackendStr(unsigned long long size,
if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i]))) if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
goto cleanup; goto cleanup;
virBufferAsprintf(&buf, "memory-backend-file,id=%s%zu", aliasPrefix, id); *backendType = "memory-backend-file";
virBufferAsprintf(&buf, ",prealloc=yes,mem-path=%s", mem_path);
if (virJSONValueObjectAdd(props,
"b:prealloc", true,
"s:mem-path", mem_path,
NULL) < 0)
goto cleanup;
switch (memAccess) { switch (memAccess) {
case VIR_MEM_ACCESS_SHARED: case VIR_MEM_ACCESS_SHARED:
virBufferAddLit(&buf, ",share=yes"); if (virJSONValueObjectAdd(props, "b:share", true, NULL) < 0)
goto cleanup;
break; break;
case VIR_MEM_ACCESS_PRIVATE: case VIR_MEM_ACCESS_PRIVATE:
virBufferAddLit(&buf, ",share=no"); if (virJSONValueObjectAdd(props, "b:share", false, NULL) < 0)
goto cleanup;
break; break;
case VIR_MEM_ACCESS_DEFAULT: case VIR_MEM_ACCESS_DEFAULT:
...@@ -4647,43 +4656,30 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -4647,43 +4656,30 @@ qemuBuildMemoryBackendStr(unsigned long long size,
goto cleanup; goto cleanup;
} }
virBufferAsprintf(&buf, "memory-backend-ram,id=%s%zu", aliasPrefix, id); *backendType = "memory-backend-ram";
} }
virBufferAsprintf(&buf, ",size=%llu", size * 1024); if (virJSONValueObjectAdd(props, "U:size", size * 1024, NULL) < 0)
goto cleanup;
if (userNodeset) { if (userNodeset) {
if (!(nodemask = virBitmapFormat(userNodeset))) nodemask = userNodeset;
goto cleanup;
} else { } else {
if (virDomainNumatuneMaybeFormatNodeset(def->numatune, autoNodeset, if (virDomainNumatuneMaybeGetNodeset(def->numatune, autoNodeset,
&nodemask, guestNode) < 0) &nodemask, guestNode) < 0)
goto cleanup; goto cleanup;
} }
if (nodemask) { if (nodemask) {
if (strchr(nodemask, ',') && if (virJSONValueObjectAdd(props,
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NUMA)) { "m:host-nodes", nodemask,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", "S:policy", qemuNumaPolicyTypeToString(mode),
_("disjoint NUMA node ranges are not supported " NULL) < 0)
"with this QEMU"));
goto cleanup; goto cleanup;
}
for (tmpmask = nodemask; tmpmask; tmpmask = next) {
if ((next = strchr(tmpmask, ',')))
*(next++) = '\0';
virBufferAddLit(&buf, ",host-nodes=");
virBufferAdd(&buf, tmpmask, -1);
}
virBufferAsprintf(&buf, ",policy=%s", qemuNumaPolicyTypeToString(mode));
} }
if (virBufferCheckError(&buf) < 0) *backendProps = props;
goto cleanup; props = NULL;
*backendStr = virBufferContentAndReset(&buf);
if (!hugepage) { if (!hugepage) {
if ((nodemask || force) && if ((nodemask || force) &&
...@@ -4705,8 +4701,7 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -4705,8 +4701,7 @@ qemuBuildMemoryBackendStr(unsigned long long size,
ret = 0; ret = 0;
cleanup: cleanup:
virBufferFreeAndReset(&buf); virJSONValueFree(props);
VIR_FREE(nodemask);
VIR_FREE(mem_path); VIR_FREE(mem_path);
return ret; return ret;
...@@ -4721,19 +4716,39 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, ...@@ -4721,19 +4716,39 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
virBitmapPtr auto_nodeset, virBitmapPtr auto_nodeset,
char **backendStr) char **backendStr)
{ {
int ret; virJSONValuePtr props = NULL;
char *alias = NULL;
const char *backendType;
int ret = -1;
int rc;
ret = qemuBuildMemoryBackendStr(def->cpu->cells[cell].mem, 0, cell, *backendStr = NULL;
NULL, auto_nodeset,
def, qemuCaps, cfg,
"ram-node", cell,
backendStr, false);
if (ret == 1) { if (virAsprintf(&alias, "ram-node%zu", cell) < 0)
VIR_FREE(*backendStr); goto cleanup;
return 0;
if ((rc = qemuBuildMemoryBackendStr(def->cpu->cells[cell].mem, 0, cell,
NULL, auto_nodeset,
def, qemuCaps, cfg,
&backendType, &props, false)) < 0)
goto cleanup;
if (rc == 1) {
ret = 0;
goto cleanup;
} }
if (!(*backendStr = qemuBuildObjectCommandlineFromJSON(backendType,
alias,
props)))
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(alias);
virJSONValueFree(props);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册