xref: /qemu/docs/interop/qmp-spec.rst (revision d56572584d9a5414c6a55c3f6b7ecce4b098926b)
1*d5657258SPeter Maydell..
2*d5657258SPeter Maydell    Copyright (C) 2009-2016 Red Hat, Inc.
3*d5657258SPeter Maydell
4*d5657258SPeter Maydell    This work is licensed under the terms of the GNU GPL, version 2 or
5*d5657258SPeter Maydell    later. See the COPYING file in the top-level directory.
6*d5657258SPeter Maydell
7*d5657258SPeter Maydell
8*d5657258SPeter Maydell===================================
9*d5657258SPeter MaydellQEMU Machine Protocol Specification
10*d5657258SPeter Maydell===================================
11*d5657258SPeter Maydell
12*d5657258SPeter MaydellThe QEMU Machine Protocol (QMP) is a JSON-based
13*d5657258SPeter Maydellprotocol which is available for applications to operate QEMU at the
14*d5657258SPeter Maydellmachine-level.  It is also in use by the QEMU Guest Agent (QGA), which
15*d5657258SPeter Maydellis available for host applications to interact with the guest
16*d5657258SPeter Maydelloperating system. This page specifies the general format of
17*d5657258SPeter Maydellthe protocol; details of the commands and data structures can
18*d5657258SPeter Maydellbe found in the :doc:`qemu-qmp-ref` and the :doc:`qemu-ga-ref`.
19*d5657258SPeter Maydell
20*d5657258SPeter Maydell.. contents::
21*d5657258SPeter Maydell
22*d5657258SPeter MaydellProtocol Specification
23*d5657258SPeter Maydell======================
24*d5657258SPeter Maydell
25*d5657258SPeter MaydellThis section details the protocol format. For the purpose of this
26*d5657258SPeter Maydelldocument, "Server" is either QEMU or the QEMU Guest Agent, and
27*d5657258SPeter Maydell"Client" is any application communicating with it via QMP.
28*d5657258SPeter Maydell
29*d5657258SPeter MaydellJSON data structures, when mentioned in this document, are always in the
30*d5657258SPeter Maydellfollowing format:
31*d5657258SPeter Maydell
32*d5657258SPeter Maydell    json-DATA-STRUCTURE-NAME
33*d5657258SPeter Maydell
34*d5657258SPeter MaydellWhere DATA-STRUCTURE-NAME is any valid JSON data structure, as defined
35*d5657258SPeter Maydellby the `JSON standard <http://www.ietf.org/rfc/rfc8259.txt>`_.
36*d5657258SPeter Maydell
37*d5657258SPeter MaydellThe server expects its input to be encoded in UTF-8, and sends its
38*d5657258SPeter Maydelloutput encoded in ASCII.
39*d5657258SPeter Maydell
40*d5657258SPeter MaydellFor convenience, json-object members mentioned in this document will
41*d5657258SPeter Maydellbe in a certain order. However, in real protocol usage they can be in
42*d5657258SPeter MaydellANY order, thus no particular order should be assumed. On the other
43*d5657258SPeter Maydellhand, use of json-array elements presumes that preserving order is
44*d5657258SPeter Maydellimportant unless specifically documented otherwise.  Repeating a key
45*d5657258SPeter Maydellwithin a json-object gives unpredictable results.
46*d5657258SPeter Maydell
47*d5657258SPeter MaydellAlso for convenience, the server will accept an extension of
48*d5657258SPeter Maydell``'single-quoted'`` strings in place of the usual ``"double-quoted"``
49*d5657258SPeter Maydelljson-string, and both input forms of strings understand an additional
50*d5657258SPeter Maydellescape sequence of ``\'`` for a single quote. The server will only use
51*d5657258SPeter Maydelldouble quoting on output.
52*d5657258SPeter Maydell
53*d5657258SPeter MaydellGeneral Definitions
54*d5657258SPeter Maydell-------------------
55*d5657258SPeter Maydell
56*d5657258SPeter MaydellAll interactions transmitted by the Server are json-objects, always
57*d5657258SPeter Maydellterminating with CRLF.
58*d5657258SPeter Maydell
59*d5657258SPeter MaydellAll json-objects members are mandatory when not specified otherwise.
60*d5657258SPeter Maydell
61*d5657258SPeter MaydellServer Greeting
62*d5657258SPeter Maydell---------------
63*d5657258SPeter Maydell
64*d5657258SPeter MaydellRight when connected the Server will issue a greeting message, which signals
65*d5657258SPeter Maydellthat the connection has been successfully established and that the Server is
66*d5657258SPeter Maydellready for capabilities negotiation (for more information refer to section
67*d5657258SPeter Maydell`Capabilities Negotiation`_).
68*d5657258SPeter Maydell
69*d5657258SPeter MaydellThe greeting message format is:
70*d5657258SPeter Maydell
71*d5657258SPeter Maydell::
72*d5657258SPeter Maydell
73*d5657258SPeter Maydell  { "QMP": { "version": json-object, "capabilities": json-array } }
74*d5657258SPeter Maydell
75*d5657258SPeter MaydellWhere:
76*d5657258SPeter Maydell
77*d5657258SPeter Maydell- The ``version`` member contains the Server's version information (the format
78*d5657258SPeter Maydell  is the same as for the query-version command).
79*d5657258SPeter Maydell- The ``capabilities`` member specifies the availability of features beyond the
80*d5657258SPeter Maydell  baseline specification; the order of elements in this array has no
81*d5657258SPeter Maydell  particular significance.
82*d5657258SPeter Maydell
83*d5657258SPeter MaydellCapabilities
84*d5657258SPeter Maydell------------
85*d5657258SPeter Maydell
86*d5657258SPeter MaydellCurrently supported capabilities are:
87*d5657258SPeter Maydell
88*d5657258SPeter Maydell``oob``
89*d5657258SPeter Maydell  the QMP server supports "out-of-band" (OOB) command
90*d5657258SPeter Maydell  execution, as described in section `Out-of-band execution`_.
91*d5657258SPeter Maydell
92*d5657258SPeter MaydellIssuing Commands
93*d5657258SPeter Maydell----------------
94*d5657258SPeter Maydell
95*d5657258SPeter MaydellThe format for command execution is:
96*d5657258SPeter Maydell
97*d5657258SPeter Maydell::
98*d5657258SPeter Maydell
99*d5657258SPeter Maydell  { "execute": json-string, "arguments": json-object, "id": json-value }
100*d5657258SPeter Maydell
101*d5657258SPeter Maydellor
102*d5657258SPeter Maydell
103*d5657258SPeter Maydell::
104*d5657258SPeter Maydell
105*d5657258SPeter Maydell  { "exec-oob": json-string, "arguments": json-object, "id": json-value }
106*d5657258SPeter Maydell
107*d5657258SPeter MaydellWhere:
108*d5657258SPeter Maydell
109*d5657258SPeter Maydell- The ``execute`` or ``exec-oob`` member identifies the command to be
110*d5657258SPeter Maydell  executed by the server.  The latter requests out-of-band execution.
111*d5657258SPeter Maydell- The ``arguments`` member is used to pass any arguments required for the
112*d5657258SPeter Maydell  execution of the command, it is optional when no arguments are
113*d5657258SPeter Maydell  required. Each command documents what contents will be considered
114*d5657258SPeter Maydell  valid when handling the json-argument.
115*d5657258SPeter Maydell- The ``id`` member is a transaction identification associated with the
116*d5657258SPeter Maydell  command execution, it is optional and will be part of the response
117*d5657258SPeter Maydell  if provided.  The ``id`` member can be any json-value.  A json-number
118*d5657258SPeter Maydell  incremented for each successive command works fine.
119*d5657258SPeter Maydell
120*d5657258SPeter MaydellThe actual commands are documented in the :doc:`qemu-qmp-ref`.
121*d5657258SPeter Maydell
122*d5657258SPeter MaydellOut-of-band execution
123*d5657258SPeter Maydell---------------------
124*d5657258SPeter Maydell
125*d5657258SPeter MaydellThe server normally reads, executes and responds to one command after
126*d5657258SPeter Maydellthe other.  The client therefore receives command responses in issue
127*d5657258SPeter Maydellorder.
128*d5657258SPeter Maydell
129*d5657258SPeter MaydellWith out-of-band execution enabled via `capabilities negotiation`_,
130*d5657258SPeter Maydellthe server reads and queues commands as they arrive.  It executes
131*d5657258SPeter Maydellcommands from the queue one after the other.  Commands executed
132*d5657258SPeter Maydellout-of-band jump the queue: the command get executed right away,
133*d5657258SPeter Maydellpossibly overtaking prior in-band commands.  The client may therefore
134*d5657258SPeter Maydellreceive such a command's response before responses from prior in-band
135*d5657258SPeter Maydellcommands.
136*d5657258SPeter Maydell
137*d5657258SPeter MaydellTo be able to match responses back to their commands, the client needs
138*d5657258SPeter Maydellto pass ``id`` with out-of-band commands.  Passing it with all commands
139*d5657258SPeter Maydellis recommended for clients that accept capability ``oob``.
140*d5657258SPeter Maydell
141*d5657258SPeter MaydellIf the client sends in-band commands faster than the server can
142*d5657258SPeter Maydellexecute them, the server will stop reading requests until the request
143*d5657258SPeter Maydellqueue length is reduced to an acceptable range.
144*d5657258SPeter Maydell
145*d5657258SPeter MaydellTo ensure commands to be executed out-of-band get read and executed,
146*d5657258SPeter Maydellthe client should have at most eight in-band commands in flight.
147*d5657258SPeter Maydell
148*d5657258SPeter MaydellOnly a few commands support out-of-band execution.  The ones that do
149*d5657258SPeter Maydellhave ``"allow-oob": true`` in the output of ``query-qmp-schema``.
150*d5657258SPeter Maydell
151*d5657258SPeter MaydellCommands Responses
152*d5657258SPeter Maydell------------------
153*d5657258SPeter Maydell
154*d5657258SPeter MaydellThere are two possible responses which the Server will issue as the result
155*d5657258SPeter Maydellof a command execution: success or error.
156*d5657258SPeter Maydell
157*d5657258SPeter MaydellAs long as the commands were issued with a proper ``id`` field, then the
158*d5657258SPeter Maydellsame ``id`` field will be attached in the corresponding response message
159*d5657258SPeter Maydellso that requests and responses can match.  Clients should drop all the
160*d5657258SPeter Maydellresponses that have an unknown ``id`` field.
161*d5657258SPeter Maydell
162*d5657258SPeter MaydellSuccess
163*d5657258SPeter Maydell-------
164*d5657258SPeter Maydell
165*d5657258SPeter MaydellThe format of a success response is:
166*d5657258SPeter Maydell
167*d5657258SPeter Maydell::
168*d5657258SPeter Maydell
169*d5657258SPeter Maydell  { "return": json-value, "id": json-value }
170*d5657258SPeter Maydell
171*d5657258SPeter MaydellWhere:
172*d5657258SPeter Maydell
173*d5657258SPeter Maydell- The ``return`` member contains the data returned by the command, which
174*d5657258SPeter Maydell  is defined on a per-command basis (usually a json-object or
175*d5657258SPeter Maydell  json-array of json-objects, but sometimes a json-number, json-string,
176*d5657258SPeter Maydell  or json-array of json-strings); it is an empty json-object if the
177*d5657258SPeter Maydell  command does not return data.
178*d5657258SPeter Maydell- The ``id`` member contains the transaction identification associated
179*d5657258SPeter Maydell  with the command execution if issued by the Client.
180*d5657258SPeter Maydell
181*d5657258SPeter MaydellError
182*d5657258SPeter Maydell-----
183*d5657258SPeter Maydell
184*d5657258SPeter MaydellThe format of an error response is:
185*d5657258SPeter Maydell
186*d5657258SPeter Maydell::
187*d5657258SPeter Maydell
188*d5657258SPeter Maydell  { "error": { "class": json-string, "desc": json-string }, "id": json-value }
189*d5657258SPeter Maydell
190*d5657258SPeter MaydellWhere:
191*d5657258SPeter Maydell
192*d5657258SPeter Maydell- The ``class`` member contains the error class name (eg. ``"GenericError"``).
193*d5657258SPeter Maydell- The ``desc`` member is a human-readable error message. Clients should
194*d5657258SPeter Maydell  not attempt to parse this message.
195*d5657258SPeter Maydell- The ``id`` member contains the transaction identification associated with
196*d5657258SPeter Maydell  the command execution if issued by the Client.
197*d5657258SPeter Maydell
198*d5657258SPeter MaydellNOTE: Some errors can occur before the Server is able to read the ``id`` member;
199*d5657258SPeter Maydellin these cases the ``id`` member will not be part of the error response, even
200*d5657258SPeter Maydellif provided by the client.
201*d5657258SPeter Maydell
202*d5657258SPeter MaydellAsynchronous events
203*d5657258SPeter Maydell-------------------
204*d5657258SPeter Maydell
205*d5657258SPeter MaydellAs a result of state changes, the Server may send messages unilaterally
206*d5657258SPeter Maydellto the Client at any time, when not in the middle of any other
207*d5657258SPeter Maydellresponse. They are called "asynchronous events".
208*d5657258SPeter Maydell
209*d5657258SPeter MaydellThe format of asynchronous events is:
210*d5657258SPeter Maydell
211*d5657258SPeter Maydell::
212*d5657258SPeter Maydell
213*d5657258SPeter Maydell  { "event": json-string, "data": json-object,
214*d5657258SPeter Maydell    "timestamp": { "seconds": json-number, "microseconds": json-number } }
215*d5657258SPeter Maydell
216*d5657258SPeter MaydellWhere:
217*d5657258SPeter Maydell
218*d5657258SPeter Maydell- The ``event`` member contains the event's name.
219*d5657258SPeter Maydell- The ``data`` member contains event specific data, which is defined in a
220*d5657258SPeter Maydell  per-event basis. It is optional.
221*d5657258SPeter Maydell- The ``timestamp`` member contains the exact time of when the event
222*d5657258SPeter Maydell  occurred in the Server. It is a fixed json-object with time in
223*d5657258SPeter Maydell  seconds and microseconds relative to the Unix Epoch (1 Jan 1970); if
224*d5657258SPeter Maydell  there is a failure to retrieve host time, both members of the
225*d5657258SPeter Maydell  timestamp will be set to -1.
226*d5657258SPeter Maydell
227*d5657258SPeter MaydellThe actual asynchronous events are documented in the :doc:`qemu-qmp-ref`.
228*d5657258SPeter Maydell
229*d5657258SPeter MaydellSome events are rate-limited to at most one per second.  If additional
230*d5657258SPeter Maydell"similar" events arrive within one second, all but the last one are
231*d5657258SPeter Maydelldropped, and the last one is delayed.  "Similar" normally means same
232*d5657258SPeter Maydellevent type.
233*d5657258SPeter Maydell
234*d5657258SPeter MaydellForcing the JSON parser into known-good state
235*d5657258SPeter Maydell---------------------------------------------
236*d5657258SPeter Maydell
237*d5657258SPeter MaydellIncomplete or invalid input can leave the server's JSON parser in a
238*d5657258SPeter Maydellstate where it can't parse additional commands.  To get it back into
239*d5657258SPeter Maydellknown-good state, the client should provoke a lexical error.
240*d5657258SPeter Maydell
241*d5657258SPeter MaydellThe cleanest way to do that is sending an ASCII control character
242*d5657258SPeter Maydellother than ``\t`` (horizontal tab), ``\r`` (carriage return), or
243*d5657258SPeter Maydell``\n`` (new line).
244*d5657258SPeter Maydell
245*d5657258SPeter MaydellSadly, older versions of QEMU can fail to flag this as an error.  If a
246*d5657258SPeter Maydellclient needs to deal with them, it should send a 0xFF byte.
247*d5657258SPeter Maydell
248*d5657258SPeter MaydellQGA Synchronization
249*d5657258SPeter Maydell-------------------
250*d5657258SPeter Maydell
251*d5657258SPeter MaydellWhen a client connects to QGA over a transport lacking proper
252*d5657258SPeter Maydellconnection semantics such as virtio-serial, QGA may have read partial
253*d5657258SPeter Maydellinput from a previous client.  The client needs to force QGA's parser
254*d5657258SPeter Maydellinto known-good state using the previous section's technique.
255*d5657258SPeter MaydellMoreover, the client may receive output a previous client didn't read.
256*d5657258SPeter MaydellTo help with skipping that output, QGA provides the
257*d5657258SPeter Maydell``guest-sync-delimited`` command.  Refer to its documentation for
258*d5657258SPeter Maydelldetails.
259*d5657258SPeter Maydell
260*d5657258SPeter Maydell
261*d5657258SPeter MaydellQMP Examples
262*d5657258SPeter Maydell============
263*d5657258SPeter Maydell
264*d5657258SPeter MaydellThis section provides some examples of real QMP usage, in all of them
265*d5657258SPeter Maydell``->`` marks text sent by the Client and ``<-`` marks replies by the Server.
266*d5657258SPeter Maydell
267*d5657258SPeter Maydell.. admonition:: Example
268*d5657258SPeter Maydell
269*d5657258SPeter Maydell  Server greeting
270*d5657258SPeter Maydell
271*d5657258SPeter Maydell  .. code-block:: QMP
272*d5657258SPeter Maydell
273*d5657258SPeter Maydell    <- { "QMP": {"version": {"qemu": {"micro": 0, "minor": 0, "major": 3},
274*d5657258SPeter Maydell         "package": "v3.0.0"}, "capabilities": ["oob"] } }
275*d5657258SPeter Maydell
276*d5657258SPeter Maydell.. admonition:: Example
277*d5657258SPeter Maydell
278*d5657258SPeter Maydell  Capabilities negotiation
279*d5657258SPeter Maydell
280*d5657258SPeter Maydell  .. code-block:: QMP
281*d5657258SPeter Maydell
282*d5657258SPeter Maydell    -> { "execute": "qmp_capabilities", "arguments": { "enable": ["oob"] } }
283*d5657258SPeter Maydell    <- { "return": {}}
284*d5657258SPeter Maydell
285*d5657258SPeter Maydell.. admonition:: Example
286*d5657258SPeter Maydell
287*d5657258SPeter Maydell  Simple 'stop' execution
288*d5657258SPeter Maydell
289*d5657258SPeter Maydell  .. code-block:: QMP
290*d5657258SPeter Maydell
291*d5657258SPeter Maydell    -> { "execute": "stop" }
292*d5657258SPeter Maydell    <- { "return": {} }
293*d5657258SPeter Maydell
294*d5657258SPeter Maydell.. admonition:: Example
295*d5657258SPeter Maydell
296*d5657258SPeter Maydell  KVM information
297*d5657258SPeter Maydell
298*d5657258SPeter Maydell  .. code-block:: QMP
299*d5657258SPeter Maydell
300*d5657258SPeter Maydell    -> { "execute": "query-kvm", "id": "example" }
301*d5657258SPeter Maydell    <- { "return": { "enabled": true, "present": true }, "id": "example"}
302*d5657258SPeter Maydell
303*d5657258SPeter Maydell.. admonition:: Example
304*d5657258SPeter Maydell
305*d5657258SPeter Maydell  Parsing error
306*d5657258SPeter Maydell
307*d5657258SPeter Maydell  .. code-block:: QMP
308*d5657258SPeter Maydell
309*d5657258SPeter Maydell    -> { "execute": }
310*d5657258SPeter Maydell    <- { "error": { "class": "GenericError", "desc": "Invalid JSON syntax" } }
311*d5657258SPeter Maydell
312*d5657258SPeter Maydell.. admonition:: Example
313*d5657258SPeter Maydell
314*d5657258SPeter Maydell  Powerdown event
315*d5657258SPeter Maydell
316*d5657258SPeter Maydell  .. code-block:: QMP
317*d5657258SPeter Maydell
318*d5657258SPeter Maydell    <- { "timestamp": { "seconds": 1258551470, "microseconds": 802384 },
319*d5657258SPeter Maydell        "event": "POWERDOWN" }
320*d5657258SPeter Maydell
321*d5657258SPeter Maydell.. admonition:: Example
322*d5657258SPeter Maydell
323*d5657258SPeter Maydell  Out-of-band execution
324*d5657258SPeter Maydell
325*d5657258SPeter Maydell  .. code-block:: QMP
326*d5657258SPeter Maydell
327*d5657258SPeter Maydell    -> { "exec-oob": "migrate-pause", "id": 42 }
328*d5657258SPeter Maydell    <- { "id": 42,
329*d5657258SPeter Maydell         "error": { "class": "GenericError",
330*d5657258SPeter Maydell          "desc": "migrate-pause is currently only supported during postcopy-active state" } }
331*d5657258SPeter Maydell
332*d5657258SPeter Maydell
333*d5657258SPeter MaydellCapabilities Negotiation
334*d5657258SPeter Maydell========================
335*d5657258SPeter Maydell
336*d5657258SPeter MaydellWhen a Client successfully establishes a connection, the Server is in
337*d5657258SPeter MaydellCapabilities Negotiation mode.
338*d5657258SPeter Maydell
339*d5657258SPeter MaydellIn this mode only the ``qmp_capabilities`` command is allowed to run; all
340*d5657258SPeter Maydellother commands will return the ``CommandNotFound`` error. Asynchronous
341*d5657258SPeter Maydellmessages are not delivered either.
342*d5657258SPeter Maydell
343*d5657258SPeter MaydellClients should use the ``qmp_capabilities`` command to enable capabilities
344*d5657258SPeter Maydelladvertised in the `Server Greeting`_ which they support.
345*d5657258SPeter Maydell
346*d5657258SPeter MaydellWhen the ``qmp_capabilities`` command is issued, and if it does not return an
347*d5657258SPeter Maydellerror, the Server enters Command mode where capabilities changes take
348*d5657258SPeter Maydelleffect, all commands (except ``qmp_capabilities``) are allowed and asynchronous
349*d5657258SPeter Maydellmessages are delivered.
350*d5657258SPeter Maydell
351*d5657258SPeter MaydellCompatibility Considerations
352*d5657258SPeter Maydell============================
353*d5657258SPeter Maydell
354*d5657258SPeter MaydellAll protocol changes or new features which modify the protocol format in an
355*d5657258SPeter Maydellincompatible way are disabled by default and will be advertised by the
356*d5657258SPeter Maydellcapabilities array (in the `Server Greeting`_). Thus, Clients can check
357*d5657258SPeter Maydellthat array and enable the capabilities they support.
358*d5657258SPeter Maydell
359*d5657258SPeter MaydellThe QMP Server performs a type check on the arguments to a command.  It
360*d5657258SPeter Maydellgenerates an error if a value does not have the expected type for its
361*d5657258SPeter Maydellkey, or if it does not understand a key that the Client included.  The
362*d5657258SPeter Maydellstrictness of the Server catches wrong assumptions of Clients about
363*d5657258SPeter Maydellthe Server's schema.  Clients can assume that, when such validation
364*d5657258SPeter Maydellerrors occur, they will be reported before the command generated any
365*d5657258SPeter Maydellside effect.
366*d5657258SPeter Maydell
367*d5657258SPeter MaydellHowever, Clients must not assume any particular:
368*d5657258SPeter Maydell
369*d5657258SPeter Maydell- Length of json-arrays
370*d5657258SPeter Maydell- Size of json-objects; in particular, future versions of QEMU may add
371*d5657258SPeter Maydell  new keys and Clients should be able to ignore them
372*d5657258SPeter Maydell- Order of json-object members or json-array elements
373*d5657258SPeter Maydell- Amount of errors generated by a command, that is, new errors can be added
374*d5657258SPeter Maydell  to any existing command in newer versions of the Server
375*d5657258SPeter Maydell
376*d5657258SPeter MaydellAny command or member name beginning with ``x-`` is deemed experimental,
377*d5657258SPeter Maydelland may be withdrawn or changed in an incompatible manner in a future
378*d5657258SPeter Maydellrelease.
379*d5657258SPeter Maydell
380*d5657258SPeter MaydellOf course, the Server does guarantee to send valid JSON.  But apart from
381*d5657258SPeter Maydellthis, a Client should be "conservative in what they send, and liberal in
382*d5657258SPeter Maydellwhat they accept".
383*d5657258SPeter Maydell
384*d5657258SPeter MaydellDownstream extension of QMP
385*d5657258SPeter Maydell===========================
386*d5657258SPeter Maydell
387*d5657258SPeter MaydellWe recommend that downstream consumers of QEMU do *not* modify QMP.
388*d5657258SPeter MaydellManagement tools should be able to support both upstream and downstream
389*d5657258SPeter Maydellversions of QMP without special logic, and downstream extensions are
390*d5657258SPeter Maydellinherently at odds with that.
391*d5657258SPeter Maydell
392*d5657258SPeter MaydellHowever, we recognize that it is sometimes impossible for downstreams to
393*d5657258SPeter Maydellavoid modifying QMP.  Both upstream and downstream need to take care to
394*d5657258SPeter Maydellpreserve long-term compatibility and interoperability.
395*d5657258SPeter Maydell
396*d5657258SPeter MaydellTo help with that, QMP reserves JSON object member names beginning with
397*d5657258SPeter Maydell``__`` (double underscore) for downstream use ("downstream names").  This
398*d5657258SPeter Maydellmeans upstream will never use any downstream names for its commands,
399*d5657258SPeter Maydellarguments, errors, asynchronous events, and so forth.
400*d5657258SPeter Maydell
401*d5657258SPeter MaydellAny new names downstream wishes to add must begin with ``__``.  To
402*d5657258SPeter Maydellensure compatibility with other downstreams, it is strongly
403*d5657258SPeter Maydellrecommended that you prefix your downstream names with ``__RFQDN_`` where
404*d5657258SPeter MaydellRFQDN is a valid, reverse fully qualified domain name which you
405*d5657258SPeter Maydellcontrol.  For example, a qemu-kvm specific monitor command would be:
406*d5657258SPeter Maydell
407*d5657258SPeter Maydell::
408*d5657258SPeter Maydell
409*d5657258SPeter Maydell    (qemu) __org.linux-kvm_enable_irqchip
410*d5657258SPeter Maydell
411*d5657258SPeter MaydellDownstream must not change the `server greeting`_ other than
412*d5657258SPeter Maydellto offer additional capabilities.  But see below for why even that is
413*d5657258SPeter Maydelldiscouraged.
414*d5657258SPeter Maydell
415*d5657258SPeter MaydellThe section `Compatibility Considerations`_ applies to downstream as well
416*d5657258SPeter Maydellas to upstream, obviously.  It follows that downstream must behave
417*d5657258SPeter Maydellexactly like upstream for any input not containing members with
418*d5657258SPeter Maydelldownstream names ("downstream members"), except it may add members
419*d5657258SPeter Maydellwith downstream names to its output.
420*d5657258SPeter Maydell
421*d5657258SPeter MaydellThus, a client should not be able to distinguish downstream from
422*d5657258SPeter Maydellupstream as long as it doesn't send input with downstream members, and
423*d5657258SPeter Maydellproperly ignores any downstream members in the output it receives.
424*d5657258SPeter Maydell
425*d5657258SPeter MaydellAdvice on downstream modifications:
426*d5657258SPeter Maydell
427*d5657258SPeter Maydell1. Introducing new commands is okay.  If you want to extend an existing
428*d5657258SPeter Maydell   command, consider introducing a new one with the new behaviour
429*d5657258SPeter Maydell   instead.
430*d5657258SPeter Maydell
431*d5657258SPeter Maydell2. Introducing new asynchronous messages is okay.  If you want to extend
432*d5657258SPeter Maydell   an existing message, consider adding a new one instead.
433*d5657258SPeter Maydell
434*d5657258SPeter Maydell3. Introducing new errors for use in new commands is okay.  Adding new
435*d5657258SPeter Maydell   errors to existing commands counts as extension, so 1. applies.
436*d5657258SPeter Maydell
437*d5657258SPeter Maydell4. New capabilities are strongly discouraged.  Capabilities are for
438*d5657258SPeter Maydell   evolving the basic protocol, and multiple diverging basic protocol
439*d5657258SPeter Maydell   dialects are most undesirable.
440