From patchwork Thu Oct 25 12:57:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 194146 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 032522C0091 for ; Thu, 25 Oct 2012 23:59:58 +1100 (EST) Received: from localhost ([::1]:44073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN2S-0000km-AO for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2012 08:59:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN10-0007HQ-Gx for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRN0u-0005Pt-Hw for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:26 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:64306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN0u-0005MJ-Ch for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:20 -0400 Received: by mail-ob0-f173.google.com with SMTP id wc18so1460065obb.4 for ; Thu, 25 Oct 2012 05:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ouirrv3alCh9GQo7XC6exlqF3vxOtkYL2AJgkCWGCVs=; b=nsqtgnHX6IS+enTs44+915T5GPZaXmeKyHIoQm8xjpucDg1HRckcOroAL5ZHXUhhUZ J0VOhMNBI10zuNZfPotHpnhQoHkUjBRwMo9+sg/nis0Oi8rnMKICJc5+qzl5rRL2SmOx IW3F2CtBJ/v6GwpREnGQEUUH1qxBoZC0yBewyT4pYY6gIZObP8S+5xJhHQsO2JpjgROD HKEK6tpFkCi/dTAmUyJZuv7+C4Bq69Si/ckMqQhAtVOZWxPr0+dAr0TAofgBJO9Xtl6O hCXBs46DzOk8X5lfuqVu7yV2q4ZH0GwEiQvZaeE01G3EyGN+3/B5V/3XtdVAH6CPjZIa meGA== Received: by 10.60.23.199 with SMTP id o7mr14927168oef.20.1351169900032; Thu, 25 Oct 2012 05:58:20 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id k9sm6019404oeg.6.2012.10.25.05.58.17 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Oct 2012 05:58:19 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2012 20:57:25 +0800 Message-Id: <1351169848-28223-8-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1351169848-28223-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1351169848-28223-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.173 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V4 07/10] add def_value 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 I re-write it and use it in qemu-img.c. qemu_opts_print will be used while using "qemu-img create", it will produce the same output as previous code. Signed-off-by: Dong Xu Wang --- qemu-option.c | 41 ++++++++++++++++++++++++++++++++--------- qemu-option.h | 1 + 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index eeb2c9c..54dbdd0 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -860,15 +860,38 @@ void qemu_opts_del(QemuOpts *opts) int qemu_opts_print(QemuOpts *opts, void *dummy) { - QemuOpt *opt; - - 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); - } - fprintf(stderr, "\n"); - return 0; + QemuOpt *opt = NULL; + QemuOptDesc *desc = opts->list->desc; + + while (desc && desc->name) { + opt = qemu_opt_find(opts, desc->name); + switch (desc->type) { + case QEMU_OPT_STRING: + if (opt != NULL) { + printf("%s='%s' ", opt->name, opt->str); + } + break; + case QEMU_OPT_BOOL: + printf("%s=%s ", desc->name, (opt && opt->str) ? "on" : "off"); + break; + case QEMU_OPT_NUMBER: + case QEMU_OPT_SIZE: + if (strcmp(desc->name, "cluster_size")) { + printf("%s=%" PRId64 " ", desc->name, + (opt && opt->value.uint) ? opt->value.uint : 0); + } else { + printf("%s=%" PRId64 " ", desc->name, + (opt && opt->value.uint) ? + opt->value.uint : desc->def_value); + } + break; + default: + printf("%s=(unknown type) ", desc->name); + break; + } + desc++; + } + return 0; } static int opts_do_parse(QemuOpts *opts, const char *params, diff --git a/qemu-option.h b/qemu-option.h index 002dd07..9ea59cf 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -96,6 +96,7 @@ typedef struct QemuOptDesc { const char *name; enum QemuOptType type; const char *help; + uint64_t def_value; } QemuOptDesc; struct QemuOptsList {