ANN: QEMU Monitor Protocol git tree
Hi there,
While I was converting command handlers to the QObject style I realized that it would be very interesting to have the protocol working up front, so that converted handlers could be tested to assure that their data types have been chosen correctly.
More importantly, some protocol design decisions can affect handlers signatures, so having at least an idea of how the protocol will look like will help us to stay on the right track during mass conversion.
So, I have implemented a rudimentary version of the QEMU Monitor Protocol (QMP) it has a command-line switch to enable the protocol.
You will find it at:
http://repo.or.cz/w/qemu/qmp-unstable.git
The QMP directory of that tree has some documents plus a Python script which communicates with QEMU by using the protocol and emulates a shell, although only few commands are working..
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
What follows is the protocol draft spec. I will not post the patches because the current implementation is buggy and limited, but it will improve in the next weeks, as I'm going to work on it in parallel with the conversions.
Thanks.
"""
QEMU Monitor Protocol Draft Specification - Version 0.1
1. Introduction
===============
This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol which is available for applications to control QEMU at the machine-level.
To enable QMP support, QEMU has to be run in "control mode". This is done by starting QEMU with the appropriate command-line options. Please, refer to the QEMU manual page for more information.
This specification is a work in progress and part of it may NOT be available in QEMU, the 'Current Implementation' section has details regarding what has already been implemented and known problems.
2. Protocol Specification
=========================
This section details the protocol format. For the purpose of this document "Client" is any application which is communicating with QEMU in control mode, and "Server" is QEMU itself.
JSON data structures, when mentioned in this document, are always in the following format:
json-DATA-STRUCTURE-NAME
Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by the JSON standard:
http://www.ietf.org/rfc/rfc4627.txt
For convenience, json-objects mentioned in this document will have its members in a certain order. However, in real protocol usage json-objects members can be in ANY order, thus no particular order should be assumed.
2.1 General Definitions
-----------------------
All interactions transmitted by Client and Server are json-objects that end with CRLF.
All json-objects members are mandatory when not specified otherwise.
2.2 Server Greeting
-------------------
Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specification
2.3 Issuing Commands
--------------------
The format for command execution is:
{ "execute": json-string, "id": json-value, "arguments": json-object }
Where,
- The "execute" member identifies the command to be executed by the Server
- The "id" member is a transaction identification associated with the command execution, it is optional
- The "arguments" member is used to pass any arguments required for the execution of the command, it is optional when no arguments are required
For a listing of supported commands and theirs arguments, please, refer to the qmp-command-set.txt file.
2.4 Commands Execution
----------------------
TODO: explain parallel execution and the "id" member.
2.5 Commands Responses
----------------------
There are two possible responses which the Server will issue as the result of a command completion: success or error.
2.5.1 success
-------------
The success response is issued when the command execution has finished without errors.
The format is:
{ "return": json-value, "id": json-value, "timestamp": json-string }
Where,
- The "return" member contains the command returned data, which is defined in a per-command basis or json-null if the command does not return data
- The "id" member contains the transaction identification associated with the command execution (if issued by the Client)
- The "timestamp" member contains the exact time of when the response was generated by the Server (FIXME: format)
2.5.2 error
-----------
The error response is issued when the command execution could not be completed because of an error condition.
The format is:
{ "error": { "code": json-number, "desc": json-string, "data": json-value } "id": json-value, "timestamp": json-string }
Where,
- The "code" member contains the error code. Its first digit indicates the error type, as show below:
1 Server
2 Protocol
3 Command Specific
- The "desc" member contains the error description
- The "data" member contains specific error data, it is optional
- The "id" member contains the transaction identification associated with the command execution (if issued by the Client)
- The "timestamp" member contains the exact time of when the response was generated by the Server (FIXME: format)
Section '2.7 Server and Protocol errors' contains additional information about error handling.
2.6 Asynchronous events
-----------------------
As a result of state changes, the Server may send messages unilaterally to the Client at any time. This is called 'asynchronous events'.
The format is:
{ "event": json-string, "timestamp": json-string, "data": json-value }
Where,
- The "event" member contains the event's name
- The "timestamp" member contains the exact time of when the event happend in the Server (FIXME: format)
- The "data" member contains event specific data, which is defined in a per-event basis, it is optional
For a listing of supported asynchronous events, please, refer to the qmp-command-set.txt file.
2.7 Server and Protocol errors
------------------------------
TODO: describe all possible server and protocol errors.
3. Examples
============
This section provides some examples of real QMP usage, in all of them 'C' stands for 'Client' and 'S' stands for 'Server'.
3.1 Simple 'stop' execution
---------------------------
S: { "QEMU": "0.11.50", "QMP": "0.1", "capabilities": [] }
C: { "execute": "stop" }
S: { "return": null, "timestamp": "" }
3.2 KVM information
-------------------
S: { "QEMU": "0.11.50", "QMP": "0.1", "capabilities": [] }
C: { "execute": "info", "id": 1, "arguments": { "item": "kvm" } }
S: { "return": "enabled", "id": 1, "timestamp": "" }
3.3 Error on 'info balloon' execution
-------------------------------------
S: { "QEMU": "0.11.50", "QMP": "0.1", "capabilities": [] }
C: { "execute": "info", "id": "abc", "arguments": { "item": "balloon" } }
S: { "error": { "code": 354, "Ballooning not activated in VM" }, "id": "abc", "timestamp": "" }
3.4 Powerdown event
-------------------
S: { "QEMU": "0.11.50", "QMP": "0.1", "capabilities": [] }
...
S: { "event": "POWERDOWN", "timestamp": "" }
...
4. Current Implementation
=========================
The current QMP implementation lacks some of the protocol capabilities specified in this document.
The most important one is the execution of commands as discussed in the section '2.3 Issuing Commands'. Currently the Server does not support it.
Protocol input is done by issuing regular ASCII strings, as it is done when using the humam Monitor protocol.
For example, to query the current balloon information the Client should issue:
"info balloon\r\n"
Additionally, the following limitations are present:
- The transaction "id" is not supported
- json-strings issued by the Server are not in Unicode format
- All "timestamp" members are always an empty json-string ""
- Error handling is basically not implemented
"""
Quoted 11 lines · Luiz Capitulino
Hi there,
While I was converting command handlers to the QObject style I realized that it would be very interesting to have the protocol working up front, so that converted handlers could be tested to assure that their data types have been chosen correctly.
More importantly, some protocol design decisions can affect handlers signatures, so having at least an idea of how the protocol will look like will help us to stay on the right track during mass conversion.
Quoted 7 lines
So, I have implemented a rudimentary version of the QEMU Monitor Protocol (QMP) it has a command-line switch to enable the protocol.
You will find it at:
I think this is a pretty reasonable approach to take since qmp is relatively isolated from the changes going on in the rest of the tree.
Quoted 6 lines
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
But the wire protocol is the thing I care the least about. I care more about the internal refactoring.
Quoted 38 lines
"""
QEMU Monitor Protocol Draft Specification - Version 0.11. Introduction
===============This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol which is available for applications to control QEMU at the machine-level.
To enable QMP support, QEMU has to be run in "control mode". This is done by starting QEMU with the appropriate command-line options. Please, refer to the QEMU manual page for more information.
This specification is a work in progress and part of it may NOT be available in QEMU, the 'Current Implementation' section has details regarding what has already been implemented and known problems.
2. Protocol Specification
=========================This section details the protocol format. For the purpose of this document "Client" is any application which is communicating with QEMU in control mode, and "Server" is QEMU itself.
JSON data structures, when mentioned in this document, are always in the following format:
json-DATA-STRUCTURE-NAME
Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by the JSON standard:
http://www.ietf.org/rfc/rfc4627.txt
For convenience, json-objects mentioned in this document will have its members in a certain order. However, in real protocol usage json-objects members can be in ANY order, thus no particular order should be assumed.
Quoted 6 lines
2.1 General Definitions
-----------------------All interactions transmitted by Client and Server are json-objects that end with CRLF.
CRLF? Really?
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
Quoted 8 lines
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specification
Version and capability are a bit redundant, no? Any reason to have QEMU's version in the initial hello too?
Regards,
Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Luiz Capitulino
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
Quoted 4 lines
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
I've googled around quickly and there are at least 5 pieces of C code and/or C libraries that can parse JSON. Hopefully one of them will be sufficient / suitable for libvirt's needs. We'll just need to try it out and see what happens....
Quoted 11 lines
Quoted 6 lines
2.1 General Definitions
-----------------------All interactions transmitted by Client and Server are json-objects that end with CRLF.
CRLF? Really?
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 15 lines · Luiz Capitulino
Hi there,
While I was converting command handlers to the QObject style I realized that it would be very interesting to have the protocol working up front, so that converted handlers could be tested to assure that their data types have been chosen correctly.
More importantly, some protocol design decisions can affect handlers signatures, so having at least an idea of how the protocol will look like will help us to stay on the right track during mass conversion.
So, I have implemented a rudimentary version of the QEMU Monitor Protocol (QMP) it has a command-line switch to enable the protocol.
Quoted 7 lines
You will find it at:
http://repo.or.cz/w/qemu/qmp-unstable.git
The QMP directory of that tree has some documents plus a Python script which communicates with QEMU by using the protocol and emulates a shell, although only few commands are working..
It doesn't compile on i386
$ make CC i386-softmmu/monitor.o cc1: warnings being treated as errors /home/berrange/src/external/qmp-unstable/monitor.c: In function ‘monitor_json_emitter’: /home/berrange/src/external/qmp-unstable/monitor.c:277: error: format ‘%li’ expects type ‘long int’, but argument 3 has type ‘int64_t’ /home/berrange/src/external/qmp-unstable/monitor.c: In function ‘monitor_print_qobject’: /home/berrange/src/external/qmp-unstable/monitor.c:398: error: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘int64_t’ make[1]: *** [monitor.o] Error 1
Having -Werror by default really is painful :-(
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 9 lines · Daniel P. Berrange
Quoted 3 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Daniel P. Berrange
Quoted 2 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Quoted 3 lines
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Agreed, regexes are unnecessary. Also because a regex cannot parse JSON; it can only detect _some_ invalid JSON inputs, and then only if you're given an already complete input.
In other words, there are Javascript JSON parsers that are just "match a regexp and run eval on the input", but the actual parsing is done by the Javascript interpreter using eval. The regexp is just avoiding the security problems that are inherent in eval.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Daniel P. Berrange
Quoted 2 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Quoted 7 lines
Quoted 3 lines
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Agreed, regexes are unnecessary. Also because a regex cannot parse JSON; it can only detect _some_ invalid JSON inputs, and then only if you're given an already complete input.
In other words, there are Javascript JSON parsers that are just "match a regexp and run eval on the input", but the actual parsing is done by the Javascript interpreter using eval. The regexp is just avoiding the security problems that are inherent in eval.
On the other hand, the two parsers I looked at only accept a string as input, not a stream (strangely, one of them internally converts the string to a stream, but doesn't expose the stream interface), so record termination might be helpful to parsers. Would be best not to rely on it in the server, though.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 15 lines · On Tue, 22 Sep 2009 20:56:04 -0500 Anthony Liguori <[email protected]>…
Quoted 14 lines · Luiz Capitulino
Hi there,
While I was converting command handlers to the QObject style I realized that it would be very interesting to have the protocol working up front, so that converted handlers could be tested to assure that their data types have been chosen correctly.
More importantly, some protocol design decisions can affect handlers signatures, so having at least an idea of how the protocol will look like will help us to stay on the right track during mass conversion.
So, I have implemented a rudimentary version of the QEMU Monitor Protocol (QMP) it has a command-line switch to enable the protocol.
Quoted 7 lines
Quoted 4 lines
You will find it at:
I think this is a pretty reasonable approach to take since qmp is relatively isolated from the changes going on in the rest of the tree.
Yeah, nice.
Quoted 11 lines
Quoted 6 lines
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
Ok, I agree. I've seen some json implementations out there
(not exactly in the form of a library), but didn't try any of them.
Quoted 2 lines
But the wire protocol is the thing I care the least about. I care more about the internal refactoring.
Yes, me too.
For now we can focus on protocol decisions that may affect the
internal refactoring (and that's my goal with this tree).
For example, looks like we are going to need a more sophisticated
error handling implementation in order to support the protocol requirements.
I'm working on this and should post patches soon.
Quoted 41 lines
Quoted 41 lines
"""
QEMU Monitor Protocol Draft Specification - Version 0.11. Introduction
===============This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol which is available for applications to control QEMU at the machine-level.
To enable QMP support, QEMU has to be run in "control mode". This is done by starting QEMU with the appropriate command-line options. Please, refer to the QEMU manual page for more information.
This specification is a work in progress and part of it may NOT be available in QEMU, the 'Current Implementation' section has details regarding what has already been implemented and known problems.
2. Protocol Specification
=========================This section details the protocol format. For the purpose of this document "Client" is any application which is communicating with QEMU in control mode, and "Server" is QEMU itself.
JSON data structures, when mentioned in this document, are always in the following format:
json-DATA-STRUCTURE-NAME
Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by the JSON standard:
http://www.ietf.org/rfc/rfc4627.txt
For convenience, json-objects mentioned in this document will have its members in a certain order. However, in real protocol usage json-objects members can be in ANY order, thus no particular order should be assumed.
2.1 General Definitions
-----------------------
Quoted 8 lines
Quoted 3 lines
All interactions transmitted by Client and Server are json-objects that end with CRLF.
CRLF? Really?
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
Hm, I've assumed some kind of end of line would be needed.
Quoted 10 lines
Quoted 8 lines
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specificationVersion and capability are a bit redundant, no? Any reason to have QEMU's version in the initial hello too?
I thought that clients would always want to know to what
QEMU they are talking to.
What do you suggest?
Quoted 26 lines · On Wed, 23 Sep 2009 11:08:22 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 15 lines · Luiz Capitulino
Hi there,
While I was converting command handlers to the QObject style I realized that it would be very interesting to have the protocol working up front, so that converted handlers could be tested to assure that their data types have been chosen correctly.
More importantly, some protocol design decisions can affect handlers signatures, so having at least an idea of how the protocol will look like will help us to stay on the right track during mass conversion.
So, I have implemented a rudimentary version of the QEMU Monitor Protocol (QMP) it has a command-line switch to enable the protocol.
Quoted 7 lines
You will find it at:
http://repo.or.cz/w/qemu/qmp-unstable.git
The QMP directory of that tree has some documents plus a Python script which communicates with QEMU by using the protocol and emulates a shell, although only few commands are working..
It doesn't compile on i386
Quoted 8 lines
$ make CC i386-softmmu/monitor.o cc1: warnings being treated as errors /home/berrange/src/external/qmp-unstable/monitor.c: In function ‘monitor_json_emitter’: /home/berrange/src/external/qmp-unstable/monitor.c:277: error: format ‘%li’ expects type ‘long int’, but argument 3 has type ‘int64_t’ /home/berrange/src/external/qmp-unstable/monitor.c: In function ‘monitor_print_qobject’: /home/berrange/src/external/qmp-unstable/monitor.c:398: error: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘int64_t’ make[1]: *** [monitor.o] Error 1
Fixed.
Note that I'm rebasing this tree, so that I can cherry-pick
patches easily for upstream submission.
Quoted 25 lines · Avi Kivity
Quoted 15 lines · Paolo Bonzini
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Daniel P. Berrange
Quoted 3 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we
need explicit message boundaries?I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Quoted 3 lines
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Quoted 8 lines
Agreed, regexes are unnecessary. Also because a regex cannot parse JSON; it can only detect _some_ invalid JSON inputs, and then only if you're given an already complete input.
In other words, there are Javascript JSON parsers that are just "match a regexp and run eval on the input", but the actual parsing is done by the Javascript interpreter using eval. The regexp is just avoiding the security problems that are inherent in eval.
Quoted 5 lines
On the other hand, the two parsers I looked at only accept a string as input, not a stream (strangely, one of them internally converts the string to a stream, but doesn't expose the stream interface), so record termination might be helpful to parsers. Would be best not to rely on it in the server, though.
Relying upon a newline to terminate is also useful in environments where it is difficult or even impossible to turn off line-buffered mode.
I sometimes have this problem when trying to consume the human-readable monitor from a pipe; if I can't disable line-buffering, I don't see "(qemu) " until I've entered the next command, which can be an inconvenience.
I strongly agree that the server shouldn't rely on the line endings. The server should accept any valid JSON syntax, being "liberal in what it accepts, and conservative in what it sends".
Quoted 35 lines · On Wed, 23 Sep 2009 16:19:41 +0100 Nathan Baum <[email protected]>…
Quoted 25 lines · Avi Kivity
Quoted 15 lines · Paolo Bonzini
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Daniel P. Berrange
Quoted 3 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we
need explicit message boundaries?I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Quoted 3 lines
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Quoted 8 lines
Agreed, regexes are unnecessary. Also because a regex cannot parse JSON; it can only detect _some_ invalid JSON inputs, and then only if you're given an already complete input.
In other words, there are Javascript JSON parsers that are just "match a regexp and run eval on the input", but the actual parsing is done by the Javascript interpreter using eval. The regexp is just avoiding the security problems that are inherent in eval.
Quoted 5 lines
On the other hand, the two parsers I looked at only accept a string as input, not a stream (strangely, one of them internally converts the string to a stream, but doesn't expose the stream interface), so record termination might be helpful to parsers. Would be best not to rely on it in the server, though.
Relying upon a newline to terminate is also useful in environments where it is difficult or even impossible to turn off line-buffered mode.
Quoted 8 lines
I sometimes have this problem when trying to consume the human-readable monitor from a pipe; if I can't disable line-buffering, I don't see "(qemu) " until I've entered the next command, which can be an inconvenience.
I strongly agree that the server shouldn't rely on the line endings. The server should accept any valid JSON syntax, being "liberal in what it accepts, and conservative in what it sends".
Right now it doesn't even accept input in json (and relies on '\n'
or '\r' as end of line), but I will update the spec to follow these guidelines.
"Daniel P. Berrange" <[email protected]> writes:
[...]
Quoted 1 line
Having -Werror by default really is painful :-(
configure --disable-werror is your friend.
Quoted 31 lines · Daniel P. Berrange
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Luiz Capitulino
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
Quoted 4 lines
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
I've googled around quickly and there are at least 5 pieces of C code and/or C libraries that can parse JSON. Hopefully one of them will be sufficient / suitable for libvirt's needs. We'll just need to try it out and see what happens....
Quoted 11 lines
Quoted 6 lines
2.1 General Definitions
-----------------------All interactions transmitted by Client and Server are json-objects that end with CRLF.
CRLF? Really?
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
Quoted 7 lines
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Daniel
If the objective is to make life as easy as possible for clients, then terminate lines with just LF.
Quoted 39 lines · On Wed, 23 Sep 2009 18:01:44 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 37 lines · Daniel P. Berrange
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Luiz Capitulino
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
Quoted 4 lines
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
I've googled around quickly and there are at least 5 pieces of C code and/or C libraries that can parse JSON. Hopefully one of them will be sufficient / suitable for libvirt's needs. We'll just need to try it out and see what happens....
Quoted 11 lines
Quoted 6 lines
2.1 General Definitions
-----------------------All interactions transmitted by Client and Server are json-objects that end with CRLF.
CRLF? Really?
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
Quoted 4 lines
Quoted 1 line
Daniel
If the objective is to make life as easy as possible for clients, then terminate lines with just LF.
Okay, but note that the '\r\n' are there because it's what
QEMU does today (look at monitor_puts()).
Quoted 14 lines · Daniel P. Berrange
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Luiz Capitulino
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
Quoted 4 lines
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
Quoted 4 lines
I've googled around quickly and there are at least 5 pieces of C code and/or C libraries that can parse JSON. Hopefully one of them will be sufficient / suitable for libvirt's needs. We'll just need to try it out and see what happens....
I'm in the process of re-factoring the libvirt monitor handling code to make it possible for us to add in support for QMP in parallel to the legacy monitor support. Once the Luiz' QMP branch progresses a little further I'll aim to make available a libvirt branch which supports QMP.
To help priortization, the one critical command we need implemented which isn't there yet is 'cont', since all our VMs are launched with CPUs initially stopped.
The next priorities would be 'stop', 'info cpus', 'balloon' and 'info balloon' (all except info cpus are there in Luiz tree already I believe).
With those we could do some useful testing & validation of the QMP work in libvirt.
Then in no particular order of preference the other commands we currently make use of are
- migrate / migrate_set_speed / info migrate
- pci_add / pci_del
- host_net_add / host_net_del / getfd / closefd
- eject / change
- usb_add / usb_del
- info block (desirable to allow query of a single device at a time)
- memsave / pmemsave
Figuring out how to handle password prompts for 'cont' for encrypted qcow is probably another unusal area. Perhaps we should have explicit commands to set the decryption passwords ahead of time, rather than having QEMU prompt in response to 'cont'
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 5 lines · Luiz Capitulino
Quoted 2 lines
If the objective is to make life as easy as possible for clients, then terminate lines with just LF.
Okay, but note that the '\r\n' are there because it's what
QEMU does today (look atmonitor_puts()).
Bear in mind: telnet expects CRLF, and CRLF tends to work better with terminals over serial ports too. You could translate LF to CRLF on output to telnet/serial - that would make sense.
-- Jamie
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Paolo Bonzini
Quoted 12 lines · Avi Kivity
Quoted 7 lines · Daniel P. Berrange
Quoted 2 lines
Ignoring the dos-ism, since you can parse JSON with a regexp, why do we need explicit message boundaries?
I think it would be nice to be able to assume that each JSON message will not cross a line-end boundary. Whether we use CRLF, just CR or just LF I don't mind. Its much easier to search for a message boundary by just doing strchr('\n') than having to actually parse the JSON or use a regexp at that point.
A good parser will consume exactly enough characters to make up an object or let you know if it needs more. I don't think using a regexp is warranted.
Quoted 5 lines
Quoted 3 lines
Agreed, regexes are unnecessary. Also because a regex cannot parse JSON; it can only detect _some_ invalid JSON inputs, and then only if you're given an already complete input.
In other words, there are Javascript JSON parsers that are just "match a regexp and run eval on the input", but the actual parsing is done by the Javascript interpreter using eval. The regexp is just avoiding the security problems that are inherent in eval.
On the other hand, the two parsers I looked at only accept a string as input, not a stream (strangely, one of them internally converts the string to a stream, but doesn't expose the stream interface), so record termination might be helpful to parsers. Would be best not to rely on it in the server, though.
The main advantage of not relying on whitespace terminated messages is that it gives us the ability to pretty print the protocol on the wire. For instance, I'd rather read:
{ "execute": "info",
"id" : "32",
"arguments": ["cpus"]}
Especially when responses get very, very long.
Regards,
Anthony Liguori
Quoted 3 lines · Markus Armbruster
If the objective is to make life as easy as possible for clients, then terminate lines with just LF.
That's because of goofiness with ANSI's emulation in the text console. No need to carry it forward. But I'd really like to see no special significance given to whitespace to give us pretty printing flexibility.
Regards,
Anthony Liguori
Quoted 1 line · Luiz Capitulino
Hm, I've assumed some kind of end of line would be needed.
We'll definitely do some sort of pretty printing but from a protocol definition perspective, I think it's good for us to not guarantee whitespace as a boundary separator. I think it just suggests that we need a streaming json parser.
Quoted 3 lines
I thought that clients would always want to know to what
QEMU they are talking to.
They definitely do but we can use a command to figure that out (like info version).
It's good to avoid putting too much in the initial hello because it's the only thing that can never change based on capabilities.
Regards,
Anthony Liguori
Quoted 2 lines
What do you suggest?
Quoted 7 lines · Anthony Liguori
The main advantage of not relying on whitespace terminated messages is that it gives us the ability to pretty print the protocol on the wire. For instance, I'd rather read:
{ "execute": "info",
"id" : "32",
"arguments": ["cpus"]}
I agree. It's not even expensive.
It's still useful for parsers to easily find the end before parsing.
So declare the JSON terminator to be "}\n" or "}\r\n". That shouldn't occur anywhere inside a pretty printed structure. The internal closing braces are all followed by a comma.
:-)
-- Jamie
Quoted 9 lines · Jamie Lokier
Quoted 7 lines · Anthony Liguori
The main advantage of not relying on whitespace terminated messages is that it gives us the ability to pretty print the protocol on the wire. For instance, I'd rather read:
{ "execute": "info",
"id" : "32",
"arguments": ["cpus"]}
Quoted 7 lines
I agree. It's not even expensive.
It's still useful for parsers to easily find the end before parsing.
So declare the JSON terminator to be "}\n" or "}\r\n". That shouldn't occur anywhere inside a pretty printed structure. The internal closing braces are all followed by a comma.
To be picky, you could have dictionaries pretty printed as
...
'key': {
'key': {
'key': {}
} }
}
I think it's either no-delimiter or "\n" or "\r\n".
Paolo
Quoted 20 lines · On Wed, 23 Sep 2009 18:08:16 +0100 "Daniel P. Berrange" <[email protected]>…
Quoted 14 lines · Daniel P. Berrange
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Luiz Capitulino
Now the controversial part: it's json based. ;)
I have chosen json because of the reasons already explained by others in the original QMP thread. Basically, json is so simple that if we design a small protocol from scratch, chances are it will look like json.
Quoted 4 lines
json is not a deal break. My main concern was our ability to extend json and whether supporting stock json libraries was a hard requirement. I also would like to see a C client library since our biggest consumer (libvirt) is based in C.
Quoted 4 lines
I've googled around quickly and there are at least 5 pieces of C code and/or C libraries that can parse JSON. Hopefully one of them will be sufficient / suitable for libvirt's needs. We'll just need to try it out and see what happens....
Quoted 4 lines
I'm in the process of re-factoring the libvirt monitor handling code to make it possible for us to add in support for QMP in parallel to the legacy monitor support. Once the Luiz' QMP branch progresses a little further I'll aim to make available a libvirt branch which supports QMP.
Great!
Quoted 3 lines
To help priortization, the one critical command we need implemented which isn't there yet is 'cont', since all our VMs are launched with CPUs initially stopped.
I will convert 'cont' as soon as the new error handling code is
finished, as 'cont' can fail.
Quoted 3 lines
The next priorities would be 'stop', 'info cpus', 'balloon' and 'info balloon' (all except info cpus are there in Luiz tree already I believe).
That's right.
Quoted 2 lines
With those we could do some useful testing & validation of the QMP work in libvirt.
Yeah, would be very nice.
I was also considering writing kvm-autotest tests, will look at it.
Quoted 12 lines
Then in no particular order of preference the other commands we currently make use of are
- migrate /
migrate_set_speed/ info migrate
-pci_add/pci_del
-host_net_add/host_net_del/ getfd / closefd
- eject / change
-usb_add/usb_del
- info block (desirable to allow query of a single device at a time)
- memsave / pmemsave
Quoted 4 lines
Figuring out how to handle password prompts for 'cont' for encrypted qcow is probably another unusal area. Perhaps we should have explicit commands to set the decryption passwords ahead of time, rather than having QEMU prompt in response to 'cont'
Hmm, yes, forgot about this.
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 9 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
Quoted 8 lines
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specification
What about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
Quoted 21 lines · On Thu, 24 Sep 2009 00:37:53 +0200 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 9 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
Quoted 8 lines
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specification
Quoted 4 lines
What about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.
Quoted 10 lines · Luiz Capitulino
Quoted 6 lines
What about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.
Other way around, enable things that you want.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Quoted 5 lines · On Thu, 24 Sep 2009 15:44:48 +0300 Avi Kivity <[email protected]> wrote:
Quoted 4 lines · Luiz Capitulino
Quoted 4 lines
What about capability negotiation? Server offers capabilities, client can accept or decline them.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
[...]
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Other way around, enable things that you want.
Ok, I will add support for this in my tree then, async messages
will be considered a capability.
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines
Quoted 5 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Other way around, enable things that you want.
Ok, I will add support for this in my tree then, async messages
will be considered a capability.
Actually, if async messages are specified from day one they can be always active. The client can easily ignore them.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
Quoted 6 lines · On Thu, 24 Sep 2009 16:07:28 +0300 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Quoted 5 lines
Quoted 5 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Other way around, enable things that you want.
Ok, I will add support for this in my tree then, async messages
will be considered a capability.Actually, if async messages are specified from day one they can be always active. The client can easily ignore them.
That's also fine by me, but we were talking about having a
command to disable async messages... If we do this, I would prefer to make it a capability instead, this way it can use the same infrastructure (as opposed to special treatment).
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Thu, 24 Sep 2009 00:37:53 +0200 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 17 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specification
Quoted 8 lines
Quoted 4 lines
What about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.
Greeting capabilities (for lack of a better word) are for the protocol. Changing protocol capabilities while you use the protocol is awkward. Better do it in an initial handshake.
Case in point: if you disable asynchronous messages with a command, you still have to be prepared to receive one between initial handshake and completion of the disable command. If I have to ignore them anyway, why bother with disabling them?
The problem becomes more serious if we ever want to add a capability that isn't fully backward compatible. Lack of feature negotiation limits protocol evolvability.
Quoted 31 lines · On Thu, 24 Sep 2009 15:28:40 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 29 lines · Luiz Capitulino
Quoted 25 lines · On Thu, 24 Sep 2009 00:37:53 +0200 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 9 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
Quoted 8 lines
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specificationWhat about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
Quoted 7 lines
Quoted 3 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Greeting capabilities (for lack of a better word) are for the protocol. Changing protocol capabilities while you use the protocol is awkward. Better do it in an initial handshake.
Maybe it's better, but I'm wondering if it's worth it, considering the
implementation and usage "complexity".
Quoted 3 lines
Case in point: if you disable asynchronous messages with a command, you still have to be prepared to receive one between initial handshake and completion of the disable command.
This is true, although I think it's a good practice for programs to
start QEMU in pause mode and only put it to run after some setup is done.
This also has to be considered with the handshake approach, eg.
if QEMU is started before the application connects to it, we will have a window of time where several things may have happened in QEMU and this may affect the protocol. Async messages is an example.
Quoted 1 line
If I have to ignore them anyway, why bother with disabling them?
I can see two separate things here: 1. do we need/want the
handshake approach? 2. Should async messages be considered a capability?
If disabling async messages is not needed, then it should
not be considered a capability.
Quoted 3 lines
The problem becomes more serious if we ever want to add a capability that isn't fully backward compatible. Lack of feature negotiation limits protocol evolvability.
Why? Enabling 'what you want' as suggested by Avi doesn't have the
same end result?
Quoted 15 lines · Luiz Capitulino
Quoted 12 lines · On Thu, 24 Sep 2009 16:07:28 +0300 Avi Kivity <[email protected]> wrote:
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines
Quoted 5 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Other way around, enable things that you want.
Ok, I will add support for this in my tree then, async messages
will be considered a capability.
Quoted 7 lines
Quoted 2 lines
Actually, if async messages are specified from day one they can be always active. The client can easily ignore them.
That's also fine by me, but we were talking about having a
command to disable async messages... If we do this, I would prefer to make it a capability instead, this way it can use the same infrastructure (as opposed to special treatment).
Maybe per message type (error/warning/info/debug).
Signature · 1 line
MST
Quoted 31 lines · Markus Armbruster
Quoted 29 lines · Luiz Capitulino
Quoted 25 lines · On Thu, 24 Sep 2009 00:37:53 +0200 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 9 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
Quoted 8 lines
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specificationWhat about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
Quoted 7 lines
Quoted 3 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Greeting capabilities (for lack of a better word) are for the protocol. Changing protocol capabilities while you use the protocol is awkward. Better do it in an initial handshake.
If we use this to supppress/enable messages, I think it's clear we need to support changing them on the fly.
Quoted 4 lines
Case in point: if you disable asynchronous messages with a command, you still have to be prepared to receive one between initial handshake and completion of the disable command. If I have to ignore them anyway, why bother with disabling them?
For debug messages, sending and discarding them might have performance impact.
Quoted 3 lines
The problem becomes more serious if we ever want to add a capability that isn't fully backward compatible. Lack of feature negotiation limits protocol evolvability.
Some kind of version is the usualy way to do this.
Signature · 1 line
MST
Quoted 48 lines · Michael S. Tsirkin
Quoted 31 lines · Markus Armbruster
Quoted 29 lines · Luiz Capitulino
Quoted 25 lines · On Thu, 24 Sep 2009 00:37:53 +0200 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 9 lines
2.2 Server Greeting
-------------------Right when connected the Server will issue a greeting message, which signals that the connection has been successfully established and that the Server is waiting for commands.
The format is:
Quoted 8 lines
{ "QEMU": json-string, "QMP": json-string, "capabilities": json-array }
Where,
- The "QEMU" member contains the QEMU version
- The "QMP" member contains the QMP version
- The "capabilities" member specify the availability of features beyond the baseline specificationWhat about capability negotiation? Server offers capabilities, client can accept or decline them.
[...]
Quoted 7 lines
Quoted 3 lines
I think the easiest way to have this would be to add a
monitor command to disable capabilities. Like a command to disable async messages.Greeting capabilities (for lack of a better word) are for the protocol. Changing protocol capabilities while you use the protocol is awkward. Better do it in an initial handshake.
If we use this to supppress/enable messages, I think it's clear we need to support changing them on the fly.
Quoted 4 lines
Case in point: if you disable asynchronous messages with a command, you still have to be prepared to receive one between initial handshake and completion of the disable command. If I have to ignore them anyway, why bother with disabling them?
Quoted 8 lines
For debug messages, sending and discarding them might have performance impact.
Quoted 3 lines
The problem becomes more serious if we ever want to add a capability that isn't fully backward compatible. Lack of feature negotiation limits protocol evolvability.
Some kind of version is the usualy way to do this.
A version number covers only server offering capabilities, not client accepting them.
If clients discover capabilities through version numbers, selective backporting becomes awkward.
In my experience (whatever that's worth), protocols that start out without capability negotiation get it retrofitted when they evolve.
The expected cost of retrofitting might be lower than the cost of doing it right from the start. I really don't want to turn this into a big argument now.