target-i386: add feature kvm_pv_unhalt
[qemu/ar7.git] / QMP / qmp-spec.txt
bloba27789692b83f5fd95280abac4349ca5e3d7892a
1            QEMU Monitor Protocol Specification - Version 0.1
3 1. Introduction
4 ===============
6 This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
7 which is available for applications to control QEMU at the machine-level.
9 To enable QMP support, QEMU has to be run in "control mode". This is done by
10 starting QEMU with the appropriate command-line options. Please, refer to the
11 QEMU manual page for more information.
13 2. Protocol Specification
14 =========================
16 This section details the protocol format. For the purpose of this document
17 "Client" is any application which is communicating with QEMU in control mode,
18 and "Server" is QEMU itself.
20 JSON data structures, when mentioned in this document, are always in the
21 following format:
23     json-DATA-STRUCTURE-NAME
25 Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
26 the JSON standard:
28 http://www.ietf.org/rfc/rfc4627.txt
30 For convenience, json-object members and json-array elements mentioned in
31 this document will be in a certain order. However, in real protocol usage
32 they can be in ANY order, thus no particular order should be assumed.
34 2.1 General Definitions
35 -----------------------
37 2.1.1 All interactions transmitted by the Server are json-objects, always
38       terminating with CRLF
40 2.1.2 All json-objects members are mandatory when not specified otherwise
42 2.2 Server Greeting
43 -------------------
45 Right when connected the Server will issue a greeting message, which signals
46 that the connection has been successfully established and that the Server is
47 ready for capabilities negotiation (for more information refer to section
48 '4. Capabilities Negotiation').
50 The format is:
52 { "QMP": { "version": json-object, "capabilities": json-array } }
54  Where,
56 - The "version" member contains the Server's version information (the format
57   is the same of the 'query-version' command)
58 - The "capabilities" member specify the availability of features beyond the
59   baseline specification
61 2.3 Issuing Commands
62 --------------------
64 The format for command execution is:
66 { "execute": json-string, "arguments": json-object, "id": json-value }
68  Where,
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
77 2.4 Commands Responses
78 ----------------------
80 There are two possible responses which the Server will issue as the result
81 of a command execution: success or error.
83 2.4.1 success
84 -------------
86 The success response is issued when the command execution has finished
87 without errors.
89 The format is:
91 { "return": json-object, "id": json-value }
93  Where,
95 - The "return" member contains the command returned data, which is defined
96   in a per-command basis or an empty json-object if the command does not
97   return data
98 - The "id" member contains the transaction identification associated
99   with the command execution (if issued by the Client)
101 2.4.2 error
102 -----------
104 The error response is issued when the command execution could not be
105 completed because of an error condition.
107 The format is:
109 { "error": { "class": json-string, "desc": json-string }, "id": json-value }
111  Where,
113 - The "class" member contains the error class name (eg. "GenericError")
114 - The "desc" member is a human-readable error message. Clients should
115   not attempt to parse this message.
116 - The "id" member contains the transaction identification associated with
117   the command execution (if issued by the Client)
119 NOTE: Some errors can occur before the Server is able to read the "id" member,
120 in these cases the "id" member will not be part of the error response, even
121 if provided by the client.
123 2.5 Asynchronous events
124 -----------------------
126 As a result of state changes, the Server may send messages unilaterally
127 to the Client at any time. They are called 'asynchronous events'.
129 The format is:
131 { "event": json-string, "data": json-object,
132   "timestamp": { "seconds": json-number, "microseconds": json-number } }
134  Where,
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
139 - The "timestamp" member contains the exact time of when the event occurred
140   in the Server. It is a fixed json-object with time in seconds and
141   microseconds
143 For a listing of supported asynchronous events, please, refer to the
144 qmp-events.txt file.
146 3. QMP Examples
147 ===============
149 This section provides some examples of real QMP usage, in all of them
150 'C' stands for 'Client' and 'S' stands for 'Server'.
152 3.1 Server greeting
153 -------------------
155 S: {"QMP": {"version": {"qemu": "0.12.50", "package": ""}, "capabilities": []}}
157 3.2 Simple 'stop' execution
158 ---------------------------
160 C: { "execute": "stop" }
161 S: {"return": {}}
163 3.3 KVM information
164 -------------------
166 C: { "execute": "query-kvm", "id": "example" }
167 S: {"return": {"enabled": true, "present": true}, "id": "example"}
169 3.4 Parsing error
170 ------------------
172 C: { "execute": }
173 S: {"error": {"class": "GenericError", "desc": "Invalid JSON syntax" } }
175 3.5 Powerdown event
176 -------------------
178 S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
179 "POWERDOWN"}
181 4. Capabilities Negotiation
182 ----------------------------
184 When a Client successfully establishes a connection, the Server is in
185 Capabilities Negotiation mode.
187 In this mode only the 'qmp_capabilities' command is allowed to run, all
188 other commands will return the CommandNotFound error. Asynchronous messages
189 are not delivered either.
191 Clients should use the 'qmp_capabilities' command to enable capabilities
192 advertised in the Server's greeting (section '2.2 Server Greeting') they
193 support.
195 When the 'qmp_capabilities' command is issued, and if it does not return an
196 error, the Server enters in Command mode where capabilities changes take
197 effect, all commands (except 'qmp_capabilities') are allowed and asynchronous
198 messages are delivered.
200 5 Compatibility Considerations
201 ------------------------------
203 All protocol changes or new features which modify the protocol format in an
204 incompatible way are disabled by default and will be advertised by the
205 capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
206 that array and enable the capabilities they support.
208 The QMP Server performs a type check on the arguments to a command.  It
209 generates an error if a value does not have the expected type for its
210 key, or if it does not understand a key that the Client included.  The
211 strictness of the Server catches wrong assumptions of Clients about
212 the Server's schema.  Clients can assume that, when such validation
213 errors occur, they will be reported before the command generated any
214 side effect.
216 However, Clients must not assume any particular:
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.
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
225 Of course, the Server does guarantee to send valid JSON.  But apart from
226 this, a Client should be "conservative in what they send, and liberal in
227 what they accept".
229 6. Downstream extension of QMP
230 ------------------------------
232 We recommend that downstream consumers of QEMU do *not* modify QMP.
233 Management tools should be able to support both upstream and downstream
234 versions of QMP without special logic, and downstream extensions are
235 inherently at odds with that.
237 However, we recognize that it is sometimes impossible for downstreams to
238 avoid modifying QMP.  Both upstream and downstream need to take care to
239 preserve long-term compatibility and interoperability.
241 To help with that, QMP reserves JSON object member names beginning with
242 '__' (double underscore) for downstream use ("downstream names").  This
243 means upstream will never use any downstream names for its commands,
244 arguments, errors, asynchronous events, and so forth.
246 Any new names downstream wishes to add must begin with '__'.  To
247 ensure compatibility with other downstreams, it is strongly
248 recommended that you prefix your downstram names with '__RFQDN_' where
249 RFQDN is a valid, reverse fully qualified domain name which you
250 control.  For example, a qemu-kvm specific monitor command would be:
252     (qemu) __org.linux-kvm_enable_irqchip
254 Downstream must not change the server greeting (section 2.2) other than
255 to offer additional capabilities.  But see below for why even that is
256 discouraged.
258 Section '5 Compatibility Considerations' applies to downstream as well
259 as to upstream, obviously.  It follows that downstream must behave
260 exactly like upstream for any input not containing members with
261 downstream names ("downstream members"), except it may add members
262 with downstream names to its output.
264 Thus, a client should not be able to distinguish downstream from
265 upstream as long as it doesn't send input with downstream members, and
266 properly ignores any downstream members in the output it receives.
268 Advice on downstream modifications:
270 1. 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.
274 2. Introducing new asynchronous messages is okay.  If you want to extend
275    an existing message, consider adding a new one instead.
277 3. Introducing new errors for use in new commands is okay.  Adding new
278    errors to existing commands counts as extension, so 1. applies.
280 4. New capabilities are strongly discouraged.  Capabilities are for
281    evolving the basic protocol, and multiple diverging basic protocol
282    dialects are most undesirable.