1 QEMU Machine Protocol Specification
6 This document specifies the QEMU Machine Protocol (QMP), a JSON-based protocol
7 which is available for applications to operate QEMU at the machine-level.
9 2. Protocol Specification
10 =========================
12 This section details the protocol format. For the purpose of this document
13 "Client" is any application which is using QMP to communicate with QEMU and
14 "Server" is QEMU itself.
16 JSON data structures, when mentioned in this document, are always in the
19 json-DATA-STRUCTURE-NAME
21 Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
24 http://www.ietf.org/rfc/rfc4627.txt
26 For convenience, json-object members and json-array elements mentioned in
27 this document will be in a certain order. However, in real protocol usage
28 they can be in ANY order, thus no particular order should be assumed.
30 2.1 General Definitions
31 -----------------------
33 2.1.1 All interactions transmitted by the Server are json-objects, always
36 2.1.2 All json-objects members are mandatory when not specified otherwise
41 Right when connected the Server will issue a greeting message, which signals
42 that the connection has been successfully established and that the Server is
43 ready for capabilities negotiation (for more information refer to section
44 '4. Capabilities Negotiation').
46 The greeting message format is:
48 { "QMP": { "version": json-object, "capabilities": json-array } }
52 - The "version" member contains the Server's version information (the format
53 is the same of the query-version command)
54 - The "capabilities" member specify the availability of features beyond the
55 baseline specification
60 The format for command execution is:
62 { "execute": json-string, "arguments": json-object, "id": json-value }
66 - The "execute" member identifies the command to be executed by the Server
67 - The "arguments" member is used to pass any arguments required for the
68 execution of the command, it is optional when no arguments are required
69 - The "id" member is a transaction identification associated with the
70 command execution, it is optional and will be part of the response if
73 2.4 Commands Responses
74 ----------------------
76 There are two possible responses which the Server will issue as the result
77 of a command execution: success or error.
82 The format of a success response is:
84 { "return": json-object, "id": json-value }
88 - The "return" member contains the command returned data, which is defined
89 in a per-command basis or an empty json-object if the command does not
91 - The "id" member contains the transaction identification associated
92 with the command execution if issued by the Client
97 The format of an error response is:
99 { "error": { "class": json-string, "desc": json-string }, "id": json-value }
103 - The "class" member contains the error class name (eg. "GenericError")
104 - The "desc" member is a human-readable error message. Clients should
105 not attempt to parse this message.
106 - The "id" member contains the transaction identification associated with
107 the command execution if issued by the Client
109 NOTE: Some errors can occur before the Server is able to read the "id" member,
110 in these cases the "id" member will not be part of the error response, even
111 if provided by the client.
113 2.5 Asynchronous events
114 -----------------------
116 As a result of state changes, the Server may send messages unilaterally
117 to the Client at any time. They are called "asynchronous events".
119 The format of asynchronous events is:
121 { "event": json-string, "data": json-object,
122 "timestamp": { "seconds": json-number, "microseconds": json-number } }
126 - The "event" member contains the event's name
127 - The "data" member contains event specific data, which is defined in a
128 per-event basis, it is optional
129 - The "timestamp" member contains the exact time of when the event occurred
130 in the Server. It is a fixed json-object with time in seconds and
133 For a listing of supported asynchronous events, please, refer to the
139 This section provides some examples of real QMP usage, in all of them
140 "C" stands for "Client" and "S" stands for "Server".
145 S: { "QMP": { "version": { "qemu": { "micro": 50, "minor": 6, "major": 1 },
146 "package": ""}, "capabilities": []}}
148 3.2 Simple 'stop' execution
149 ---------------------------
151 C: { "execute": "stop" }
157 C: { "execute": "query-kvm", "id": "example" }
158 S: { "return": { "enabled": true, "present": true }, "id": "example"}
164 S: { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
169 S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
170 "event": "POWERDOWN" }
172 4. Capabilities Negotiation
173 ----------------------------
175 When a Client successfully establishes a connection, the Server is in
176 Capabilities Negotiation mode.
178 In this mode only the qmp_capabilities command is allowed to run, all
179 other commands will return the CommandNotFound error. Asynchronous
180 messages are not delivered either.
182 Clients should use the qmp_capabilities command to enable capabilities
183 advertised in the Server's greeting (section '2.2 Server Greeting') they
186 When the qmp_capabilities command is issued, and if it does not return an
187 error, the Server enters in Command mode where capabilities changes take
188 effect, all commands (except qmp_capabilities) are allowed and asynchronous
189 messages are delivered.
191 5 Compatibility Considerations
192 ------------------------------
194 All protocol changes or new features which modify the protocol format in an
195 incompatible way are disabled by default and will be advertised by the
196 capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
197 that array and enable the capabilities they support.
199 The QMP Server performs a type check on the arguments to a command. It
200 generates an error if a value does not have the expected type for its
201 key, or if it does not understand a key that the Client included. The
202 strictness of the Server catches wrong assumptions of Clients about
203 the Server's schema. Clients can assume that, when such validation
204 errors occur, they will be reported before the command generated any
207 However, Clients must not assume any particular:
209 - Length of json-arrays
210 - Size of json-objects; in particular, future versions of QEMU may add
211 new keys and Clients should be able to ignore them.
212 - Order of json-object members or json-array elements
213 - Amount of errors generated by a command, that is, new errors can be added
214 to any existing command in newer versions of the Server
216 Of course, the Server does guarantee to send valid JSON. But apart from
217 this, a Client should be "conservative in what they send, and liberal in
220 6. Downstream extension of QMP
221 ------------------------------
223 We recommend that downstream consumers of QEMU do *not* modify QMP.
224 Management tools should be able to support both upstream and downstream
225 versions of QMP without special logic, and downstream extensions are
226 inherently at odds with that.
228 However, we recognize that it is sometimes impossible for downstreams to
229 avoid modifying QMP. Both upstream and downstream need to take care to
230 preserve long-term compatibility and interoperability.
232 To help with that, QMP reserves JSON object member names beginning with
233 '__' (double underscore) for downstream use ("downstream names"). This
234 means upstream will never use any downstream names for its commands,
235 arguments, errors, asynchronous events, and so forth.
237 Any new names downstream wishes to add must begin with '__'. To
238 ensure compatibility with other downstreams, it is strongly
239 recommended that you prefix your downstream names with '__RFQDN_' where
240 RFQDN is a valid, reverse fully qualified domain name which you
241 control. For example, a qemu-kvm specific monitor command would be:
243 (qemu) __org.linux-kvm_enable_irqchip
245 Downstream must not change the server greeting (section 2.2) other than
246 to offer additional capabilities. But see below for why even that is
249 Section '5 Compatibility Considerations' applies to downstream as well
250 as to upstream, obviously. It follows that downstream must behave
251 exactly like upstream for any input not containing members with
252 downstream names ("downstream members"), except it may add members
253 with downstream names to its output.
255 Thus, a client should not be able to distinguish downstream from
256 upstream as long as it doesn't send input with downstream members, and
257 properly ignores any downstream members in the output it receives.
259 Advice on downstream modifications:
261 1. Introducing new commands is okay. If you want to extend an existing
262 command, consider introducing a new one with the new behaviour
265 2. Introducing new asynchronous messages is okay. If you want to extend
266 an existing message, consider adding a new one instead.
268 3. Introducing new errors for use in new commands is okay. Adding new
269 errors to existing commands counts as extension, so 1. applies.
271 4. New capabilities are strongly discouraged. Capabilities are for
272 evolving the basic protocol, and multiple diverging basic protocol
273 dialects are most undesirable.