Reorganize the module to put all the -m argument processing code together after the domain loader to form a logical order of processing for qemuBuildCommandLine working top down in the module. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_command.c | 217 ++++++++++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 100 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 70da921..a8d1f4f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -861,6 +861,121 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd, } +/** Start Memory (-m) arguments */ +static int +qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, + const virDomainDef *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 +qemuBuildMemCommandLine(virCommandPtr cmd, + virQEMUDriverConfigPtr cfg, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + if (qemuDomainDefValidateMemoryHotplug(def, qemuCaps, NULL) < 0) + goto error; + + virCommandAddArg(cmd, "-m"); + + if (virDomainDefHasMemoryHotplug(def)) { + /* Use the 'k' suffix to let qemu handle the units */ + virCommandAddArgFormat(cmd, "size=%lluk,slots=%u,maxmem=%lluk", + virDomainDefGetMemoryInitial(def), + def->mem.memory_slots, + def->mem.max_memory); + + } else { + virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def) / 1024); + } + + /* + * Add '-mem-path' (and '-mem-prealloc') parameter here only if + * there is no numa node specified. + */ + if (!virDomainNumaGetNodeCount(def->numa) && + qemuBuildMemPathStr(cfg, def, qemuCaps, cmd) < 0) + goto error; + + if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("memory locking not supported by QEMU binary")); + goto error; + } + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) { + virCommandAddArg(cmd, "-realtime"); + virCommandAddArgFormat(cmd, "mlock=%s", + def->mem.locked ? "on" : "off"); + } + + return 0; + + error: + return -1; +} + + static int qemuBuildObjectCommandLinePropsInternal(const char *key, const virJSONValue *value, @@ -5310,71 +5425,6 @@ qemuBuildSmpArgStr(const virDomainDef *def, } 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 qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, virDomainDefPtr def, virCommandPtr cmd, @@ -6844,44 +6894,11 @@ qemuBuildCommandLine(virConnectPtr conn, if (qemuBuildDomainLoaderCommandLine(cmd, def, qemuCaps) < 0) goto error; - if (!migrateURI && !snapshot && - qemuDomainAlignMemorySizes(def) < 0) - goto error; - - if (qemuDomainDefValidateMemoryHotplug(def, qemuCaps, NULL) < 0) - goto error; - - virCommandAddArg(cmd, "-m"); - - if (virDomainDefHasMemoryHotplug(def)) { - /* Use the 'k' suffix to let qemu handle the units */ - virCommandAddArgFormat(cmd, "size=%lluk,slots=%u,maxmem=%lluk", - virDomainDefGetMemoryInitial(def), - def->mem.memory_slots, - def->mem.max_memory); - - } else { - virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def) / 1024); - } - - /* - * Add '-mem-path' (and '-mem-prealloc') parameter here only if - * there is no numa node specified. - */ - if (!virDomainNumaGetNodeCount(def->numa) && - qemuBuildMemPathStr(cfg, def, qemuCaps, cmd) < 0) + if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0) goto error; - if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("memory locking not supported by QEMU binary")); + if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps) < 0) goto error; - } - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) { - virCommandAddArg(cmd, "-realtime"); - virCommandAddArgFormat(cmd, "mlock=%s", - def->mem.locked ? "on" : "off"); - } virCommandAddArg(cmd, "-smp"); if (!(smp = qemuBuildSmpArgStr(def, qemuCaps))) -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list