@@ -138,9 +138,14 @@ QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict,
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
bool qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
+typedef bool (*qemu_opts_filterfunc)(void *opaque, QemuOpts *opts);
typedef int (*qemu_opts_loopfunc)(void *opaque, QemuOpts *opts, Error **errp);
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
void *opaque, Error **errp);
+int qemu_opts_filter_foreach(QemuOptsList *list,
+ qemu_opts_filterfunc filter,
+ qemu_opts_loopfunc func,
+ void *opaque, Error **errp);
void qemu_opts_print(QemuOpts *opts, const char *sep);
void qemu_opts_print_help(QemuOptsList *list, bool print_caption);
void qemu_opts_free(QemuOptsList *list);
@@ -1142,6 +1142,31 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
return rc;
}
+int qemu_opts_filter_foreach(QemuOptsList *list,
+ qemu_opts_filterfunc filter,
+ qemu_opts_loopfunc func,
+ void *opaque, Error **errp)
+{
+ Location loc;
+ QemuOpts *opts, *next;
+ int rc = 0;
+
+ loc_push_none(&loc);
+ QTAILQ_FOREACH_SAFE(opts, &list->head, next, next) {
+ if (!filter(opaque, opts)) {
+ continue;
+ }
+ loc_restore(&opts->loc);
+ rc = func(opaque, opts, errp);
+ if (rc) {
+ break;
+ }
+ assert(!errp || !*errp);
+ }
+ loc_pop(&loc);
+ return rc;
+}
+
static size_t count_opts_list(QemuOptsList *list)
{
QemuOptDesc *desc = NULL;
Define an accessor to loop over an options list and call a function for each element that passes a filter function. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- include/qemu/option.h | 5 +++++ util/qemu-option.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+)