qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Krempa <pkrempa@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] vl.c: Fix error messages when parsing maxmem parameters
Date: Wed, 28 Jan 2015 08:18:56 +0100	[thread overview]
Message-ID: <20150128071856.GC5003@andariel.home> (raw)
In-Reply-To: <54C7D5CD.5010406@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3484 bytes --]

On Tue, Jan 27, 2015 at 11:15:41 -0700, Eric Blake wrote:
> On 01/26/2015 08:31 AM, Peter Krempa wrote:
> > Produce more human readable error messages and fix few spelling
> > mistakes.
> > 
> > Also remove a redundant check for the max memory size.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> >  vl.c | 22 +++++++---------------
> >  1 file changed, 7 insertions(+), 15 deletions(-)
> > 
> > diff --git a/vl.c b/vl.c
> > index 983259b..cdc920c 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -2694,29 +2694,21 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size)
> >          uint64_t slots;
> > 
> >          sz = qemu_opt_get_size(opts, "maxmem", 0);
> > -        if (sz < ram_size) {
> > -            error_report("invalid -m option value: maxmem "
> > -                    "(0x%" PRIx64 ") <= initial memory (0x"
> > -                    RAM_ADDR_FMT ")", sz, ram_size);
> > +        if (sz <= ram_size) {
> 
> Why are we changing from '<' to '<='?  I think the error was in the
> message, not in the code, and that setting max == size should be
> allowed. [1]
> 
> > +            error_report("invalid value of -m option maxmem: "
> > +                         "maximum memory size (0x%" PRIx64 ") must be greater "
> > +                         "than initial memory size (0x"  RAM_ADDR_FMT ")",
> 
> Why two spaces?  If I'm correct that we want '<' in the condition, then
> the wording 'must be at least the initial memory size' would be better.
> 
> > +                         sz, ram_size);
> >              exit(EXIT_FAILURE);
> >          }
> > 
> >          slots = qemu_opt_get_number(opts, "slots", 0);
> >          if ((sz > ram_size) && !slots) {
> > -            error_report("invalid -m option value: maxmem "
> > -                    "(0x%" PRIx64 ") more than initial memory (0x"
> > -                    RAM_ADDR_FMT ") but no hotplug slots where "
> > -                    "specified", sz, ram_size);
> > +            error_report("invalid value of -m option: maxmem was specified, "
> > +                         "but no hotplug slots were specified");
> >              exit(EXIT_FAILURE);
> >          }
> > 
> > -        if ((sz <= ram_size) && slots) {
> > -            error_report("invalid -m option value:  %"
> > -                    PRIu64 " hotplug slots where specified but "
> > -                    "maxmem (0x%" PRIx64 ") <= initial memory (0x"
> > -                    RAM_ADDR_FMT ")", slots, sz, ram_size);
> > -            exit(EXIT_FAILURE);
> > -        }
> 
> Okay, I see.  This is dead if condition [1] is changed to '<=', but
> still reachable (sz == ram_size) if condition [1] is left at '<'.  Maybe
> better logic would be:
> 
> if (sz < ram_size) {
>     max cannot be less than memory
> }
> if (sz > ram_size) {
>     if (!slots) {
>         max cannot be larger than size without hotplug slots
>     }
> } else if (slots) {
>     max must be larger than size to support hotplug slots
> }
> 
> to allow max==ram_size when slots is not present.

This will only allow to specify ram_size equal to max if the slot
parameter _is_ present and set to 0. If the string is not present a
different branch is taken and the config will be rejected, as the two
parameters have to be specified together.

I'll post an updated version though, the control flow in your suggestion
seems more clear.

Thanks.

Peter

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-01-28  7:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26 15:31 [Qemu-devel] [PATCH 0/2] pc: Fix startup with memory hotplug enabled Peter Krempa
2015-01-26 15:31 ` [Qemu-devel] [PATCH 1/2] vl.c: Fix error messages when parsing maxmem parameters Peter Krempa
2015-01-27 18:15   ` Eric Blake
2015-01-28  7:18     ` Peter Krempa [this message]
2015-01-26 15:31 ` [Qemu-devel] [PATCH 2/2] pc: memory: Validate alignment of maxram_size to page size Peter Krempa
2015-01-27 18:16   ` Eric Blake

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=20150128071856.GC5003@andariel.home \
    --to=pkrempa@redhat.com \
    --cc=eblake@redhat.com \
    --cc=imammedo@redhat.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).