From patchwork Sun Oct 14 12:51:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 191342 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 F3B7E2C0095 for ; Sun, 14 Oct 2012 23:55:49 +1100 (EST) Received: from localhost ([::1]:33808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNjQ-0005OJ-1t for incoming@patchwork.ozlabs.org; Sun, 14 Oct 2012 08:55:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNg1-00057j-Cz for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNNg0-0003a7-DD for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:17 -0400 Received: from mail-da0-f45.google.com ([209.85.210.45]:42438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNg0-0003Zt-6j for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:16 -0400 Received: by mail-da0-f45.google.com with SMTP id n15so2087935dad.4 for ; Sun, 14 Oct 2012 05:52:15 -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=reRXc1uvv7/Lb+lHQVjo7wp6Vl7LQ+OazXOiTfOMsl+LMnNqR5HIVs6VhitaCs57N2 Y6rgbmSsEcTYcZGjYVnhI8sBitPHwpV2E56ZNgeVK6T3SZ5d7/XPSyk3cbyEZc0tyk/V 5s+rgSN9g7hvDf0d4t1PK/NDa20iUKRIiGGRkuCA/ZQp9rEZsb0+Y0byNCm7fmEJiT+A Ut7oiNH/QIC/wgKK3Ee0OFh1ZgDOk3fQAHWMQFu2mqq+c+eznxWh6JGxpBV9LnSnjijW gBBhNrAYeY4FgRqdtW695FTbsYwo2FKcGKkmkcYxKmSs8GglYEpBzZ9bQY5IC30V1aVn 1jNQ== Received: by 10.68.232.131 with SMTP id to3mr29295552pbc.58.1350219135416; Sun, 14 Oct 2012 05:52:15 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id nt7sm7447649pbb.33.2012.10.14.05.52.12 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Oct 2012 05:52:14 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Sun, 14 Oct 2012 20:51:32 +0800 Message-Id: <1350219095-3378-8-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1350219095-3378-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1350219095-3378-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.210.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V3 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 {