]> git.proxmox.com Git - qemu.git/blame - QMP/qmp-spec.txt
qemu-iotests: exclude vmdk and qcow from 043
[qemu.git] / QMP / qmp-spec.txt
CommitLineData
94048982 1 QEMU Monitor Protocol Specification - Version 0.1
f544d174
LC
2
31. Introduction
4===============
5
6This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
7which is available for applications to control QEMU at the machine-level.
8
9To enable QMP support, QEMU has to be run in "control mode". This is done by
10starting QEMU with the appropriate command-line options. Please, refer to the
11QEMU manual page for more information.
12
132. Protocol Specification
14=========================
15
16This section details the protocol format. For the purpose of this document
17"Client" is any application which is communicating with QEMU in control mode,
18and "Server" is QEMU itself.
19
20JSON data structures, when mentioned in this document, are always in the
21following format:
22
23 json-DATA-STRUCTURE-NAME
24
25Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
26the JSON standard:
27
28http://www.ietf.org/rfc/rfc4627.txt
29
94048982
LC
30For convenience, json-object members and json-array elements mentioned in
31this document will be in a certain order. However, in real protocol usage
32they can be in ANY order, thus no particular order should be assumed.
f544d174
LC
33
342.1 General Definitions
35-----------------------
36
372.1.1 All interactions transmitted by the Server are json-objects, always
38 terminating with CRLF
39
402.1.2 All json-objects members are mandatory when not specified otherwise
41
422.2 Server Greeting
43-------------------
44
45Right when connected the Server will issue a greeting message, which signals
46that the connection has been successfully established and that the Server is
5307d7d3
LC
47ready for capabilities negotiation (for more information refer to section
48'4. Capabilities Negotiation').
f544d174
LC
49
50The format is:
51
ca9567e2 52{ "QMP": { "version": json-object, "capabilities": json-array } }
f544d174
LC
53
54 Where,
55
ca9567e2
LC
56- The "version" member contains the Server's version information (the format
57 is the same of the 'query-version' command)
f544d174
LC
58- The "capabilities" member specify the availability of features beyond the
59 baseline specification
60
612.3 Issuing Commands
62--------------------
63
64The format for command execution is:
65
66{ "execute": json-string, "arguments": json-object, "id": json-value }
67
68 Where,
69
70- The "execute" member identifies the command to be executed by the Server
71- The "arguments" member is used to pass any arguments required for the
72 execution of the command, it is optional when no arguments are required
73- The "id" member is a transaction identification associated with the
74 command execution, it is optional and will be part of the response if
75 provided
76
772.4 Commands Responses
78----------------------
79
80There are two possible responses which the Server will issue as the result
81of a command execution: success or error.
82
832.4.1 success
84-------------
85
86The success response is issued when the command execution has finished
87without errors.
88
89The format is:
90
94048982 91{ "return": json-object, "id": json-value }
f544d174
LC
92
93 Where,
94
95- The "return" member contains the command returned data, which is defined
94048982
LC
96 in a per-command basis or an empty json-object if the command does not
97 return data
f544d174
LC
98- The "id" member contains the transaction identification associated
99 with the command execution (if issued by the Client)
100
1012.4.2 error
102-----------
103
104The error response is issued when the command execution could not be
105completed because of an error condition.
106
107The format is:
108
de253f14 109{ "error": { "class": json-string, "desc": json-string }, "id": json-value }
f544d174
LC
110
111 Where,
112
de253f14 113- The "class" member contains the error class name (eg. "GenericError")
94048982 114- The "desc" member is a human-readable error message. Clients should
77e595e7 115 not attempt to parse this message.
f544d174
LC
116- The "id" member contains the transaction identification associated with
117 the command execution (if issued by the Client)
118
119NOTE: Some errors can occur before the Server is able to read the "id" member,
120in these cases the "id" member will not be part of the error response, even
121if provided by the client.
122
1232.5 Asynchronous events
124-----------------------
125
126As a result of state changes, the Server may send messages unilaterally
127to the Client at any time. They are called 'asynchronous events'.
128
129The format is:
130
94048982 131{ "event": json-string, "data": json-object,
f544d174
LC
132 "timestamp": { "seconds": json-number, "microseconds": json-number } }
133
134 Where,
135
136- The "event" member contains the event's name
137- The "data" member contains event specific data, which is defined in a
138 per-event basis, it is optional
94048982 139- The "timestamp" member contains the exact time of when the event occurred
f544d174
LC
140 in the Server. It is a fixed json-object with time in seconds and
141 microseconds
142
143For a listing of supported asynchronous events, please, refer to the
144qmp-events.txt file.
145
1463. QMP Examples
147===============
148
149This section provides some examples of real QMP usage, in all of them
150'C' stands for 'Client' and 'S' stands for 'Server'.
151
1523.1 Server greeting
153-------------------
154
ca9567e2 155S: {"QMP": {"version": {"qemu": "0.12.50", "package": ""}, "capabilities": []}}
f544d174
LC
156
1573.2 Simple 'stop' execution
158---------------------------
159
160C: { "execute": "stop" }
94048982 161S: {"return": {}}
f544d174
LC
162
1633.3 KVM information
164-------------------
165
94048982
LC
166C: { "execute": "query-kvm", "id": "example" }
167S: {"return": {"enabled": true, "present": true}, "id": "example"}
f544d174
LC
168
1693.4 Parsing error
170------------------
171
172C: { "execute": }
de253f14 173S: {"error": {"class": "GenericError", "desc": "Invalid JSON syntax" } }
f544d174
LC
174
1753.5 Powerdown event
176-------------------
177
178S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
179"POWERDOWN"}
180
5307d7d3
LC
1814. Capabilities Negotiation
182----------------------------
f544d174 183
5307d7d3
LC
184When a Client successfully establishes a connection, the Server is in
185Capabilities Negotiation mode.
f544d174 186
5307d7d3
LC
187In this mode only the 'qmp_capabilities' command is allowed to run, all
188other commands will return the CommandNotFound error. Asynchronous messages
189are not delivered either.
190
191Clients should use the 'qmp_capabilities' command to enable capabilities
192advertised in the Server's greeting (section '2.2 Server Greeting') they
193support.
f544d174 194
5307d7d3
LC
195When the 'qmp_capabilities' command is issued, and if it does not return an
196error, the Server enters in Command mode where capabilities changes take
197effect, all commands (except 'qmp_capabilities') are allowed and asynchronous
198messages are delivered.
f544d174 199
5307d7d3
LC
2005 Compatibility Considerations
201------------------------------
94048982 202
5307d7d3
LC
203All protocol changes or new features which modify the protocol format in an
204incompatible way are disabled by default and will be advertised by the
205capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
206that array and enable the capabilities they support.
94048982 207
1829851c
PB
208The QMP Server performs a type check on the arguments to a command. It
209generates an error if a value does not have the expected type for its
210key, or if it does not understand a key that the Client included. The
211strictness of the Server catches wrong assumptions of Clients about
212the Server's schema. Clients can assume that, when such validation
213errors occur, they will be reported before the command generated any
214side effect.
215
216However, Clients must not assume any particular:
217
218- Length of json-arrays
219- Size of json-objects; in particular, future versions of QEMU may add
220 new keys and Clients should be able to ignore them.
5307d7d3
LC
221- Order of json-object members or json-array elements
222- Amount of errors generated by a command, that is, new errors can be added
223 to any existing command in newer versions of the Server
b3e5e3e6 224
1829851c
PB
225Of course, the Server does guarantee to send valid JSON. But apart from
226this, a Client should be "conservative in what they send, and liberal in
227what they accept".
228
b3e5e3e6
MA
2296. Downstream extension of QMP
230------------------------------
231
232We recommend that downstream consumers of QEMU do *not* modify QMP.
233Management tools should be able to support both upstream and downstream
234versions of QMP without special logic, and downstream extensions are
235inherently at odds with that.
236
237However, we recognize that it is sometimes impossible for downstreams to
238avoid modifying QMP. Both upstream and downstream need to take care to
239preserve long-term compatibility and interoperability.
240
241To help with that, QMP reserves JSON object member names beginning with
242'__' (double underscore) for downstream use ("downstream names"). This
243means upstream will never use any downstream names for its commands,
244arguments, errors, asynchronous events, and so forth.
245
246Any new names downstream wishes to add must begin with '__'. To
247ensure compatibility with other downstreams, it is strongly
248recommended that you prefix your downstram names with '__RFQDN_' where
249RFQDN is a valid, reverse fully qualified domain name which you
250control. For example, a qemu-kvm specific monitor command would be:
251
252 (qemu) __org.linux-kvm_enable_irqchip
253
254Downstream must not change the server greeting (section 2.2) other than
255to offer additional capabilities. But see below for why even that is
256discouraged.
257
258Section '5 Compatibility Considerations' applies to downstream as well
259as to upstream, obviously. It follows that downstream must behave
260exactly like upstream for any input not containing members with
261downstream names ("downstream members"), except it may add members
262with downstream names to its output.
263
264Thus, a client should not be able to distinguish downstream from
265upstream as long as it doesn't send input with downstream members, and
266properly ignores any downstream members in the output it receives.
267
268Advice on downstream modifications:
269
2701. Introducing new commands is okay. If you want to extend an existing
271 command, consider introducing a new one with the new behaviour
272 instead.
273
2742. Introducing new asynchronous messages is okay. If you want to extend
275 an existing message, consider adding a new one instead.
276
2773. Introducing new errors for use in new commands is okay. Adding new
278 errors to existing commands counts as extension, so 1. applies.
279
2804. New capabilities are strongly discouraged. Capabilities are for
281 evolving the basic protocol, and multiple diverging basic protocol
282 dialects are most undesirable.