- To: krkumar2@xxxxxxxxxx, habanero@xxxxxxxxxxxxxxxxxx, aliguori@xxxxxxxxxx, rusty@xxxxxxxxxxxxxxx, mst@xxxxxxxxxx, mashirle@xxxxxxxxxx, qemu-devel@xxxxxxxxxx, virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx, tahm@xxxxxxxxxxxxxxxxxx, jwhan@xxxxxxxxxxxxxxxxxx, akong@xxxxxxxxxx
- Subject: [RFC V3 1/5] option: introduce qemu_get_opt_all()
- From: Jason Wang <jasowang@xxxxxxxxxx>
- Date: Fri, 6 Jul 2012 17:31:06 +0800
- Cc: kvm@xxxxxxxxxxxxxxx
- Delivered-to: virtualization@xxxxxxxxxxxxxxxxxxxxxxxx
- In-reply-to: <1341567070-14136-1-git-send-email-jasowang@redhat.com>
Sometimes, we need to pass option like -netdev tap,fd=100,fd=101,fd=102 which
can not be properly parsed by qemu_find_opt() because it only returns the first
matched option. So qemu_get_opt_all() were introduced to return an array of
pointers which contains all matched option.
Signed-off-by: Jason Wang <jasowang@xxxxxxxxxx>
---
qemu-option.c | 19 +++++++++++++++++++
qemu-option.h | 2 ++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index bb3886c..9263125 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -545,6 +545,25 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
return NULL;
}
+int qemu_opt_get_all(QemuOpts *opts, const char *name, const char **optp,
+ int max)
+{
+ QemuOpt *opt;
+ int index = 0;
+
+ QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
+ if (strcmp(opt->name, name) == 0) {
+ if (index < max) {
+ optp[index++] = opt->str;
+ }
+ if (index == max) {
+ break;
+ }
+ }
+ }
+ return index;
+}
+
const char *qemu_opt_get(QemuOpts *opts, const char *name)
{
QemuOpt *opt = qemu_opt_find(opts, name);
diff --git a/qemu-option.h b/qemu-option.h
index 951dec3..3c9a273 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -106,6 +106,8 @@ struct QemuOptsList {
QemuOptDesc desc[];
};
+int qemu_opt_get_all(QemuOpts *opts, const char *name, const char **optp,
+ int max);
const char *qemu_opt_get(QemuOpts *opts, const char *name);
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
--
1.7.1
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[KVM Development]
[CentOS Virtualization]
[Netdev]
[Ethernet Bridging]
[Linux Wireless]
[Kernel Newbies]
[Security]
[Linux for Hams]
[Netfilter]
[Bugtraq]
[Photo]
[Yosemite]
[Yosemite Forum]
[MIPS Linux]
[ARM Linux]
[Linux RAID]
[Linux Admin]
[Samba]
[Find Someone Nice]
[Video 4 Linux]
[Linux Resources]