[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v25 09/31] QemuOpts: add qemu_opts_append to replace
From: |
Chunyan Liu |
Subject: |
[Qemu-devel] [PATCH v25 09/31] QemuOpts: add qemu_opts_append to replace append_option_parameters |
Date: |
Fri, 11 Apr 2014 01:54:05 +0800 |
For later merge .create_opts of drv and proto_drv in qemu-img commands.
Reviewed-by: Leandro Dorileo <address@hidden>
Signed-off-by: Chunyan Liu <address@hidden>
---
include/qemu/option.h | 5 ++++
util/qemu-option.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 4e637b5..88c4733 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -175,5 +175,10 @@ void qemu_opts_print_help(QemuOptsList *list);
void qemu_opts_free(QemuOptsList *list);
QEMUOptionParameter *opts_to_params(QemuOpts *opts);
QemuOptsList *params_to_opts(QEMUOptionParameter *list);
+/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+ QemuOptsList *list,
+ QEMUOptionParameter *param);
#endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index d658505..d1e4d94 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1498,3 +1498,68 @@ void qemu_opts_free(QemuOptsList *list)
g_free(list);
}
+
+/* Realloc dst option list and append options either from an option list (list)
+ * or a QEMUOptionParameter (param) to it. dst could be NULL or a malloced
list.
+ * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+ QemuOptsList *list,
+ QEMUOptionParameter *param)
+{
+ size_t num_opts, num_dst_opts;
+ QemuOptsList *tmp_list = NULL;
+ QemuOptDesc *desc;
+ bool need_init = false;
+
+ assert(!(list && param));
+ if (!param && !list) {
+ return dst;
+ }
+
+ if (param) {
+ list = tmp_list = params_to_opts(param);
+ }
+
+ /* If dst is NULL, after realloc, some area of dst should be initialized
+ * before adding options to it.
+ */
+ if (!dst) {
+ need_init = true;
+ }
+
+ num_opts = count_opts_list(dst);
+ num_dst_opts = num_opts;
+ num_opts += count_opts_list(list);
+ dst = g_realloc(dst, sizeof(QemuOptsList) +
+ (num_opts + 1) * sizeof(QemuOptDesc));
+ if (need_init) {
+ dst->name = NULL;
+ dst->implied_opt_name = NULL;
+ QTAILQ_INIT(&dst->head);
+ dst->allocated = true;
+ }
+ dst->desc[num_dst_opts].name = NULL;
+
+ /* (const char *) members of result dst are malloced, need free. */
+ assert(dst->allocated);
+ /* append list->desc to dst->desc */
+ if (list) {
+ desc = list->desc;
+ while (desc && desc->name) {
+ if (find_desc_by_name(dst->desc, desc->name) == NULL) {
+ dst->desc[num_dst_opts].name = g_strdup(desc->name);
+ dst->desc[num_dst_opts].type = desc->type;
+ dst->desc[num_dst_opts].help = g_strdup(desc->help);
+ dst->desc[num_dst_opts].def_value_str =
+ g_strdup(desc->def_value_str);
+ num_dst_opts++;
+ dst->desc[num_dst_opts].name = NULL;
+ }
+ desc++;
+ }
+ }
+
+ g_free(tmp_list);
+ return dst;
+}
--
1.7.12.4
- Re: [Qemu-devel] [PATCH v25 04/31] QemuOpts: change opt->name|str from (const char *) to (char *), (continued)
- [Qemu-devel] [PATCH v25 01/31] QemuOpts: move find_desc_by_name ahead for later calling, Chunyan Liu, 2014/04/11
- [Qemu-devel] [PATCH v25 03/31] qapi: output def_value_str when query command line options, Chunyan Liu, 2014/04/11
- [Qemu-devel] [PATCH v25 06/31] QemuOpts: add qemu_opt_get_*_del functions for replace work, Chunyan Liu, 2014/04/11
- [Qemu-devel] [PATCH v25 07/31] QemuOpts: add qemu_opts_print_help to replace print_option_help, Chunyan Liu, 2014/04/11
- [Qemu-devel] [PATCH v25 09/31] QemuOpts: add qemu_opts_append to replace append_option_parameters,
Chunyan Liu <=
- [Qemu-devel] [PATCH v25 08/31] QemuOpts: add conversion between QEMUOptionParameter to QemuOpts, Chunyan Liu, 2014/04/11
- [Qemu-devel] [PATCH v25 11/31] change block layer to support both QemuOpts and QEMUOptionParamter, Chunyan Liu, 2014/04/11