qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Benoît Canet" <benoit@irqsave.net>
Cc: stefanha@linux.vnet.ibm.com, qemu-devel@nongnu.org,
	blauwirbel@gmail.com, pbonzini@redhat.com, eblake@redhat.com,
	xiawenc@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH V7 2/2] qemu-img: Add json output option to the info command.
Date: Wed, 05 Sep 2012 11:41:06 +0200	[thread overview]
Message-ID: <50471E32.9090901@redhat.com> (raw)
In-Reply-To: <1346837144-22881-3-git-send-email-benoit@irqsave.net>

Am 05.09.2012 11:25, schrieb Benoît Canet:
> This option --output=[human|json] make qemu-img info output on
> human or JSON representation at the choice of the user.
> 
> 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
> }
> 
> Signed-off-by: Benoit Canet <benoit@irqsave.net>

Looks much better, but I still have a few comments:

> +    bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
> +    if (backing_filename[0] != '\0') {
> +        info->backing_filename = g_strdup(backing_filename);
> +        info->has_backing_filename = true;
> +        bdrv_get_full_backing_filename(bs, backing_filename2,
> +                                       sizeof(backing_filename2));
> +
> +        if (strcmp(backing_filename, backing_filename2) != 0) {
> +            info->full_backing_filename =
> +                        g_strdup(backing_filename2);
> +             info->has_full_backing_filename = true;
> +        }
> +
> +        info->backing_filename_format = bs->backing_format;
> +        info->has_backing_filename_format = 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 = argv[optind++];
>  
> +    if (output && !strcmp(output, "json")) {
> +        output_format = OFORMAT_JSON;
> +    } else if (output && !strcmp(output, "human")) {
> +        output_format = OFORMAT_HUMAN;
> +    } else if (output) {
> +        error_report("--output must be used with human or json as argument.");
> +        return 1;
> +    }
> +
> +    info = g_new0(ImageInfo, 1);
>      bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING);
>      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 image,
>  however the path, image format, etc may differ.
>  
> -@item info [-f @var{fmt}] @var{filename}
> +@item info [-f @var{fmt}] [--output=@var{ofmt}] @var{filename}
>  
>  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

      reply	other threads:[~2012-09-05  9:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05  9:25 [Qemu-devel] [PATCH V7 0/2] Add JSON output to qemu-img info Benoît Canet
2012-09-05  9:25 ` [Qemu-devel] [PATCH V7 1/2] qapi: Add SnapshotInfo and ImageInfo Benoît Canet
2012-09-05  9:25 ` [Qemu-devel] [PATCH V7 2/2] qemu-img: Add json output option to the info command Benoît Canet
2012-09-05  9:41   ` Kevin Wolf [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50471E32.9090901@redhat.com \
    --to=kwolf@redhat.com \
    --cc=benoit@irqsave.net \
    --cc=blauwirbel@gmail.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=xiawenc@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).