Skip to contentSkip to conversation

convert -m to QemuOpts

PATCH Superseded Igor Mammedov 5 participants 9 messages Feb 13, 2014 – Feb 17, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover convert -m to QemuOpts

changes since v1:
- check for overflow
- check for empty mem="" case
- reshuffle code to avoid conflicts with another series on list
- some style/typo fixes

changes since RFC:
- resolved conflict with error_abort change
in qemu_get_machine_opts()

git tree for testing:
https://github.com/imammedo/qemu/tree/qoptify-m.v2

Igor Mammedov (1):
vl: convert -m to QemuOpts

Paolo Bonzini (1):
QemuOpts: introduce qemu_find_opts_singleton

 include/qemu/config-file.h |    2 +
 qemu-options.hx            |   12 ++++--
 util/qemu-config.c         |   14 ++++++++
 vl.c                       |   79 ++++++++++++++++++++++++++++++++------------
 4 files changed, 82 insertions(+), 25 deletions(-)
#1 lore raw

PATCH v2 1/2 QemuOpts: introduce qemu_find_opts_singleton

From: Paolo Bonzini <[email protected]>

Allows to use singleton idiom for getting access to a specified option list pre-creating it if necessary.

---
 include/qemu/config-file.h |    2 ++
 util/qemu-config.c         |   14 ++++++++++++++
 vl.c                       |   11 +----------
 3 files changed, 17 insertions(+), 10 deletions(-)
include/qemu/config-file.h +2 -0
index dbd97c4..d4ba20e 100644
@@ -8,6 +8,8 @@
 
 QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
+QemuOpts *qemu_find_opts_singleton(const char *group);
+
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_set_option(const char *str);
util/qemu-config.c +14 -0
index 9298f55..9dfacbc 100644
@@ -39,6 +39,20 @@ QemuOptsList *qemu_find_opts(const char *group)
     return ret;
 }
 
+QemuOpts *qemu_find_opts_singleton(const char *group)
+{
+    QemuOptsList *list;
+    QemuOpts *opts;
+
+    list = qemu_find_opts(group);
+    assert(list);
+    opts = qemu_opts_find(list, NULL);
+    if (!opts) {
+        opts = qemu_opts_create(list, NULL, 0, &error_abort);
+    }
+    return opts;
+}
+
 static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
 {
     CommandLineParameterInfoList *param_list = NULL, *entry;
vl.c +1 -10
index 383be1b..7f2595c 100644
@@ -539,16 +539,7 @@ static QemuOptsList qemu_msg_opts = {
  */
 QemuOpts *qemu_get_machine_opts(void)
 {
-    QemuOptsList *list;
-    QemuOpts *opts;
-
-    list = qemu_find_opts("machine");
-    assert(list);
-    opts = qemu_opts_find(list, NULL);
-    if (!opts) {
-        opts = qemu_opts_create(list, NULL, 0, &error_abort);
-    }
-    return opts;
+    return qemu_find_opts_singleton("machine");
 }
 
 const char *qemu_get_vm_name(void)
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/2 vl: convert -m to QemuOpts

In reply to Igor Mammedov

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in Mb.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

---
v2:
- various fixes suggested by Laszlo Ersek <[email protected]>
- check for overflow
- check for empty mem="" case
- reshuffle code to avoid conflicts with another series on list
- some style/typo fixes

---
 qemu-options.hx |   12 ++++++---
 vl.c            |   68 ++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 65 insertions(+), 15 deletions(-)
qemu-options.hx +8 -4
index 56e5fdf..42f7b64 100644
@@ -210,14 +210,18 @@ use is discouraged as it may be removed from future versions.
 ETEXI
 
 DEF("m", HAS_ARG, QEMU_OPTION_m,
-    "-m megs         set virtual RAM size to megs MB [default="
-    stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_ARCH_ALL)
+    "-m [mem=]size\n"
+    "                configure guest RAM size\n"
+    "                mem: initial amount of guest memory (default: "
+    stringify(DEFAULT_RAM_SIZE) "MB)\n",
+    QEMU_ARCH_ALL)
 STEXI
 @item -m @var{megs}
 @findex -m
-Set virtual RAM size to @var{megs} megabytes. Default is 128 MiB.  Optionally,
+Set virtual RAM size to @var{size} megabytes. Default is 128 MiB.  Optionally,
 a suffix of ``M'' or ``G'' can be used to signify a value in megabytes or
-gigabytes respectively.
+gigabytes respectively. If @var{size} is provided without unit suffix then MB
+is assumed.
 ETEXI
 
 DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
vl.c +57 -11

108 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] vl: convert -m to QemuOpts

Quoted 23 lines · Igor Mammedov

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in Mb.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

---
v2:
- various fixes suggested by Laszlo Ersek <[email protected]>
- check for overflow
- check for empty mem="" case
- reshuffle code to avoid conflicts with another series on list
- some style/typo fixes

---
 qemu-options.hx |   12 ++++++---
 vl.c            |   68 ++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 65 insertions(+), 15 deletions(-)

qemu-options.hx use is discouraged as it may be removed from future versions. · line 216

Quoted 3 lines
qemu-options.hx +3 -0
+    "                configure guest RAM size\n"
+    "                mem: initial amount of guest memory (default: "
+    stringify(DEFAULT_RAM_SIZE) "MB)\n",

MB here...

qemu-options.hx use is discouraged as it may be removed from future versions. · line 224

Quoted 10 lines
qemu-options.hx +4 -2
+    QEMU_ARCH_ALL)
 STEXI
 @item -m @var{megs}
 @findex -m
