From patchwork Thu Jan 24 10:23:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Xu Wang X-Patchwork-Id: 215309 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 95F652C007C for ; Thu, 24 Jan 2013 21:46:01 +1100 (EST) Received: from localhost ([::1]:43498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyJyi-0004Se-Te for incoming@patchwork.ozlabs.org; Thu, 24 Jan 2013 05:24:16 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyJxy-0002di-Im for qemu-devel@nongnu.org; Thu, 24 Jan 2013 05:23:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyJxr-0008Hk-Ju for qemu-devel@nongnu.org; Thu, 24 Jan 2013 05:23:30 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:43727) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyJxq-0008GY-UL for qemu-devel@nongnu.org; Thu, 24 Jan 2013 05:23:23 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 24 Jan 2013 15:51:28 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 24 Jan 2013 15:51:25 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id D05D5125804E for ; Thu, 24 Jan 2013 15:53:42 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0OANFiU7602520 for ; Thu, 24 Jan 2013 15:53:15 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0OANH9K018055 for ; Thu, 24 Jan 2013 21:23:17 +1100 Received: from dong-T410.cn.ibm.com (dong-t410.cn.ibm.com [9.115.118.84]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0OANE7v017931; Thu, 24 Jan 2013 21:23:16 +1100 From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 24 Jan 2013 18:23:03 +0800 Message-Id: <1359022987-6274-2-git-send-email-wdongxu@vnet.linux.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359022987-6274-1-git-send-email-wdongxu@vnet.linux.ibm.com> References: <1359022987-6274-1-git-send-email-wdongxu@vnet.linux.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13012410-8878-0000-0000-000005A4B6FE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.7 Cc: kwolf@redhat.com, Dong Xu Wang , stefanha@redhat.com Subject: [Qemu-devel] [PATCH V11 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 --- 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 | 30 +++++++++++++++++++++++++----- 2 files changed, 26 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 f532b76..1aed418 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -863,13 +863,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; }