diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 4f59e5fb07..8de887d1fa 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1576,3 +1576,30 @@ qemuGetMemoryBackingPath(virQEMUDriver *driver, *memPath = g_strdup_printf("%s/%s", domainPath, alias); return 0; } + + +int +qemuHugepageMakeBasedir(virQEMUDriver *driver, + virHugeTLBFS *hugepage) +{ + + g_autofree char *hugepagePath = NULL; + + hugepagePath = qemuGetBaseHugepagePath(driver, hugepage); + + if (!hugepagePath) + return -1; + + if (g_mkdir_with_parents(hugepagePath, 0777) < 0) { + virReportSystemError(errno, + _("unable to create hugepage path %s"), + hugepagePath); + return -1; + } + + if (driver->privileged && + virFileUpdatePerm(hugepage->mnt_dir, 0, S_IXGRP | S_IXOTH) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index c40c452f58..ac911b03c2 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -359,3 +359,6 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver, const virDomainDef *def, const char *alias, char **memPath); + +int qemuHugepageMakeBasedir(virQEMUDriver *driver, + virHugeTLBFS *hugepage); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 40d23b5723..5c75000742 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -837,22 +837,7 @@ qemuStateInitialize(bool privileged, * it, since we can't assume the root mount point has permissions that * will let our spawned QEMU instances use it. */ for (i = 0; i < cfg->nhugetlbfs; i++) { - g_autofree char *hugepagePath = NULL; - - hugepagePath = qemuGetBaseHugepagePath(qemu_driver, &cfg->hugetlbfs[i]); - - if (!hugepagePath) - goto error; - - if (g_mkdir_with_parents(hugepagePath, 0777) < 0) { - virReportSystemError(errno, - _("unable to create hugepage path %s"), - hugepagePath); - goto error; - } - if (privileged && - virFileUpdatePerm(cfg->hugetlbfs[i].mnt_dir, - 0, S_IXGRP | S_IXOTH) < 0) + if (qemuHugepageMakeBasedir(qemu_driver, &cfg->hugetlbfs[i]) < 0) goto error; }