From: Juergen Gross <jgross@suse.com>
To: Chunyan Liu <cyliu@suse.com>, xen-devel@lists.xen.org
Cc: lars.kurth@citrix.com, wei.liu2@citrix.com,
ian.campbell@citrix.com, george.dunlap@eu.citrix.com,
ian.jackson@citrix.com, caobosimon@gmail.com
Subject: Re: [PATCH V3 4/6] xl: add pvusb commands
Date: Mon, 20 Apr 2015 10:12:08 +0200 [thread overview]
Message-ID: <5534B4D8.4010109@suse.com> (raw)
In-Reply-To: <1429415452-6161-5-git-send-email-cyliu@suse.com>
On 04/19/2015 05:50 AM, Chunyan Liu wrote:
> Add pvusb commands: usb-ctrl-attach, usb-ctrl-detach, usb-list,
> usb-attach and usb-detach.
>
> To attach a usb device to guest through pvusb, one could follow
> following example:
>
> #xl usb-ctrl-attach test_vm version=1 num_ports=8
>
> #xl usb-list test_vm
> will show the usb controllers and port usage under the domain.
>
> #xl usb-attach test_vm 1.6
> will find the first usable controller:port, and attach usb
> device whose bus address is 1.6 (busnum is 1, devnum is 6)
> to it. One could also specify which <controller> and which <port>.
>
> #xl usb-detach test_vm 1.6
>
> #xl usb-ctrl-detach test_vm dev_id
> will destroy the controller with specified dev_id. Dev_id
> can be traced in usb-list info.
>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> Signed-off-by: Simon Cao <caobosimon@gmail.com>
> ---
> Changes to v2:
> * use bus.addr as user interface instead of busid in usb-attach|detach
> * remove usb-assignable-list interface
Why? While lsusb in combination with xl usb-list for each domain will
give the same information, having to iterate through all domains can be
quite annoying.
An alternative would be to accept omitting the domain for xl usb-list
and list all domains with assigned usb devices in this case.
> * add documentation
>
> docs/man/xl.pod.1 | 38 ++++++++
> tools/libxl/xl.h | 5 +
> tools/libxl/xl_cmdimpl.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++
> tools/libxl/xl_cmdtable.c | 25 +++++
> 4 files changed, 306 insertions(+)
>
...
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -3196,6 +3196,244 @@ int main_cd_insert(int argc, char **argv)
> return 0;
> }
>
> +static void usbinfo_print(libxl_device_usb *usbs, int num) {
> + int i;
> + if ( usbs == NULL )
Coding style.
> + return;
> + for (i = 0; i < num; i++) {
> + libxl_usbinfo usbinfo;
> + libxl_usbinfo_init(&usbinfo);
> +
> + if (usbs[i].port )
Coding style.
> + printf(" Port %d:", usbs[i].port);
> + if (!libxl_device_usb_getinfo(ctx, usbs[i].busid, &usbinfo)) {
> + printf(" Bus %03x Device %03x: ID %04x:%04x %s %s\n",
> + usbinfo.busnum, usbinfo.devnum, usbinfo.idVendor,
> + usbinfo.idProduct, usbinfo.manuf, usbinfo.prod);
> + }
> + libxl_usbinfo_dispose(&usbinfo);
> + }
> +}
> +
> +int main_usbctrl_attach(int argc, char **argv)
> +{
> + uint32_t domid;
> + int opt;
> + char *oparg;
> + libxl_device_usbctrl usbctrl;
> +
> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-ctrl-attach", 1) {
> + /* No options */
> + }
> +
> + domid = find_domain(argv[optind++]);
> +
> + libxl_device_usbctrl_init(&usbctrl);
> +
> + while (argc > optind) {
> + if (MATCH_OPTION("version", argv[optind], oparg)) {
> + usbctrl.version = atoi(oparg);
> + } else if (MATCH_OPTION("ports", argv[optind], oparg)) {
> + usbctrl.ports = atoi(oparg);
> + } else {
> + fprintf(stderr, "unrecognized argument `%s'\n", argv[optind]);
> + exit(-1);
I don't think this is the preferred way of error handling.
Returning with an appropriate error code would be better.
Same applies to all other uses of exit() below.
> + }
> + optind++;
> + }
> +
> + if (dryrun_only) {
> + char* json = libxl_device_usbctrl_to_json(ctx, &usbctrl);
> + printf("usb controller: %s\n", json);
> + free(json);
> + libxl_device_usbctrl_dispose(&usbctrl);
> + if (ferror(stdout) || fflush(stdout)) {
> + perror("stdout");
> + exit(-1);
> + }
> + return 0;
> + }
> +
> + if (libxl_device_usbctrl_add(ctx, domid, &usbctrl, 0)) {
> + fprintf(stderr, "libxl_device_usbctrl_add failed.\n");
> + exit(-1);
> + }
> + libxl_device_usbctrl_dispose(&usbctrl);
> + return 0;
> +}
> +
> +int main_usbctrl_detach(int argc, char **argv)
> +{
> + uint32_t domid;
> + int opt;
> + libxl_device_usbctrl usbctrl;
> +
> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-ctrl-detach", 2) {
> + /* No options */
> + }
> +
> + domid = find_domain(argv[optind]);
> +
> + libxl_device_usbctrl_init(&usbctrl);
> + usbctrl.devid = atoi(argv[optind+1]);
> +
> + if(libxl_device_usbctrl_remove(ctx, domid, &usbctrl, 0)) {
Coding style.
> + fprintf(stderr, "libxl_device_usbctrl_add failed.\n");
> + exit(-1);
> + }
> + libxl_device_usbctrl_dispose(&usbctrl);
> + return 0;
> +
> +}
Juergen
next prev parent reply other threads:[~2015-04-20 8:12 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-19 3:50 [PATCH V3 0/6] libxl pvusb toolstack work Chunyan Liu
2015-04-19 3:50 ` [PATCH V3 1/6] libxl: export some functions for pvusb use Chunyan Liu
2015-04-20 16:25 ` Olaf Hering
2015-05-18 13:34 ` George Dunlap
2015-05-18 14:05 ` Wei Liu
2015-04-19 3:50 ` [PATCH V3 2/6] libxl_read_file_contents: fix reading sysfs file Chunyan Liu
2015-05-18 14:23 ` Ian Jackson
2015-05-18 14:28 ` Ian Campbell
2015-05-18 14:30 ` Wei Liu
2015-05-19 3:21 ` Chun Yan Liu
2015-05-18 14:25 ` Wei Liu
2015-04-19 3:50 ` [PATCH V3 3/6] libxl: add pvusb API Chunyan Liu
2015-04-20 5:53 ` Juergen Gross
2015-05-18 13:55 ` Olaf Hering
2015-05-18 18:07 ` Wei Liu
2015-05-19 3:20 ` Chun Yan Liu
2015-05-19 10:20 ` George Dunlap
2015-05-19 11:31 ` Jürgen Groß
2015-05-20 9:04 ` Wei Liu
2015-05-20 9:12 ` Ian Campbell
2015-05-20 9:30 ` Chun Yan Liu
2015-06-11 16:54 ` Ian Jackson
2015-05-19 18:06 ` George Dunlap
2015-05-19 18:24 ` Ian Campbell
2015-06-08 9:06 ` 答复: " Chun Yan Liu
2015-05-19 18:16 ` George Dunlap
2015-06-08 11:15 ` 答复: " Chun Yan Liu
2015-05-19 18:20 ` George Dunlap
2015-04-19 3:50 ` [PATCH V3 4/6] xl: add pvusb commands Chunyan Liu
2015-04-20 8:12 ` Juergen Gross [this message]
2015-04-21 2:21 ` Chun Yan Liu
2015-05-20 14:20 ` George Dunlap
2015-05-20 14:33 ` Juergen Gross
2015-05-20 14:41 ` George Dunlap
2015-05-20 14:55 ` Juergen Gross
2015-05-20 15:25 ` George Dunlap
2015-05-21 3:35 ` Juergen Gross
2015-05-21 10:37 ` George Dunlap
2015-05-21 10:52 ` Juergen Gross
2015-05-21 11:11 ` George Dunlap
2015-05-21 11:58 ` Juergen Gross
2015-05-21 13:01 ` George Dunlap
2015-05-21 13:08 ` Juergen Gross
2015-05-21 13:43 ` George Dunlap
2015-05-21 13:55 ` Juergen Gross
2015-05-21 14:00 ` George Dunlap
2015-05-21 14:14 ` Juergen Gross
2015-05-20 14:23 ` George Dunlap
2015-05-20 15:46 ` George Dunlap
2015-05-20 15:55 ` George Dunlap
2015-04-19 3:50 ` [PATCH V3 5/6] domcreate: support pvusb in configuration file Chunyan Liu
2015-04-19 3:50 ` [PATCH V3 6/6] refactor codes to unify pvusb and qemu emulated usb Chunyan Liu
2015-05-21 14:17 ` George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5534B4D8.4010109@suse.com \
--to=jgross@suse.com \
--cc=caobosimon@gmail.com \
--cc=cyliu@suse.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=lars.kurth@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.