All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@eu.citrix.com>
To: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Cc: "sstanisi@cbnco.com" <sstanisi@cbnco.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH RFC 0.2 2/2] xl: Add usb-add and usb-del commands
Date: Thu, 11 Apr 2013 16:22:18 +0100	[thread overview]
Message-ID: <5166D52A.3060507@eu.citrix.com> (raw)
In-Reply-To: <1365693659-29317-2-git-send-email-george.dunlap@eu.citrix.com>

On 11/04/13 16:20, George Dunlap wrote:
> Add commands to add and remove host USB to HVM guests.
>
> WARNING: STILL A PROTOTYPE
>
> Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
> ---
>   docs/man/xl.pod.1         |   51 ++++++++++++++++++++++
>   tools/libxl/xl.h          |    2 +
>   tools/libxl/xl_cmdimpl.c  |  105 +++++++++++++++++++++++++++++++++++++++++++++
>   tools/libxl/xl_cmdtable.c |    5 +++
>   4 files changed, 163 insertions(+)
>
> diff --git a/docs/man/xl.pod.1 b/docs/man/xl.pod.1
> index a0e298e..2b5e6d7 100644
> --- a/docs/man/xl.pod.1
> +++ b/docs/man/xl.pod.1
> @@ -1110,6 +1110,57 @@ List virtual network interfaces for a domain.
>   
>   =back
>   
> +=head2 HVM DEVICES
> +
> +=over 4
> +
> +=item B<hvm-host-usb-add> I<-d domain-id> I<-v host-device-spec> [I<-i devname>]

Hmm, it should be obvious that this bit is pure fiction... I'll of 
course fix it up before the final submission.

  -G

