]> git.proxmox.com Git - qemu.git/blame - QMP/qmp-spec.txt
user_only: compile everything with -fpie
[qemu.git] / QMP / qmp-spec.txt
CommitLineData
9c49a253 1 QEMU Monitor Protocol Specification - Version 0.1
f544d174
LC
2
31. Introduction
4===============
5
6This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
7which is available for applications to control QEMU at the machine-level.
8
9To enable QMP support, QEMU has to be run in "control mode". This is done by
10starting QEMU with the appropriate command-line options. Please, refer to the
11QEMU manual page for more information.
12
132. Protocol Specification
14=========================
15
16This section details the protocol format. For the purpose of this document
17"Client" is any application which is communicating with QEMU in control mode,
18and "Server" is QEMU itself.
19
20JSON data structures, when mentioned in this document, are always in the
21following format:
22
23 json-DATA-STRUCTURE-NAME
24
25Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
26the JSON standard:
27
28http://www.ietf.org/rfc/rfc4627.txt
29
9c49a253
LC
30For convenience, json-object members and json-array elements mentioned in
31this document will be in a certain order. However, in real protocol usage
32they can be in ANY order, thus no particular order should be assumed.
f544d174
LC
33
342.1 General Definitions
35-----------------------
36
372.1.1 All interactions transmitted by the Server are json-objects, always
38 terminating with CRLF
39
402.1.2 All json-objects members are mandatory when not specified otherwise
41
422.2 Server Greeting
43-------------------
44
45Right when connected the Server will issue a greeting message, which signals
46that the connection has been successfully established and that the Server is
47waiting for commands.
48
49The format is:
50
51{ "QMP": { "capabilities": json-array } }
52
53 Where,
54
55- The "capabilities" member specify the availability of features beyond the
56 baseline specification
57
582.3 Issuing Commands
59--------------------
60
61The format for command execution is:
62
63{ "execute": json-string, "arguments": json-object, "id": json-value }
64
65 Where,
66
67- The "execute" member identifies the command to be executed by the Server
68- The "arguments" member is used to pass any arguments required for the
69 execution of the command, it is optional when no arguments are required
70- The "id" member is a transaction identification associated with the
71 command execution, it is optional and will be part of the response if
72 provided
73
742.4 Commands Responses
75----------------------
76
77There are two possible responses which the Server will issue as the result
78of a command execution: success or error.
79
802.4.1 success
81-------------
82
83The success response is issued when the command execution has finished
84without errors.
85
86The format is:
87
9c49a253 88{ "return": json-object, "id": json-value }
f544d174
LC
89
90 Where,
91
92- The "return" member contains the command returned data, which is defined
9c49a253
LC
93 in a per-command basis or an empty json-object if the command does not
94 return data
f544d174
LC
95- The "id" member contains the transaction identification associated
96 with the command execution (if issued by the Client)
97
982.4.2 error
99-----------
100
101The error response is issued when the command execution could not be
102completed because of an error condition.
103
104The format is:
105
9c49a253 106{ "error": { "class": json-string, "data": json-object, "desc": json-string },
143d288c 107 "id": json-value }
f544d174
LC
108
109 Where,
110
111- The "class" member contains the error class name (eg. "ServiceUnavailable")
112- The "data" member contains specific error data and is defined in a
113 per-command basis, it will be an empty json-object if the error has no data
9c49a253 114- The "desc" member is a human-readable error message. Clients should
143d288c 115 not attempt to parse this message.
f544d174
LC
116- The "id" member contains the transaction identification associated with
117 the command execution (if issued by the Client)
118
119NOTE: Some errors can occur before the Server is able to read the "id" member,
120in these cases the "id" member will not be part of the error response, even
121if provided by the client.
122
1232.5 Asynchronous events
124-----------------------
125
126As a result of state changes, the Server may send messages unilaterally
127to the Client at any time. They are called 'asynchronous events'.
128
129The format is:
130
9c49a253 131{ "event": json-string, "data": json-object,
f544d174
LC
132 "timestamp": { "seconds": json-number, "microseconds": json-number } }
133
134 Where,
135
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
9c49a253 139- The "timestamp" member contains the exact time of when the event occurred
f544d174
LC
140 in the Server. It is a fixed json-object with time in seconds and
141 microseconds
142
143For a listing of supported asynchronous events, please, refer to the
144qmp-events.txt file.
145
1463. QMP Examples
147===============
148
149This section provides some examples of real QMP usage, in all of them
150'C' stands for 'Client' and 'S' stands for 'Server'.
151
1523.1 Server greeting
153-------------------
154
155S: {"QMP": {"capabilities": []}}
156
1573.2 Simple 'stop' execution
158---------------------------
159
160C: { "execute": "stop" }
9c49a253 161S: {"return": {}}
f544d174
LC
162
1633.3 KVM information
164-------------------
165
9c49a253
LC
166C: { "execute": "query-kvm", "id": "example" }
167S: {"return": {"enabled": true, "present": true}, "id": "example"}
f544d174
LC
168
1693.4 Parsing error
170------------------
171
172C: { "execute": }
9c49a253
LC
173S: {"error": {"class": "JSONParsing", "desc": "Invalid JSON syntax", "data":
174{}}}
f544d174
LC
175
1763.5 Powerdown event
177-------------------
178
179S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
180"POWERDOWN"}
181
9c49a253
LC
1824. Compatibility Considerations
183--------------------------------
f544d174 184
9c49a253
LC
185In order to achieve maximum compatibility between versions, Clients must not
186assume any particular:
f544d174 187
9c49a253
LC
188- Size of json-objects or length of json-arrays
189- Order of json-object members or json-array elements
190- Amount of errors generated by a command, that is, new errors can be added
191 to any existing command in newer versions of the Server
f544d174 192
9c49a253 193Additionally, Clients should always:
f544d174 194
9c49a253
LC
195- Check the capabilities json-array at connection time
196- Check the availability of commands with 'query-commands' before issuing them
197
1985. Recommendations to Client implementors
199-----------------------------------------
200
2015.1 The Server should be always started in pause mode, thus the Client is
202 able to perform any setup procedure without the risk of race conditions
203 and related problems