[libvirt] [PATCH] qemu: Changes in parsing qemu commandline memory section

Existing qemuParseCommandLineMem() will parse "-m 4G" format string. This patch allows it to parse "-m size=8126464k,slots=32,maxmem=33554432k" format along with existing format. Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com> --- src/qemu/qemu_parse_command.c | 89 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index 37e1149..c30e8ed 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -1629,26 +1629,91 @@ static int qemuParseCommandLineMem(virDomainDefPtr dom, const char *val) { - unsigned long long mem; + unsigned long long mem = 0; + unsigned long long size = 0; + unsigned long long maxmem = 0; + unsigned int slots = 0; char *end; + size_t i; + int nkws; + char **kws; + char **vals; + int n; + int ret = -1; - if (virStrToLong_ull(val, &end, 10, &mem) < 0) { + if (qemuParseKeywords(val, &kws, &vals, &nkws, 1) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse memory level '%s'"), val); - return -1; + _("cannot parse memory '%s'"), val); + goto cleanup; } - if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot scale memory: %s"), - virGetLastErrorMessage()); - return -1; + for (i = 0; i < nkws; i++) { + if (vals[i] == NULL) { + if (i > 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory '%s'"), val); + goto cleanup; + } + if (virStrToLong_ull(kws[i], &end, 10, &mem) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory level '%s'"), kws[i]); + goto cleanup; + } + if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot scale memory: %s"), + virGetLastErrorMessage()); + goto cleanup; + } + + size = mem; + + } else { + if (STREQ(kws[i], "size") || STREQ(kws[i], "maxmem")) { + if (virStrToLong_ull(vals[i], &end, 10, &mem) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory level '%s'"), vals[i]); + goto cleanup; + } + if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot scale memory: %s"), + virGetLastErrorMessage()); + goto cleanup; + } + + STREQ(kws[i], "size") ? (size = mem) : (maxmem = mem); + + } + if (STREQ(kws[i], "slots")) { + if (virStrToLong_i(vals[i], &end, 10, &n) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse slots value '%s'"), vals[i]); + goto cleanup; + } + + slots = n; + + } + } } - virDomainDefSetMemoryTotal(dom, mem / 1024); - dom->mem.cur_balloon = mem / 1024; + virDomainDefSetMemoryTotal(dom, size / 1024); + dom->mem.cur_balloon = size / 1024; + dom->mem.memory_slots = slots; + dom->mem.max_memory = maxmem; - return 0; + ret = 0; + + cleanup: + for (i = 0; i < nkws; i++) { + VIR_FREE(kws[i]); + VIR_FREE(vals[i]); + } + VIR_FREE(kws); + VIR_FREE(vals); + + return ret; } -- 1.8.3.1

On Mon, Oct 09, 2017 at 04:32:38PM +0530, Kothapally Madhu Pavan wrote:
Existing qemuParseCommandLineMem() will parse "-m 4G" format string. This patch allows it to parse "-m size=8126464k,slots=32,maxmem=33554432k" format along with existing format.
Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com> --- src/qemu/qemu_parse_command.c | 89 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 12 deletions(-)
This needs to have a corresponding addition to tests/qemuargv2xmltest.c to validate the code is operating correctly. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 10/09/2017 04:34 PM, Daniel P. Berrange wrote:
On Mon, Oct 09, 2017 at 04:32:38PM +0530, Kothapally Madhu Pavan wrote:
Existing qemuParseCommandLineMem() will parse "-m 4G" format string. This patch allows it to parse "-m size=8126464k,slots=32,maxmem=33554432k" format along with existing format.
Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com> --- src/qemu/qemu_parse_command.c | 89 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 12 deletions(-) This needs to have a corresponding addition to tests/qemuargv2xmltest.c to validate the code is operating correctly. Sure. I will add it and post a v2.
Thanks, Madhu.
participants (3)
-
Daniel P. Berrange
-
Kothapally Madhu Pavan
-
Madhu Pavan