The QemuOpts parser accepts repeated option names, storing all the provided values. qemu_opt_get() then just returns the last value. There is no way to get the other values without using a callback function to iterate over all option names. Add a qemu_opt_get_all() method to return a string list of all values.
Signed-off-by: Daniel P. Berrange <berra...@redhat.com> --- include/qemu/option.h | 1 + util/qemu-option.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 1f9e3f9..689e0a8 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -65,6 +65,7 @@ struct QemuOptsList { }; const char *qemu_opt_get(QemuOpts *opts, const char *name); +size_t qemu_opt_get_all(QemuOpts *opts, const char *name, char ***vals); char *qemu_opt_get_del(QemuOpts *opts, const char *name); /** * qemu_opt_has_help_opt: diff --git a/util/qemu-option.c b/util/qemu-option.c index 3467dc2..0418d71 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -332,6 +332,28 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name) return opt ? opt->str : NULL; } +size_t qemu_opt_get_all(QemuOpts *opts, const char *name, char ***vals) +{ + QemuOpt *opt; + size_t nvals = 0; + + *vals = NULL; + + QTAILQ_FOREACH(opt, &opts->head, next) { + if (!g_str_equal(opt->name, name)) { + continue; + } + + *vals = g_renew(char *, *vals, nvals + 1); + (*vals)[nvals++] = g_strdup(opt->str); + } + if (nvals) { + *vals = g_renew(char *, *vals, nvals + 1); + (*vals)[nvals] = NULL; + } + return nvals; +} + /* Get a known option (or its default) and remove it from the list * all in one action. Return a malloced string of the option value. * Result must be freed by caller with g_free(). -- 2.9.3