-Set virtual RAM size to @var{megs} megabytes. Default is 128 MiB.  Optionally,
+Set virtual RAM size to @var{size} megabytes. Default is 128 MiB.  Optionally,
 a suffix of ``M'' or ``G'' can be used to signify a value in megabytes or
-gigabytes respectively.
+gigabytes respectively. If @var{size} is provided without unit suffix then MB
+is assumed.

...and inconsistent on MiB vs MB here. If we're going to use MiB (which is the correct term), it would be worth using it everywhere.

vl.c int main(int argc, char **argv, char **envp) · line 3225

Quoted 4 lines
vl.c +4 -0
+                opts = qemu_opts_parse(qemu_find_opts(MEMORY_OPTS),
+                                       optarg, 1);
+                if (!opts) {
+                    exit(1);

I prefer EXIT_FAILURE, but that's a change for another patch (you're just following conventions).

Quoted 1 line

+ if (!strlen(mem_str)) {

More efficient as 'if (!*mem_str)'...

vl.c int main(int argc, char **argv, char **envp) · line 3242

Quoted 9 lines
vl.c +6 -1
+                    fprintf(stderr, "qemu: missing 'mem' option value\n");
                     exit(1);
                 }
-                sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
+
+                sz = qemu_opt_get_size(opts, "mem", ram_size);
+
+                /* Fix up legacy suffix-less format */
+                if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {

...either that, or cache your strlen() result so you only call it once.

vl.c int main(int argc, char **argv, char **envp) · line 3250

Quoted 8 lines
vl.c +8 -0
+                    uint64_t overflow_check = sz;
+
+                    sz <<= 20;
+                    if ((sz >> 20) != overflow_check) {
+                        fprintf(stderr, "qemu: too large 'mem' option "
+                                "value\n");
+                    }
+                }

What? We print the warning, but then use the bogus value? Missing exit().

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

PATCH v3 1/1 vl: convert -m to QemuOpts

In reply to Igor Mammedov

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in MiB.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

---
v3:
- fixes suggested by Eric Blake <[email protected]>
- check for empty string in more efficient way
- fix MB/MiB inconsistency
- use EXIT_FAILURE instead of 1
- add missing exit() if overflow occurres
v2:
- various fixes suggested by Laszlo Ersek <[email protected]>
- check for overflow
- check for empty mem="" case
- reshuffle code to avoid conflicts with another series on list
- some style/typo fixes

---
 qemu-options.hx |   12 ++++++---
 vl.c            |   73 +++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 68 insertions(+), 17 deletions(-)
qemu-options.hx +8 -4
index 56e5fdf..2057fc6 100644
@@ -210,14 +210,18 @@ use is discouraged as it may be removed from future versions.
 ETEXI
 
 DEF("m", HAS_ARG, QEMU_OPTION_m,
-    "-m megs         set virtual RAM size to megs MB [default="
-    stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_ARCH_ALL)
+    "-m [mem=]size\n"
+    "                configure guest RAM size\n"
+    "                mem: initial amount of guest memory (default: "
+    stringify(DEFAULT_RAM_SIZE) "MiB)\n",
+    QEMU_ARCH_ALL)
 STEXI
 @item -m @var{megs}
 @findex -m
-Set virtual RAM size to @var{megs} megabytes. Default is 128 MiB.  Optionally,
+Set virtual RAM size to @var{size} megabytes. Default is 128 MiB.  Optionally,
 a suffix of ``M'' or ``G'' can be used to signify a value in megabytes or
-gigabytes respectively.
+gigabytes respectively. If @var{size} is provided without unit suffix then MiB
+is assumed.
 ETEXI
 
 DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
vl.c +60 -13

115 lines not on this page · raw message

Signature · 1 line
1.7.1
Reviewed-by on v3 1/1
#5 lore raw

Re: [Qemu-devel] [PATCH v3] vl: convert -m to QemuOpts

Quoted 10 lines · Igor Mammedov

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in MiB.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

Quoted 7 lines

---
v3:
- fixes suggested by Eric Blake <[email protected]>
- check for empty string in more efficient way
- fix MB/MiB inconsistency
- use EXIT_FAILURE instead of 1
- add missing exit() if overflow occurres

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by
#6 lore raw

Re: [Qemu-devel] [PATCH v3] vl: convert -m to QemuOpts

Quoted 19 lines · Eric Blake
Quoted 10 lines · Igor Mammedov

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in MiB.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

Quoted 7 lines

---
v3:
- fixes suggested by Eric Blake <[email protected]>
- check for empty string in more efficient way
- fix MB/MiB inconsistency
- use EXIT_FAILURE instead of 1
- add missing exit() if overflow occurres

Quoted 1 line

Me too:

#7 lore raw

Re: [Qemu-devel] [PATCH v3] vl: convert -m to QemuOpts

In reply to Igor Mammedov

Il 13/02/2014 17:13, Igor Mammedov ha scritto:

Quoted 10 lines

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in MiB.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

I am applying this to a NUMA branch that will be on top of Luiz's qmp queue. Because of this, it will be rebased.

Paolo

#8 lore raw

Re: [Qemu-devel] [PATCH v3] vl: convert -m to QemuOpts

Quoted 7 lines · On Mon, 17 Feb 2014 17:18:25 +0100 Paolo Bonzini <[email protected]> wrote:

Il 13/02/2014 17:13, Igor Mammedov ha scritto:

Quoted 6 lines

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in MiB.

Quoted 7 lines
Quoted 4 lines

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

I am applying this to a NUMA branch that will be on top of Luiz's qmp queue. Because of this, it will be rebased.

My queue is going to be rebased because it broke the build... And, as you have a NUMA branch:

http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02484.html