[libvirt] [PATCH v2 1/2] qemu: parse: Use qemuParseCommandLineMem for -m memory
Cole Robinson
crobinso at redhat.com
Thu May 19 12:08:39 UTC 2016
On 05/18/2016 02:36 AM, Nishith Shah wrote:
> Move the parsing of -m memory to a new function, qemuParseCommandLineMem
>
> Signed-off-by: Nishith Shah <nishithshah.2211 at gmail.com>
> ---
> src/qemu/qemu_parse_command.c | 30 +++++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
> index e30586f..334dcf8 100644
> --- a/src/qemu/qemu_parse_command.c
> +++ b/src/qemu/qemu_parse_command.c
> @@ -1633,6 +1633,28 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
>
>
> static int
> +qemuParseCommandLineMem(virDomainDefPtr dom,
> + const char *val)
> +{
> + unsigned long long mem;
> + char *end;
> + if (virStrToLong_ull(val, &end, 10, &mem) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("cannot parse memory level '%s'"), val);
> + goto error;
> + }
> +
> + virDomainDefSetMemoryTotal(dom, mem * 1024);
> + dom->mem.cur_balloon = mem * 1024;
> +
> + return 0;
> +
> + error:
> + return -1;
> +}
> +
Typically when we use the 'goto error' pattern, what we do is:
int ret = -1;
if (condition)
goto error;
ret = 0;
error:
return ret;
So there's only one 'return'
That said, in this function there isn't any special error handling, so I
suggest dropping the 'error' label entirely and just 'return -1' at the goto
error calls
Thanks,
Cole
More information about the libvir-list
mailing list