From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T9C6q-00025h-Fb for qemu-devel@nongnu.org; Wed, 05 Sep 2012 05:41:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T9C6m-0004OU-4m for qemu-devel@nongnu.org; Wed, 05 Sep 2012 05:41:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5481) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T9C6l-0004ON-T2 for qemu-devel@nongnu.org; Wed, 05 Sep 2012 05:41:16 -0400 Message-ID: <50471E32.9090901@redhat.com> Date: Wed, 05 Sep 2012 11:41:06 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <1346837144-22881-1-git-send-email-benoit@irqsave.net> <1346837144-22881-3-git-send-email-benoit@irqsave.net> In-Reply-To: <1346837144-22881-3-git-send-email-benoit@irqsave.net> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V7 2/2] qemu-img: Add json output option to the info command. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-15?Q?Beno=EEt_Canet?= Cc: stefanha@linux.vnet.ibm.com, qemu-devel@nongnu.org, blauwirbel@gmail.com, pbonzini@redhat.com, eblake@redhat.com, xiawenc@linux.vnet.ibm.com Am 05.09.2012 11:25, schrieb Beno=EEt Canet: > This option --output=3D[human|json] make qemu-img info output on > human or JSON representation at the choice of the user. >=20 > example: > { > "snapshots": [ > { > "vm-clock-nsec": 637102488, > "name": "vm-20120821145509", > "date-sec": 1345553709, > "date-nsec": 220289000, > "vm-clock-sec": 20, > "id": "1", > "vm-state-size": 96522745 > }, > { > "vm-clock-nsec": 28210866, > "name": "vm-20120821154059", > "date-sec": 1345556459, > "date-nsec": 171392000, > "vm-clock-sec": 46, > "id": "2", > "vm-state-size": 101208714 > } > ], > "virtual-size": 1073741824, > "filename": "snap.qcow2", > "cluster-size": 65536, > "format": "qcow2", > "actual-size": 985587712, > "dirty-flag": false > } >=20 > Signed-off-by: Benoit Canet Looks much better, but I still have a few comments: > + bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_fil= ename)); > + if (backing_filename[0] !=3D '\0') { > + info->backing_filename =3D g_strdup(backing_filename); > + info->has_backing_filename =3D true; > + bdrv_get_full_backing_filename(bs, backing_filename2, > + sizeof(backing_filename2)); > + > + if (strcmp(backing_filename, backing_filename2) !=3D 0) { > + info->full_backing_filename =3D > + g_strdup(backing_filename2); > + info->has_full_backing_filename =3D true; > + } > + > + info->backing_filename_format =3D bs->backing_format; > + info->has_backing_filename_format =3D true; I believe we should check bs->backing_format[0] first. If it's empty, don't include the format. > + } > +} > + > +static void dump_human_image_info(ImageInfo *info) > +{ > + char size_buf[128], dsize_buf[128]; > + if (!info->has_actual_size) { > + snprintf(dsize_buf, sizeof(dsize_buf), "unavailable"); > + } else { > + get_human_readable_size(dsize_buf, sizeof(dsize_buf), > + info->actual_size); > + } > + get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_= size); > + printf("image: %s\n" > + "file format: %s\n" > + "virtual size: %s (%" PRId64 " bytes)\n" > + "disk size: %s\n", > + info->filename, info->format, size_buf, > + info->virtual_size, > + dsize_buf); > + > + if (info->has_encrypted && info->encrypted) { > + printf("encrypted: yes\n"); > + } > + > + if (info->has_cluster_size) { > + printf("cluster_size: %" PRId64 "\n", info->cluster_size); > + } > + > + if (info->has_dirty_flag && info->dirty_flag) { > + printf("cleanly shut down: no\n"); > + } > + > + if (info->has_backing_filename) { > + printf("backing file: %s", info->backing_filename); > + if (info->has_full_backing_filename) { > + printf(" (actual path: %s)", info->full_backing_filename); > + } Maybe add the backing file format here if it's available? > @@ -1135,48 +1291,36 @@ static int img_info(int argc, char **argv) > } > filename =3D argv[optind++]; > =20 > + if (output && !strcmp(output, "json")) { > + output_format =3D OFORMAT_JSON; > + } else if (output && !strcmp(output, "human")) { > + output_format =3D OFORMAT_HUMAN; > + } else if (output) { > + error_report("--output must be used with human or json as argu= ment."); > + return 1; > + } > + > + info =3D g_new0(ImageInfo, 1); > bs =3D bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKI= NG); > if (!bs) { > + g_free(info); > return 1; > } If you move thee g_new0 below, you don't have to free here. > diff --git a/qemu-img.texi b/qemu-img.texi > index 6b42e35..75a7c8b 100644 > --- a/qemu-img.texi > +++ b/qemu-img.texi > @@ -129,12 +129,13 @@ created as a copy on write image of the specified= base image; the > @var{backing_file} should have the same content as the input's base im= age, > however the path, image format, etc may differ. > =20 > -@item info [-f @var{fmt}] @var{filename} > +@item info [-f @var{fmt}] [--output=3D@var{ofmt}] @var{filename} > =20 > Give information about the disk image @var{filename}. Use it in > particular to know the size reserved on disk which can be different > from the displayed size. If VM snapshots are stored in the disk image, > -they are displayed too. > +they are displayed too. The command can output in the format @var{ofmt= } > +which is either human or json. "...@code{human} or @code{json}" is better, I think. Kevin