From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Svr3j-0003bk-4E for qemu-devel@nongnu.org; Mon, 30 Jul 2012 10:35:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Svr3d-00042b-5d for qemu-devel@nongnu.org; Mon, 30 Jul 2012 10:34:59 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:41871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Svr3c-000429-TP for qemu-devel@nongnu.org; Mon, 30 Jul 2012 10:34:53 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 30 Jul 2012 15:34:50 +0100 Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6UEYF5m2576566 for ; Mon, 30 Jul 2012 15:34:15 +0100 Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6UE92gO025642 for ; Mon, 30 Jul 2012 10:09:02 -0400 Date: Mon, 30 Jul 2012 15:34:11 +0100 From: Stefan Hajnoczi Message-ID: <20120730143411.GB10211@stefanha-thinkpad.localdomain> References: <1343384448-21828-1-git-send-email-xiawenc@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1343384448-21828-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH] let qemu-img info genereate json output List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: pbonzini@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org On Fri, Jul 27, 2012 at 06:20:48PM +0800, Wenchao Xia wrote: > This patch would add option -j in qemu-img info command, which > would generate json output in stdout. > > Signed-off-by: Wenchao Xia > --- > qemu-img.c | 306 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- > 1 files changed, 264 insertions(+), 42 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index 80cfb9b..a514c17 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -33,6 +33,9 @@ > #include > #endif > > +#include "qint.h" > +#include "qjson.h" > + > typedef struct img_cmd_t { > const char *name; > int (*handler)(int argc, char **argv); > @@ -84,6 +87,7 @@ static void help(void) > " '-p' show progress of command (only certain commands)\n" > " '-S' indicates the consecutive number of bytes that must contain only zeros\n" > " for qemu-img to create a sparse image during conversion\n" > + " '-j' try get json output, which would be in stdout, only valid in info command\n" "try" makes it sound like this command can fail in some special way. Instead, I suggest: " '--format=json' show output in machine-parsable JSON (only for info command)" > "\n" > "Parameters to check subcommand:\n" > " '-r' tries to repair any inconsistencies that are found during the check.\n" > @@ -1102,21 +1106,210 @@ static void dump_snapshots(BlockDriverState *bs) > g_free(sn_tab); > } > > +/* string must be allocated on heap */ > +struct img_infos { > + char *filename; > + char *fmt; > + uint64_t total_sectors; > + int64_t allocated_size; > + int32 enc_flag; > + BlockDriverInfo *bdi; > + char *backing_filename; > + char *backing_filename_full; > + QEMUSnapshotInfo *sn_tab; > + int nb_sns; > +}; > + > +static void img_infos_init(struct img_infos *pinfo) > +{ > + memset(pinfo, 0, sizeof(struct img_infos)); > +} > + > +#define TRY_FREE(p) { \ > + if ((p) != NULL) { \ > + g_free((p)); \ > + (p) = NULL; \ > + } \ > +} This is not necessary because free(NULL) is a nop. Stefan