Add JSON output to qemu-img info
v8 cover Add JSON output to qemu-img info
This patchset add a JSON output mode to the qemu-img info command. It's a rewrite from scratch of the original patchset by Wenchao Xia following Anthony Liguori advices on JSON formating.
the --output=(json|human) option is now mandatory on the command line.
Benoît Canet (3):
qapi: Add SnapshotInfo.
qapi: Add ImageInfo.
qemu-img: Add json output option to the info command.
in v2:
eblake: make some field optionals
squash the two qapi patchs together
fix a typo on vm_clock_nsec
bcanet: fix a potential memory leak
in v3:
lcapitulino:
remove unneeded test
put '\n' at the end of json in printf statement drop the uneeded head pointer in collect_snapshots
in v4:
Wenchao Xia && Kevin Wolf: -Refactor to separate rate ImageInfo
collection from human printing.
Kevin Wolf: -Use --output=(json|human).
-make the two choice exclusive and print a message if none is specified.
-cosmetic '=' alignement in collect snapshots.
Benoît Canet: -add full-backing-filename to the ImageInfo structure
(needed for human printing)
-make ImageInfo->actual_size optional depending on the context.
in v5:
Eric Blake: -use a constant for getopt parsing to avoid future
short options collision.
-make the command default to --output=human. -fix spurious whitespace change.
-split vm-clock-nsec in two fields vm-clock-sec and
vm-clock-nsec.
-declare JSON structure as "Since 1.3"
in v6:
Blue Swirl: -Add missing const in getopt structure declaration.
Eric Blake: -Remove spurious undef.
-Use an enum instead of two boolean.
in v7:
Kevin Wolf: -Add missing documentation.
-Change bogus comment about chained lists support in qapi. -Remove collect_backing_file_format and use bs->backing_format instead. -Remove uneeded if.
-Change bogus printing logic for backing file format. -Rename Format enum to OutputFormat.
-Use OFORMAT_HUMAN by default and get rid of uneeded else branch -Use error_report insted of fprintf.
-Use a switch instead of ifs.
Benoît Canet: Rename FORMAT_HUMAN and FORMAT_JSON to OFORMAT_JSON and OFORMAT_HUMAN
in v8:
Kevin Wolf: -Check bs->backing_format[0] value to conditionaly include the format.
-print the backing format if available in human output. -Move g_new0 down so we don't have the free it on error. -better documentation via @code usage.
Benoît Canet (2):
qapi: Add SnapshotInfo and ImageInfo.
qemu-img: Add json output option to the info command.
Makefile | 3 +- qapi-schema.json | 64 +++++++++++++++ qemu-img-cmds.hx | 4 +- qemu-img.c | 236 ++++++++++++++++++++++++++++++++++++++++++++---------- qemu-img.texi | 5 +- 5 files changed, 263 insertions(+), 49 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v8 1/2 qapi: Add SnapshotInfo and ImageInfo.
--- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
qapi-schema.json +64 -0
@@ -156,6 +156,70 @@ 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog' ] } ## +# @SnapshotInfo +# +# @id: unique snapshot id +# +# @name: user chosen name +# +# @vm-state-size: size of the VM state +# +# @date-sec: UTC date of the snapshot in seconds +# +# @date-nsec: fractional part in nano seconds to be used with date-sec +# +# @vm-clock-sec: VM clock relative to boot in seconds +# +# @vm-clock-nsec: fractional part in nano seconds to be used with vm-clock-sec +# +# Since: 1.3 +# +## + +{ 'type': 'SnapshotInfo', + 'data': { 'id': 'str', 'name': 'str', 'vm-state-size': 'int', + 'date-sec': 'int', 'date-nsec': 'int', + 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } } + +## +# @ImageInfo: +# +# Information about a QEMU image file +# +# @filename: name of the image file +# +# @format: format of the image file +# +# @virtual-size: maximum capacity in bytes of the image +# +# @actual-size: #optional actual size on disk in bytes of the image +# +# @dirty-flag: #optional true if image is not cleanly closed +# +# @cluster-size: #optional size of a cluster in bytes +# +# @encrypted: #optional true if the image is encrypted +# +# @backing-filename: #optional name of the backing file +# +# @full-backing-filename: #optional full path of the backing file +# +# @backing-filename-format: #optional the format of the backing file +# +# @snapshots: #optional list of VM snapshots +# +# Since: 1.3 +# +## + +{ 'type': 'ImageInfo', + 'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool', + '*actual-size': 'int', 'virtual-size': 'int', + '*cluster-size': 'int', '*encrypted': 'bool', + '*backing-filename': 'str', '*full-backing-filename': 'str', + '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } } + +## # @StatusInfo: # # Information about VCPU run state
Signature · 1 line
1.7.9.5
PATCH v8 2/2 qemu-img: Add json output option to the info command.
In reply to Benoît CanetThis 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
}--- Makefile | 3 +- qemu-img-cmds.hx | 4 +- qemu-img.c | 236 ++++++++++++++++++++++++++++++++++++++++++++---------- qemu-img.texi | 5 +- 4 files changed, 199 insertions(+), 49 deletions(-)
Makefile +2 -1
@@ -157,7 +157,8 @@ tools-obj-y = $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \ iohandler.o cutils.o iov.o async.o tools-obj-$(CONFIG_POSIX) += compatfd.o -qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) +qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) $(qapi-obj-y) \ + qapi-visit.o qapi-types.o qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
qemu-img-cmds.hx +2 -2
@@ -34,9 +34,9 @@ STEXI ETEXI DEF("info", img_info, - "info [-f fmt] filename") + "info [-f fmt] [--output=ofmt] filename") STEXI -@item info [-f @var{fmt}] @var{filename} +@item info [-f @var{fmt}] [--output=@var{ofmt}] @var{filename} ETEXI DEF("snapshot", img_snapshot,
qemu-img.c +192 -44
285 lines not on this page · raw message
qemu-img.texi +3 -2
@@ -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 @code{human} or @code{json}. @item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot} ] @var{filename}
Signature · 1 line
1.7.9.5
Kevin Wolf
AppliedAm 05.09.2012 13:09, schrieb Benoît Canet:
Quoted 10 lines
This patchset add a JSON output mode to the qemu-img info command. It's a rewrite from scratch of the original patchset by Wenchao Xia following Anthony Liguori advices on JSON formating.
the --output=(json|human) option is now mandatory on the command line.
Benoît Canet (3):
qapi: Add SnapshotInfo.
qapi: Add ImageInfo.
qemu-img: Add json output option to the info command.
Thanks, applied both to block-next.
Kevin