From: Chunyan Liu <cyliu@suse.com>
To: qemu-devel@nongnu.org, stefanha@redhat.com, kwolf@redhat.com
Cc: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>, Chunyan Liu <cyliu@suse.com>
Subject: [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work
Date: Mon, 20 Jan 2014 22:19:47 +0800 [thread overview]
Message-ID: <1390227608-7225-5-git-send-email-cyliu@suse.com> (raw)
In-Reply-To: <1390227608-7225-1-git-send-email-cyliu@suse.com>
Add some qemu_opt functions to replace the same functionality of
QEMUOptionParameter handling.
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
include/qemu/option.h | 7 +++
util/qemu-option.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 2c5b03f..8d77e2e 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -109,6 +109,7 @@ struct QemuOptsList {
};
const char *qemu_opt_get(QemuOpts *opts, const char *name);
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name);
/**
* qemu_opt_has_help_opt:
* @opts: options to search for a help request
@@ -124,6 +125,9 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
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);
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t defval);
int qemu_opt_unset(QemuOpts *opts, const char *name);
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -159,4 +163,7 @@ void qemu_opts_print(QemuOpts *opts);
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
int abort_on_failure);
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
#endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8944b62..6bd5154 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -379,6 +379,72 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
return dest;
}
+static size_t count_opts_list(QemuOptsList *list)
+{
+ QemuOptDesc *desc = NULL;
+ size_t num_opts = 0;
+
+ if (!list)
+ return 0;
+
+ desc = list->desc;
+ while (desc && desc->name) {
+ num_opts ++;
+ desc ++;
+ }
+
+ return num_opts;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both lists can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+ QemuOptsList *list)
+{
+ size_t num_opts, num_dst_opts;
+ QemuOptsList *tmp;
+ QemuOptDesc *desc;
+
+ if (!dst && !list)
+ return NULL;
+
+ num_opts = count_opts_list(dst);
+ num_opts += count_opts_list(list);
+
+ tmp = g_malloc0(sizeof(QemuOptsList) + (num_opts + 1) * sizeof(QemuOptDesc));
+ QTAILQ_INIT(&tmp->head);
+ num_dst_opts = 0;
+
+ /* copy dst->desc to new list */
+ if (dst) {
+ desc = dst->desc;
+ while (desc && desc->name) {
+ tmp->desc[num_dst_opts++] = *desc;
+ tmp->desc[num_dst_opts].name = NULL;
+ desc++;
+ }
+ }
+
+ /* add list->desc to new list */
+ if (list) {
+ desc = list->desc;
+ while (desc && desc->name) {
+ if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
+ tmp->desc[num_dst_opts++] = *desc;
+ tmp->desc[num_dst_opts].name = NULL;
+ }
+ desc++;
+ }
+ }
+
+ return tmp;
+}
+
/*
* Parses a parameter string (param) into an option list (dest).
*
@@ -528,6 +594,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
return opt ? opt->str : NULL;
}
+static void qemu_opt_del(QemuOpt *opt);
+
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+ const char *str = qemu_opt_get(opts, name);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return str;
+}
+
bool qemu_opt_has_help_opt(QemuOpts *opts)
{
QemuOpt *opt;
@@ -563,6 +641,16 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
return opt->value.boolean;
}
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+ bool ret = qemu_opt_get_bool(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt;
@@ -586,6 +674,18 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
return opt->value.uint;
}
+uint64_t qemu_opt_get_number_del(QemuOpts *opts,
+ const char *name,
+ uint64_t defval)
+{
+ uint64_t ret = qemu_opt_get_number(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
{
QemuOpt *opt;
@@ -608,6 +708,17 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
return opt->value.uint;
}
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+ uint64_t defval)
+{
+ uint64_t ret = qemu_opt_get_size(opts, name, defval);
+ QemuOpt *opt = qemu_opt_find(opts, name);
+ if (opt) {
+ qemu_opt_del(opt);
+ }
+ return ret;
+}
+
static void qemu_opt_parse(QemuOpt *opt, Error **errp)
{
if (opt->desc == NULL)
@@ -1261,3 +1372,23 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
loc_pop(&loc);
return rc;
}
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+ if (!list)
+ return;
+
+ g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+ int i;
+ printf("Supported options:\n");
+ for (i = 0; list && list->desc[i].name; i++) {
+ printf("%-16s %s\n", list->desc[i].name,
+ list->desc[i].help ?
+ list->desc[i].help : "");
+ }
+}
--
1.6.0.2
next prev parent reply other threads:[~2014-01-20 14:20 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-20 14:19 [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 01/25] add def_value_str to QemuOptDesc Chunyan Liu
2014-01-22 13:25 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 02/25] qapi: output def_value_str when query command line options Chunyan Liu
2014-01-20 15:53 ` Eric Blake
2014-01-20 14:19 ` [Qemu-devel] [v19 03/25] improve some functions in qemu-option.c Chunyan Liu
2014-01-22 13:33 ` Kevin Wolf
2014-01-20 14:19 ` Chunyan Liu [this message]
2014-01-22 13:57 ` [Qemu-devel] [v19 04/25] add some QemuOpts functions for replace work Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 05/25] change block layer to support both QemuOpts and QEMUOptionParameter Chunyan Liu
2014-01-22 14:19 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 06/25] cow.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-01-22 14:20 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 07/25] gluster.c: " Chunyan Liu
2014-01-22 13:10 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 08/25] iscsi.c: replace QEMUOptionParamter " Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 09/25] qcow.c: " Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 10/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in create Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 11/25] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 12/25] qed.c: replace QEMUOptionParameter with QemuOpts Chunyan Liu
2014-01-22 14:24 ` Kevin Wolf
2014-01-20 14:19 ` [Qemu-devel] [v19 13/25] raw-posix.c: " Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 14/25] raw-win32.c: " Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 15/25] rbd.c: " Chunyan Liu
2014-01-20 14:19 ` [Qemu-devel] [v19 16/25] sheepdog.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 17/25] ssh.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 18/25] vdi.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 19/25] vmdk.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 20/25] vpc.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 21/25] raw_bsd.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 22/25] vhdx.c: " Chunyan Liu
2014-01-22 14:26 ` Kevin Wolf
2014-01-20 14:20 ` [Qemu-devel] [v19 23/25] vvfat.c: " Chunyan Liu
2014-01-20 14:20 ` [Qemu-devel] [v19 24/25] cleanup QEMUOptionParameter Chunyan Liu
2014-01-22 14:33 ` Kevin Wolf
2014-01-20 14:20 ` [Qemu-devel] [v19 25/25] change back to original name from bdrv_create2 to bdrv_create Chunyan Liu
2014-01-22 14:35 ` [Qemu-devel] [v19 00/25] replace QEMUOptionParameter with QemuOpts Kevin Wolf
2014-01-22 16:11 ` Stefan Hajnoczi
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=1390227608-7225-5-git-send-email-cyliu@suse.com \
--to=cyliu@suse.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=wdongxu@linux.vnet.ibm.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).