]> Git Repo - qemu.git/blame - docs/interop/qmp-spec.txt
works with less than base ISA qemu-system-riscv32 -M virt -bios none -kernel output...
[qemu.git] / docs / interop / qmp-spec.txt
CommitLineData
715c1860 1 QEMU Machine Protocol Specification
f544d174 2
6fb55451
EB
30. About This Document
4======================
5
9ee86b85 6Copyright (C) 2009-2016 Red Hat, Inc.
6fb55451
EB
7
8This work is licensed under the terms of the GNU GPL, version 2 or
9later. See the COPYING file in the top-level directory.
10
f544d174
LC
111. Introduction
12===============
13
e790e666
EB
14This document specifies the QEMU Machine Protocol (QMP), a JSON-based
15protocol which is available for applications to operate QEMU at the
16machine-level. It is also in use by the QEMU Guest Agent (QGA), which
17is available for host applications to interact with the guest
18operating system.
f544d174
LC
19
202. Protocol Specification
21=========================
22
72e9e569
MA
23This section details the protocol format. For the purpose of this
24document, "Server" is either QEMU or the QEMU Guest Agent, and
25"Client" is any application communicating with it via QMP.
f544d174
LC
26
27JSON data structures, when mentioned in this document, are always in the
28following format:
29
30 json-DATA-STRUCTURE-NAME
31
e790e666
EB
32Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined
33by the JSON standard:
f544d174 34
aee03bf3 35http://www.ietf.org/rfc/rfc8259.txt
f544d174 36
72e9e569
MA
37The server expects its input to be encoded in UTF-8, and sends its
38output encoded in ASCII.
e790e666
EB
39
40For convenience, json-object members mentioned in this document will
41be in a certain order. However, in real protocol usage they can be in
42ANY order, thus no particular order should be assumed. On the other
43hand, use of json-array elements presumes that preserving order is
44important unless specifically documented otherwise. Repeating a key
45within a json-object gives unpredictable results.
46
47Also for convenience, the server will accept an extension of
48'single-quoted' strings in place of the usual "double-quoted"
49json-string, and both input forms of strings understand an additional
50escape sequence of "\'" for a single quote. The server will only use
51double quoting on output.
f544d174
LC
52
532.1 General Definitions
54-----------------------
55
562.1.1 All interactions transmitted by the Server are json-objects, always
57 terminating with CRLF
58
592.1.2 All json-objects members are mandatory when not specified otherwise
60
612.2 Server Greeting
62-------------------
63
64Right when connected the Server will issue a greeting message, which signals
65that the connection has been successfully established and that the Server is
5307d7d3
LC
66ready for capabilities negotiation (for more information refer to section
67'4. Capabilities Negotiation').
f544d174 68
715c1860 69The greeting message format is:
f544d174 70
ca9567e2 71{ "QMP": { "version": json-object, "capabilities": json-array } }
f544d174
LC
72
73 Where,
74
ca9567e2 75- The "version" member contains the Server's version information (the format
715c1860 76 is the same of the query-version command)
f544d174 77- The "capabilities" member specify the availability of features beyond the
e790e666 78 baseline specification; the order of elements in this array has no
71696cc6 79 particular significance.
e790e666
EB
80
812.2.1 Capabilities
82------------------
83
378112b0 84Currently supported capabilities are:
e790e666 85
c0698212 86- "oob": the QMP server supports "out-of-band" (OOB) command
71696cc6 87 execution, as described in section "2.3.1 Out-of-band execution".
f544d174
LC
88
892.3 Issuing Commands
90--------------------
91
92The format for command execution is:
93
00ecec15
MA
94{ "execute": json-string, "arguments": json-object, "id": json-value }
95
96or
97
98{ "exec-oob": json-string, "arguments": json-object, "id": json-value }
f544d174
LC
99
100 Where,
101
00ecec15
MA
102- The "execute" or "exec-oob" member identifies the command to be
103 executed by the server. The latter requests out-of-band execution.
f544d174 104- The "arguments" member is used to pass any arguments required for the
e790e666
EB
105 execution of the command, it is optional when no arguments are
106 required. Each command documents what contents will be considered
107 valid when handling the json-argument
f544d174 108- The "id" member is a transaction identification associated with the
80cd93bd
MA
109 command execution, it is optional and will be part of the response
110 if provided. The "id" member can be any json-value. A json-number
111 incremented for each successive command works fine.
71696cc6 112
a7742549
MA
113The actual commands are documented in the QEMU QMP reference manual
114docs/interop/qemu-qmp-ref.{7,html,info,pdf,txt}.
115
71696cc6
MA
1162.3.1 Out-of-band execution
117---------------------------
118
119The server normally reads, executes and responds to one command after
120the other. The client therefore receives command responses in issue
121order.
122
123With out-of-band execution enabled via capability negotiation (section
1244.), the server reads and queues commands as they arrive. It executes
125commands from the queue one after the other. Commands executed
126out-of-band jump the queue: the command get executed right away,
127possibly overtaking prior in-band commands. The client may therefore
128receive such a command's response before responses from prior in-band
129commands.
130
80cd93bd
MA
131To be able to match responses back to their commands, the client needs
132to pass "id" with out-of-band commands. Passing it with all commands
133is recommended for clients that accept capability "oob".
134
71696cc6 135If the client sends in-band commands faster than the server can
781386af
MA
136execute them, the server will stop reading requests until the request
137queue length is reduced to an acceptable range.
138
139To ensure commands to be executed out-of-band get read and executed,
140the client should have at most eight in-band commands in flight.
71696cc6
MA
141
142Only a few commands support out-of-band execution. The ones that do
143have "allow-oob": true in output of query-qmp-schema.
f544d174
LC
144
1452.4 Commands Responses
146----------------------
147
148There are two possible responses which the Server will issue as the result
149of a command execution: success or error.
150
378112b0
PX
151As long as the commands were issued with a proper "id" field, then the
152same "id" field will be attached in the corresponding response message
153so that requests and responses can match. Clients should drop all the
154responses that have an unknown "id" field.
155
f544d174
LC
1562.4.1 success
157-------------
158
715c1860 159The format of a success response is:
f544d174 160
e790e666 161{ "return": json-value, "id": json-value }
f544d174
LC
162
163 Where,
164
e790e666
EB
165- The "return" member contains the data returned by the command, which
166 is defined on a per-command basis (usually a json-object or
167 json-array of json-objects, but sometimes a json-number, json-string,
168 or json-array of json-strings); it is an empty json-object if the
169 command does not return data
f544d174 170- The "id" member contains the transaction identification associated
715c1860 171 with the command execution if issued by the Client
f544d174
LC
172
1732.4.2 error
174-----------
175
715c1860 176The format of an error response is:
f544d174 177
de253f14 178{ "error": { "class": json-string, "desc": json-string }, "id": json-value }
f544d174
LC
179
180 Where,
181
de253f14 182- The "class" member contains the error class name (eg. "GenericError")
94048982 183- The "desc" member is a human-readable error message. Clients should
77e595e7 184 not attempt to parse this message.
f544d174 185- The "id" member contains the transaction identification associated with
715c1860 186 the command execution if issued by the Client
f544d174
LC
187
188NOTE: Some errors can occur before the Server is able to read the "id" member,
189in these cases the "id" member will not be part of the error response, even
190if provided by the client.
191
1922.5 Asynchronous events
193-----------------------
194
195As a result of state changes, the Server may send messages unilaterally
e790e666
EB
196to the Client at any time, when not in the middle of any other
197response. They are called "asynchronous events".
f544d174 198
715c1860 199The format of asynchronous events is:
f544d174 200
94048982 201{ "event": json-string, "data": json-object,
f544d174
LC
202 "timestamp": { "seconds": json-number, "microseconds": json-number } }
203
204 Where,
205
206- The "event" member contains the event's name
207- The "data" member contains event specific data, which is defined in a
208 per-event basis, it is optional
e790e666
EB
209- The "timestamp" member contains the exact time of when the event
210 occurred in the Server. It is a fixed json-object with time in
211 seconds and microseconds relative to the Unix Epoch (1 Jan 1970); if
212 there is a failure to retrieve host time, both members of the
213 timestamp will be set to -1.
f544d174 214
a7742549
MA
215The actual asynchronous events are documented in the QEMU QMP
216reference manual docs/interop/qemu-qmp-ref.{7,html,info,pdf,txt}.
f544d174 217
7f1e7b23
MA
218Some events are rate-limited to at most one per second. If additional
219"similar" events arrive within one second, all but the last one are
220dropped, and the last one is delayed. "Similar" normally means same
a7742549 221event type.
7f1e7b23 222
72e9e569
MA
2232.6 Forcing the JSON parser into known-good state
224-------------------------------------------------
225
226Incomplete or invalid input can leave the server's JSON parser in a
227state where it can't parse additional commands. To get it back into
228known-good state, the client should provoke a lexical error.
229
230The cleanest way to do that is sending an ASCII control character
231other than '\t' (horizontal tab), '\r' (carriage return), or '\n' (new
232line).
233
234Sadly, older versions of QEMU can fail to flag this as an error. If a
235client needs to deal with them, it should send a 0xFF byte.
236
2372.7 QGA Synchronization
e790e666
EB
238-----------------------
239
72e9e569
MA
240When a client connects to QGA over a transport lacking proper
241connection semantics such as virtio-serial, QGA may have read partial
242input from a previous client. The client needs to force QGA's parser
243into known-good state using the previous section's technique.
244Moreover, the client may receive output a previous client didn't read.
245To help with skipping that output, QGA provides the
246'guest-sync-delimited' command. Refer to its documentation for
247details.
e790e666
EB
248
249
f544d174
LC
2503. QMP Examples
251===============
252
253This section provides some examples of real QMP usage, in all of them
715c1860 254"C" stands for "Client" and "S" stands for "Server".
f544d174
LC
255
2563.1 Server greeting
257-------------------
258
71696cc6
MA
259S: { "QMP": {"version": {"qemu": {"micro": 0, "minor": 0, "major": 3},
260 "package": "v3.0.0"}, "capabilities": ["oob"] } }
261
2623.2 Capabilities negotiation
263----------------------------
f544d174 264
71696cc6 265C: { "execute": "qmp_capabilities", "arguments": { "enable": ["oob"] } }
e790e666
EB
266S: { "return": {}}
267
2683.3 Simple 'stop' execution
f544d174
LC
269---------------------------
270
271C: { "execute": "stop" }
715c1860 272S: { "return": {} }
f544d174 273
e790e666 2743.4 KVM information
f544d174
LC
275-------------------
276
94048982 277C: { "execute": "query-kvm", "id": "example" }
715c1860 278S: { "return": { "enabled": true, "present": true }, "id": "example"}
f544d174 279
e790e666 2803.5 Parsing error
f544d174
LC
281------------------
282
283C: { "execute": }
715c1860 284S: { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
f544d174 285
e790e666 2863.6 Powerdown event
f544d174
LC
287-------------------
288
715c1860
LC
289S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
290 "event": "POWERDOWN" }
f544d174 291
71696cc6
MA
2923.7 Out-of-band execution
293-------------------------
294
00ecec15 295C: { "exec-oob": "migrate-pause", "id": 42 }
71696cc6
MA
296S: { "id": 42,
297 "error": { "class": "GenericError",
298 "desc": "migrate-pause is currently only supported during postcopy-active state" } }
299
300
5307d7d3 3014. Capabilities Negotiation
e790e666 302===========================
f544d174 303
5307d7d3
LC
304When a Client successfully establishes a connection, the Server is in
305Capabilities Negotiation mode.
f544d174 306
715c1860
LC
307In this mode only the qmp_capabilities command is allowed to run, all
308other commands will return the CommandNotFound error. Asynchronous
309messages are not delivered either.
5307d7d3 310
715c1860 311Clients should use the qmp_capabilities command to enable capabilities
5307d7d3
LC
312advertised in the Server's greeting (section '2.2 Server Greeting') they
313support.
f544d174 314
715c1860 315When the qmp_capabilities command is issued, and if it does not return an
5307d7d3 316error, the Server enters in Command mode where capabilities changes take
715c1860 317effect, all commands (except qmp_capabilities) are allowed and asynchronous
5307d7d3 318messages are delivered.
f544d174 319
5307d7d3 3205 Compatibility Considerations
e790e666 321==============================
94048982 322
5307d7d3
LC
323All protocol changes or new features which modify the protocol format in an
324incompatible way are disabled by default and will be advertised by the
325capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
326that array and enable the capabilities they support.
94048982 327
1829851c
PB
328The QMP Server performs a type check on the arguments to a command. It
329generates an error if a value does not have the expected type for its
330key, or if it does not understand a key that the Client included. The
331strictness of the Server catches wrong assumptions of Clients about
332the Server's schema. Clients can assume that, when such validation
333errors occur, they will be reported before the command generated any
334side effect.
335
336However, Clients must not assume any particular:
337
338- Length of json-arrays
339- Size of json-objects; in particular, future versions of QEMU may add
340 new keys and Clients should be able to ignore them.
5307d7d3
LC
341- Order of json-object members or json-array elements
342- Amount of errors generated by a command, that is, new errors can be added
343 to any existing command in newer versions of the Server
b3e5e3e6 344
9ee86b85 345Any command or member name beginning with "x-" is deemed experimental,
e790e666
EB
346and may be withdrawn or changed in an incompatible manner in a future
347release.
348
1829851c
PB
349Of course, the Server does guarantee to send valid JSON. But apart from
350this, a Client should be "conservative in what they send, and liberal in
351what they accept".
352
b3e5e3e6 3536. Downstream extension of QMP
e790e666 354==============================
b3e5e3e6
MA
355
356We recommend that downstream consumers of QEMU do *not* modify QMP.
357Management tools should be able to support both upstream and downstream
358versions of QMP without special logic, and downstream extensions are
359inherently at odds with that.
360
361However, we recognize that it is sometimes impossible for downstreams to
362avoid modifying QMP. Both upstream and downstream need to take care to
363preserve long-term compatibility and interoperability.
364
365To help with that, QMP reserves JSON object member names beginning with
366'__' (double underscore) for downstream use ("downstream names"). This
367means upstream will never use any downstream names for its commands,
368arguments, errors, asynchronous events, and so forth.
369
370Any new names downstream wishes to add must begin with '__'. To
371ensure compatibility with other downstreams, it is strongly
715c1860 372recommended that you prefix your downstream names with '__RFQDN_' where
b3e5e3e6
MA
373RFQDN is a valid, reverse fully qualified domain name which you
374control. For example, a qemu-kvm specific monitor command would be:
375
376 (qemu) __org.linux-kvm_enable_irqchip
377
378Downstream must not change the server greeting (section 2.2) other than
379to offer additional capabilities. But see below for why even that is
380discouraged.
381
382Section '5 Compatibility Considerations' applies to downstream as well
383as to upstream, obviously. It follows that downstream must behave
384exactly like upstream for any input not containing members with
385downstream names ("downstream members"), except it may add members
386with downstream names to its output.
387
388Thus, a client should not be able to distinguish downstream from
389upstream as long as it doesn't send input with downstream members, and
390properly ignores any downstream members in the output it receives.
391
392Advice on downstream modifications:
393
3941. Introducing new commands is okay. If you want to extend an existing
395 command, consider introducing a new one with the new behaviour
396 instead.
397
3982. Introducing new asynchronous messages is okay. If you want to extend
399 an existing message, consider adding a new one instead.
400
4013. Introducing new errors for use in new commands is okay. Adding new
402 errors to existing commands counts as extension, so 1. applies.
403
4044. New capabilities are strongly discouraged. Capabilities are for
405 evolving the basic protocol, and multiple diverging basic protocol
406 dialects are most undesirable.
This page took 0.551961 seconds and 5 git commands to generate.