libxl: add "xl qemu-monitor-command"
PATCH v3 1/1 libxl: add "xl qemu-monitor-command"
Add a new xl command "qemu-monitor-command" to issue arbitrary commands to a domain's device model. Syntax is:
xl qemu-monitor-command <domain> <command>
The command is issued via qmp human-monitor-command command. Any information returned by the command is printed to stdout.
---
V3: - add GC_FREE as requested by Dario Faggioli
- return with EXIT_FAILURE/SUCCESS as requested by Dario Faggioli
- don't initialize rc statically as requested by Dario Faggioli
V2: - add warning to man page as requested by Ian Jackson
--- docs/man/xl.pod.1.in | 36 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 14 ++++++++++++++ tools/libxl/libxl_colo_qdisk.c | 2 +- tools/libxl/libxl_internal.h | 3 ++- tools/libxl/libxl_qmp.c | 44 ++++++++++++++++++++++++++++++++++++++++-- tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 29 ++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 5 +++++ 8 files changed, 130 insertions(+), 4 deletions(-)
docs/man/xl.pod.1.in +36 -0
@@ -1516,6 +1516,42 @@ List pass-through usb devices for a domain. =back +=head1 DEVICE-MODEL CONTROL + +=over 4 + +=item B<qemu-monitor-command> I<domain-id> I<command> + +Issue a monitor command to the device model of the domain specified by +I<domain-id>. I<command> can be any valid command qemu understands. This +can be e.g. used to add non-standard devices or devices with non-standard +parameters to a domain. The output of the command is printed to stdout. + +B<Warning:> This qemu monitor access is provided for convenience when +debugging, troubleshooting, and experimenting. Its use is not +supported by the Xen Project. + +Specifically, not all information printed by the qemu monitor will +necessarily be accurate or complete, because in a Xen system qemu +does not have a complete view of the guest. + +Furthermore, modifying the guest's setup via the qemu monitor may +conflict with the Xen toolstack's assumptions. Resulting problems +may include, but are not limited to: guest crashes; toolstack error +messages; inability to migrate the guest; and security +vulnerabilities which are not covered by the Xen Project security +response policy. + +B<EXAMPLE> + +Obtain information of USB devices connected as such via the device model +(only!) to a domain: + + xl qemu-monitor-command vm1 'info usb' + Device 0.2, Port 5, Speed 480 Mb/s, Product Mass Storage + +=back + =head1 TMEM =over 4
tools/libxl/libxl.h +14 -0
@@ -275,6 +275,12 @@#define LIBXL_HAVE_BUILD_ID 1/* +* LIBXL_HAVE_QEMU_MONITOR_COMMAND indiactes the availability of the +* libxl_qemu_monitor_command() function. +*/ +#define LIBXL_HAVE_QEMU_MONITOR_COMMAND 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
@@ -2152,6 +2158,14 @@ void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr);int libxl_fd_set_cloexec (libxl_ctx *ctx,int fd,int cloexec);int libxl_fd_set_nonblock (libxl_ctx *ctx,int fd,int nonblock); +/* +* Issue a qmp monitor command to the device model of the specified domain. +* The function returns the output of the command in a new allocated buffer +* via output. +*/ +int libxl_qemu_monitor_command (libxl_ctx *ctx,uint32_t domid, +const char *command_line,char **output); +#include <libxl_event.h> #endif /* LIBXL_H */
tools/libxl/libxl_colo_qdisk.c +1 -1
@@ -173,7 +173,7 @@ static void colo_qdisk_save_preresume(libxl__egc *egc,"file.driver=nbd,file.host=%s,file.port=%d," "file.export=%s,node-name=%s,if=none" , host, port, export_name, node); - ret =libxl__qmp_hmp (gc, domid, cmd); + ret =libxl__qmp_hmp (gc, domid, cmd,NULL );if (ret) rc =ERROR_FAIL ;
tools/libxl/libxl_internal.h +2 -1
@@ -1818,7 +1818,8 @@ _hidden int libxl__qmp_x_blockdev_change(libxl__gc *gc, int domid,const char *parant, const char *child, const char *node);/* run a hmp command in qmp mode */ -_hidden int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line); +_hidden int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line, +char **out);/* close and free the QMP handler */ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);/* remove the socket file, if the file has already been removed,
tools/libxl/libxl_qmp.c +42 -2
56 lines not on this page · raw message
tools/libxl/xl.h +1 -0
@@ -133,6 +133,7 @@ int main_psr_cmt_show(int argc, char **argv);int main_psr_cat_cbm_set (int argc,char **argv);int main_psr_cat_show (int argc,char **argv);#endif +int main_qemu_monitor_command (int argc,char **argv);void help (const char *command);
tools/libxl/xl_cmdimpl.c +29 -0
@@ -9536,6 +9536,35 @@ int main_psr_hwinfo(int argc, char **argv)#endif +int main_qemu_monitor_command (int argc,char **argv) +{ +int opt; +uint32_t domid; +char *cmd; +char *output; +int ret; + + SWITCH_FOREACH_OPT(opt, "", NULL, "qemu-monitor-command", 2) { +/* No options */ + } + + domid =find_domain (argv[optind]); + cmd = argv[optind +1 ]; + +if (argc - optind >2 ) { +fprintf (stderr,"Invalid arguments.\n" ); +return 1 ; + } + + ret =libxl_qemu_monitor_command (ctx, domid, cmd, &output); +if (!ret && output) { +printf ("%s\n" , output); +free (output); + } + +return ret ?EXIT_FAILURE :EXIT_SUCCESS ; +} +/* * Local variables: * mode: C
tools/libxl/xl_cmdtable.c +5 -0
@@ -584,6 +584,11 @@ struct cmd_spec cmd_table[] = { "List information about all USB controllers and devices for a domain", "<Domain>", }, + { "qemu-monitor-command", + &main_qemu_monitor_command, 0, 1, + "Issue a qemu monitor command to the device model of a domain", + "<Domain> <Command>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 6 lines · Juergen Gross
Add a new xl command "qemu-monitor-command" to issue arbitrary commands
to a domain's device model. Syntax is:xl qemu-monitor-command <domain> <command>
Quoted 8 lines
The command is issued via qmp human-monitor-command command. Any information returned by the command is printed to stdout.
Signed-off-by Juergen Gross <[email protected]>---
V3: - addGC_FREEas requested by Dario Faggioli
- return with EXIT_FAILURE/SUCCESS as requested by Dario Faggioli
I think you missed one...
Quoted 17 lines
tools/libxl/xl_cmdimpl.c +0
-0@@ -9536,6 +9536,35 @@ int main_psr_hwinfo(int argc, char **argv)
#endiftools/libxl/xl_cmdimpl.c +8
-0+int main_qemu_monitor_command (int argc,char **argv) +{ + int opt; + uint32_t domid; + char *cmd; + char *output; + int ret; +
tools/libxl/xl_cmdimpl.c int main_psr_hwinfo(int argc, char **argv) · line 9556
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+ SWITCH_FOREACH_OPT(opt, "", NULL, "qemu-monitor-command", 2) { + /* No options */ + } + + domid = find_domain(argv[optind]); + cmd = argv[optind + 1]; + + if (argc - optind > 2) { + fprintf(stderr, "Invalid arguments.\n"); + return 1;
...here.
Anyway, this is
if possible, with the above 'return 1' converted to 'return EXIT_FAILURE' (either by resending or done upon commit).
If a maintainer wants to ack and commit this as is, my R-b still stands. In fact, as I said, xl is still not yet 100% consistent wrt this, and although I think new code should comply with the rule, I won't stand in the way of a patch for something like this.
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu
Acked-byQuoted 46 lines · Dario Faggioli
Quoted 6 lines · Juergen Gross
Add a new xl command "qemu-monitor-command" to issue arbitrary commands
to a domain's device model. Syntax is:xl qemu-monitor-command <domain> <command>
Quoted 8 lines
The command is issued via qmp human-monitor-command command. Any information returned by the command is printed to stdout.
Signed-off-by Juergen Gross <[email protected]>---
V3: - addGC_FREEas requested by Dario Faggioli
- return with EXIT_FAILURE/SUCCESS as requested by Dario FaggioliI think you missed one...
Quoted 17 lines
tools/libxl/xl_cmdimpl.c +0
-0@@ -9536,6 +9536,35 @@ int main_psr_hwinfo(int argc, char **argv)
#endiftools/libxl/xl_cmdimpl.c +8
-0+int main_qemu_monitor_command (int argc,char **argv) +{ + int opt; + uint32_t domid; + char *cmd; + char *output; + int ret; +tools/libxl/xl_cmdimpl.c int main_psr_hwinfo(int argc, char **argv) · line 9556
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+ SWITCH_FOREACH_OPT(opt, "", NULL, "qemu-monitor-command", 2) { + /* No options */ + } + + domid = find_domain(argv[optind]); + cmd = argv[optind + 1]; + + if (argc - optind > 2) { + fprintf(stderr, "Invalid arguments.\n"); + return 1;...here.
Quoted 3 lines
Anyway, this is
Reviewed-by Dario Faggioli <[email protected]>
Thanks for reviewing.
Quoted 4 lines
if possible, with the above 'return 1' converted to 'return
EXIT_FAILURE' (either by resending or done upon commit).
I can fix that up, no need to resend.
Wei.
Quoted 5 lines
If a maintainer wants to ack and commit this as is, my R-b still stands. In fact, as I said, xl is still not yet 100% consistent wrt this, and although I think new code should comply with the rule, I won't stand in the way of a patch for something like this.
Quoted 8 lines
Regards,
DarioSignature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 53 lines · Wei Liu
Quoted 46 lines · Dario Faggioli
Quoted 6 lines · Juergen Gross
Add a new xl command "qemu-monitor-command" to issue arbitrary commands
to a domain's device model. Syntax is:xl qemu-monitor-command <domain> <command>
Quoted 8 lines
The command is issued via qmp human-monitor-command command. Any information returned by the command is printed to stdout.
Signed-off-by Juergen Gross <[email protected]>---
V3: - addGC_FREEas requested by Dario Faggioli
- return with EXIT_FAILURE/SUCCESS as requested by Dario FaggioliI think you missed one...
Quoted 17 lines
tools/libxl/xl_cmdimpl.c +0
-0@@ -9536,6 +9536,35 @@ int main_psr_hwinfo(int argc, char **argv)
#endiftools/libxl/xl_cmdimpl.c +8
-0+int main_qemu_monitor_command (int argc,char **argv) +{ + int opt; + uint32_t domid; + char *cmd; + char *output; + int ret; +tools/libxl/xl_cmdimpl.c int main_psr_hwinfo(int argc, char **argv) · line 9556
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+ SWITCH_FOREACH_OPT(opt, "", NULL, "qemu-monitor-command", 2) { + /* No options */ + } + + domid = find_domain(argv[optind]); + cmd = argv[optind + 1]; + + if (argc - optind > 2) { + fprintf(stderr, "Invalid arguments.\n"); + return 1;...here.
Quoted 3 lines
Anyway, this is
Reviewed-by Dario Faggioli <[email protected]>Thanks for reviewing.
Quoted 9 lines
Acked-by Wei Liu <[email protected]>Quoted 4 lines
if possible, with the above 'return 1' converted to 'return
EXIT_FAILURE' (either by resending or done upon commit).I can fix that up, no need to resend.
Fixed up the patch and pushed.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel