qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: tianyu.lan@intel.com, Paolo Bonzini <pbonzini@redhat.com>,
	kevin.tian@intel.com, yi.l.liu@intel.com,
	Marcel Apfelbaum <marcel@redhat.com>,
	"\\  Michael S . Tsirkin \\ " <mst@redhat.com>,
	peterx@redhat.com, Jason Wang <jasowang@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH for-2.10 1/5] QemuOpts: introduce qemu_opts_extract()
Date: Fri, 31 Mar 2017 15:36:29 +0800	[thread overview]
Message-ID: <1490945793-21276-2-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1490945793-21276-1-git-send-email-peterx@redhat.com>

This helper function is used to extract specific QemuOpts item from an
existing QemuOptsList which matches specific patterns.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/qemu/option.h |  2 ++
 util/qemu-option.c    | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index f7338db..355cee8 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -136,6 +136,8 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 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);
+QemuOpts *qemu_opts_extract(QemuOptsList *list, qemu_opts_loopfunc func,
+                            void *opaque, Error **errp);
 void qemu_opts_print(QemuOpts *opts, const char *sep);
 void qemu_opts_print_help(QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 5ce1b5c..7c34d88 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1121,6 +1121,30 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
     return rc;
 }
 
+/*
+ * Extract specific QemuOpts from a QemuOptsList. For each QemuOpts
+ * item, if checks against func() returns zero, it'll be picked out
+ * from current QemuOptsList, then returned. If there are more than
+ * one QemuOpts that match the check, will only return the first one
+ * found.
+ */
+QemuOpts *qemu_opts_extract(QemuOptsList *list, qemu_opts_loopfunc func,
+                            void *opaque, Error **errp)
+{
+    QemuOpts *opts, *next_opts;
+
+    assert(list && func);
+
+    QTAILQ_FOREACH_SAFE(opts, &list->head, next, next_opts) {
+        if (func(opaque, opts, errp) == 0) {
+            QTAILQ_REMOVE(&list->head, opts, next);
+            return opts;
+        }
+    }
+
+    return NULL;
+}
+
 static size_t count_opts_list(QemuOptsList *list)
 {
     QemuOptDesc *desc = NULL;
-- 
2.7.4

  reply	other threads:[~2017-03-31  7:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31  7:36 [Qemu-devel] [PATCH for-2.10 0/5] x86/vIOMMU: move init back to machine init phase Peter Xu
2017-03-31  7:36 ` Peter Xu [this message]
2017-03-31  7:36 ` [Qemu-devel] [PATCH for-2.10 2/5] util: export device_init_func() Peter Xu
2017-03-31  7:36 ` [Qemu-devel] [PATCH for-2.10 3/5] util: propagate error for device_func_init() Peter Xu
2017-03-31  7:36 ` [Qemu-devel] [PATCH for-2.10 4/5] q35: init vIOMMU during machine init Peter Xu
2017-03-31  7:36 ` [Qemu-devel] [PATCH for-2.10 5/5] pci: move dma_as init back to bus realize Peter Xu
2017-03-31 16:17 ` [Qemu-devel] [PATCH for-2.10 0/5] x86/vIOMMU: move init back to machine init phase Michael S. Tsirkin
2017-04-01  1:29   ` Peter Xu
2017-04-11  9:22     ` Markus Armbruster
2017-04-11 10:08       ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490945793-21276-2-git-send-email-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kevin.tian@intel.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tianyu.lan@intel.com \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).