提交 8b277ae2 编写于 作者: M Michal Privoznik

qemuBuildMemoryBackendStr: Pass virDomainMemoryDefPtr

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 cce282fe
...@@ -3177,11 +3177,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, ...@@ -3177,11 +3177,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
/** /**
* qemuBuildMemoryBackendStr: * qemuBuildMemoryBackendStr:
* @size: size of the memory device in kibibytes * @mem: memory definition object
* @pagesize: size of the requested memory page in KiB, 0 for default
* @guestNode: NUMA node in the guest that the memory object will be attached
* to, or -1 if NUMA is not used in the guest
* @hostNodes: map of host nodes to alloc the memory in, NULL for default
* @autoNodeset: fallback nodeset in case of automatic numa placement * @autoNodeset: fallback nodeset in case of automatic numa placement
* @def: domain definition object * @def: domain definition object
* @qemuCaps: qemu capabilities object * @qemuCaps: qemu capabilities object
...@@ -3199,10 +3195,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, ...@@ -3199,10 +3195,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
* -1 in case of an error. * -1 in case of an error.
*/ */
int int
qemuBuildMemoryBackendStr(unsigned long long size, qemuBuildMemoryBackendStr(virDomainMemoryDefPtr mem,
unsigned long long pagesize,
int guestNode,
virBitmapPtr userNodeset,
virBitmapPtr autoNodeset, virBitmapPtr autoNodeset,
virDomainDefPtr def, virDomainDefPtr def,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
...@@ -3221,26 +3214,27 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -3221,26 +3214,27 @@ qemuBuildMemoryBackendStr(unsigned long long size,
virBitmapPtr nodemask = NULL; virBitmapPtr nodemask = NULL;
int ret = -1; int ret = -1;
virJSONValuePtr props = NULL; virJSONValuePtr props = NULL;
bool nodeSpecified = virDomainNumatuneNodeSpecified(def->numa, guestNode); bool nodeSpecified = virDomainNumatuneNodeSpecified(def->numa, mem->targetNode);
unsigned long long pagesize = mem->pagesize;
bool needHugepage = !!pagesize; bool needHugepage = !!pagesize;
*backendProps = NULL; *backendProps = NULL;
*backendType = NULL; *backendType = NULL;
if (guestNode >= 0) { if (mem->targetNode >= 0) {
/* memory devices could provide a invalid guest node */ /* memory devices could provide a invalid guest node */
if (guestNode >= virDomainNumaGetNodeCount(def->numa)) { if (mem->targetNode >= virDomainNumaGetNodeCount(def->numa)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("can't add memory backend for guest node '%d' as " _("can't add memory backend for guest node '%d' as "
"the guest has only '%zu' NUMA nodes configured"), "the guest has only '%zu' NUMA nodes configured"),
guestNode, virDomainNumaGetNodeCount(def->numa)); mem->targetNode, virDomainNumaGetNodeCount(def->numa));
return -1; return -1;
} }
memAccess = virDomainNumaGetNodeMemoryAccessMode(def->numa, guestNode); memAccess = virDomainNumaGetNodeMemoryAccessMode(def->numa, mem->targetNode);
} }
if (virDomainNumatuneGetMode(def->numa, guestNode, &mode) < 0 && if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 &&
virDomainNumatuneGetMode(def->numa, -1, &mode) < 0) virDomainNumatuneGetMode(def->numa, -1, &mode) < 0)
mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
...@@ -3257,10 +3251,10 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -3257,10 +3251,10 @@ qemuBuildMemoryBackendStr(unsigned long long size,
} }
/* just find the master hugepage in case we don't use NUMA */ /* just find the master hugepage in case we don't use NUMA */
if (guestNode < 0) if (mem->targetNode < 0)
continue; continue;
if (virBitmapGetBit(hugepage->nodemask, guestNode, if (virBitmapGetBit(hugepage->nodemask, mem->targetNode,
&thisHugepage) < 0) { &thisHugepage) < 0) {
/* Ignore this error. It's not an error after all. Well, /* Ignore this error. It's not an error after all. Well,
* the nodemask for this <page/> can contain lower NUMA * the nodemask for this <page/> can contain lower NUMA
...@@ -3349,14 +3343,14 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -3349,14 +3343,14 @@ qemuBuildMemoryBackendStr(unsigned long long size,
*backendType = "memory-backend-ram"; *backendType = "memory-backend-ram";
} }
if (virJSONValueObjectAdd(props, "U:size", size * 1024, NULL) < 0) if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0)
goto cleanup; goto cleanup;
if (userNodeset) { if (mem->sourceNodes) {
nodemask = userNodeset; nodemask = mem->sourceNodes;
} else { } else {
if (virDomainNumatuneMaybeGetNodeset(def->numa, autoNodeset, if (virDomainNumatuneMaybeGetNodeset(def->numa, autoNodeset,
&nodemask, guestNode) < 0) &nodemask, mem->targetNode) < 0)
goto cleanup; goto cleanup;
} }
...@@ -3371,7 +3365,7 @@ qemuBuildMemoryBackendStr(unsigned long long size, ...@@ -3371,7 +3365,7 @@ qemuBuildMemoryBackendStr(unsigned long long size,
} }
/* If none of the following is requested... */ /* If none of the following is requested... */
if (!needHugepage && !userNodeset && !nodeSpecified && if (!needHugepage && !mem->sourceNodes && !nodeSpecified &&
memAccess == VIR_DOMAIN_MEMORY_ACCESS_DEFAULT && memAccess == VIR_DOMAIN_MEMORY_ACCESS_DEFAULT &&
def->mem.source != VIR_DOMAIN_MEMORY_SOURCE_FILE && !force) { def->mem.source != VIR_DOMAIN_MEMORY_SOURCE_FILE && !force) {
/* report back that using the new backend is not necessary /* report back that using the new backend is not necessary
...@@ -3420,17 +3414,19 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, ...@@ -3420,17 +3414,19 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
const char *backendType; const char *backendType;
int ret = -1; int ret = -1;
int rc; int rc;
virDomainMemoryDef mem = { 0 };
unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa, unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa,
cell); cell);
*backendStr = NULL; *backendStr = NULL;
mem.size = memsize;
mem.targetNode = cell;
if (virAsprintf(&alias, "ram-node%zu", cell) < 0) if (virAsprintf(&alias, "ram-node%zu", cell) < 0)
goto cleanup; goto cleanup;
if ((rc = qemuBuildMemoryBackendStr(memsize, 0, cell, NULL, auto_nodeset, if ((rc = qemuBuildMemoryBackendStr(&mem, auto_nodeset, def, qemuCaps,
def, qemuCaps, cfg, &backendType, cfg, &backendType, &props, false)) < 0)
&props, false)) < 0)
goto cleanup; goto cleanup;
if (!(*backendStr = virQEMUBuildObjectCommandlineFromJSON(backendType, if (!(*backendStr = virQEMUBuildObjectCommandlineFromJSON(backendType,
...@@ -3469,8 +3465,7 @@ qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem, ...@@ -3469,8 +3465,7 @@ qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem,
if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0) if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0)
goto cleanup; goto cleanup;
if (qemuBuildMemoryBackendStr(mem->size, mem->pagesize, if (qemuBuildMemoryBackendStr(mem, auto_nodeset,
mem->targetNode, mem->sourceNodes, auto_nodeset,
def, qemuCaps, cfg, def, qemuCaps, cfg,
&backendType, &props, true) < 0) &backendType, &props, true) < 0)
goto cleanup; goto cleanup;
......
...@@ -124,10 +124,7 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef, ...@@ -124,10 +124,7 @@ char *qemuBuildControllerDevStr(const virDomainDef *domainDef,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
int *nusbcontroller); int *nusbcontroller);
int qemuBuildMemoryBackendStr(unsigned long long size, int qemuBuildMemoryBackendStr(virDomainMemoryDefPtr mem,
unsigned long long pagesize,
int guestNode,
virBitmapPtr userNodeset,
virBitmapPtr autoNodeset, virBitmapPtr autoNodeset,
virDomainDefPtr def, virDomainDefPtr def,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
......
...@@ -2240,10 +2240,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, ...@@ -2240,10 +2240,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildMemoryDeviceStr(mem))) if (!(devstr = qemuBuildMemoryDeviceStr(mem)))
goto cleanup; goto cleanup;
if (qemuBuildMemoryBackendStr(mem->size, mem->pagesize, if (qemuBuildMemoryBackendStr(mem, NULL, vm->def, priv->qemuCaps,
mem->targetNode, mem->sourceNodes, NULL, cfg, &backendType, &props, true) < 0)
vm->def, priv->qemuCaps, cfg,
&backendType, &props, true) < 0)
goto cleanup; goto cleanup;
if (virDomainMemoryInsert(vm->def, mem) < 0) { if (virDomainMemoryInsert(vm->def, mem) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册