1 QEMU Machine Protocol Specification
6 Copyright (C) 2009-2016 Red Hat, Inc.
8 This work is licensed under the terms of the GNU GPL, version 2 or
9 later. See the COPYING file in the top-level directory.
14 This document specifies the QEMU Machine Protocol (QMP), a JSON-based
15 protocol which is available for applications to operate QEMU at the
16 machine-level. It is also in use by the QEMU Guest Agent (QGA), which
17 is available for host applications to interact with the guest
20 2. Protocol Specification
21 =========================
23 This section details the protocol format. For the purpose of this document
24 "Client" is any application which is using QMP to communicate with QEMU and
25 "Server" is QEMU itself.
27 JSON data structures, when mentioned in this document, are always in the
30 json-DATA-STRUCTURE-NAME
32 Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined
35 http://www.ietf.org/rfc/rfc7159.txt
37 The protocol is always encoded in UTF-8 except for synchronization
38 bytes (documented below); although thanks to json-string escape
39 sequences, the server will reply using only the strict ASCII subset.
41 For convenience, json-object members mentioned in this document will
42 be in a certain order. However, in real protocol usage they can be in
43 ANY order, thus no particular order should be assumed. On the other
44 hand, use of json-array elements presumes that preserving order is
45 important unless specifically documented otherwise. Repeating a key
46 within a json-object gives unpredictable results.
48 Also for convenience, the server will accept an extension of
49 'single-quoted' strings in place of the usual "double-quoted"
50 json-string, and both input forms of strings understand an additional
51 escape sequence of "\'" for a single quote. The server will only use
52 double quoting on output.
54 2.1 General Definitions
55 -----------------------
57 2.1.1 All interactions transmitted by the Server are json-objects, always
60 2.1.2 All json-objects members are mandatory when not specified otherwise
65 Right when connected the Server will issue a greeting message, which signals
66 that the connection has been successfully established and that the Server is
67 ready for capabilities negotiation (for more information refer to section
68 '4. Capabilities Negotiation').
70 The greeting message format is:
72 { "QMP": { "version": json-object, "capabilities": json-array } }
76 - The "version" member contains the Server's version information (the format
77 is the same of the query-version command)
78 - The "capabilities" member specify the availability of features beyond the
79 baseline specification; the order of elements in this array has no
80 particular significance.
85 Currently supported capabilities are:
87 - "oob": the QMP server supports "out-of-band" (OOB) command
88 execution, as described in section "2.3.1 Out-of-band execution".
93 The format for command execution is:
95 { "execute": json-string, "arguments": json-object, "id": json-value }
99 { "exec-oob": json-string, "arguments": json-object, "id": json-value }
103 - The "execute" or "exec-oob" member identifies the command to be
104 executed by the server. The latter requests out-of-band execution.
105 - The "arguments" member is used to pass any arguments required for the
106 execution of the command, it is optional when no arguments are
107 required. Each command documents what contents will be considered
108 valid when handling the json-argument
109 - The "id" member is a transaction identification associated with the
110 command execution, it is optional and will be part of the response
111 if provided. The "id" member can be any json-value. A json-number
112 incremented for each successive command works fine.
114 2.3.1 Out-of-band execution
115 ---------------------------
117 The server normally reads, executes and responds to one command after
118 the other. The client therefore receives command responses in issue
121 With out-of-band execution enabled via capability negotiation (section
122 4.), the server reads and queues commands as they arrive. It executes
123 commands from the queue one after the other. Commands executed
124 out-of-band jump the queue: the command get executed right away,
125 possibly overtaking prior in-band commands. The client may therefore
126 receive such a command's response before responses from prior in-band
129 To be able to match responses back to their commands, the client needs
130 to pass "id" with out-of-band commands. Passing it with all commands
131 is recommended for clients that accept capability "oob".
133 If the client sends in-band commands faster than the server can
134 execute them, the server will eventually drop commands to limit the
135 queue length. The sever sends event COMMAND_DROPPED then.
137 Only a few commands support out-of-band execution. The ones that do
138 have "allow-oob": true in output of query-qmp-schema.
140 2.4 Commands Responses
141 ----------------------
143 There are two possible responses which the Server will issue as the result
144 of a command execution: success or error.
146 As long as the commands were issued with a proper "id" field, then the
147 same "id" field will be attached in the corresponding response message
148 so that requests and responses can match. Clients should drop all the
149 responses that have an unknown "id" field.
154 The format of a success response is:
156 { "return": json-value, "id": json-value }
160 - The "return" member contains the data returned by the command, which
161 is defined on a per-command basis (usually a json-object or
162 json-array of json-objects, but sometimes a json-number, json-string,
163 or json-array of json-strings); it is an empty json-object if the
164 command does not return data
165 - The "id" member contains the transaction identification associated
166 with the command execution if issued by the Client
171 The format of an error response is:
173 { "error": { "class": json-string, "desc": json-string }, "id": json-value }
177 - The "class" member contains the error class name (eg. "GenericError")
178 - The "desc" member is a human-readable error message. Clients should
179 not attempt to parse this message.
180 - The "id" member contains the transaction identification associated with
181 the command execution if issued by the Client
183 NOTE: Some errors can occur before the Server is able to read the "id" member,
184 in these cases the "id" member will not be part of the error response, even
185 if provided by the client.
187 2.5 Asynchronous events
188 -----------------------
190 As a result of state changes, the Server may send messages unilaterally
191 to the Client at any time, when not in the middle of any other
192 response. They are called "asynchronous events".
194 The format of asynchronous events is:
196 { "event": json-string, "data": json-object,
197 "timestamp": { "seconds": json-number, "microseconds": json-number } }
201 - The "event" member contains the event's name
202 - The "data" member contains event specific data, which is defined in a
203 per-event basis, it is optional
204 - The "timestamp" member contains the exact time of when the event
205 occurred in the Server. It is a fixed json-object with time in
206 seconds and microseconds relative to the Unix Epoch (1 Jan 1970); if
207 there is a failure to retrieve host time, both members of the
208 timestamp will be set to -1.
210 For a listing of supported asynchronous events, please, refer to the
213 Some events are rate-limited to at most one per second. If additional
214 "similar" events arrive within one second, all but the last one are
215 dropped, and the last one is delayed. "Similar" normally means same
216 event type. See qmp-events.txt for details.
218 2.6 QGA Synchronization
219 -----------------------
221 When using QGA, an additional synchronization feature is built into
222 the protocol. If the Client sends a raw 0xFF sentinel byte (not valid
223 JSON), then the Server will reset its state and discard all pending
224 data prior to the sentinel. Conversely, if the Client makes use of
225 the 'guest-sync-delimited' command, the Server will send a raw 0xFF
226 sentinel byte prior to its response, to aid the Client in discarding
227 any data prior to the sentinel.
233 This section provides some examples of real QMP usage, in all of them
234 "C" stands for "Client" and "S" stands for "Server".
239 S: { "QMP": {"version": {"qemu": {"micro": 0, "minor": 0, "major": 3},
240 "package": "v3.0.0"}, "capabilities": ["oob"] } }
242 3.2 Capabilities negotiation
243 ----------------------------
245 C: { "execute": "qmp_capabilities", "arguments": { "enable": ["oob"] } }
248 3.3 Simple 'stop' execution
249 ---------------------------
251 C: { "execute": "stop" }
257 C: { "execute": "query-kvm", "id": "example" }
258 S: { "return": { "enabled": true, "present": true }, "id": "example"}
264 S: { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
269 S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
270 "event": "POWERDOWN" }
272 3.7 Out-of-band execution
273 -------------------------
275 C: { "exec-oob": "migrate-pause", "id": 42 }
277 "error": { "class": "GenericError",
278 "desc": "migrate-pause is currently only supported during postcopy-active state" } }
281 4. Capabilities Negotiation
282 ===========================
284 When a Client successfully establishes a connection, the Server is in
285 Capabilities Negotiation mode.
287 In this mode only the qmp_capabilities command is allowed to run, all
288 other commands will return the CommandNotFound error. Asynchronous
289 messages are not delivered either.
291 Clients should use the qmp_capabilities command to enable capabilities
292 advertised in the Server's greeting (section '2.2 Server Greeting') they
295 When the qmp_capabilities command is issued, and if it does not return an
296 error, the Server enters in Command mode where capabilities changes take
297 effect, all commands (except qmp_capabilities) are allowed and asynchronous
298 messages are delivered.
300 5 Compatibility Considerations
301 ==============================
303 All protocol changes or new features which modify the protocol format in an
304 incompatible way are disabled by default and will be advertised by the
305 capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
306 that array and enable the capabilities they support.
308 The QMP Server performs a type check on the arguments to a command. It
309 generates an error if a value does not have the expected type for its
310 key, or if it does not understand a key that the Client included. The
311 strictness of the Server catches wrong assumptions of Clients about
312 the Server's schema. Clients can assume that, when such validation
313 errors occur, they will be reported before the command generated any
316 However, Clients must not assume any particular:
318 - Length of json-arrays
319 - Size of json-objects; in particular, future versions of QEMU may add
320 new keys and Clients should be able to ignore them.
321 - Order of json-object members or json-array elements
322 - Amount of errors generated by a command, that is, new errors can be added
323 to any existing command in newer versions of the Server
325 Any command or member name beginning with "x-" is deemed experimental,
326 and may be withdrawn or changed in an incompatible manner in a future
329 Of course, the Server does guarantee to send valid JSON. But apart from
330 this, a Client should be "conservative in what they send, and liberal in
333 6. Downstream extension of QMP
334 ==============================
336 We recommend that downstream consumers of QEMU do *not* modify QMP.
337 Management tools should be able to support both upstream and downstream
338 versions of QMP without special logic, and downstream extensions are
339 inherently at odds with that.
341 However, we recognize that it is sometimes impossible for downstreams to
342 avoid modifying QMP. Both upstream and downstream need to take care to
343 preserve long-term compatibility and interoperability.
345 To help with that, QMP reserves JSON object member names beginning with
346 '__' (double underscore) for downstream use ("downstream names"). This
347 means upstream will never use any downstream names for its commands,
348 arguments, errors, asynchronous events, and so forth.
350 Any new names downstream wishes to add must begin with '__'. To
351 ensure compatibility with other downstreams, it is strongly
352 recommended that you prefix your downstream names with '__RFQDN_' where
353 RFQDN is a valid, reverse fully qualified domain name which you
354 control. For example, a qemu-kvm specific monitor command would be:
356 (qemu) __org.linux-kvm_enable_irqchip
358 Downstream must not change the server greeting (section 2.2) other than
359 to offer additional capabilities. But see below for why even that is
362 Section '5 Compatibility Considerations' applies to downstream as well
363 as to upstream, obviously. It follows that downstream must behave
364 exactly like upstream for any input not containing members with
365 downstream names ("downstream members"), except it may add members
366 with downstream names to its output.
368 Thus, a client should not be able to distinguish downstream from
369 upstream as long as it doesn't send input with downstream members, and
370 properly ignores any downstream members in the output it receives.
372 Advice on downstream modifications:
374 1. Introducing new commands is okay. If you want to extend an existing
375 command, consider introducing a new one with the new behaviour
378 2. Introducing new asynchronous messages is okay. If you want to extend
379 an existing message, consider adding a new one instead.
381 3. Introducing new errors for use in new commands is okay. Adding new
382 errors to existing commands counts as extension, so 1. applies.
384 4. New capabilities are strongly discouraged. Capabilities are for
385 evolving the basic protocol, and multiple diverging basic protocol
386 dialects are most undesirable.