qemuDomainAttachMemory: Crate hugepage dir if needed

https://bugzilla.redhat.com/show_bug.cgi?id=1455819

It may happen that a domain is started without any huge pages.
However, user might try to attach a DIMM module later. DIMM
backed by huge pages (why would somebody want to mix regular and
huge pages is beyond me). Therefore we have to create the dir if
we haven't done so far.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Michal Privoznik 2017-06-07 14:47:37 +02:00
parent 055c7c48f7
commit 5b24d25062
3 changed files with 27 additions and 6 deletions

View File

@ -2258,6 +2258,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
priv->qemuCaps, vm->def, mem, NULL, true) < 0)
goto cleanup;
if (qemuProcessBuildDestroyHugepagesPath(driver, vm, mem, true) < 0)
goto cleanup;
if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0)
goto cleanup;
teardowndevice = true;

View File

@ -3284,7 +3284,8 @@ qemuProcessReconnectCheckMemAliasOrderMismatch(virDomainObjPtr vm)
static bool
qemuProcessNeedHugepagesPath(virDomainDefPtr def)
qemuProcessNeedHugepagesPath(virDomainDefPtr def,
virDomainMemoryDefPtr mem)
{
const long system_pagesize = virGetSystemPageSizeKB();
size_t i;
@ -3304,13 +3305,20 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def)
return true;
}
if (mem &&
mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
mem->pagesize &&
mem->pagesize != system_pagesize)
return true;
return false;
}
static int
int
qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMemoryDefPtr mem,
bool build)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@ -3320,7 +3328,7 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
int ret = -1;
if (build)
shouldBuild = qemuProcessNeedHugepagesPath(vm->def);
shouldBuild = qemuProcessNeedHugepagesPath(vm->def, mem);
if (!build || shouldBuild) {
for (i = 0; i < cfg->nhugetlbfs; i++) {
@ -3331,6 +3339,11 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
goto cleanup;
if (build) {
if (virFileExists(hugepagePath)) {
ret = 0;
goto cleanup;
}
if (virFileMakePathWithMode(hugepagePath, 0700) < 0) {
virReportSystemError(errno,
_("Unable to create %s"),
@ -3504,7 +3517,7 @@ qemuProcessReconnect(void *opaque)
goto cleanup;
}
if (qemuProcessBuildDestroyHugepagesPath(driver, obj, true) < 0)
if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0)
goto error;
if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps,
@ -5572,7 +5585,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
NULL) < 0)
goto cleanup;
if (qemuProcessBuildDestroyHugepagesPath(driver, vm, true) < 0)
if (qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, true) < 0)
goto cleanup;
/* Ensure no historical cgroup for this VM is lying around bogus
@ -6259,7 +6272,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
goto endjob;
}
qemuProcessBuildDestroyHugepagesPath(driver, vm, false);
qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, false);
vm->def->id = -1;

View File

@ -38,6 +38,11 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver,
virDomainPausedReason reason,
qemuDomainAsyncJob asyncJob);
int qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMemoryDefPtr mem,
bool build);
void qemuProcessAutostartAll(virQEMUDriverPtr driver);
void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);