[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/12] QemuOpts: use strtosz
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 02/12] QemuOpts: use strtosz |
Date: |
Tue, 20 Mar 2012 09:01:28 +0100 |
This will simplify conversion of -numa node,mem=... and -m to QemuOpts.
Signed-off-by: Paolo Bonzini <address@hidden>
---
qemu-option.c | 41 ++++++++++-------------------------------
1 files changed, 10 insertions(+), 31 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 35cd609..55cbee8 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -204,41 +204,20 @@ static int parse_option_number(const char *name, const
char *value, uint64_t *re
return 0;
}
-static int parse_option_size(const char *name, const char *value, uint64_t
*ret)
+static int parse_option_size(const char *name, const char *value,
+ const char default_suffix, uint64_t *ret)
{
char *postfix;
- double sizef;
+ int64_t size;
- if (value != NULL) {
- sizef = strtod(value, &postfix);
- switch (*postfix) {
- case 'T':
- sizef *= 1024;
- /* fall through */
- case 'G':
- sizef *= 1024;
- /* fall through */
- case 'M':
- sizef *= 1024;
- /* fall through */
- case 'K':
- case 'k':
- sizef *= 1024;
- /* fall through */
- case 'b':
- case '\0':
- *ret = (uint64_t) sizef;
- break;
- default:
- qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
- error_printf_unless_qmp("You may use k, M, G or T suffixes for "
- "kilobytes, megabytes, gigabytes and terabytes.\n");
- return -1;
- }
- } else {
+ size = strtosz_suffix(value, &postfix, default_suffix);
+ if (size < 0 || *postfix) {
qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
+ error_printf_unless_qmp("You may use k, M, G or T suffixes for "
+ "kilobytes, megabytes, gigabytes and terabytes.\n");
return -1;
}
+ *ret = size;
return 0;
}
@@ -289,7 +268,7 @@ int set_option_parameter(QEMUOptionParameter *list, const
char *name,
break;
case OPT_SIZE:
- if (parse_option_size(name, value, &list->value.n) == -1)
+ if (parse_option_size(name, value, 'B', &list->value.n) == -1)
return -1;
break;
@@ -589,7 +568,7 @@ static int qemu_opt_parse(QemuOpt *opt)
case QEMU_OPT_NUMBER:
return parse_option_number(opt->name, opt->str, &opt->value.uint);
case QEMU_OPT_SIZE:
- return parse_option_size(opt->name, opt->str, &opt->value.uint);
+ return parse_option_size(opt->name, opt->str, 'M', &opt->value.uint);
default:
abort();
}
--
1.7.7.6
- [Qemu-devel] [PATCH 00/12] convert many options to QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 05/12] cmdline: implement -bios with QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 10/12] cmdline: convert -numa to QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 06/12] cmdline: implement -localtime with QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 01/12] vga: disable default VGA if appropriate -device is used, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 02/12] QemuOpts: use strtosz,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 04/12] cmdline: implement -S with QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 07/12] cmdline: make -M a simple alias for -machine type, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 12/12] cmdline: convert -no-shutdown and -no-reboot to QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 03/12] cmdline: implement -m with QemuOpts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 09/12] cmdline: reindent numa_add, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 11/12] cmdline: implement -nodefaults with qemuopts, Paolo Bonzini, 2012/03/20
- [Qemu-devel] [PATCH 08/12] cmdline: convert -smp to QemuOpts, Paolo Bonzini, 2012/03/20