From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
qemu-block@nongnu.org, Jeff Cody <jcody@redhat.com>,
Peter Lieven <pl@kamp.de>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output
Date: Tue, 24 Nov 2015 13:45:49 +0100 [thread overview]
Message-ID: <87y4dn36rm.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <56544F43.3090603@redhat.com> (Paolo Bonzini's message of "Tue, 24 Nov 2015 12:51:31 +0100")
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 24/11/2015 06:22, Fam Zheng wrote:
>> case OFORMAT_JSON:
>> - printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64", \"depth\": %d,"
>> - " \"zero\": %s, \"data\": %s",
>> - (e->start == 0 ? "[" : ",\n"),
>> - e->start, e->length, e->depth,
>> - (e->flags & BDRV_BLOCK_ZERO) ? "true" : "false",
>> - (e->flags & BDRV_BLOCK_DATA) ? "true" : "false");
>> + if (e->start == 0) {
>> + printf("[");
>> + } else {
>> + printf(",");
>> + }
>> +
>> + dict = qdict_new();
>> + qdict_put(dict, "start", qint_from_int(e->start));
>> + qdict_put(dict, "length", qint_from_int(e->length));
>> + qdict_put(dict, "depth", qint_from_int(e->depth));
>> + qdict_put(dict, "zero", qbool_from_bool(e->flags & BDRV_BLOCK_ZERO));
>> + qdict_put(dict, "data", qbool_from_bool(e->flags & BDRV_BLOCK_DATA));
>> if (e->flags & BDRV_BLOCK_OFFSET_VALID) {
>> - printf(", \"offset\": %"PRId64"", e->offset);
>> + qdict_put(dict, "offset", qint_from_int(e->offset));
>> }
>> - putchar('}');
>> + str = qobject_to_json(QOBJECT(dict));
>> + printf("%s\n", qstring_get_str(str));
>
> I think it's better if you use QAPI for this. You can make MapEntry a
> QAPI struct and generate the QObject through a QMP visitor.
>
> The reason is that we could add JSON visitors that let us parse or
> produce JSON without going through the expensive QObject creation. Even
> though that is far away, the least explicit QObject manipulation we
> have, the better.
I concur.
Manual messing with QDict is of course fine when a higher-level
interface doesn't fit. But here, we serialize a struct to JSON, and
that's something QAPI is meant to do. Having to define a QAPI type may
be a bit of a bother, but once that's done, the "serialize this struct
to JSON" code becomes less tedious. qemu-img.c already has a few
examples; search for qmp_output_visitor_new().
next prev parent reply other threads:[~2015-11-24 12:46 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-24 5:21 [Qemu-devel] [PATCH for-2.6 00/14] qemu-img map: Allow driver to return file of the allocated block Fam Zheng
2015-11-24 5:21 ` [Qemu-devel] [PATCH for-2.6 01/14] block: Add "file" output parameter to block status query functions Fam Zheng
2015-11-24 5:30 ` Eric Blake
2015-11-24 5:42 ` Fam Zheng
2015-11-24 11:47 ` Paolo Bonzini
2015-11-24 12:50 ` Fam Zheng
2015-11-24 12:51 ` Paolo Bonzini
2015-11-24 13:01 ` Fam Zheng
2015-11-24 5:21 ` [Qemu-devel] [PATCH for-2.6 02/14] qcow: Assign bs->file->bs to file in qcow_co_get_block_status Fam Zheng
2015-11-24 15:28 ` Eric Blake
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 03/14] qcow2: Assign bs->file->bs to file in qcow2_co_get_block_status Fam Zheng
2015-11-24 16:00 ` Eric Blake
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 04/14] raw: Assign bs to file in raw_co_get_block_status Fam Zheng
2015-11-24 16:37 ` Eric Blake
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 05/14] iscsi: Assign bs to file in iscsi_co_get_block_status Fam Zheng
2015-11-24 18:30 ` Eric Blake
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 06/14] parallels: Assign bs->file->bs to file in parallels_co_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 07/14] qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 08/14] sheepdog: Assign bs to file in sd_co_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 09/14] vdi: Assign bs->file->bs to file in vdi_co_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 10/14] vpc: Assign bs->file->bs to file in vpc_co_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 11/14] vmdk: Return extent's file in bdrv_get_block_status Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output Fam Zheng
2015-11-24 5:42 ` Eric Blake
2015-11-24 6:00 ` Fam Zheng
2015-11-24 11:51 ` Paolo Bonzini
2015-11-24 12:45 ` Markus Armbruster [this message]
2015-11-24 13:25 ` Fam Zheng
2015-11-24 13:30 ` Fam Zheng
2015-11-24 13:35 ` Paolo Bonzini
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 13/14] qemu-img: In "map" output, support external file name Fam Zheng
2015-11-24 5:22 ` [Qemu-devel] [PATCH for-2.6 14/14] iotests: Add "qemu-img map" test for VMDK extents Fam Zheng
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=87y4dn36rm.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.