[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to
From: |
Markus Armbruster |
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 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Paolo Bonzini <address@hidden> 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().
- [Qemu-devel] [PATCH for-2.6 06/14] parallels: Assign bs->file->bs to file in parallels_co_get_block_status, (continued)
- [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
- [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
- [Qemu-devel] [PATCH for-2.6 08/14] sheepdog: Assign bs to file in sd_co_get_block_status, Fam Zheng, 2015/11/24
- [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
- [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
- [Qemu-devel] [PATCH for-2.6 11/14] vmdk: Return extent's file in bdrv_get_block_status, Fam Zheng, 2015/11/24
- [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Fam Zheng, 2015/11/24
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Eric Blake, 2015/11/24
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Paolo Bonzini, 2015/11/24
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output,
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Fam Zheng, 2015/11/24
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Fam Zheng, 2015/11/24
- Re: [Qemu-devel] [PATCH for-2.6 12/14] qemu-img: In 'map', use QDict to generate JSON output, Paolo Bonzini, 2015/11/24
[Qemu-devel] [PATCH for-2.6 13/14] qemu-img: In "map" output, support external file name, Fam Zheng, 2015/11/24
[Qemu-devel] [PATCH for-2.6 14/14] iotests: Add "qemu-img map" test for VMDK extents, Fam Zheng, 2015/11/24