qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: qemu-devel@nongnu.org
Cc: imammedo@redhat.com, luonengjun@huawei.com,
	peter.huangpeng@huawei.com, aliguori@amazon.com,
	zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PATCH 1/2] vl: Fix the confused logic for '-m' option
Date: Fri, 12 Sep 2014 13:58:55 +0800	[thread overview]
Message-ID: <1410501536-1516-1-git-send-email-zhang.zhanghailiang@huawei.com> (raw)

It should be valid for the follow configure:
-m 256,slots=0
-m 256,maxmem=256M
-m 256,slots=0,maxmem=256M
-m 256,slots=x,maxmem=y  where x > 0 and y > 256M

Fix the confused code logic and use error_report instead of fprintf.

Printing the maxmem in hex, same with ram_size.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 vl.c | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/vl.c b/vl.c
index 9c9acf5..f547405 100644
--- a/vl.c
+++ b/vl.c
@@ -3306,6 +3306,7 @@ int main(int argc, char **argv, char **envp)
                 break;
             case QEMU_OPTION_m: {
                 uint64_t sz;
+                uint64_t slots;
                 const char *mem_str;
                 const char *maxmem_str, *slots_str;
 
@@ -3353,40 +3354,47 @@ int main(int argc, char **argv, char **envp)
 
                 maxmem_str = qemu_opt_get(opts, "maxmem");
                 slots_str = qemu_opt_get(opts, "slots");
-                if (maxmem_str && slots_str) {
-                    uint64_t slots;
-
+                if (maxmem_str) {
                     sz = qemu_opt_get_size(opts, "maxmem", 0);
+                }
+                if (slots_str) {
+                    slots = qemu_opt_get_number(opts, "slots", 0);
+                }
+                if (maxmem_str && slots_str) {
                     if (sz < ram_size) {
-                        fprintf(stderr, "qemu: invalid -m option value: maxmem "
-                                "(%" PRIu64 ") <= initial memory ("
+                        error_report("qemu: invalid -m option value: maxmem "
+                                "(%" PRIx64 ") < initial memory ("
                                 RAM_ADDR_FMT ")\n", sz, ram_size);
                         exit(EXIT_FAILURE);
                     }
-
-                    slots = qemu_opt_get_number(opts, "slots", 0);
-                    if ((sz > ram_size) && !slots) {
-                        fprintf(stderr, "qemu: invalid -m option value: maxmem "
-                                "(%" PRIu64 ") more than initial memory ("
+                    if (!slots && (sz != ram_size)) {
+                        error_report("qemu: invalid -m option value: maxmem "
+                                "(%" PRIx64 ") more than initial memory ("
                                 RAM_ADDR_FMT ") but no hotplug slots where "
                                 "specified\n", sz, ram_size);
                         exit(EXIT_FAILURE);
                     }
-
-                    if ((sz <= ram_size) && slots) {
-                        fprintf(stderr, "qemu: invalid -m option value:  %"
+                    if (slots && (sz == ram_size)) {
+                        error_report("qemu: invalid -m option value:  %"
                                 PRIu64 " hotplug slots where specified but "
-                                "maxmem (%" PRIu64 ") <= initial memory ("
+                                "maxmem (%" PRIx64 ") = initial memory ("
                                 RAM_ADDR_FMT ")\n", slots, sz, ram_size);
                         exit(EXIT_FAILURE);
                     }
                     maxram_size = sz;
                     ram_slots = slots;
-                } else if ((!maxmem_str && slots_str) ||
-                           (maxmem_str && !slots_str)) {
-                    fprintf(stderr, "qemu: invalid -m option value: missing "
-                            "'%s' option\n", slots_str ? "maxmem" : "slots");
-                    exit(EXIT_FAILURE);
+                } else if (!maxmem_str && slots_str) {
+                    if (slots > 0) {
+                        error_report("qemu: invalid -m option value: missing "
+                                "'maxmem' option\n");
+                        exit(EXIT_FAILURE);
+                    }
+                } else if (maxmem_str && !slots_str) {
+                    if (sz != ram_size) {
+                        error_report("qemu: invalid -m option value: missing "
+                                "'slot' option\n");
+                        exit(EXIT_FAILURE);
+                    }
                 }
                 break;
             }
-- 
1.7.12.4

             reply	other threads:[~2014-09-12  6:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12  5:58 zhanghailiang [this message]
2014-09-12  6:46 ` [Qemu-devel] [PATCH 1/2] vl: Fix the confused logic for '-m' option Li Liu
2014-09-12 13:52 ` Igor Mammedov
2014-09-15  7:15   ` zhanghailiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410501536-1516-1-git-send-email-zhang.zhanghailiang@huawei.com \
    --to=zhang.zhanghailiang@huawei.com \
    --cc=aliguori@amazon.com \
    --cc=imammedo@redhat.com \
    --cc=luonengjun@huawei.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).