提交 3fb08198 编写于 作者: P Peter Krempa

qemu: Make memory alignment helper more universal

Extract the size determination into a separate function and reuse it
across the memory device alignment functions. Since later we will need
to decide the alignment size according to architecture let's pass def to
the functions.
上级 1891cad5
...@@ -3361,30 +3361,39 @@ qemuDomainAgentAvailable(virDomainObjPtr vm, ...@@ -3361,30 +3361,39 @@ qemuDomainAgentAvailable(virDomainObjPtr vm,
} }
static unsigned long long
qemuDomainGetMemorySizeAlignment(virDomainDefPtr def ATTRIBUTE_UNUSED)
{
/* Align memory size. QEMU requires rounding to next 4KiB block.
* We'll take the "traditional" path and round it to 1MiB*/
return 1024;
}
int int
qemuDomainAlignMemorySizes(virDomainDefPtr def) qemuDomainAlignMemorySizes(virDomainDefPtr def)
{ {
unsigned long long mem; unsigned long long mem;
unsigned long long align = qemuDomainGetMemorySizeAlignment(def);
size_t ncells = virDomainNumaGetNodeCount(def->numa); size_t ncells = virDomainNumaGetNodeCount(def->numa);
size_t i; size_t i;
/* align NUMA cell sizes if relevant */ /* align NUMA cell sizes if relevant */
for (i = 0; i < ncells; i++) { for (i = 0; i < ncells; i++) {
mem = virDomainNumaGetNodeMemorySize(def->numa, i); mem = virDomainNumaGetNodeMemorySize(def->numa, i);
virDomainNumaSetNodeMemorySize(def->numa, i, VIR_ROUND_UP(mem, 1024)); virDomainNumaSetNodeMemorySize(def->numa, i, VIR_ROUND_UP(mem, align));
} }
/* align initial memory size */ /* align initial memory size */
mem = virDomainDefGetMemoryInitial(def); mem = virDomainDefGetMemoryInitial(def);
virDomainDefSetMemoryInitial(def, VIR_ROUND_UP(mem, 1024)); virDomainDefSetMemoryInitial(def, VIR_ROUND_UP(mem, align));
/* Align maximum memory size. QEMU requires rounding to next 4KiB block. def->mem.max_memory = VIR_ROUND_UP(def->mem.max_memory, align);
* We'll take the "traditional" path and round it to 1MiB*/
def->mem.max_memory = VIR_ROUND_UP(def->mem.max_memory, 1024);
/* Align memory module sizes */ /* Align memory module sizes */
for (i = 0; i < def->nmems; i++) for (i = 0; i < def->nmems; i++)
qemuDomainMemoryDeviceAlignSize(def->mems[i]); def->mems[i]->size = VIR_ROUND_UP(def->mems[i]->size, align);
return 0; return 0;
} }
...@@ -3399,9 +3408,10 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def) ...@@ -3399,9 +3408,10 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def)
* size so this should be safe). * size so this should be safe).
*/ */
void void
qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem) qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
virDomainMemoryDefPtr mem)
{ {
mem->size = VIR_ROUND_UP(mem->size, 1024); mem->size = VIR_ROUND_UP(mem->size, qemuDomainGetMemorySizeAlignment(def));
} }
......
...@@ -469,7 +469,8 @@ bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only) ...@@ -469,7 +469,8 @@ bool qemuDomainHasBlockjob(virDomainObjPtr vm, bool copy_only)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int qemuDomainAlignMemorySizes(virDomainDefPtr def); int qemuDomainAlignMemorySizes(virDomainDefPtr def);
void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem); void qemuDomainMemoryDeviceAlignSize(virDomainDefPtr def,
virDomainMemoryDefPtr mem);
virDomainChrSourceDefPtr qemuFindAgentConfig(virDomainDefPtr def); virDomainChrSourceDefPtr qemuFindAgentConfig(virDomainDefPtr def);
......
...@@ -1802,7 +1802,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, ...@@ -1802,7 +1802,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps))) if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps)))
goto cleanup; goto cleanup;
qemuDomainMemoryDeviceAlignSize(mem); qemuDomainMemoryDeviceAlignSize(vm->def, mem);
if (qemuBuildMemoryBackendStr(mem->size, mem->pagesize, if (qemuBuildMemoryBackendStr(mem->size, mem->pagesize,
mem->targetNode, mem->sourceNodes, NULL, mem->targetNode, mem->sourceNodes, NULL,
...@@ -4273,7 +4273,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver, ...@@ -4273,7 +4273,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
return -1; return -1;
} }
qemuDomainMemoryDeviceAlignSize(memdef); qemuDomainMemoryDeviceAlignSize(vm->def, memdef);
if ((idx = virDomainMemoryFindByDef(vm->def, memdef)) < 0) { if ((idx = virDomainMemoryFindByDef(vm->def, memdef)) < 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册