: Monitor queue
Anthony,
The following patches have been sent to the list and look good to me. I've also tested them.
The changes (since 578c7b2ca8ee9e97fa8693b1a83d517e8e3f962e) are available in the following repository:
git://repo.or.cz/qemu/qmp-unstable.git for-anthony
Lai Jiangshan (2):
QMP: QError: New QERR_UNSUPPORTED
QMP: add inject-nmi qmp command
Luiz Capitulino (1):
HMP: Use QMP inject nmi implementation
Stefan Hajnoczi (2):
QMP: add get_events(wait=True) option
QMP: add server mode to QEMUMonitorProtocol
QMP/qmp.py | 54 ++++++++++++++++++++++++++++++++++++++++-------------- hmp-commands.hx | 9 +++++---- monitor.c | 19 ++++++++++++------- qerror.c | 4 ++++ qerror.h | 3 +++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 25 deletions(-)
PATCH 1/5 QMP: QError: New QERR_UNSUPPORTED
From: Lai Jiangshan <[email protected]>
New QERR_UNSUPPORTED for unsupported commands or requests.
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -201,6 +201,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "An undefined error has ocurred", }, { + .error_fmt = QERR_UNSUPPORTED, + .desc = "this feature or command is not currently supported", + }, + { .error_fmt = QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, .desc ="'%(device)' uses a %(format) feature which is not " "supported by this qemu version: %(feature)",
qerror.h +3 -0
@@ -165,6 +165,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }" +#define QERR_UNSUPPORTED \ + "{ 'class': 'Unsupported', 'data': {} }" +#define QERR_UNKNOWN_BLOCK_FORMAT_FEATURE \ "{ 'class': 'UnknownBlockFormatFeature', 'data': { 'device': %s, 'format': %s, 'feature': %s } }"
Signature · 1 line
1.7.4.4
PATCH 2/5 QMP: add inject-nmi qmp command
In reply to Luiz CapitulinoFrom: Lai Jiangshan <[email protected]>
inject-nmi command injects an NMI on all CPUs of guest. It is only supported for x86 guest currently, it will returns "Unsupported" error for non-x86 guest.
--- monitor.c | 17 +++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
monitor.c +17 -0
@@ -2555,6 +2555,23 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) break; } } + +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +CPUState *env; + +for (env = first_cpu; env !=NULL ; env = env->next_cpu) { +cpu_interrupt (env,CPU_INTERRUPT_NMI ); + } + +return 0 ; +} +#else +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +qerror_report (QERR_UNSUPPORTED ); +return -1 ; +}#endif static void do_info_status_print (Monitor *mon,const QObject *data)
qmp-commands.hx +27 -0
@@ -430,6 +430,33 @@ Example: EQMP { + .name = "inject-nmi", + .args_type = "", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_inject_nmi_all, + }, + +SQMP +inject-nmi +---------- + +Inject an NMI on guest's CPUs. + +Arguments: None. + +Example: + +-> { "execute": "inject-nmi" } +<- { "return": {} } + +Note: inject-nmi is only supported for x86 guest currently, it will + returns "Unsupported" error for non-x86 guest. + +EQMP + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri",
Signature · 1 line
1.7.4.4
Re: [Qemu-devel] [PATCH 2/5] QMP: add inject-nmi qmp command
Quoted 5 lines · Luiz Capitulino
From: Lai Jiangshan <[email protected]>
inject-nmi command injects an NMI on all CPUs of guest. It is only supported for x86 guest currently, it will returns "Unsupported" error for non-x86 guest.
Please rename the command to 'x-inject-nmi' to point out that it will be replaced by a generic method later.
Quoted 77 lines
Signed-off-by Luiz Capitulino <[email protected]>---
monitor.c | 17 +++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++2 files changed, 44 insertions(+), 0 deletions(-)monitor.c +17
-0@@ -2555,6 +2555,23 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) break; } } + +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ + CPUState *env; + + for (env = first_cpu; env != NULL; env = env->next_cpu) { + cpu_interrupt(env, CPU_INTERRUPT_NMI); + } + + return 0; +} +#else +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ + qerror_report(QERR_UNSUPPORTED); + return -1; +} #endif static void do_info_status_print(Monitor *mon, const QObject *data)qmp-commands.hx +0
-0@@ -430,6 +430,33 @@ Example:EQMP
{
+ .name = "inject-nmi",
+ .args_type = "",
+ .params = "",
+ .help = "",
+ .user_print =monitor_user_noop,
+ .mhandler.cmd_new =do_inject_nmi_all,
+ },qmp-commands.hx +20
-0+ +SQMP +inject-nmi +---------- + +Inject an NMI on guest's CPUs. + +Arguments: None. + +Example: + +-> { "execute": "inject-nmi" } +<- { "return": {} } + +Note: inject-nmi is only supported for x86 guest currently, it will + returns "Unsupported" error for non-x86 guest. + +EQMP + + {.name = "migrate",
.args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri", --
1.7.4.4
Re: [Qemu-devel] [PATCH 2/5] QMP: add inject-nmi qmp command
Quoted 9 lines · On Sat, 4 Jun 2011 11:34:17 +0300 Blue Swirl <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
From: Lai Jiangshan <[email protected]>
inject-nmi command injects an NMI on all CPUs of guest. It is only supported for x86 guest currently, it will returns "Unsupported" error for non-x86 guest.
Please rename the command to 'x-inject-nmi' to point out that it will be replaced by a generic method later.
Won't the generic interface be called 'inject'? In that case calling this command 'inject-nmi' makes sense as it's exactly what the command does and in the future it can be written in terms of the new 'inject' command.
Quoted 79 lines
Quoted 78 lines
Signed-off-by Luiz Capitulino <[email protected]>---
monitor.c | 17 +++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++2 files changed, 44 insertions(+), 0 deletions(-)monitor.c +17
-0@@ -2555,6 +2555,23 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) break; } } + +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ + CPUState *env; + + for (env = first_cpu; env != NULL; env = env->next_cpu) { + cpu_interrupt(env, CPU_INTERRUPT_NMI); + } + + return 0; +} +#else +static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ + qerror_report(QERR_UNSUPPORTED); + return -1; +} #endif static void do_info_status_print(Monitor *mon, const QObject *data)qmp-commands.hx +0
-0@@ -430,6 +430,33 @@ Example:EQMP
{
+ .name = "inject-nmi",
+ .args_type = "",
+ .params = "",
+ .help = "",
+ .user_print =monitor_user_noop,
+ .mhandler.cmd_new =do_inject_nmi_all,
+ },qmp-commands.hx +20
-0+ +SQMP +inject-nmi +---------- + +Inject an NMI on guest's CPUs. + +Arguments: None. + +Example: + +-> { "execute": "inject-nmi" } +<- { "return": {} } + +Note: inject-nmi is only supported for x86 guest currently, it will + returns "Unsupported" error for non-x86 guest. + +EQMP + + {.name = "migrate",
.args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri", --
1.7.4.4
Re: [Qemu-devel] [PATCH 2/5] QMP: add inject-nmi qmp command
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines · On Sat, 4 Jun 2011 11:34:17 +0300 Blue Swirl <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
From: Lai Jiangshan <[email protected]>
inject-nmi command injects an NMI on all CPUs of guest. It is only supported for x86 guest currently, it will returns "Unsupported" error for non-x86 guest.
Quoted 6 lines
Quoted 2 lines
Please rename the command to 'x-inject-nmi' to point out that it will be replaced by a generic method later.
Won't the generic interface be called 'inject'? In that case calling this command 'inject-nmi' makes sense as it's exactly what the command does and in the future it can be written in terms of the new 'inject' command.
This is a bit useless since the patch was committed, but I was pointed out that 'inject' wasn't so great name, 'raise/lower/pulse' should have been more precise. But I guess we can live with yet another poor interface, so who cares what the name is.
PATCH 3/5 HMP: Use QMP inject nmi implementation
In reply to Luiz CapitulinoThis **CHANGES** the human monitor "nmi" command behavior.
Currently it accepts an CPU argument which, when provided, will send the NMI to the specified CPU. This feature is of discussable value though and HMP shouldn't have more features than QMP, so let's use QMP's instead (it's also simpler).
--- hmp-commands.hx | 9 +++++---- monitor.c | 16 ++-------------- qmp-commands.hx | 2 +- 3 files changed, 8 insertions(+), 19 deletions(-)
hmp-commands.hx +5 -4
@@ -740,10 +740,11 @@ ETEXI #if defined(TARGET_I386) { .name = "nmi", - .args_type = "cpu_index:i", - .params = "cpu", - .help = "inject an NMI on the given CPU", - .mhandler.cmd = do_inject_nmi, + .args_type = "", + .params = "", + .help = "inject an NMI on all guest's CPUs", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_inject_nmi, }, #endif STEXI
monitor.c +2 -14
@@ -2544,19 +2544,7 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict)#endif #if defined(TARGET_I386 ) -static void do_inject_nmi (Monitor *mon,const QDict *qdict) -{ -CPUState *env; -int cpu_index =qdict_get_int (qdict,"cpu_index" ); - -for (env = first_cpu; env !=NULL ; env = env->next_cpu) -if (env->cpu_index == cpu_index) { -cpu_interrupt (env,CPU_INTERRUPT_NMI ); -break ; - } -} - -static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +static int do_inject_nmi (Monitor *mon,const QDict *qdict,QObject **ret_data) {CPUState *env;
@@ -2567,7 +2555,7 @@ static int do_inject_nmi_all(Monitor *mon, const QDict *qdict, QObject **ret_dat return 0; }#else -static int do_inject_nmi_all (Monitor *mon,const QDict *qdict,QObject **ret_data) +static int do_inject_nmi (Monitor *mon,const QDict *qdict,QObject **ret_data) {qerror_report (QERR_UNSUPPORTED );return -1 ;
qmp-commands.hx +1 -1
@@ -435,7 +435,7 @@ EQMP .params = "", .help = "", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_inject_nmi_all, + .mhandler.cmd_new = do_inject_nmi, }, SQMP
Signature · 1 line
1.7.4.4
PATCH 4/5 QMP: add get_events(wait=True) option
In reply to Luiz CapitulinoFrom: Stefan Hajnoczi <[email protected]>
The get_events() function polls for new QMP events and then returns. It can be useful to wait for the next QMP event so add the boolean 'wait' keyword argument.
--- QMP/qmp.py | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
QMP/qmp.py +8 -3
@@ -43,7 +43,7 @@ class QEMUMonitorProtocol: family = socket.AF_UNIX return socket.socket(family, socket.SOCK_STREAM) - def __json_read(self): + def __json_read(self, only_event=False): while True: data = self.__sockfile.readline() if not data:
@@ -51,7 +51,8 @@ class QEMUMonitorProtocol: resp = json.loads(data) if 'event' in resp: self.__events.append(resp) - continue + if not only_event: + continue return resp error = socket.error
@@ -106,9 +107,11 @@ class QEMUMonitorProtocol: qmp_cmd['id'] = id return self.cmd_obj(qmp_cmd) - def get_events(self): + def get_events(self, wait=False): """ Get a list of available QMP events. + + @param wait: block until an event is available (bool) """ self.__sock.setblocking(0) try:
@@ -118,6 +121,8 @@ class QEMUMonitorProtocol: # No data available pass self.__sock.setblocking(1) + if not self.__events and wait: + self.__json_read(only_event=True) return self.__events def clear_events(self):
Signature · 1 line
1.7.4.4
PATCH 5/5 QMP: add server mode to QEMUMonitorProtocol
In reply to Luiz CapitulinoFrom: Stefan Hajnoczi <[email protected]>
QEMU supports socket chardevs that establish connections like a server or a client. The QEMUMonitorProtocol class only supports connecting as a client. It is not possible to connect race-free when launching QEMU since trying to connect before QEMU has bound and is listening on the socket results in failure.
Add the QEMUMonitorProtocol(server=True) argument to bind and listen on the socket. The QEMU process can then be launched and connects to the already existing QMP socket without a race condition:
qmp = qmp.QEMUMonitorProtocol(monitor_path, server=True) popen = subprocess.Popen(args)
qmp.accept()
--- QMP/qmp.py | 43 ++++++++++++++++++++++++++++++++----------- 1 files changed, 32 insertions(+), 11 deletions(-)
QMP/qmp.py +32 -11
@@ -22,19 +22,24 @@ class QMPCapabilitiesError(QMPError): pass class QEMUMonitorProtocol: - def __init__(self, address): + def __init__(self, address, server=False): """ Create a QEMUMonitorProtocol class. @param address: QEMU address, can be either a unix socket path (string) or a tuple in the form ( address, port ) for a TCP connection - @note No connection is established, this is done by the connect() method + @param server: server mode listens on the socket (bool) + @raise socket.error on socket connection errors + @note No connection is established, this is done by the connect() or + accept() methods """ self.__events = [] self.__address = address self.__sock = self.__get_sock() - self.__sockfile = self.__sock.makefile() + if server: + self.__sock.bind(self.__address) + self.__sock.listen(1) def __get_sock(self): if isinstance(self.__address, tuple):
@@ -43,6 +48,17 @@ class QEMUMonitorProtocol: family = socket.AF_UNIX return socket.socket(family, socket.SOCK_STREAM) + def __negotiate_capabilities(self): + self.__sockfile = self.__sock.makefile() + greeting = self.__json_read() + if greeting is None or not greeting.has_key('QMP'): + raise QMPConnectError + # Greeting seems ok, negotiate capabilities + resp = self.cmd('qmp_capabilities') + if "return" in resp: + return greeting + raise QMPCapabilitiesError + def __json_read(self, only_event=False): while True: data = self.__sockfile.readline()
@@ -67,14 +83,19 @@ class QEMUMonitorProtocol: @raise QMPCapabilitiesError if fails to negotiate capabilities """ self.__sock.connect(self.__address) - greeting = self.__json_read() - if greeting is None or not greeting.has_key('QMP'): - raise QMPConnectError - # Greeting seems ok, negotiate capabilities - resp = self.cmd('qmp_capabilities') - if "return" in resp: - return greeting - raise QMPCapabilitiesError + return self.__negotiate_capabilities() + + def accept(self): + """ + Await connection from QMP Monitor and perform capabilities negotiation. + + @return QMP greeting dict + @raise socket.error on socket connection errors + @raise QMPConnectError if the greeting is not received + @raise QMPCapabilitiesError if fails to negotiate capabilities + """ + self.__sock, _ = self.__sock.accept() + return self.__negotiate_capabilities() def cmd_obj(self, qmp_cmd): """
Signature · 1 line
1.7.4.4
Re: [Qemu-devel] [PATCH 5/5] QMP: add server mode to QEMUMonitorProtocol
Quoted 2 lines · Luiz Capitulino
QEMU supports socket chardevs that establish connections like a server or a client.
Is this protocol documented anywhere?
Brad
Re: [Qemu-devel] [PATCH 5/5] QMP: add server mode to QEMUMonitorProtocol
Quoted 4 lines · Brad Hards
Quoted 2 lines · Luiz Capitulino
QEMU supports socket chardevs that establish connections like a server or a client.
Is this protocol documented anywhere?
There are docs for the QMP monitor in the QMP/ subdirectory of the QEMU source tree, while the chardev options are documented in the man page
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 9 lines · Luiz Capitulino
Anthony,
The following patches have been sent to the list and look good to me. I've also tested them.
The changes (since
578c7b2ca8ee9e97fa8693b1a83d517e8e3f962e) are available in the following repository:
git://repo.or.cz/qemu/qmp-unstable.gitfor-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 22 lines
Lai Jiangshan (2):
QMP: QError: NewQERR_UNSUPPORTED
QMP: add inject-nmi qmp commandLuiz Capitulino (1):
HMP: Use QMP inject nmi implementationStefan Hajnoczi (2):
QMP: addget_events(wait=True)option
QMP: add server mode to QEMUMonitorProtocolQMP/qmp.py | 54 ++++++++++++++++++++++++++++++++++++++++-------------- hmp-commands.hx | 9 +++++---- monitor.c | 19 ++++++++++++------- qerror.c | 4 ++++ qerror.h | 3 +++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 25 deletions(-)