> +
> +Passes through the host USB device specified by I<host-device-spec> to the
> +HVM domain I<domain-id>.  Host-device-spec can be one of the following:
> +
> +=over 4
> +
> +=item <hostbus>.<hostaddr>
> +
> +=item <vendorid>:<productid>
> +
> +=item <hostbus>.<hostaddr>:<vendorid>:<productid>
> +
> +=back
> +
> +The best way to find out the information for the device is typically using
> +lsusb.
> +
> +Using the I<-i> option, you can specify a I<devname> for the
> +device. This is an arbitrary string that can be used by
> +I<hvm-host-usb-del> to remove the device later.  If no name is
> +specified, then one will be chosen automatically.  In any case the
> +devname will be printed to stdout if the device is successfully added.
> +
> +If the I<-i> option is used, then it must be used on device removal;
> +I<host-device-spec> cannot be used.
> +
> +This command is only available for domains using qemu-xen, not
> +qemu-traditional.
> +
> +=item B<hvm-host-usb-del> I<-d domain-id> (I<-i devname> | I<-v host-device-spec>)
> +
> +Remove the host USB device from I<domain-id> which is specified either
> +by I<devname> or I<host-device-spec>.  Exactly one of the two must be
> +specified.  I<devname> is a string that was specified when the device
> +was inserted by B<hvm-host-usb-add>.  I<host-device-spec> can only be
> +used if no name I<devname> was specified when the device was added,
> +and it must match exactly the specification given at that time.
> +
> +Devices specified in the config file do not have an associated
> +devname, and thus cannot be removed using this command.
> +
> +This command is only available for domains using qemu-xen, not
> +qemu-traditional.
> +
> +=back
> +
>   =head2 VTPM DEVICES
>   
>   =over 4
> diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
> index b881f92..1af0f3b 100644
> --- a/tools/libxl/xl.h
> +++ b/tools/libxl/xl.h
> @@ -35,6 +35,8 @@ int main_info(int argc, char **argv);
>   int main_sharing(int argc, char **argv);
>   int main_cd_eject(int argc, char **argv);
>   int main_cd_insert(int argc, char **argv);
> +int main_usb_add(int argc, char **argv);
> +int main_usb_del(int argc, char **argv);
>   int main_console(int argc, char **argv);
>   int main_vncviewer(int argc, char **argv);
>   int main_pcilist(int argc, char **argv);
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 61f7b96..502a677 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -2600,6 +2600,111 @@ int main_cd_insert(int argc, char **argv)
>       return 0;
>   }
>   
> +
> +
> +static int parse_usb_hostdev_specifier(libxl_device_usb *dev, const char *s)
> +{
> +    const char * hostbus, *hostaddr, *p;
> +
> +    hostbus = s;
> +    hostaddr=NULL;
> +
> +#define is_dec(_c) ((_c) >= '0' && (_c) <= '9')
> +#define is_hex(_c) (is_dec(_c) || ((_c) >= 'a' && (_c) <= 'f'))
> +
> +    /* Match [0-9]+\.[0-9] */
> +    if (!is_dec(*hostbus))
> +        return -1;
> +
> +    for(p=s; *p; p++) {
> +        if(*p == '.') {
> +            if ( !hostaddr )
> +                hostaddr = p+1;
> +            else {
> +                return -1;
> +            }
> +        } else if (!is_dec(*p)) {
> +            return -1;
> +        }
> +    }
> +    if (!hostaddr || !is_dec(*hostaddr))
> +        return -1;
> +    dev->u.hostdev.hostbus  = strtoul(hostbus,  NULL, 10);
> +    dev->u.hostdev.hostaddr = strtoul(hostaddr, NULL, 10);
> +#undef is_dec
> +#undef is_hex
> +
> +    return 0;
> +}
> +
> +static int usb_add(uint32_t domid, libxl_device_usb_type type,
> +                            const char * device)
> +{
> +    libxl_device_usb usbdev;
> +    int rc;
> +
> +    libxl_device_usb_init(&usbdev);
> +
> +    usbdev.type = type;
> +
> +    switch(type) {
> +    case LIBXL_DEVICE_USB_TYPE_HOSTDEV:
> +        if ( parse_usb_hostdev_specifier(&usbdev, device) < 0 ) {
> +            rc = ERROR_FAIL;
> +            goto out;
> +        }
> +        break;
> +    default:
> +        fprintf(stderr, "INTERNAL ERROR: Unimplemented type.\n");
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +
> +    if ( (rc = libxl_device_usb_add(ctx, domid, &usbdev, NULL)) < 0 )
> +        fprintf(stderr, "libxl_usb_add failed.\n");
> +
> +    libxl_device_usb_dispose(&usbdev);
> +
> +out:
> +    return rc;
> +}
> +
> +int main_usb_add(int argc, char **argv)
> +{
> +    uint32_t domid = -1;
> +    int opt = 0, rc;
> +    const char *device = NULL;
> +    int type = 0;
> +
> +    SWITCH_FOREACH_OPT(opt, "d:v:", NULL, "usb-add", 0) {
> +    case 'd':
> +        domid = find_domain(optarg);
> +        break;
> +    case 'v':
> +        type = LIBXL_DEVICE_USB_TYPE_HOSTDEV;
> +        device = optarg;
> +        break;
> +    }
> +
> +    if ( domid == -1 ) {
> +        fprintf(stderr, "Must specify domid\n\n");
> +        help("usb-add");
> +        return 2;
> +    }
> +
> +    if ( !device ) {
> +        fprintf(stderr, "Must specify a device\n\n");
> +        help("usb-add");
> +        return 2;
> +    }
> +
> +    rc = usb_add(domid, type, device);
> +    if ( rc < 0 )
> +        return 1;
> +    else
> +        return 0;
> +}
> +
>   int main_console(int argc, char **argv)
>   {
>       uint32_t domid;
> diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
> index b4a87ca..948dae1 100644
> --- a/tools/libxl/xl_cmdtable.c
> +++ b/tools/libxl/xl_cmdtable.c
> @@ -187,6 +187,11 @@ struct cmd_spec cmd_table[] = {
>         "Eject a cdrom from a guest's cd drive",
>         "<Domain> <VirtualDevice>",
>       },
> +    { "usb-add",
> +      &main_usb_add, 1, 1,
> +      "Hot-plug a usb device to a domain.",
> +      "-d <Domain> [-v <hostbus.hostaddr>]",
> +    },
>       { "mem-max",
>         &main_memmax, 0, 1,
>         "Set the maximum amount reservation for a domain",

  reply	other threads:[~2013-04-11 15:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 15:20 [PATCH RFC 0.2 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest George Dunlap
2013-04-11 15:20 ` [PATCH RFC 0.2 2/2] xl: Add usb-add and usb-del commands George Dunlap
2013-04-11 15:22   ` George Dunlap [this message]
2013-04-11 15:26 ` [PATCH RFC 0.2 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest George Dunlap
     [not found]   ` <5166DA1E.3030600@cbnco.com>
2013-04-11 15:47     ` 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=5166D52A.3060507@eu.citrix.com \
    --to=george.dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=sstanisi@cbnco.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.