[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v6 2/2] xl: Add commands for usb hot-plug



On Fri, 2013-04-19 at 16:59 +0100, George Dunlap wrote:
> +
> +int main_usb_attach(int argc, char **argv)
> +{
> +    uint32_t domid = INVALID_DOMID;
> +    int opt = 0, rc;
> +    char *device = NULL;
> +
> +    SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) {
> +        /* No options */
> +    }
> +
> +    domid = find_domain(argv[optind]);
> +    device = argv[optind + 1];
> +
> +    if (domid == INVALID_DOMID) {
> +        fprintf(stderr, "Must specify domid\n\n");
> +        help("usb-attach");
> +        return 2;
> +    }

find_domain won't return in this case, so no need to worry about it
yourself.

> +int main_usb_detach(int argc, char **argv)
> +{
> +    uint32_t domid = INVALID_DOMID;
> +    int opt = 0, rc;
> +    char *device = NULL;
> +    int type = 0;
> +
> +    SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 2) {
> +        /* No options */
> +    }
> +
> +    domid = find_domain(argv[optind]);
> +    device = argv[optind + 1];
> +
> +    if (domid == INVALID_DOMID) {
> +        fprintf(stderr, "Must specify domid\n\n");
> +        help("usb-detach");
> +        return 2;
> +    }


Same again.

> +
> +    rc = usb_detach(domid, type, device);
> +    if (rc < 0)
> +        return 1;
> +    else
> +        return 0;
> +}
> +
> +static void usb_list(uint32_t domid)
> +{
> +    libxl_device_usb *dev;
> +    int num, i;
> +
> +    dev = libxl_device_usb_list(ctx, domid, &num);
> +    if (dev == NULL)
> +        return;
> +    printf("protocol  backend  type     device\n");
> +    for (i = 0; i < num; i++) {
> +        printf("%8s  ", (dev[i].protocol==LIBXL_USB_PROTOCOL_PV)?"pv":"dm");

You can use libxl_usb_protocol_to_string here.

> +        printf("%7d  ", dev[i].backend_domid);
> +        printf("%7s  ", 
> (dev[i].type==LIBXL_DEVICE_USB_TYPE_HOSTDEV)?"hostdev":"unknown");

libxl_device_usb_type_to_string.

> +        if (dev[i].type == LIBXL_DEVICE_USB_TYPE_HOSTDEV)
> +            printf("%03d.%03d",
> +                   dev[i].u.hostdev.hostbus,
> +                   dev[i].u.hostdev.hostaddr);
> +        printf("\n");
> +    }
> +    free(dev);

You leak the content of the devices, you need to call
libxl_device_usb_dispose on each, or better define
libxl_device_usb_list_free (this is inconsistently provided by other
devices, but may as well get it right for new code).

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.