From patchwork Thu Apr 3 09:54:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 336561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EA67C1400AE for ; Thu, 3 Apr 2014 20:54:37 +1100 (EST) Received: from localhost ([::1]:42971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVeLz-0002xT-V5 for incoming@patchwork.ozlabs.org; Thu, 03 Apr 2014 05:54:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVeLF-0002hZ-Nf for qemu-devel@nongnu.org; Thu, 03 Apr 2014 05:53:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVeL8-0006jH-Vf for qemu-devel@nongnu.org; Thu, 03 Apr 2014 05:53:49 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:56776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVeL8-0006iz-Nj for qemu-devel@nongnu.org; Thu, 03 Apr 2014 05:53:42 -0400 Received: from linux-cyliu.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (NOT encrypted); Thu, 03 Apr 2014 03:53:38 -0600 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Thu, 3 Apr 2014 17:54:27 +0800 Message-Id: <1396518889-21681-10-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1396518889-21681-1-git-send-email-cyliu@suse.com> References: <1396518889-21681-1-git-send-email-cyliu@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.26 Cc: l@dorileo.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v24 09/31] QemuOpts: add qemu_opts_append to replace append_option_parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For later merge .create_opts of drv and proto_drv in qemu-img commands. Reviewed-by: Leandro Dorileo Signed-off-by: Chunyan Liu --- Changes: * some fixes for spelling and space 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 32e13d1..c9df671 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; +}