All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <George.Dunlap@eu.citrix.com>
To: Chunyan Liu <cyliu@suse.com>
Cc: "Jürgen Groß" <jgross@suse.com>, "Wei Liu" <wei.liu2@citrix.com>,
	"Ian Campbell" <ian.campbell@citrix.com>,
	"Ian Jackson" <Ian.Jackson@eu.citrix.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	"Jim Fehlig" <jfehlig@suse.com>,
	"Simon Cao" <caobosimon@gmail.com>
Subject: Re: [PATCH V8 3/7] libxl: add pvusb API
Date: Thu, 12 Nov 2015 17:27:59 +0000	[thread overview]
Message-ID: <CAFLBxZawnBaQ791ebbv1bmw3DX2+cWfk8QD1JdAVopk0-Ma6Zw@mail.gmail.com> (raw)
In-Reply-To: <1445418510-19614-4-git-send-email-cyliu@suse.com>

On Wed, Oct 21, 2015 at 10:08 AM, Chunyan Liu <cyliu@suse.com> wrote:
> +static int
> +get_assigned_devices(libxl__gc *gc,
> +                     libxl_device_usb **list, int *num)
> +{
> +    char **domlist;
> +    unsigned int nd = 0, i, j, k;
> +    int rc;
> +
> +    *list = NULL;
> +    *num = 0;
> +
> +    domlist = libxl__xs_directory(gc, XBT_NULL, "/local/domain", &nd);
> +    for (i = 0; i < nd; i++) {
> +        char *path, **ctrl_list;
> +        unsigned int nc = 0;
> +
> +        path = GCSPRINTF("/local/domain/%s/device/vusb", domlist[i]);
> +        ctrl_list = libxl__xs_directory(gc, XBT_NULL, path, &nc);
> +
> +        for (j = 0; j < nc; j++) {
> +            const char *be_path, *num_ports;
> +            int nport;
> +
> +            rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                          GCSPRINTF("%s/%s/backend", path, ctrl_list[j]),
> +                          &be_path);
> +            if (rc) goto out;
> +
> +            rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                                        GCSPRINTF("%s/num-ports", be_path),
> +                                        &num_ports);
> +            if (rc) goto out;
> +
> +            nport = atoi(num_ports);
> +            for (k = 0; k < nport; k++) {
> +                libxl_device_usb *usb;
> +                const char *portpath, *busid;
> +
> +                portpath = GCSPRINTF("%s/port/%d", be_path, k + 1);
> +                busid = libxl__xs_read(gc, XBT_NULL, portpath);
> +                /* If there is USB device attached, add it to list */
> +                if (busid && strcmp(busid, "")) {
> +                    GCREALLOC_ARRAY(*list, *num + 1);
> +                    usb = *list + *num;
> +                    (*num)++;
> +                    libxl_device_usb_init(usb);
> +                    usb->ctrl = atoi(ctrl_list[j]);
> +                    usb->port = k + 1;
> +                    rc = usb_busaddr_from_busid(gc, busid,
> +                                                &usb->u.hostdev.hostbus,
> +                                                &usb->u.hostdev.hostaddr);

You should probably set usb->devtype to HOSTDEV here, even though this
function is internal.

> +                    if (rc) goto out;
> +                }
> +            }
> +        }
> +    }
> +
> +    rc = 0;
> +
> +out:
> +    if (rc) {
> +        *list = NULL;
> +        *num = 0;
> +    }
> +    return rc;
> +}
> +
> +static bool is_usbdev_in_array(libxl_device_usb *usbs, int num,
> +                               libxl_device_usb *usb)
> +{
> +    int i;
> +
> +    for (i = 0; i < num; i++) {
> +        if (usbs[i].u.hostdev.hostbus == usb->u.hostdev.hostbus &&
> +            usbs[i].u.hostdev.hostaddr == usb->u.hostdev.hostaddr)
> +            return true;
> +    }
> +
> +    return false;
> +}
> +
> +/* check if USB device is already assigned to a domain */
> +/* check if USB device type is assignable */
> +static bool is_usb_assignable(libxl__gc *gc, libxl_device_usb *usb)
> +{
> +    int classcode;
> +    char *filename;
> +    void *buf = NULL;
> +    char *busid = NULL;
> +
> +    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,
> +                                 usb->u.hostdev.hostaddr);
> +    if (!busid) return false;
> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/bDeviceClass", busid);
> +    if (libxl__read_sysfs_file_contents(gc, filename, &buf, NULL))
> +        return false;
> +
> +    classcode = atoi(buf);
> +    return classcode != USBHUB_CLASS_CODE;
> +}
> +
> +/* get usb devices under certain usb controller */
> +static int
> +libxl__device_usb_list_for_usbctrl(libxl__gc *gc, uint32_t domid,
> +                                   libxl_devid usbctrl,
> +                                   libxl_device_usb **usbs, int *num)
> +{
> +    const char *fe_path, *be_path, *num_devs;
> +    int n, i, rc;
> +
> +    *usbs = NULL;
> +    *num = 0;
> +
> +    fe_path = GCSPRINTF("%s/device/vusb/%d",
> +                        libxl__xs_get_dompath(gc, domid), usbctrl);
> +
> +    rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                                GCSPRINTF("%s/backend", fe_path),
> +                                &be_path);
> +    if (rc) return rc;
> +
> +    rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                                GCSPRINTF("%s/num-ports", be_path),
> +                                &num_devs);
> +    if (rc) return rc;
> +
> +    n = atoi(num_devs);
> +
> +    for (i = 0; i < n; i++) {
> +        char *busid;
> +        libxl_device_usb *usb;
> +
> +        busid = libxl__xs_read(gc, XBT_NULL,
> +                               GCSPRINTF("%s/port/%d", be_path, i + 1));
> +        if (busid && strcmp(busid, "")) {
> +            GCREALLOC_ARRAY(*usbs, *num + 1);
> +            usb = *usbs + *num;
> +            (*num)++;
> +            libxl_device_usb_init(usb);
> +            usb->ctrl = usbctrl;
> +            usb->port = i + 1;
> +            rc = usb_busaddr_from_busid(gc, busid,
> +                                        &usb->u.hostdev.hostbus,
> +                                        &usb->u.hostdev.hostaddr);

Same thing re devtype.

> +int libxl_ctrlport_to_device_usb(libxl_ctx *ctx,
> +                                 uint32_t domid,
> +                                 int ctrl,
> +                                 int port,
> +                                 libxl_device_usb *usb)
> +{
> +    GC_INIT(ctx);
> +    const char *dompath, *be_path, *busid;
> +    int rc;
> +
> +    dompath = libxl__xs_get_dompath(gc, domid);
> +
> +    rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                  GCSPRINTF("%s/device/vusb/%d/backend", dompath, ctrl),
> +                  &be_path);
> +    if (rc) goto out;
> +
> +    rc = libxl__xs_read_checked(gc, XBT_NULL,
> +                           GCSPRINTF("%s/port/%d", be_path, port),
> +                           &busid);
> +    if (rc) goto out;
> +
> +    if (!strcmp(busid, "")) {
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +
> +    usb->ctrl = ctrl;
> +    usb->port = port;
> +    rc = usb_busaddr_from_busid(gc, busid, &usb->u.hostdev.hostbus,
> +                                &usb->u.hostdev.hostaddr);

You definitely need to set usb->devtype here to HOSTDEV.

> +libxl_usbinfo = Struct("usbinfo", [
> +    ("ctrl", libxl_devid),
> +    ("port", integer),
> +    ("busnum", uint8),
> +    ("devnum", uint8),
> +    ("idVendor", uint16),
> +    ("idProduct", uint16),
> +    ("prod", string),
> +    ("manuf", string),
> +    ], dir=DIR_OUT)

As mentioned in the review of another patch, it looks like this is
vestigal and should be removed.

> +void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr)
> +{
> +   int i;
> +   for (i = 0; i < nr; i++)
> +       libxl_device_usbctrl_dispose(&list[i]);
> +   free(list);
> +}
> +
> +void libxl_device_usb_list_free(libxl_device_usb *list, int nr)
> +{
> +   int i;
> +   for (i = 0; i < nr; i++)
> +       libxl_device_usb_dispose(&list[i]);
> +   free(list);
> +}

This is nitpicky, but as long as you're going to repost: the
first-level indents in these two functions are only 3 spaces instead
of 4.

Other than that (and my previous comments + Ian's comments) it looks good to me!

 -George

  parent reply	other threads:[~2015-11-12 17:27 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-21  9:08 [PATCH V8 0/7] xen pvusb toolstack work Chunyan Liu
2015-10-21  9:08 ` [PATCH V8 1/7] libxl: export some functions for pvusb use Chunyan Liu
2015-10-27 11:08   ` Juergen Gross
2015-10-21  9:08 ` [PATCH V8 2/7] libxl_read_file_contents: add new entry to read sysfs file Chunyan Liu
2015-10-27 11:31   ` Juergen Gross
2015-11-16 14:03   ` Ian Campbell
2015-11-16 18:15     ` Ian Jackson
2015-10-21  9:08 ` [PATCH V8 3/7] libxl: add pvusb API Chunyan Liu
2015-10-27 11:31   ` Juergen Gross
2015-11-04  6:31   ` Chun Yan Liu
2015-11-05 15:54     ` George Dunlap
2015-11-09 18:11   ` Ian Jackson
2015-11-10  8:41     ` Chun Yan Liu
2015-11-10 17:57       ` George Dunlap
2015-11-10 18:11         ` Ian Jackson
2015-11-11  7:21           ` Chun Yan Liu
2015-11-11  2:37         ` Chun Yan Liu
2015-11-12 17:00       ` Ian Jackson
2015-11-13  2:30         ` Chun Yan Liu
2015-11-16 18:06           ` Ian Jackson
2015-11-17  5:47             ` Chun Yan Liu
2015-11-12 11:32   ` Olaf Hering
2015-11-13  2:32     ` Chun Yan Liu
2015-11-12 17:27   ` George Dunlap [this message]
2015-11-13  2:56     ` Chun Yan Liu
2015-11-13 11:19   ` Olaf Hering
2015-11-16 10:01     ` George Dunlap
2015-11-18  5:48       ` Chun Yan Liu
2015-11-18  9:44         ` Olaf Hering
2015-11-18 10:03           ` Ian Campbell
2015-11-18 10:42             ` Olaf Hering
2015-11-19  1:33           ` Chun Yan Liu
2015-11-19  6:24             ` Chun Yan Liu
2015-11-23 17:24               ` George Dunlap
2015-10-21  9:08 ` [PATCH V8 4/7] libxl: add libxl_device_usb_assignable_list API Chunyan Liu
2015-10-27 11:32   ` Juergen Gross
2015-11-11 16:07   ` George Dunlap
2015-10-21  9:08 ` [PATCH V8 5/7] xl: add pvusb commands Chunyan Liu
2015-10-27 11:37   ` Juergen Gross
2015-11-12 11:38   ` George Dunlap
2015-11-12 11:39     ` George Dunlap
2015-11-13  2:43     ` Chun Yan Liu
2015-11-16 10:05       ` George Dunlap
2015-11-12 14:42   ` Olaf Hering
2015-11-12 14:49     ` George Dunlap
2015-11-13  2:49     ` Chun Yan Liu
2015-10-21  9:08 ` [PATCH V8 6/7] xl: add usb-assignable-list command Chunyan Liu
2015-10-27 11:38   ` Juergen Gross
2015-11-12 11:44   ` George Dunlap
2015-10-21  9:08 ` [PATCH V8 7/7] domcreate: support pvusb in configuration file Chunyan Liu
2015-10-27 11:41   ` Juergen Gross
2015-11-12 16:10   ` George Dunlap
2015-11-13  2:54     ` Chun Yan Liu

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=CAFLBxZawnBaQ791ebbv1bmw3DX2+cWfk8QD1JdAVopk0-Ma6Zw@mail.gmail.com \
    --to=george.dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=jgross@suse.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.