All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, peter.crosthwaite@xilinx.com, akong@redhat.com,
	stefanha@redhat.com, mjt@tls.msk.ru, armbru@redhat.com,
	mreitz@redhat.com, aliguori@amazon.com, pbonzini@redhat.com,
	lcapitulino@redhat.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/2] vl: convert -m to QemuOpts
Date: Thu, 13 Feb 2014 08:14:45 -0700	[thread overview]
Message-ID: <52FCE165.4080608@redhat.com> (raw)
In-Reply-To: <1392299426-13160-3-git-send-email-imammedo@redhat.com>

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

On 02/13/2014 06:50 AM, Igor Mammedov wrote:
> 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
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> v2:
>  - various fixes suggested by Laszlo Ersek <lersek@redhat.com>
>    - 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(-)
> 

> +    "                configure guest RAM size\n"
> +    "                mem: initial amount of guest memory (default: "
> +    stringify(DEFAULT_RAM_SIZE) "MB)\n",

MB here...

> +    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.


> +                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).

> +                if (!strlen(mem_str)) {

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

> +                    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.

> +                    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().

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2014-02-13 15:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 13:50 [Qemu-devel] [PATCH v2 0/2] convert -m to QemuOpts Igor Mammedov
2014-02-13 13:50 ` [Qemu-devel] [PATCH v2 1/2] QemuOpts: introduce qemu_find_opts_singleton Igor Mammedov
2014-02-13 13:50 ` [Qemu-devel] [PATCH v2 2/2] vl: convert -m to QemuOpts Igor Mammedov
2014-02-13 15:14   ` Eric Blake [this message]
2014-02-13 16:13   ` [Qemu-devel] [PATCH v3] " Igor Mammedov
2014-02-13 17:45     ` Eric Blake
2014-02-13 20:06       ` Laszlo Ersek
2014-02-17 16:18     ` Paolo Bonzini
2014-02-17 16:42       ` Luiz Capitulino

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=52FCE165.4080608@redhat.com \
    --to=eblake@redhat.com \
    --cc=akong@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.