aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorChunyan Liu <cyliu@suse.com>2014-06-05 17:20:42 +0800
committerStefan Hajnoczi <stefanha@redhat.com>2014-06-16 17:23:20 +0800
commit09722032e15669e653991923613761602c745fa0 (patch)
treec25f90910ebc8f4a1c2bed88c8ee280b3253a669 /util
parente67905426bf3cf811d31c87789c1c7e986849d66 (diff)
QemuOpts: add def_value_str to QemuOptDesc
Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. Improve qemu_opts_get_* functions: if find opt, return opt->str; otherwise, if desc->def_value_str is set, return desc->def_value_str; otherwise, return input defval. Improve qemu_opts_print: if option is set, print opt->str; otherwise, if desc->def_value_str is set, print it. Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Chunyan Liu <cyliu@suse.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-option.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 2c467918be..5af39a2f18 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
const char *qemu_opt_get(QemuOpts *opts, const char *name)
{
QemuOpt *opt = qemu_opt_find(opts, name);
+
+ if (!opt) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ return desc->def_value_str;
+ }
+ }
return opt ? opt->str : NULL;
}
@@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_bool(name, desc->def_value_str, &defval, &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
return opt->value.boolean;
}
@@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_number(name, desc->def_value_str, &defval,
+ &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
return opt->value.uint;
}
@@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt = qemu_opt_find(opts, name);
- if (opt == NULL)
+ if (opt == NULL) {
+ const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+ if (desc && desc->def_value_str) {
+ parse_option_size(name, desc->def_value_str, &defval, &error_abort);
+ }
return defval;
+ }
assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
return opt->value.uint;
}
@@ -898,11 +921,30 @@ void qemu_opts_del(QemuOpts *opts)
void qemu_opts_print(QemuOpts *opts)
{
QemuOpt *opt;
+ QemuOptDesc *desc = opts->list->desc;
- printf("%s: %s:", opts->list->name,
- opts->id ? opts->id : "<noid>");
- QTAILQ_FOREACH(opt, &opts->head, next) {
- printf(" %s=\"%s\"", opt->name, opt->str);
+ if (desc[0].name == NULL) {
+ QTAILQ_FOREACH(opt, &opts->head, next) {
+ printf("%s=\"%s\" ", opt->name, opt->str);
+ }
+ return;
+ }
+ for (; desc && desc->name; desc++) {
+ const char *value;
+ QemuOpt *opt = qemu_opt_find(opts, desc->name);
+
+ value = opt ? opt->str : desc->def_value_str;
+ if (!value) {
+ continue;
+ }
+ if (desc->type == QEMU_OPT_STRING) {
+ printf("%s='%s' ", desc->name, value);
+ } else if ((desc->type == QEMU_OPT_SIZE ||
+ desc->type == QEMU_OPT_NUMBER) && opt) {
+ printf("%s=%" PRId64 " ", desc->name, opt->value.uint);
+ } else {
+ printf("%s=%s ", desc->name, value);
+ }
}
}