spapr_cpu_core: add missing rollback on realization path
[qemu/ar7.git] / docs / interop / qmp-spec.txt
blob6fa193a80bc8045d9cd89a1b2d0b67c1c5045c90
1                       QEMU Machine Protocol Specification
3 0. About This Document
4 ======================
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.
11 1. Introduction
12 ===============
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
18 operating system.
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
28 following format:
30     json-DATA-STRUCTURE-NAME
32 Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined
33 by the JSON standard:
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
58       terminating with CRLF
60 2.1.2 All json-objects members are mandatory when not specified otherwise
62 2.2 Server Greeting
63 -------------------
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 } }
74  Where,
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, so a client must search the entire array
81   when looking for a particular capability
83 2.2.1 Capabilities
84 ------------------
86 Currently supported capabilities are:
88 - "oob": the QMP server supports "Out-Of-Band" (OOB) command
89   execution.  For more details, please see the "run-oob" parameter in
90   the "Issuing Commands" section below.  Not all commands allow this
91   "oob" execution.  The "query-qmp-schema" command can be used to
92   inspect which commands support "oob" execution.
94 QMP clients can get a list of supported QMP capabilities of the QMP
95 server in the greeting message mentioned above.  By default, all the
96 capabilities are off.  To enable any QMP capabilities, the QMP client
97 needs to send the "qmp_capabilities" command with an extra parameter
98 for the requested capabilities.
100 2.3 Issuing Commands
101 --------------------
103 The format for command execution is:
105 { "execute": json-string, "arguments": json-object, "id": json-value,
106   "control": json-object }
108  Where,
110 - The "execute" member identifies the command to be executed by the Server
111 - The "arguments" member is used to pass any arguments required for the
112   execution of the command, it is optional when no arguments are
113   required. Each command documents what contents will be considered
114   valid when handling the json-argument
115 - The "id" member is a transaction identification associated with the
116   command execution.  It is required for all commands if the OOB -
117   capability was enabled at startup, and optional otherwise.  The same
118   "id" field will be part of the response if provided. The "id" member
119   can be any json-value, although most clients merely use a
120   json-number incremented for each successive command
121 - The "control" member is optional, and currently only used for
122   out-of-band execution. The handling or response of an "oob" command
123   can overtake prior in-band commands.  To enable "oob" handling of a
124   particular command, just provide a control field with: { "control":
125   { "run-oob": true } }
127 2.4 Commands Responses
128 ----------------------
130 There are two possible responses which the Server will issue as the result
131 of a command execution: success or error.
133 As long as the commands were issued with a proper "id" field, then the
134 same "id" field will be attached in the corresponding response message
135 so that requests and responses can match.  Clients should drop all the
136 responses that have an unknown "id" field.
138 2.4.1 success
139 -------------
141 The format of a success response is:
143 { "return": json-value, "id": json-value }
145  Where,
147 - The "return" member contains the data returned by the command, which
148   is defined on a per-command basis (usually a json-object or
149   json-array of json-objects, but sometimes a json-number, json-string,
150   or json-array of json-strings); it is an empty json-object if the
151   command does not return data
152 - The "id" member contains the transaction identification associated
153   with the command execution if issued by the Client
155 2.4.2 error
156 -----------
158 The format of an error response is:
160 { "error": { "class": json-string, "desc": json-string }, "id": json-value }
162  Where,
164 - The "class" member contains the error class name (eg. "GenericError")
165 - The "desc" member is a human-readable error message. Clients should
166   not attempt to parse this message.
167 - The "id" member contains the transaction identification associated with
168   the command execution if issued by the Client
170 NOTE: Some errors can occur before the Server is able to read the "id" member,
171 in these cases the "id" member will not be part of the error response, even
172 if provided by the client.
174 2.5 Asynchronous events
175 -----------------------
177 As a result of state changes, the Server may send messages unilaterally
178 to the Client at any time, when not in the middle of any other
179 response. They are called "asynchronous events".
181 The format of asynchronous events is:
183 { "event": json-string, "data": json-object,
184   "timestamp": { "seconds": json-number, "microseconds": json-number } }
186  Where,
188 - The "event" member contains the event's name
189 - The "data" member contains event specific data, which is defined in a
190   per-event basis, it is optional
191 - The "timestamp" member contains the exact time of when the event
192   occurred in the Server. It is a fixed json-object with time in
193   seconds and microseconds relative to the Unix Epoch (1 Jan 1970); if
194   there is a failure to retrieve host time, both members of the
195   timestamp will be set to -1.
197 For a listing of supported asynchronous events, please, refer to the
198 qmp-events.txt file.
200 Some events are rate-limited to at most one per second.  If additional
201 "similar" events arrive within one second, all but the last one are
202 dropped, and the last one is delayed.  "Similar" normally means same
203 event type.  See qmp-events.txt for details.
205 2.6 QGA Synchronization
206 -----------------------
208 When using QGA, an additional synchronization feature is built into
209 the protocol.  If the Client sends a raw 0xFF sentinel byte (not valid
210 JSON), then the Server will reset its state and discard all pending
211 data prior to the sentinel.  Conversely, if the Client makes use of
212 the 'guest-sync-delimited' command, the Server will send a raw 0xFF
213 sentinel byte prior to its response, to aid the Client in discarding
214 any data prior to the sentinel.
217 3. QMP Examples
218 ===============
220 This section provides some examples of real QMP usage, in all of them
221 "C" stands for "Client" and "S" stands for "Server".
223 3.1 Server greeting
224 -------------------
226 S: { "QMP": { "version": { "qemu": { "micro": 50, "minor": 6, "major": 1 },
227      "package": ""}, "capabilities": []}}
229 3.2 Client QMP negotiation
230 --------------------------
231 C: { "execute": "qmp_capabilities" }
232 S: { "return": {}}
234 3.3 Simple 'stop' execution
235 ---------------------------
237 C: { "execute": "stop" }
238 S: { "return": {} }
240 3.4 KVM information
241 -------------------
243 C: { "execute": "query-kvm", "id": "example" }
244 S: { "return": { "enabled": true, "present": true }, "id": "example"}
246 3.5 Parsing error
247 ------------------
249 C: { "execute": }
250 S: { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
252 3.6 Powerdown event
253 -------------------
255 S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
256     "event": "POWERDOWN" }
258 4. Capabilities Negotiation
259 ===========================
261 When a Client successfully establishes a connection, the Server is in
262 Capabilities Negotiation mode.
264 In this mode only the qmp_capabilities command is allowed to run, all
265 other commands will return the CommandNotFound error. Asynchronous
266 messages are not delivered either.
268 Clients should use the qmp_capabilities command to enable capabilities
269 advertised in the Server's greeting (section '2.2 Server Greeting') they
270 support.
272 When the qmp_capabilities command is issued, and if it does not return an
273 error, the Server enters in Command mode where capabilities changes take
274 effect, all commands (except qmp_capabilities) are allowed and asynchronous
275 messages are delivered.
277 5 Compatibility Considerations
278 ==============================
280 All protocol changes or new features which modify the protocol format in an
281 incompatible way are disabled by default and will be advertised by the
282 capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
283 that array and enable the capabilities they support.
285 The QMP Server performs a type check on the arguments to a command.  It
286 generates an error if a value does not have the expected type for its
287 key, or if it does not understand a key that the Client included.  The
288 strictness of the Server catches wrong assumptions of Clients about
289 the Server's schema.  Clients can assume that, when such validation
290 errors occur, they will be reported before the command generated any
291 side effect.
293 However, Clients must not assume any particular:
295 - Length of json-arrays
296 - Size of json-objects; in particular, future versions of QEMU may add
297   new keys and Clients should be able to ignore them.
298 - Order of json-object members or json-array elements
299 - Amount of errors generated by a command, that is, new errors can be added
300   to any existing command in newer versions of the Server
302 Any command or member name beginning with "x-" is deemed experimental,
303 and may be withdrawn or changed in an incompatible manner in a future
304 release.
306 Of course, the Server does guarantee to send valid JSON.  But apart from
307 this, a Client should be "conservative in what they send, and liberal in
308 what they accept".
310 6. Downstream extension of QMP
311 ==============================
313 We recommend that downstream consumers of QEMU do *not* modify QMP.
314 Management tools should be able to support both upstream and downstream
315 versions of QMP without special logic, and downstream extensions are
316 inherently at odds with that.
318 However, we recognize that it is sometimes impossible for downstreams to
319 avoid modifying QMP.  Both upstream and downstream need to take care to
320 preserve long-term compatibility and interoperability.
322 To help with that, QMP reserves JSON object member names beginning with
323 '__' (double underscore) for downstream use ("downstream names").  This
324 means upstream will never use any downstream names for its commands,
325 arguments, errors, asynchronous events, and so forth.
327 Any new names downstream wishes to add must begin with '__'.  To
328 ensure compatibility with other downstreams, it is strongly
329 recommended that you prefix your downstream names with '__RFQDN_' where
330 RFQDN is a valid, reverse fully qualified domain name which you
331 control.  For example, a qemu-kvm specific monitor command would be:
333     (qemu) __org.linux-kvm_enable_irqchip
335 Downstream must not change the server greeting (section 2.2) other than
336 to offer additional capabilities.  But see below for why even that is
337 discouraged.
339 Section '5 Compatibility Considerations' applies to downstream as well
340 as to upstream, obviously.  It follows that downstream must behave
341 exactly like upstream for any input not containing members with
342 downstream names ("downstream members"), except it may add members
343 with downstream names to its output.
345 Thus, a client should not be able to distinguish downstream from
346 upstream as long as it doesn't send input with downstream members, and
347 properly ignores any downstream members in the output it receives.
349 Advice on downstream modifications:
351 1. Introducing new commands is okay.  If you want to extend an existing
352    command, consider introducing a new one with the new behaviour
353    instead.
355 2. Introducing new asynchronous messages is okay.  If you want to extend
356    an existing message, consider adding a new one instead.
358 3. Introducing new errors for use in new commands is okay.  Adding new
359    errors to existing commands counts as extension, so 1. applies.
361 4. New capabilities are strongly discouraged.  Capabilities are for
362    evolving the basic protocol, and multiple diverging basic protocol
363    dialects are most undesirable.