提交 ad8ab88c 编写于 作者: M Martin Kletzander

qemu: Extract -mem-path building into its own function

That function is called qemuBuildMemPathStr() and will be used in
other places in the future.  The change in the test suite is proper due
to the fact that -mem-prealloc makes only sense with -mem-path (from
qemu documentation -- html/qemu-doc.html).
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 5f12b844
...@@ -7996,6 +7996,71 @@ qemuBuildSmpArgStr(const virDomainDef *def, ...@@ -7996,6 +7996,71 @@ qemuBuildSmpArgStr(const virDomainDef *def,
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
static int
qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
virCommandPtr cmd)
{
const long system_page_size = virGetSystemPageSizeKB();
char *mem_path = NULL;
size_t i = 0;
/*
* No-op if hugepages were not requested.
*/
if (!def->mem.nhugepages)
return 0;
/* There is one special case: if user specified "huge"
* pages of regular system pages size.
* And there is nothing to do in this case.
*/
if (def->mem.hugepages[0].size == system_page_size)
return 0;
if (!cfg->nhugetlbfs) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("hugetlbfs filesystem is not mounted "
"or disabled by administrator config"));
return -1;
}
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_PATH)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("hugepage backing not supported by '%s'"),
def->emulator);
return -1;
}
if (!def->mem.hugepages[0].size) {
if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
cfg->nhugetlbfs)))
return -1;
} else {
for (i = 0; i < cfg->nhugetlbfs; i++) {
if (cfg->hugetlbfs[i].size == def->mem.hugepages[0].size)
break;
}
if (i == cfg->nhugetlbfs) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to find any usable hugetlbfs "
"mount for %llu KiB"),
def->mem.hugepages[0].size);
return -1;
}
if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
return -1;
}
virCommandAddArgList(cmd, "-mem-prealloc", "-mem-path", mem_path, NULL);
VIR_FREE(mem_path);
return 0;
}
static int static int
qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def, virDomainDefPtr def,
...@@ -9370,54 +9435,13 @@ qemuBuildCommandLine(virConnectPtr conn, ...@@ -9370,54 +9435,13 @@ qemuBuildCommandLine(virConnectPtr conn,
virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def) / 1024); virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def) / 1024);
} }
if (def->mem.nhugepages && !virDomainNumaGetNodeCount(def->numa)) { /*
const long system_page_size = virGetSystemPageSizeKB(); * Add '-mem-path' (and '-mem-prealloc') parameter here only if
char *mem_path = NULL; * there is no numa node specified.
*/
if (def->mem.hugepages[0].size == system_page_size) { if (!virDomainNumaGetNodeCount(def->numa) &&
/* There is one special case: if user specified "huge" qemuBuildMemPathStr(cfg, def, qemuCaps, cmd) < 0)
* pages of regular system pages size. */ goto error;
} else {
if (!cfg->nhugetlbfs) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("hugetlbfs filesystem is not mounted "
"or disabled by administrator config"));
goto error;
}
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_PATH)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("hugepage backing not supported by '%s'"),
def->emulator);
goto error;
}
if (def->mem.hugepages[0].size) {
for (j = 0; j < cfg->nhugetlbfs; j++) {
if (cfg->hugetlbfs[j].size == def->mem.hugepages[0].size)
break;
}
if (j == cfg->nhugetlbfs) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to find any usable hugetlbfs mount for %llu KiB"),
def->mem.hugepages[0].size);
goto error;
}
if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[j])))
goto error;
} else {
if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
cfg->nhugetlbfs)))
goto error;
}
}
virCommandAddArg(cmd, "-mem-prealloc");
if (mem_path)
virCommandAddArgList(cmd, "-mem-path", mem_path, NULL);
VIR_FREE(mem_path);
}
if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) { if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
/usr/bin/qemu -S -M pc -m 1024 -mem-prealloc -smp 2 -nographic \ /usr/bin/qemu -S -M pc -m 1024 -smp 2 -nographic \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册