: QMP: Human Monitor passthrough
cover : QMP: Human Monitor passthrough
Simple example:
-> { "execute": "hmp_passthrough", "arguments": { "command-line": "print /i 10+25" } } <- { "return": "35\r\n" }
Please, check individual patches for details. Also note that this series depends on the script improvements one.
Thanks.
PATCH 1/3 qemu-char: Introduce Buffered driver
This driver handles in-memory chardev operations. That's, all writes to this driver are stored in an internal buffer and it doesn't talk to the external world in any way.
Right now it's very simple: it supports only writes. But it can be easily extended to support more operations.
This is going to be used by the monitor's "HMP passthrough via QMP" feature, which needs to run monitor handlers without a backing device.
--- qemu-char.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.h | 6 +++++ 2 files changed, 69 insertions(+), 0 deletions(-)
qemu-char.c +63 -0
@@ -2279,6 +2279,69 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)return NULL ; } +/***********************************************************/ +/* Buffered chardev */ +typedef struct { +size_t outbuf_size; +size_t outbuf_capacity; +uint8_t *outbuf; +}BufferedDriver ; + +static int buffered_chr_write (CharDriverState *chr,const uint8_t *buf,int len) +{ +BufferedDriver *d = chr->opaque; + +if (d->outbuf_capacity < (d->outbuf_size + len)) { +/* grown outbuf */ + d->outbuf_capacity += len; + d->outbuf_capacity *=2 ; + d->outbuf =qemu_realloc (d->outbuf, d->outbuf_capacity); + } + +memcpy (d->outbuf + d->outbuf_size, buf, len); + d->outbuf_size += len; + +return len; +} + +#define DEFAULT_BUF_SIZE 4096 + +void qemu_chr_init_buffered (CharDriverState *chr) +{ +BufferedDriver *d; + + d =qemu_malloc (sizeof (*d)); + d->outbuf_size =0 ; + d->outbuf_capacity =DEFAULT_BUF_SIZE ; + d->outbuf =qemu_mallocz (d->outbuf_capacity); + +memset (chr,0 ,sizeof (*chr)); + chr->opaque = d; + chr->chr_write = buffered_chr_write; +} + +/* assumes the stored data is a string */ +QString *qemu_chr_buffered_to_qs (CharDriverState *chr) +{ +BufferedDriver *d = chr->opaque; + +if (d->outbuf_size ==0 ) { +return NULL ; + } + +return qstring_from_substr ((char *) d->outbuf,0 , d->outbuf_size -1 ); +} + +void qemu_chr_close_buffered (CharDriverState *chr) +{ +BufferedDriver *d = chr->opaque; + +qemu_free (d->outbuf); +qemu_free (chr->opaque); + chr->opaque =NULL ; + chr->chr_write =NULL ; +} +QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename) {char host[65 ], port[33 ], width[8 ], height[8 ];
qemu-char.h +6 -0
@@ -6,6 +6,7 @@#include "qemu-option.h" #include "qemu-config.h" #include "qobject.h" +#include "qstring.h" /* character device */
@@ -100,6 +101,11 @@ CharDriverState *qemu_chr_open_eventfd(int eventfd);extern int term_escape_char; +/* buffered chardev */ +void qemu_chr_init_buffered (CharDriverState *chr); +void qemu_chr_close_buffered (CharDriverState *chr); +QString *qemu_chr_buffered_to_qs (CharDriverState *chr); +/* async I/O support */ int qemu_set_fd_handler2(int fd,
Signature · 1 line
1.7.3.2.145.g7ebee
PATCH 2/3 QMP: Introduce Human Monitor passthrough command
In reply to Luiz CapitulinoThis command allows QMP clients to execute HMP commands.
Please, check the documentation added to the qmp-commands.hx file for additional details about the interface and its limitations.
--- monitor.c | 42 ++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 0 deletions(-)
monitor.c +42 -0
@@ -490,6 +490,48 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params,return 0 ; } +static int mon_set_cpu (int cpu_index); +static void handle_user_command (Monitor *mon,const char *cmdline); + +static int do_hmp_passthrough (Monitor *mon,const QDict *params, +QObject **ret_data) +{ +int ret =0 ; +QString *qs; +Monitor *old_mon, hmp; +CharDriverState bufchr; + +memset (&hmp,0 ,sizeof (hmp)); + hmp.chr = &bufchr; +qemu_chr_init_buffered (hmp.chr); + + old_mon = cur_mon; + cur_mon = &hmp; + +if (qdict_haskey (params,"cpu-index" )) { + ret =mon_set_cpu (qdict_get_int (params,"cpu-index" )); +if (ret <0 ) { + goto out; + } + } + +handle_user_command (&hmp,qdict_get_str (params,"command-line" )); + + qs =qemu_chr_buffered_to_qs (hmp.chr); +if (qs) { + *ret_data =QOBJECT (qs); + } + +out: + cur_mon = old_mon; +qemu_chr_close_buffered (hmp.chr); + +if (ret <0 ) { +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"cpu-index" ,"a CPU number" ); + } +return ret; +} +static int compare_cmd (const char *name,const char *list) {const char *p, *pstart;
qmp-commands.hx +45 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.3.2.145.g7ebee
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 48 lines · Luiz Capitulino
This command allows QMP clients to execute HMP commands.
Please, check the documentation added to the qmp-commands.hx file for additional details about the interface and its limitations.
Signed-off-by Luiz Capitulino <[email protected]>--- monitor.c | 42 ++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 0 deletions(-)monitor.c +29
-0@@ -490,6 +490,48 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params,return 0 ; } +static int mon_set_cpu (int cpu_index); +static void handle_user_command (Monitor *mon,const char *cmdline); + +static int do_hmp_passthrough (Monitor *mon,const QDict *params, +QObject **ret_data) +{ +int ret =0 ; +QString *qs; +Monitor *old_mon, hmp; +CharDriverState bufchr; + +memset (&hmp,0 ,sizeof (hmp)); + hmp.chr = &bufchr; +qemu_chr_init_buffered (hmp.chr); + + old_mon = cur_mon; + cur_mon = &hmp; + +if (qdict_haskey (params,"cpu-index" )) { + ret =mon_set_cpu (qdict_get_int (params,"cpu-index" )); +if (ret <0 ) { + goto out; + } + } + +handle_user_command (&hmp,qdict_get_str (params,"command-line" )); + + qs =qemu_chr_buffered_to_qs (hmp.chr); +if (qs) {
monitor.c static int do_qmp_capabilities(Monitor *mon, const QDict *params, · line 531
Quoted 10 lines
monitor.c +10
-0+ *ret_data =QOBJECT (qs); + } + +out: + cur_mon = old_mon; +qemu_chr_close_buffered (hmp.chr); + +if (ret <0 ) { +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"cpu-index" ,"a CPU number" ); + }
Emit the error right where ret becomes negative. Cleaner, and allows for other errors, should they become necessary.
Quoted 51 lines
monitor.c +3
-0+return ret; +} +static int compare_cmd (const char *name,const char *list) {const char *p, *pstart;qmp-commands.hx +37
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command +
qmp-commands.hx Example: · line 810
Quoted 10 lines
qmp-commands.hx +8
-0+(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently work + 3. Query Commands =================
In the real human monitor, cpu-index is state (Monitor member mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.
A possible alternative would be to keep the state around instead of creating a new one for each pass through command. Dunno, haven't thought that through. Maybe you did?
Regardless, this is clearly better than nothing. We can work on limitations later, should they turn out to be bothersome.
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 122 lines · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 48 lines · Luiz Capitulino
This command allows QMP clients to execute HMP commands.
Please, check the documentation added to the qmp-commands.hx file for additional details about the interface and its limitations.
Signed-off-by Luiz Capitulino <[email protected]>--- monitor.c | 42 ++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 0 deletions(-)monitor.c +29
-0@@ -490,6 +490,48 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params,return 0 ; } +static int mon_set_cpu (int cpu_index); +static void handle_user_command (Monitor *mon,const char *cmdline); + +static int do_hmp_passthrough (Monitor *mon,const QDict *params, +QObject **ret_data) +{ +int ret =0 ; +QString *qs; +Monitor *old_mon, hmp; +CharDriverState bufchr; + +memset (&hmp,0 ,sizeof (hmp)); + hmp.chr = &bufchr; +qemu_chr_init_buffered (hmp.chr); + + old_mon = cur_mon; + cur_mon = &hmp; + +if (qdict_haskey (params,"cpu-index" )) { + ret =mon_set_cpu (qdict_get_int (params,"cpu-index" )); +if (ret <0 ) { + goto out; + } + } + +handle_user_command (&hmp,qdict_get_str (params,"command-line" )); + + qs =qemu_chr_buffered_to_qs (hmp.chr); +if (qs) {monitor.c static int do_qmp_capabilities(Monitor *mon, const QDict *params, · line 531
Quoted 10 lines
monitor.c +10
-0+ *ret_data =QOBJECT (qs); + } + +out: + cur_mon = old_mon; +qemu_chr_close_buffered (hmp.chr); + +if (ret <0 ) { +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"cpu-index" ,"a CPU number" ); + }Emit the error right where ret becomes negative. Cleaner, and allows for other errors, should they become necessary.
Quoted 58 lines
monitor.c +3
-0+return ret; +} +static int compare_cmd (const char *name,const char *list) {const char *p, *pstart;qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently work
Quoted 8 lines
qmp-commands.hx Example: · line 810
Quoted 3 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.
Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Quoted 3 lines
A possible alternative would be to keep the state around instead of creating a new one for each pass through command. Dunno, haven't thought that through. Maybe you did?
It's above ;) becoming stateless seems to be the way for QMP.
Quoted 2 lines
Regardless, this is clearly better than nothing. We can work on limitations later, should they turn out to be bothersome.
Agreed.
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 4 lines · Luiz Capitulino
Quoted 1 line · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 61 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 8 lines
qmp-commands.hx Example: · line 810
Quoted 3 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.
Quoted 6 lines
Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
[...]
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 70 lines · Markus Armbruster
Quoted 4 lines · Luiz Capitulino
Quoted 1 line · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 63 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 8 lines
qmp-commands.hx Example: · line 810
Quoted 3 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Surprisingly or not, this is a very important question for QMP itself.
Quoted 7 lines
Quoted 4 lines
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
The SCM_RIGHTS code allows you to send/receive multiple file handles in a single sendmsg/recvmsg call. So why don't we just allow sending of the file handles with the monitor command that actually needs them, instead of ahead of time using send_fd. This simplifies life for the client because they also don't have to worry about cleanup using close_fd if the command using the FD fails.
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://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 84 lines · Daniel P. Berrange
Quoted 74 lines · Markus Armbruster
Quoted 6 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster<[email protected]> wrote:
Luiz Capitulino<[email protected]> writes:
[...]
Quoted 63 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 9 lines
qmp-commands.hx Example: · line 811
Quoted 4 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Surprisingly or not, this is a very important question for QMP itself.
Quoted 8 lines
Quoted 5 lines
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Quoted 7 lines
The
SCM_RIGHTScode allows you to send/receive multiple file handles in a single sendmsg/recvmsg call. So why don't we just allow sending of the file handles with the monitor command that actually needs them, instead of ahead of time usingsend_fd. This simplifies life for the client because they also don't have to worry about cleanup usingclose_fdif the command using the FD fails.
How do we identify file descriptors and then map them to a command?
Regards,
Anthony Liguori
Quoted 3 lines
Regards,
Daniel
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 20 lines · Anthony Liguori
Quoted 19 lines · Daniel P. Berrange
Quoted 18 lines · Markus Armbruster
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
3. Query Commands
=================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Quoted 7 lines
Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Quoted 8 lines
Quoted 6 lines
The
SCM_RIGHTScode allows you to send/receive multiple file handles in a single sendmsg/recvmsg call. So why don't we just allow sending of the file handles with the monitor command that actually needs them, instead of ahead of time usingsend_fd. This simplifies life for the client because they also don't have to worry about cleanup usingclose_fdif the command using the FD fails.How do we identify file descriptors and then map them to a command?
IIUC, the FDs sent/received via struct cmsghdr are in a strictly ordered array, so why not just define a placeholder syntax for the commands that maps to the array indexes. eg
netdev_add tap,fd=$0,vhost_fd=$1,id=hostnet0
The '$' sign is not valid for a normal FD number, so use of a $0, $1, $2, etc can reliably be substituted with the real FD number from the cmsghdr array elements 0, 1, 2, etc
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://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 34 lines · On Thu, 11 Nov 2010 16:39:52 +0000 "Daniel P. Berrange" <[email protected]>…
Quoted 20 lines · Anthony Liguori
Quoted 19 lines · Daniel P. Berrange
Quoted 18 lines · Markus Armbruster
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
3. Query Commands
=================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Quoted 7 lines
Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Quoted 8 lines
Quoted 6 lines
The
SCM_RIGHTScode allows you to send/receive multiple file handles in a single sendmsg/recvmsg call. So why don't we just allow sending of the file handles with the monitor command that actually needs them, instead of ahead of time usingsend_fd. This simplifies life for the client because they also don't have to worry about cleanup usingclose_fdif the command using the FD fails.How do we identify file descriptors and then map them to a command?
IIUC, the FDs sent/received via struct cmsghdr are in a strictly ordered array, so why not just define a placeholder syntax for the commands that maps to the array indexes. eg
Quoted 5 lines
netdev_addtap,fd=$0,vhost_fd=$1,id=hostnet0The '$' sign is not valid for a normal FD number, so use of a $0, $1, $2, etc can reliably be substituted with the real FD number from the cmsghdr array elements 0, 1, 2, etc
I have the impression that the real problem is that they are being stored in the wrong place (ie. the monitor), *maybe* they should be stored somewhere else, ie. a special chardev or something.
Today those fds are linked to a given monitor session..
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
In reply to Daniel P. BerrangeQuoted 10 lines · Daniel P. Berrange
IIUC, the FDs sent/received via struct cmsghdr are in a strictly ordered array, so why not just define a placeholder syntax for the commands that maps to the array indexes. eg
netdev_add tap,fd=$0,vhost_fd=$1,id=hostnet0The '$' sign is not valid for a normal FD number, so use of a $0, $1, $2, etc can reliably be substituted with the real FD number from the cmsghdr array elements 0, 1, 2, etc
Character devices are streaming so it's hard to refer to array indexes in a single message. You could count it for the entire session but session boundaries aren't really well defined.
I don't think it's an obvious win.
Regards,
Anthony Liguori
Quoted 3 lines
Regards,
Daniel
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
In reply to Markus ArmbrusterQuoted 70 lines · On Thu, 11 Nov 2010 16:47:41 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 4 lines · Luiz Capitulino
Quoted 1 line · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 63 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 8 lines
qmp-commands.hx Example: · line 810
Quoted 3 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Surprisingly or not, this is a very important question for QMP itself.
Quoted 7 lines
Quoted 4 lines
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Absolutely, but this shouldn't prevent this series of being merged, right?
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
Quoted 81 lines · Luiz Capitulino
Quoted 77 lines · On Thu, 11 Nov 2010 16:47:41 +0100 Markus Armbruster<[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster<[email protected]> wrote:
Luiz Capitulino<[email protected]> writes:
[...]
Quoted 66 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 9 lines
qmp-commands.hx Example: · line 811
Quoted 4 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Absolutely, but this shouldn't prevent this series of being merged, right?
BTW, don't we have all of the fd= commands covered in QMP already?
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 2/3] QMP: Introduce Human Monitor passthrough command
In reply to Luiz CapitulinoQuoted 76 lines · Luiz Capitulino
Quoted 73 lines · On Thu, 11 Nov 2010 16:47:41 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 4 lines · Luiz Capitulino
Quoted 1 line · On Wed, 10 Nov 2010 14:20:12 +0100 Markus Armbruster <[email protected]> wrote:
Luiz Capitulino <[email protected]> writes:
[...]
Quoted 66 lines
Quoted 52 lines
Quoted 52 lines
qmp-commands.hx +44
-0@@ -761,6 +761,51 @@ Example: Note: This command must be issued before issuing any other command. +EQMP + + { + .name = "hmp_passthrough", + .args_type = "command-line:s,cpu-index:i?", + .params = "", + .help = "", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_hmp_passthrough, + }, + +SQMP +hmp_passthrough +--------------- + +Execute a Human Monitor command. + +Arguments: + +- command-line: the command name and its arguments, just like the + Human Monitor's shell (json-string) +- cpu-index: select the CPU number to be used by commands which access CPU + data, like 'info registers'. The Monitor selects CPU 0 if this + argument is not provided (json-int, optional) + +Example: + +-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info kvm" } } +<- { "return": "kvm support: enabled\r\n" } + +Notes: + +(1) The Human Monitor is NOT an stable interface, this means that command + names, arguments and responses can change or be removed at ANY time. + Applications that rely on long term stability guarantees should NOT + use this command + +(2) Limitations: + + o This command is stateless, this means that commands that depend + on state information (such as getfd) might not work + + o Commands that prompt the user for data (eg. 'cont' when the block + device is encrypted) don't currently workQuoted 8 lines
qmp-commands.hx Example: · line 810
Quoted 3 lines
qmp-commands.hx +1
-0+ 3. Query Commands =================In the real human monitor, cpu-index is state (Monitor member
mon_cpu). For pass through, you shift that state into the client (argument cpu-index). Is there any other state that could need shifting? You mention getfd.Surprisingly or not, this is a very important question for QMP itself.
Anthony has said that we should make it stateless, and I do think this is good because it seems to simplify things considerably.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
However, I haven't thought about how to make things like getfd stateless.
Hmm, that sounds like we should investigate the getfd problem sooner rather than later.
Absolutely, but this shouldn't prevent this series of being merged, right?
Right.
PATCH 3/3 QMP/qmp-shell: Introduce HMP mode
In reply to Luiz CapitulinoIn which qmp-shell will exclusively use the HMP passthrough feature, this is useful for testing.
Example:
(QEMU) info network
VLAN 0 devices:
user.0: net=10.0.2.0, restricted=n
e1000.0: model=e1000,macaddr=52:54:00:12:34:56 Devices not on any VLAN:
(QEMU)
--- QMP/qmp-shell | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-)
QMP/qmp-shell +70 -0
@@ -145,6 +145,72 @@ class QMPShell(qmp.QEMUMonitorProtocol): else: return self._execute_cmd(cmdline) +class HMPShell(QMPShell): + def __init__(self, address): + QMPShell.__init__(self, address) + self.__cpu_index = 0 + + def __cmd_completion(self): + for cmd in self.__cmd_passthrough('help')['return'].split('\r\n'): + if cmd and cmd[0] != '[' and cmd[0] != '\t': + name = cmd.split()[0] # drop help text + if name == 'info': + continue + if name.find('|') != -1: + # Command in the form 'foobar|f' or 'f|foobar', take the + # full name + opt = name.split('|') + if len(opt[0]) == 1: + name = opt[1] + else: + name = opt[0] + self._completer.append(name) + self._completer.append('help ' + name) # help completion + + def __info_completion(self): + for cmd in self.__cmd_passthrough('info')['return'].split('\r\n'): + if cmd: + self._completer.append('info ' + cmd.split()[1]) + + def __other_completion(self): + # special cases + self._completer.append('help info') + + def _fill_completion(self): + self.__cmd_completion() + self.__info_completion() + self.__other_completion() + + def __cmd_passthrough(self, cmdline): + return self.cmd_obj({ 'execute': 'hmp_passthrough', 'arguments': + { 'command-line': cmdline, + 'cpu-index': self.__cpu_index } }) + + def _execute_cmd(self, cmdline): + if cmdline.split()[0] == "cpu": + # trap the cpu command, it requires special setting + try: + self.__cpu_index = int(cmdline.split()[1]) + except ValueError: + print 'cpu command takes an integer argument' + return True + resp = self.__cmd_passthrough(cmdline) + if resp is None: + print 'Disconnected' + return False + assert 'return' in resp or 'error' in resp + if 'return' in resp: + # Success + if len(resp['return']) > 0: + print resp['return'], + else: + # Error + print '%s: %s' % (resp['error']['class'], resp['error']['desc']) + return True + + def show_banner(self): + QMPShell.show_banner(self, msg='Welcome to the HMP shell!') + def die(msg): sys.stderr.write('ERROR: %s\n' % msg) sys.exit(1)
@@ -159,6 +225,10 @@ def main(): try: if len(sys.argv) == 2: qemu = QMPShell(sys.argv[1]) + elif len(sys.argv) == 3: + if sys.argv[1] != '-H': + fail_cmdline(sys.argv[1]) + qemu = HMPShell(sys.argv[2]) else: fail_cmdline() except QMPShellBadPort:
Signature · 1 line
1.7.3.2.145.g7ebee
Re: [Qemu-devel] [PATCH 3/3] QMP/qmp-shell: Introduce HMP mode
Quoted 5 lines · Luiz Capitulino
In which qmp-shell will exclusively use the HMP passthrough feature, this is useful for testing.
Example:
If you respin anyway, consider inserting something like "$ qmp-shell -H ..." here, to point to the new -H.
Quoted 6 lines
(QEMU) info network
VLAN 0 devices:
user.0: net=10.0.2.0, restricted=n
e1000.0: model=e1000,macaddr=52:54:00:12:34:56 Devices not on any VLAN:
(QEMU)
[...]
Quoted 5 lines · Luiz Capitulino
Simple example:
-> { "execute": "
hmp_passthrough", "arguments": { "command-line": "print /i 10+25" } } <- { "return": "35\r\n" }
Why are the names so cryptic?
-> { "execute": "human-monitor-command", ... }
<- { "return": "42\r\n" }
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · On Thu, 11 Nov 2010 18:22:13 +0200 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Luiz Capitulino
Simple example:
-> { "execute": "
hmp_passthrough", "arguments": { "command-line": "print /i 10+25" } } <- { "return": "35\r\n" }Why are the names so cryptic?
-> { "execute": "human-monitor-command", ... }
Hm, Markus suggested something like it.
Quoted 1 line
<- { "return": "42\r\n" }
My examples are so boring...