[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RESEND][PATCH V9 4/7] libxl: add libxl_device_usbdev_assignable_list API
Add API for listing assignable USB devices info. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet. Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> --- This could be squashed with previous patch. Split because there is some dispute on this. If this is acceptable, could be squashed, otherwise could be removed. Changes: - update usb device naming tools/libxl/libxl.h | 2 ++ tools/libxl/libxl_pvusb.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 609d068..d659ec3 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1479,6 +1479,8 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_usbctrlinfo *usbctrlinfo); /* USB Devices */ +libxl_device_usbdev * +libxl_device_usbdev_assignable_list(libxl_ctx *ctx, int *num); int libxl_device_usbdev_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usbdev *usbdev, diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c index e35c6b5..b0f0808 100644 --- a/tools/libxl/libxl_pvusb.c +++ b/tools/libxl/libxl_pvusb.c @@ -592,6 +592,68 @@ static bool is_usbdev_assignable(libxl__gc *gc, libxl_device_usbdev *usbdev) return classcode != USBHUB_CLASS_CODE; } +libxl_device_usbdev * +libxl_device_usbdev_assignable_list(libxl_ctx *ctx, int *num) +{ + GC_INIT(ctx); + libxl_device_usbdev *usbdevs = NULL; + libxl_device_usbdev *assigned; + int num_assigned; + DIR *dir; + int r; + + *num = 0; + + r = get_assigned_devices(gc, &assigned, &num_assigned); + if (r) { + LOG(ERROR, "cannot determine if device is assigned"); + goto out; + } + + dir = opendir(SYSFS_USB_DEV); + if (!dir) goto out; + + size_t need = offsetof(struct dirent, d_name) + + pathconf(SYSFS_USB_DEV, _PC_NAME_MAX) + 1; + struct dirent *de_buf = libxl__zalloc(gc, need); + struct dirent *de; + + while (readdir_r(dir, de_buf, &de) == 0 && de != NULL) { + libxl_device_usbdev *usbdev; + uint8_t bus, addr; + + if (!strcmp(de->d_name, ".") || + !strcmp(de->d_name, "..")) + continue; + + if (usbdev_busaddr_from_busid(gc, de->d_name, &bus, &addr)) + continue; + + GCNEW(usbdev); + usbdev->u.hostdev.hostbus = bus; + usbdev->u.hostdev.hostaddr = addr; + + if (!is_usbdev_assignable(gc, usbdev)) + continue; + + if (is_usbdev_in_array(assigned, num_assigned, usbdev)) + continue; + + usbdevs = libxl__realloc(NOGC, usbdevs, + sizeof(*usbdevs) * (*num + 1)); + libxl_device_usbdev_init(usbdevs + *num); + usbdevs[*num].u.hostdev.hostbus = bus; + usbdevs[*num].u.hostdev.hostaddr = addr; + (*num)++; + } + + closedir(dir); + +out: + GC_FREE; + return usbdevs; +} + /* get usb devices under certain usb controller */ static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |