]> git.proxmox.com Git - qemu.git/blame - docs/qmp/qmp-spec.txt
qdev-properties-system.c: Allow vlan or netdev for -device, not both
[qemu.git] / docs / qmp / qmp-spec.txt
CommitLineData
715c1860 1 QEMU Machine Protocol Specification
f544d174
LC
2
31. Introduction
4===============
5
715c1860
LC
6This document specifies the QEMU Machine Protocol (QMP), a JSON-based protocol
7which is available for applications to operate QEMU at the machine-level.
f544d174
LC
8
92. Protocol Specification
10=========================
11
12This section details the protocol format. For the purpose of this document
715c1860
LC
13"Client" is any application which is using QMP to communicate with QEMU and
14"Server" is QEMU itself.
f544d174
LC
15
16JSON data structures, when mentioned in this document, are always in the
17following format:
18
19 json-DATA-STRUCTURE-NAME
20
21Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
22the JSON standard:
23
24http://www.ietf.org/rfc/rfc4627.txt
25
94048982
LC
26For convenience, json-object members and json-array elements mentioned in
27this document will be in a certain order. However, in real protocol usage
28they can be in ANY order, thus no particular order should be assumed.
f544d174
LC
29
302.1 General Definitions
31-----------------------
32
332.1.1 All interactions transmitted by the Server are json-objects, always
34 terminating with CRLF
35
362.1.2 All json-objects members are mandatory when not specified otherwise
37
382.2 Server Greeting
39-------------------
40
41Right when connected the Server will issue a greeting message, which signals
42that the connection has been successfully established and that the Server is
5307d7d3
LC
43ready for capabilities negotiation (for more information refer to section
44'4. Capabilities Negotiation').
f544d174 45
715c1860 46The greeting message format is:
f544d174 47
ca9567e2 48{ "QMP": { "version": json-object, "capabilities": json-array } }
f544d174
LC
49
50 Where,
51
ca9567e2 52- The "version" member contains the Server's version information (the format
715c1860 53 is the same of the query-version command)
f544d174
LC
54- The "capabilities" member specify the availability of features beyond the
55 baseline specification
56
572.3 Issuing Commands
58--------------------
59
60The format for command execution is:
61
62{ "execute": json-string, "arguments": json-object, "id": json-value }
63
64 Where,
65
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
71 provided
72
732.4 Commands Responses
74----------------------
75
76There are two possible responses which the Server will issue as the result
77of a command execution: success or error.
78
792.4.1 success
80-------------
81
715c1860 82The format of a success response is:
f544d174 83
94048982 84{ "return": json-object, "id": json-value }
f544d174
LC
85
86 Where,
87
88- The "return" member contains the command returned data, which is defined
94048982
LC
89 in a per-command basis or an empty json-object if the command does not
90 return data
f544d174 91- The "id" member contains the transaction identification associated
715c1860 92 with the command execution if issued by the Client
f544d174
LC
93
942.4.2 error
95-----------
96
715c1860 97The format of an error response is:
f544d174 98
de253f14 99{ "error": { "class": json-string, "desc": json-string }, "id": json-value }
f544d174
LC
100
101 Where,
102
de253f14 103- The "class" member contains the error class name (eg. "GenericError")
94048982 104- The "desc" member is a human-readable error message. Clients should
77e595e7 105 not attempt to parse this message.
f544d174 106- The "id" member contains the transaction identification associated with
715c1860 107 the command execution if issued by the Client
f544d174
LC
108
109NOTE: Some errors can occur before the Server is able to read the "id" member,
110in these cases the "id" member will not be part of the error response, even
111if provided by the client.
112
1132.5 Asynchronous events
114-----------------------
115
116As a result of state changes, the Server may send messages unilaterally
715c1860 117to the Client at any time. They are called "asynchronous events".
f544d174 118
715c1860 119The format of asynchronous events is:
f544d174 120
94048982 121{ "event": json-string, "data": json-object,
f544d174
LC
122 "timestamp": { "seconds": json-number, "microseconds": json-number } }
123
124 Where,
125
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
94048982 129- The "timestamp" member contains the exact time of when the event occurred
f544d174
LC
130 in the Server. It is a fixed json-object with time in seconds and
131 microseconds
132
133For a listing of supported asynchronous events, please, refer to the
134qmp-events.txt file.
135
1363. QMP Examples
137===============
138
139This section provides some examples of real QMP usage, in all of them
715c1860 140"C" stands for "Client" and "S" stands for "Server".
f544d174
LC
141
1423.1 Server greeting
143-------------------
144
715c1860
LC
145S: { "QMP": { "version": { "qemu": { "micro": 50, "minor": 6, "major": 1 },
146 "package": ""}, "capabilities": []}}
f544d174
LC
147
1483.2 Simple 'stop' execution
149---------------------------
150
151C: { "execute": "stop" }
715c1860 152S: { "return": {} }
f544d174
LC
153
1543.3 KVM information
155-------------------
156
94048982 157C: { "execute": "query-kvm", "id": "example" }
715c1860 158S: { "return": { "enabled": true, "present": true }, "id": "example"}
f544d174
LC
159
1603.4 Parsing error
161------------------
162
163C: { "execute": }
715c1860 164S: { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
f544d174
LC
165
1663.5 Powerdown event
167-------------------
168
715c1860
LC
169S: { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
170 "event": "POWERDOWN" }
f544d174 171
5307d7d3
LC
1724. Capabilities Negotiation
173----------------------------
f544d174 174
5307d7d3
LC
175When a Client successfully establishes a connection, the Server is in
176Capabilities Negotiation mode.
f544d174 177
715c1860
LC
178In this mode only the qmp_capabilities command is allowed to run, all
179other commands will return the CommandNotFound error. Asynchronous
180messages are not delivered either.
5307d7d3 181
715c1860 182Clients should use the qmp_capabilities command to enable capabilities
5307d7d3
LC
183advertised in the Server's greeting (section '2.2 Server Greeting') they
184support.
f544d174 185
715c1860 186When the qmp_capabilities command is issued, and if it does not return an
5307d7d3 187error, the Server enters in Command mode where capabilities changes take
715c1860 188effect, all commands (except qmp_capabilities) are allowed and asynchronous
5307d7d3 189messages are delivered.
f544d174 190
5307d7d3
LC
1915 Compatibility Considerations
192------------------------------
94048982 193
5307d7d3
LC
194All protocol changes or new features which modify the protocol format in an
195incompatible way are disabled by default and will be advertised by the
196capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
197that array and enable the capabilities they support.
94048982 198
1829851c
PB
199The QMP Server performs a type check on the arguments to a command. It
200generates an error if a value does not have the expected type for its
201key, or if it does not understand a key that the Client included. The
202strictness of the Server catches wrong assumptions of Clients about
203the Server's schema. Clients can assume that, when such validation
204errors occur, they will be reported before the command generated any
205side effect.
206
207However, Clients must not assume any particular:
208
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.
5307d7d3
LC
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
b3e5e3e6 215
1829851c
PB
216Of course, the Server does guarantee to send valid JSON. But apart from
217this, a Client should be "conservative in what they send, and liberal in
218what they accept".
219
b3e5e3e6
MA
2206. Downstream extension of QMP
221------------------------------
222
223We recommend that downstream consumers of QEMU do *not* modify QMP.
224Management tools should be able to support both upstream and downstream
225versions of QMP without special logic, and downstream extensions are
226inherently at odds with that.
227
228However, we recognize that it is sometimes impossible for downstreams to
229avoid modifying QMP. Both upstream and downstream need to take care to
230preserve long-term compatibility and interoperability.
231
232To help with that, QMP reserves JSON object member names beginning with
233'__' (double underscore) for downstream use ("downstream names"). This
234means upstream will never use any downstream names for its commands,
235arguments, errors, asynchronous events, and so forth.
236
237Any new names downstream wishes to add must begin with '__'. To
238ensure compatibility with other downstreams, it is strongly
715c1860 239recommended that you prefix your downstream names with '__RFQDN_' where
b3e5e3e6
MA
240RFQDN is a valid, reverse fully qualified domain name which you
241control. For example, a qemu-kvm specific monitor command would be:
242
243 (qemu) __org.linux-kvm_enable_irqchip
244
245Downstream must not change the server greeting (section 2.2) other than
246to offer additional capabilities. But see below for why even that is
247discouraged.
248
249Section '5 Compatibility Considerations' applies to downstream as well
250as to upstream, obviously. It follows that downstream must behave
251exactly like upstream for any input not containing members with
252downstream names ("downstream members"), except it may add members
253with downstream names to its output.
254
255Thus, a client should not be able to distinguish downstream from
256upstream as long as it doesn't send input with downstream members, and
257properly ignores any downstream members in the output it receives.
258
259Advice on downstream modifications:
260
2611. Introducing new commands is okay. If you want to extend an existing
262 command, consider introducing a new one with the new behaviour
263 instead.
264
2652. Introducing new asynchronous messages is okay. If you want to extend
266 an existing message, consider adding a new one instead.
267
2683. Introducing new errors for use in new commands is okay. Adding new
269 errors to existing commands counts as extension, so 1. applies.
270
2714. New capabilities are strongly discouraged. Capabilities are for
272 evolving the basic protocol, and multiple diverging basic protocol
273 dialects are most undesirable.