From patchwork Thu Feb 28 09:20:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 223840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8FF502C0094 for ; Thu, 28 Feb 2013 20:22:06 +1100 (EST) Received: from localhost ([::1]:35453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAzgi-0000OP-M6 for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2013 04:22:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAzgF-0000ED-Eo for qemu-devel@nongnu.org; Thu, 28 Feb 2013 04:21:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAzgE-0001Bm-1B for qemu-devel@nongnu.org; Thu, 28 Feb 2013 04:21:35 -0500 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:45138) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAzgD-0001BP-DO for qemu-devel@nongnu.org; Thu, 28 Feb 2013 04:21:33 -0500 Received: from /spool/local by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Feb 2013 19:15:05 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp02.au.ibm.com (202.81.31.208) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 28 Feb 2013 19:15:02 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 32EB23578051 for ; Thu, 28 Feb 2013 20:21:21 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1S9LIWH62980334 for ; Thu, 28 Feb 2013 20:21:18 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1S9LKF7022556 for ; Thu, 28 Feb 2013 20:21:20 +1100 Received: from localhost.localdomain ([9.181.129.58]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1S9LGCL022499; Thu, 28 Feb 2013 20:21:18 +1100 From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2013 17:20:33 +0800 Message-Id: <1362043236-4635-2-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1362043236-4635-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1362043236-4635-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022809-5490-0000-0000-000003096002 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.144 Cc: kwolf@redhat.com, Dong Xu Wang , armbru@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH V12 1/4] add def_value_str and use it in qemu_opts_print 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 qemu_opts_print has no user now, so can re-write the function safely. qemu_opts_print will be used while using "qemu-img create", it will produce the same output as previous code. The behavior of this function has changed: 1. Print every possible option, whether a value has been set or not. 2. Option descriptors may provide a default value. 3. Print to stdout instead of stderr. Previously the behavior was to print every option that has been set. Options that have not been set would be skipped. Signed-off-by: Dong Xu Wang --- v11->v12 1) make def_value_str become the real default value string in opt_set function. v10->v11: 1) print all values that have actually been assigned while accept-any cases. v7->v8: 1) print "elements => accept any params" while opts_accepts_any() == true. 2) since def_print_str is the default value if an option isn't set, so rename it to def_value_str. include/qemu/option.h | 1 + util/qemu-option.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index ba197cd..394170a 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -96,6 +96,7 @@ typedef struct QemuOptDesc { const char *name; enum QemuOptType type; const char *help; + const char *def_value_str; } QemuOptDesc; struct QemuOptsList { diff --git a/util/qemu-option.c b/util/qemu-option.c index 5a1d03c..dbb77b9 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -646,6 +646,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value, } opt->desc = desc; opt->str = g_strdup(value); + opt->str = g_strdup(value ?: desc->def_value_str); qemu_opt_parse(opt, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); @@ -863,13 +864,33 @@ void qemu_opts_del(QemuOpts *opts) int qemu_opts_print(QemuOpts *opts, void *dummy) { QemuOpt *opt; + QemuOptDesc *desc = opts->list->desc; - fprintf(stderr, "%s: %s:", opts->list->name, - opts->id ? opts->id : ""); - QTAILQ_FOREACH(opt, &opts->head, next) { - fprintf(stderr, " %s=\"%s\"", opt->name, opt->str); + if (desc[0].name == NULL) { + QTAILQ_FOREACH(opt, &opts->head, next) { + printf("%s=\"%s\" ", opt->name, opt->str); + } + return 0; + } + for (; desc && desc->name; desc++) { + const char *value = desc->def_value_str; + QemuOpt *opt; + + opt = qemu_opt_find(opts, desc->name); + if (opt) { + value = opt->str; + } + + if (!value) { + continue; + } + + if (desc->type == QEMU_OPT_STRING) { + printf("%s='%s' ", desc->name, value); + } else { + printf("%s=%s ", desc->name, value); + } } - fprintf(stderr, "\n"); return 0; }