Skip to contentSkip to conversation

Add JSON output to qemu-img info

PATCH Superseded Benoît Canet 1 participant 3 messages Aug 15, 2012 Kbuild

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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.

To use it simply add --machine=json to 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

Benoît Canet (2):
qapi: Add SnapshotInfo and ImageInfo.
qemu-img: Add json output option to the info command.

 Makefile         |    3 +-
 qapi-schema.json |   60 ++++++++++++++++++++++++
 qemu-img.c       |  138 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 189 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/2 qapi: Add SnapshotInfo and ImageInfo.

---
 qapi-schema.json |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
qapi-schema.json +60 -0
index a92adb1..fbf61e7 100644
@@ -126,6 +126,66 @@
             'running', 'save-vm', 'shutdown', 'suspended', 'watchdog' ] }
 
 ##
+# @SnapshotInfo
+#
+# @id: unique snapshot id
+#
+# @name: user choosen name
+#
+# @vm-state-size: size of the VM state
+#
+# @date-sec: UTC date of the snapshot
+#
+# @date-nsec: date in nano seconds
+#
+# @vm-clock-nsec: VM clock relative to boot in nano seconds
+#
+# Since: 1.2
+#
+##
+
+{ 'type': 'SnapshotInfo',
+  'data': { 'id': 'str', 'name': 'str', 'vm-state-size': 'int',
+            'date-sec': 'int', 'date-nsec': 'int',
+            'vm-clock-nsec': 'int' } }
+
+##
+# @ImageInfo:
+#
+# Information about a QEMU image file
+#
+# @filename: name of the image file
+#
+# @format: format of the image file
+#
+# @actual-size: actual size on disk in bytes of the image
+#
+# @virtual-size: maximum capacity 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
+#
+# @backing-filename-format: #optional the format of the backing file
+#
+# @snapshots: #optional list of VM snapshots
+#
+# Since: 1.2
+#
+##
+
+{ 'type': 'ImageInfo',
+  'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
+           'actual-size': 'int', 'virtual-size': 'int',
+           '*cluster-size': 'int', '*encrypted': 'bool',
+           '*backing-filename': 'str', '*backing-filename-format': 'str',
+           '*snapshots': ['SnapshotInfo'] } }
+
+##
 # @StatusInfo:
 #
 # Information about VCPU run state
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/2 qemu-img: Add json output option to the info command.

In reply to Benoît Canet

This additionnal --machine=json option make qemu-img info output on stdout a JSON formated representation of the image informations.

--machine=json was choosen instead of --format=json because the info command already have a -f parameter.

example:

{
    "backing-filename-format": "raw",
    "snapshots": [
        {
            "vm-clock-nsec": 4647590161,
            "name": "truc",
            "date-sec": 1345034924,
            "date-nsec": 870405000,
            "id": "1",
            "vm-state-size": 80805256
        },
        {
            "vm-clock-nsec": 7065282574,
            "name": "onx",
            "date-sec": 1345034927,
            "date-nsec": 914633000,
            "id": "2",
            "vm-state-size": 75927370
        },
        {
            "vm-clock-nsec": 10108695046,
            "name": "list",
            "date-sec": 1345034939,
            "date-nsec": 39119000,
            "id": "3",
            "vm-state-size": 75890567
        }
    ],
    "virtual-size": 1073741824,
    "filename": "./snapshot.img",
    "cluster-size": 65536,
    "format": "qcow2",
    "actual-size": 242614272,
    "backing-filename": "truc5.raw",
    "dirty-flag": false
}
---
 Makefile   |    3 +-
 qemu-img.c |  138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 129 insertions(+), 12 deletions(-)
Makefile +2 -1
index ab82ef3..9ba064b 100644
@@ -160,7 +160,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.c +127 -11

219 lines not on this page · raw message

Signature · 1 line
1.7.9.5