qemu_process: Deduplicate code in qemuProcessNeedHugepagesPath()

The aim of qemuProcessNeedHugepagesPath() is to return whether
guest needs private path inside HugeTLBFS mounts (deducted from
domain definition @def) or whether the memory device that user is
hotplugging in needs the private path (deducted from the @mem
argument). The actual creation of the path is done in the only
caller qemuProcessBuildDestroyMemoryPaths().

The rule for the first case (@def) and the second case (@mem) is
the same (domain has a DIMM device that has HP requested) and is
written twice. Move the logic into a function to deduplicate the
code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2021-02-05 13:34:35 +01:00
parent 0ccc73ef52
commit 4d779874ef

View File

@ -3872,6 +3872,26 @@ qemuProcessReconnectCheckMemAliasOrderMismatch(virDomainObj *vm)
}
static bool
qemuProcessDomainMemoryDefNeedHugepagesPath(const virDomainMemoryDef *mem,
const long system_pagesize)
{
switch (mem->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
return mem->pagesize && mem->pagesize != system_pagesize;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
case VIR_DOMAIN_MEMORY_MODEL_LAST:
/* None of these can be backed by hugepages. */
return false;
}
return false;
}
static bool
qemuProcessNeedHugepagesPath(virDomainDef *def,
virDomainMemoryDef *mem)
@ -3888,16 +3908,12 @@ qemuProcessNeedHugepagesPath(virDomainDef *def,
}
for (i = 0; i < def->nmems; i++) {
if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
def->mems[i]->pagesize &&
def->mems[i]->pagesize != system_pagesize)
if (qemuProcessDomainMemoryDefNeedHugepagesPath(def->mems[i], system_pagesize))
return true;
}
if (mem &&
mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
mem->pagesize &&
mem->pagesize != system_pagesize)
qemuProcessDomainMemoryDefNeedHugepagesPath(mem, system_pagesize))
return true;
return false;