xen pvusb toolstack work
v7 cover xen pvusb toolstack work
This patch series is to add pvusb toolstack work, supporting hot add|remove USB device to|from guest and specify USB device in domain configuration file.
Changes to V6:
* Update libxl API hostbus/hostaddr/idVendor/idProduct type, update API to check PV/DEVICEMODEL
* address other comments to V6
V6:
http://lists.xen.org/archives/html/xen-devel/2015-08/msg00750.html
V5:
http://lists.xen.org/archives/html/xen-devel/2015-06/msg04052.html
V4:
http://lists.xenproject.org/archives/html/xen-devel/2015-06/msg01327.html
Related Discussion Threads:
http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html
http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html
<<< pvusb work introduction >>>
1. Overview
There are two general methods for passing through individual host devices to a guest. The first is via an emulated USB device controller; the second is PVUSB.
Additionally, there are two ways to add USB devices to a guest: via the config file at domain creation time, and via hot-plug while the VM is running.
* Emulated USB
In emulated USB, the device model (qemu) presents an emulated USB controller to the guest. The device model process then grabs control of the device from domain 0 and and passes the USB commands between the guest OS and the host USB device.
This method is only available to HVM domains, and is not available for domains running with device model stubdomains.
* PVUSB
PVUSB uses a paravirtialized front-end/back-end interface, similar to the traditional Xen PV network and disk protocols. In order to use PVUSB, you need usbfront in your guest OS, and usbback in dom0 (or your USB driver domain).
2. Specifying a host USB device
QEMU qmp commands allows USB devices to be specified either by their bus address (in the form bus.device) or their device tag (in the form vendorid:deviceid).
Each way of specifying has its advantages:
Specifying by device tag will always get the same device,
regardless of where the device ends up in the USB bus topology. However, if there are two identical devices, it will not allow you to specify which one.
Specifying by bus address will always allow you to choose a
specific device, even if you have duplicates. However, the bus address may change depending on which port you plugged the device into, and possibly also after a reboot.
To avoid duplication of vendorid:deviceid, we'll use bus address to specify host USB device in xl toolstack.
You can use lsusb to list the USB devices on the system:
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 003 Device 002: ID f617:0905
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0424:2640 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 005: ID 0424:4060 Standard Microsystems Corp. Ultra Fast Media Reader
Bus 001 Device 006: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
To pass through the Logitec mouse, for instance, you could specify 1.6 (remove leading zeroes).
Note: USB hubs can not be assigned to guest.
3. PVUSB toolstack
* Specify USB device in xl config file
You can just specify usb devices, like:
usbdev=['1.6']
Then it will create a USB controller automatically and attach the USB device to the first available USB controller:port.
or, you can explicitly specify usb controllers and usb devices, like:
usbctrl=['verison=1, ports=4', 'version=2, ports=8', ] usbdev=['1.6, controller=0, port=1']
Then it will create two USB controllers as you specified. And if controller and port are specified in usb config, then it will attach the USB device to that controller:port. About the controller and port value:
Each USB controller has a index (or called devid) based on 0. The 1st controller has index 0, the 2nd controller has index 1, ... Under controller, each port has a port number based on 1. In above configuration, the 1st controller will have port 1,2,3,4.
* Hot-Plug USB device
To attach a USB device, you should first create a USB controller. e.g.
xl usb-ctrl-attach domain [version=1|2] [ports=value] By default, it will create a USB2.0 controller with 8 ports.
Then you could attach a USB device.
e.g.
xl usb-attach domain 1.6 [controller=index port=number] By default, it will find the 1st available controller:port to attach the USB device.
You could view USB device status of the domain by usb-list. e.g.
xl usb-list domain
It will list USB controllers and USB devices under each controller.
You could detach a USB device with usb-detach command. e.g.
xl usb-detach domain 1.6
You can also remove the whole USB controller by usb-ctrl-detach command.
e.g.
xl usb-ctrl-detach domain 0
It will remove the USB controller with index 0 and all USB devices under it.
4. PVUSB Libxl implementation
* usb-ctrl-attach
To create a usb controller, we need:
1) generate usb controler related information
2) write usb controller frontend/backend info to xenstore PVUSB frontend and backend driver will probe xenstore paths and build connection between frontend and backend.
* usb-ctrl-detach
To remove a usb controller, we need:
1) check if the usb controller exists or not
2) remove all usb devices under controller
3) remove usb controller info from xenstore
* usb-attach
To attach a usb device, we need:
1) check if the usb device type is assignable
2) check if the usb device is already assigned to a domain
3) add 'busid' of the usb device to xenstore contoller/port/. PVUSB driver watches the xenstore changes and detects that, and needs to use 'busid' to do following work.
4) unbind usb device from original driver and bind to usbback. If usb device has many interfaces, then:
- unbind each interface from its original driver and bind to usbback.
- store the original driver to xenstore for later rebinding when detaching the device.
* usb-detach
To detach a usb device, we need:
1) check if the usb device is assigned to the domain
2) remove the usb device from xenstore controller/port.
3) unbind usb device from usbback and rebind to its original driver. If usb device has many interfaces, do it to each interface.
* usb-list
List all USB controllers and USB devices under each controller.
5. PVUSB xenstore information
PVUSB xenstore information includes three parts: frontend, backend and /libxl part.
A USB controller is corresponding to a "vusb" device in xenstore. Adding a USB controller will add a new "vusb" device, removing a USB controller will delete the related "vusb" device.
Following is an example xenstore values of a USB controller. Backend:
backend = ""
vusb = ""
1 = ""
0 = ""
frontend = "/local/domain/1/device/vusb/0"
frontend-id = "1"
online = "1"
state = "4"
type = "pv"
usb-ver = "1"
num-ports = "4"
port = ""
1 = ""
2 = ""
3 = ""
4 = ""Frontend:
device = ""
vusb = ""
0 = ""
backend = "/local/domain/0/backend/vusb/1/0"
backend-id = "0"
state = "4"
urb-ring-ref = "348"
conn-ring-ref = "346"
event-channel = "20"Adding a USB device won't create a new "vusb" device, but only write the USB device busid to one port of USB controller.
For example, attaching a USB device (busid is 2-1.6) to above USB controller port 1, it only need write 2-1.6 to port 1 of this USB controller:
Backend:
backend = ""
vusb = ""
1 = ""
0 = ""
frontend = "/local/domain/1/device/vusb/0"
frontend-id = "1"
online = "1"
state = "4"
type = "pv"
usb-ver = "1"
num-ports = "4"
port = ""
1 = "2-1.6"
2 = ""
3 = ""
4 = ""Frontend doesn't change.
Since assign a host USB device to guest, we'll unbind USB interfaces from their original drivers and bind them to usbback. After detaching this USB device from guest, one would hope the USB interfaces could be rebind to their original drivers, so there should some place to get the original driver info. To support that, when attaching a USB device to guest, we'll save the original driver info in xenstore too, the place is /libxl/usbback, for example:
libxl = ""
1 = ""
dm-version = "qemu_xen"
usbback = ""
3-11 = ""
3-11-1_0 = ""
driver_path = "/sys/bus/usb/drivers/btusb"
In this example, USB device (busid is 3-11, /sys/bus/usb/devices/3-11). It has interface 3-11:1.0, whose original dirver is btusb. Since xenstore doesn't allow ':' and '.' in a key, so we encode the interface by changing ':' to '-' and changing '.' to '_'.
When detaching the USB device from guest, we can rebind 3-11:1.0 to btusb driver.
Chunyan Liu (7):
libxl: export some functions for pvusb use
libxl_read_file_contents: add new entry to read sysfs file
libxl: add pvusb API
libxl: add libxl_device_usb_assignable_list API
xl: add pvusb commands
xl: add usb-assignable-list command
domcreate: support pvusb in configuration file
docs/man/xl.cfg.pod.5 | 75 ++ docs/man/xl.pod.1 | 40 + tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 57 +- tools/libxl/libxl.h | 81 ++ tools/libxl/libxl_create.c | 73 +- tools/libxl/libxl_device.c | 8 + tools/libxl/libxl_internal.h | 33 +- tools/libxl/libxl_osdeps.h | 13 + tools/libxl/libxl_pvusb.c | 1477 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 57 ++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.c | 68 +- tools/libxl/libxl_utils.h | 5 + tools/libxl/xl.h | 6 + tools/libxl/xl_cmdimpl.c | 364 ++++++++- tools/libxl/xl_cmdtable.c | 29 + 17 files changed, 2370 insertions(+), 19 deletions(-) create mode 100644 tools/libxl/libxl_pvusb.c
Signature · 1 line
2.1.4
PATCH v7 1/7 libxl: export some functions for pvusb use
--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +2 -2
@@ -2006,7 +2006,7 @@ out: }/* common function to get next device id */ -static int libxl__device_nextid (libxl__gc *gc,uint32_t domid,char *device) +int libxl__device_nextid (libxl__gc *gc,uint32_t domid,char *device) {char *dompath, **l;unsigned int nb;
@@ -2025,7 +2025,7 @@ static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device)return nextid; } -static int libxl__resolve_domid (libxl__gc *gc,const char *name, +int libxl__resolve_domid (libxl__gc *gc,const char *name,uint32_t *domid) {if (!name)
tools/libxl/libxl_internal.h +3 -0
@@ -1164,6 +1164,9 @@ _hidden int libxl__init_console_from_channel(libxl__gc *gc,libxl__device_console *console, int dev_num, libxl_device_channel *channel); +_hidden int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device); +_hidden int libxl__resolve_domid(libxl__gc *gc, const char *name, +uint32_t *domid);/* * For each aggregate type which can be used as an input we provide:
Signature · 1 line
2.1.4
PATCH v7 2/7 libxl_read_file_contents: add new entry to read sysfs file
In reply to Chunyan LiuSysfs file has size=4096 but actual file content is less than that. Current libxl_read_file_contents will treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.
Add a new entry libxl_read_sysfs_file_contents to handle sysfs file specially. It would be used in later pvusb work.
---
Changes:
- check return value after realloc
tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_utils.c | 52 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-)
tools/libxl/libxl_internal.h +2 -0
@@ -4015,6 +4015,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,int libxl__count_physical_sockets (libxl__gc *gc,int *sockets);#endif +_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename, +void **data_r,int *datalen_r);/* * Local variables:
tools/libxl/libxl_utils.c +41 -11
75 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH V7 2/7] libxl_read_file_contents: add new entry to read sysfs file
Quoted 10 lines · Chunyan Liu
Sysfs file has size=4096 but actual file content is less than that. Current
libxl_read_file_contentswill treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.Add a new entry
libxl_read_sysfs_file_contentsto handle sysfs file specially. It would be used in later pvusb work.Signed-off-by Chunyan Liu <[email protected]>Reviewed-by Wei Liu <[email protected]>
This seems like it's a generic enough improvement to stand on its own -- would it make sense to check this in regardless, so we can remove it from the series?
-George
Quoted 104 lines
---
Changes:
- check return value after realloctools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_utils.c | 52 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-)tools/libxl/libxl_internal.h +2
-0@@ -4015,6 +4015,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,int libxl__count_physical_sockets (libxl__gc *gc,int *sockets);#endif +_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename, +void **data_r,int *datalen_r);/* * Local variables: tools/libxl/libxl_utils.c +41
-11@@ -322,8 +322,10 @@ out:return rc; } -int libxl_read_file_contents (libxl_ctx *ctx,const char *filename, -void **data_r,int *datalen_r) { +static int libxl_read_file_contents_core (libxl_ctx *ctx,const char *filename, +void **data_r,int *datalen_r, +bool tolerate_shrinking_file) +{GC_INIT (ctx);FILE *f =0 ;uint8_t *data =0 ;@@ -359,20 +361,35 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, datalen = stab.st_size;if (stab.st_size && data_r) { - data =malloc (datalen); + data =malloc (datalen +1 );if (!data) goto xe; - rs =fread (data,1 , datalen, f); -if (rs != datalen) { -if (ferror (f)) + rs =fread (data,1 , datalen +1 , f); +if (rs > datalen) { +LOG (ERROR ,"%s increased size while we were reading it" , + filename); + goto xe; + } + +if (rs < datalen) { +if (ferror (f)) {LOGE (ERROR ,"failed to read %s" , filename); -else if (feof (f)) -LOG (ERROR ,"%s changed size while we were reading it" , - filename); -else + goto xe; + }else if (feof (f)) { +if (tolerate_shrinking_file) { + datalen = rs; + }else { +LOG (ERROR ,"%s shrunk size while we were reading it" , + filename); + goto xe; + } + }else {abort (); - goto xe; + } } + + data =realloc (data, datalen); +if (!data) goto xe; }if (fclose (f)) {@@ -396,6 +413,19 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,return e; } +int libxl_read_file_contents (libxl_ctx *ctx,const char *filename, +void **data_r,int *datalen_r) +{ +return libxl_read_file_contents_core (ctx, filename, data_r, datalen_r,0 ); +} + +int libxl_read_sysfs_file_contents (libxl_ctx *ctx,const char *filename, +void **data_r,int *datalen_r) +{ +return libxl_read_file_contents_core (ctx, filename, data_r, datalen_r,1 ); +} + +#define READ_WRITE_EXACTLY (rw, zero_is_eof, constdata) \ \ int libxl_##rw##_exactly(libxl_ctx *ctx, int fd, \
Re: [PATCH V7 2/7] libxl_read_file_contents: add new entry to read sysfs file
In reply to Chunyan LiuQuoted 10 lines · Chunyan Liu
Sysfs file has size=4096 but actual file content is less than that. Current
libxl_read_file_contentswill treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.Add a new entry
libxl_read_sysfs_file_contentsto handle sysfs file specially. It would be used in later pvusb work.Signed-off-by Chunyan Liu <[email protected]>Reviewed-by Wei Liu <[email protected]>
I'm afraid I have one issue with this patch, sorry.
Review void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, · line 4019
Quoted 6 lines
(quoted diff) +2
-0@@ -4015,6 +4015,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, int libxl__count_physical_sockets(libxl__gc *gc, int *sockets); #endif +_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename, + void **data_r, int *datalen_r);
As an internal function this should be called libxl__foo (double underscore) and take a libxl__gc *gc not libxl_ctx *ctx.
This will require some other subtle adjustments which I'll outline below.
tools/libxl/libxl_utils.c +0 -0
tools/libxl/libxl_utils.c out: · line 325
Quoted 10 lines
index bfc9699..72f8f4f 100644
tools/libxl/libxl_utils.c +1
-2@@ -322,8 +322,10 @@ out:return rc; } -int libxl_read_file_contents (libxl_ctx *ctx,const char *filename, -void **data_r,int *datalen_r) { +static int libxl_read_file_contents_core(libxl_ctx *ctx, const char *filename,
Being static this can now get a shorter name. Perhaps just read_file_contents_core (or even drop the _core). It should also take a gc instead of a ctx, since it will be used by both internal and external facing wrappers.
tools/libxl/libxl_utils.c out: · line 329
Quoted 4 lines
tools/libxl/libxl_utils.c +3
-0+ void **data_r, int *datalen_r, + bool tolerate_shrinking_file) +{GC_INIT (ctx );
Having changed the function to take a gc you will instead want to do this GC_INIT(ctx) in the libxl_read_file_contents public interface wrapper, which will then give you the gc to pass here.
You will likewise need to do the GC_FREE in that wrapper too instead of here.
@@ -396,6 +413,19 @@ int libxl_read_file_contents(libxl_ctx *ctx, const
Quoted 9 lines
tools/libxl/libxl_utils.c +0
-0char *filename, return e;}
tools/libxl/libxl_utils.c +4
-0+int libxl_read_file_contents (libxl_ctx *ctx,const char *filename, +void **data_r,int *datalen_r) +{ + return libxl_read_file_contents_core(ctx, filename, data_r,
datalen_r, 0);
As above this will need the GC_INIT and GC_FREE stuff doing here.
libxl_cpupool_info() looks like a good template to follow.
Quoted 7 lines
tools/libxl/libxl_utils.c +6
-0+} + +int libxl_read_sysfs_file_contents (libxl_ctx *ctx,const char *filename, +void **data_r,int *datalen_r) +{ + return libxl_read_file_contents_core(ctx, filename, data_r,
datalen_r, 1);
While this should take a gc and can just pass it on.
Ian.
PATCH v7 3/7 libxl: add pvusb API
In reply to Chunyan LiuAdd pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controllers and usb devices
- get information of usb controller and usb device
- some other helper functions
---
changes:
- Update hostbus/hostaddr/idVendor/idProduct types in libxl_types.idl
- Add PV/DEVICEMODEL check in libxl API, take George's HVM patch series for reference.
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 53 ++ tools/libxl/libxl.h | 78 ++ tools/libxl/libxl_device.c | 4 + tools/libxl/libxl_internal.h | 20 +- tools/libxl/libxl_osdeps.h | 13 + tools/libxl/libxl_pvusb.c | 1422 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 57 ++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.c | 16 + tools/libxl/libxl_utils.h | 5 + 11 files changed, 1669 insertions(+), 2 deletions(-) create mode 100644 tools/libxl/libxl_pvusb.c
tools/libxl/Makefile +1 -1
@@ -103,7 +103,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_stream_read.o libxl_stream_write.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ libxl_qmp.o libxl_event.o libxl_fork.o \ - libxl_dom_suspend.o $(LIBXL_OBJS-y) + libxl_dom_suspend.o libxl_pvusb.o $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl.c +53 -0
76 lines not on this page · raw message
tools/libxl/libxl.h +78 -0
90 lines not on this page · raw message
tools/libxl/libxl_device.c +4 -0
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; aodev->dev = dev; aodev->force = drs->force; +if (dev->backend_kind ==LIBXL__DEVICE_KIND_VUSB ) { +libxl__initiate_device_usbctrl_remove (egc, aodev); +continue ; + }libxl__initiate_device_remove (egc, aodev); } }
tools/libxl/libxl_internal.h +19 -1
@@ -2565,6 +2565,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, libxl_device_vtpm *vtpm, libxl__ao_device *aodev); +_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl__ao_device *aodev); + +_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, +libxl_device_usb *usb, +libxl__ao_device *aodev); +/* Internal function to connect a vkb device */ _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,libxl_device_vkb *vkb);
@@ -2597,6 +2605,13 @@ _hidden void libxl__wait_device_connection(libxl__egc*, _hidden void libxl__initiate_device_remove(libxl__egc *egc,libxl__ao_device *aodev); +_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl__device *device); + +_hidden void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, +libxl__ao_device *aodev); +/* * libxl__get_hotplug_script_info returns the args and env that should * be passed to the hotplug script for the requested device.
@@ -3951,7 +3966,10 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,#define COMPARE_PCI (a, b) ((a)->func == (b)->func && \ (a)->bus == (b)->bus && \ (a)->dev == (b)->dev) - +#define COMPARE_USB (a, b) ((a)->u.hostdev.hostbus == (b)->u.hostdev.hostbus && \ + (a)->u.hostdev.hostaddr == (b)->u.hostdev.hostaddr) +#define COMPARE_USBCTRL (a, b) ((a)->devid == (b)->devid) +/* DEVICE_ADD * * Add a device in libxl_domain_config structure
tools/libxl/libxl_osdeps.h +13 -0
@@ -24,6 +24,8 @@#define _GNU_SOURCE#if defined(__NetBSD__) +#define SYSFS_USB_DEV "/sys/bus/usb/devices" +#define SYSFS_USBBACK_DRIVER "/kern/xen/usb"#define SYSFS_PCI_DEV "/sys/bus/pci/devices"#define SYSFS_PCIBACK_DRIVER "/kern/xen/pci"#define NETBACK_NIC_NAME "xvif%ui%d"
@@ -31,6 +33,8 @@#elif defined(__OpenBSD__)#include <util.h> #elif defined(__linux__) +#define SYSFS_USB_DEV "/sys/bus/usb/devices" +#define SYSFS_USBBACK_DRIVER "/sys/bus/usb/drivers/usbback"#define SYSFS_PCI_DEV "/sys/bus/pci/devices"#define SYSFS_PCIBACK_DRIVER "/sys/bus/pci/drivers/pciback"#define NETBACK_NIC_NAME "vif%u.%d"
@@ -38,6 +42,8 @@#elif defined(__sun__)#include <stropts.h> #elif defined(__FreeBSD__) +#define SYSFS_USB_DEV "/dev/null" +#define SYSFS_USBBACK_DRIVER "/dev/null"#define SYSFS_PCI_DEV "/dev/null"#define SYSFS_PCIBACK_DRIVER "/dev/null"#define NETBACK_NIC_NAME "xnb%u.%d"
@@ -45,6 +51,13 @@#include <sys/endian.h> #endif +#ifndef SYSFS_USBBACK_DRIVER +#error define SYSFS_USBBACK_DRIVER for your platform +#endif +#ifndef SYSFS_USB_DEV +#error define SYSFS_USB_DEV for your platform +#endif +#ifndef SYSFS_PCIBACK_DRIVER #error define SYSFS_PCIBACK_DRIVER for your platform#endif
tools/libxl/libxl_pvusb.c new file +1422 -0
1,422 lines not on this page · raw message
tools/libxl/libxl_types.idl +57 -0
75 lines not on this page · raw message
tools/libxl/libxl_types_internal.idl +1 -0
@@ -22,6 +22,7 @@ libxl__device_kind = Enumeration("device_kind", [ (6, "VKBD"), (7, "CONSOLE"), (8, "VTPM"), + (9, "VUSB"), ]) libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_utils.c +16 -0
@@ -1242,6 +1242,22 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len)return ret; } +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); +} +/* * Local variables: * mode: C
tools/libxl/libxl_utils.h +5 -0
@@ -76,6 +76,11 @@ int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, libxl_uuid *uuid, libxl_device_vtpm *vtpm);int libxl_devid_to_device_vtpm (libxl_ctx *ctx,uint32_t domid,int devid,libxl_device_vtpm *vtpm); +int libxl_devid_to_device_usbctrl (libxl_ctx *ctx,uint32_t domid, +int devid,libxl_device_usbctrl *usbctrl); +int libxl_ctrlport_to_device_usb (libxl_ctx *ctx,uint32_t domid, +int ctrl,int port, +libxl_device_usb *usb);int libxl_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *bitmap,int n_bits);/* Allocated bimap is from malloc, libxl_bitmap_dispose() to be
Signature · 1 line
2.1.4
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 9 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controllers and usb devices
- get information of usb controller and usb device
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>
Hey Chunyan! This looks pretty close to being ready to check in to me.
There are four basic comments I have. I'm keen to get this series in so that we can start doing more collaborative improvement; so I'll give my comments, and then talk about timing and a plan to get this in as quikcly as possible at the bottom.
Quoted 25 lines
tools/libxl/libxl.c +17
-0@@ -4192,11 +4192,54 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)/******************************************************************************/ +/* Macro for defining device remove/destroy functions for usbctrl */ +/* Following functions are defined: +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy +*/ + +#define DEFINE_DEVICE_REMOVE_EXT (type, removedestroy, f) \ + int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ + uint32_t domid, libxl_device_##type *type, \ + const libxl_asyncop_how *ao_how) \ + { \ + AO_CREATE(ctx, domid, ao_how); \ + libxl__device *device; \ + libxl__ao_device *aodev; \ + int rc; \ + \ + GCNEW(device); \
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) · line 4221
Quoted 10 lines
tools/libxl/libxl.c +10
-0+ rc = libxl__device_from_##type(gc, domid, type, device); \ + if (rc != 0) goto out; \ + \ + GCNEW(aodev); \ + libxl__prepare_ao_device(ao, aodev); \ + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ + aodev->dev = device; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->force = f; \ + libxl__initiate_device_##type##_remove(egc, aodev); \
So this seems to be exactly the same as DEFINE_DEVICE_REMOVE(), except that you call libxl__initiate_device_usbctrl_remove() here rather than libxl__initiate_device_remove().
It seems like it might be better to have a separate patch renaming libxl__initiate_device_remove to libxl__initiate_device_generic_remove (or something like that), and then add a parameter to the definition above making it so that the definitions above pass in "generic".
tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 683
Quoted 13 lines
tools/libxl/libxl_device.c +4
-0@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; aodev->dev = dev; aodev->force = drs->force; +if (dev->backend_kind ==LIBXL__DEVICE_KIND_VUSB ) { +libxl__initiate_device_usbctrl_remove (egc, aodev); +continue ; + }libxl__initiate_device_remove (egc, aodev);
I think this would probably be more clear if you did:
if(dev->backend_kind == LIBXL__DEVICE_KIND_VUSB)
libxl__initiate_device_usbctl_remove()
else
libxl__initiate_device_remove()
tools/libxl/libxl_device.c static inline void libxl__update_config_vtpm(libxl__gc *gc, · line 3970
Quoted 7 lines
tools/libxl/libxl_device.c +2
-1@@ -3951,7 +3966,10 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,#define COMPARE_PCI (a, b) ((a)->func == (b)->func && \ (a)->bus == (b)->bus && \ (a)->dev == (b)->dev) - +#define COMPARE_USB (a, b) ((a)->u.hostdev.hostbus == (b)->u.hostdev.hostbus && \ + (a)->u.hostdev.hostaddr == (b)->u.hostdev.hostaddr)
Hmm... COMPARE_USB is used in three places:
1. Used in libxl.c:libxl_retrieve_domain_configuration() to de-duplicate JSON and xenstore configuration
2. Used in libxl_pvusb.c:libxl__device_usb_add_xentore() to avoid adding the same device twice
3. Used in libxl_pvusb.c:is_usbdev_in_array() to avoid assigning the same host device
For #3, we pretty clearly want to be comparing hostbus/hostaddr. (In fact, you didn't use the COMPARE_USB macro until I suggested it in v3.)
But for #1 and #2, is that what we want? Should we be comparing <ctrl,port> instead?
In fact, after thinking about pvusb backends more, I think I want to assert that we do want to compare <ctrl,port> instead: <crtl,port> is guaranteed to be unique for a domain, but it's entirely possible to have two different devices, from two different backend domains, with the same bus.addr.
Quoted 6 lines
tools/libxl/libxl_device.c +6
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx);
tools/libxl/libxl_device.c static inline void libxl__update_config_vtpm(libxl__gc *gc,
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &nb); +if (!nb) goto out; + +for (i =0 ; i < nb; i++) { +if (devid == usbctrls[i].devid) { + *usbctrl = usbctrls[i];
libxl maintainers: Is this kind of copying OK?
The analog functions for vtpm and nic both take very different approaches; both call libxl_device_[type]_init() and then fill in individual elements (albeit in different ways).
Quoted 18 lines
tools/libxl/libxl_device.c +18
-0+/* +* USB add +*/ +static int do_usb_add (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usbdev, +libxl__ao_device *aodev) +{ +libxl_ctx *ctx =CTX ; +libxl_usbctrlinfo usbctrlinfo; +libxl_device_usbctrl usbctrl; +int rc; + +libxl_usbctrlinfo_init (&usbctrlinfo); + usbctrl.devid = usbdev->ctrl; + rc =libxl_device_usbctrl_getinfo (ctx, domid, &usbctrl, &usbctrlinfo); +if (rc) + goto out; +
tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+switch (usbctrlinfo.type) { +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : +LOG (ERROR ,"Not supported" ); +break ; +case LIBXL_USBCTRL_TYPE_PV : + rc =libxl__device_usb_add_xenstore (gc, domid, usbdev, + aodev->update_json); +if (rc) goto out; + + rc =usbback_dev_assign (gc, usbdev);
This assumes that the usb controller is dom0; but the interface explicitly allows pvusb driver domains.
I think it would be enough here to do this check if the usbctrl device is dom0. We should then assume that a pvusb driver domain will be configured with all usb devices assigned to usbback already.
I assume that there's a feedback mechanisms for backends for situations where the requested device can't be made, right? For example, if you have a network driver domain and request a non-existent bridge? If so, I think we can let the same mechanism worth for pvusb backends to say "I don't have that device available".
Quoted 41 lines
tools/libxl/libxl_device.c +41
-0+if (rc) { +libxl__device_usb_remove_xenstore (gc, domid, usbdev); + goto out; + } +break ; +default : + rc =ERROR_FAIL ; + goto out; + } + +out: +libxl_usbctrlinfo_dispose (&usbctrlinfo); +return rc; +} + +/* AO operation to add a usb device. +* +* Generally, it does: +* 1) check if the usb device type is assignable +* 2) check if the usb device is already assigned to a domain +* 3) add 'busid' of the usb device to xenstore contoller/port/. +* (PVUSB driver watches the xenstore changes and will detect that.) +* 4) unbind usb device from original driver and bind to usbback. +* If usb device has many interfaces, then: +* - unbind each interface from its original driver and bind to usbback. +* - store the original driver to xenstore for later rebinding when +* detaching the device. +*/ +void libxl__device_usb_add (libxl__egc *egc,uint32_t domid, +libxl_device_usb *usb, +libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +int rc =ERROR_FAIL ; +char *busid =NULL ; +libxl_device_usb *assigned; +int num_assigned; + +assert (usb->u.hostdev.hostbus >0 && usb->u.hostdev.hostaddr >0 ); + + busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,
tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ usb->u.hostdev.hostaddr); +if (!busid) { +LOG (ERROR ,"USB device doesn't exist in sysfs" ); + goto out; + } + +if (!is_usb_assignable (gc, usb)) { +LOG (ERROR ,"USB device is not assignable." ); + goto out; + }
Similar issue with pvusb driver domains: we can't do this check for driver domains.
I wonder if we should do this check instead down on the usbback_assign_path().
If we assume that for pvusb driver domains:
1. All assignable devices will be assigned to usbback
2. No controllers will be assigned (since they can't be)
3. pvusb can say "no such device" for unassigned devices then we can safely ignore the check for pvusb driver domains
Quoted 4 lines
tools/libxl/libxl_device.c +4
-0+ +/* check usb device is already assigned */ + rc =get_assigned_devices (gc, &assigned, &num_assigned); +if (rc) {
tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+LOG (ERROR ,"cannot determine if device is assigned," +" refusing to continue" ); + goto out; + } + +if (is_usbdev_in_array (assigned, num_assigned, usb)) { +LOG (ERROR ,"USB device already attached to a domain" ); + rc =ERROR_FAIL ; + goto out; + }
WRT driver domains: Since we're looking inside xenstore instead of sysfs, we *can* actually do these checks.
However, the "bus.addr" space is defined by the driver domain kernel, and is not unique across all driver domains: If we have one usb controller assigned to domain 0, and another assigned to a driver domain, two distinct devices are likely to end up with the same bus.addr.
So to be compatible with driver domains, we'd need to have get_assigned_devices() only get devices with the same backend_domid as the controller we're checking.
Quoted 8 lines
tools/libxl/libxl_device.c +8
-0+int libxl_device_usb_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx); +char *filename; +char *busid; +void *buf =NULL ;
tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+int buflen, rc; + + usbinfo->ctrl = usb->ctrl; + usbinfo->port = usb->port; + +if (libxl_ctrlport_to_device_usb (ctx, domid, + usb->ctrl, usb->port, usb) <0 ) { + rc =ERROR_FAIL ; + goto out; + }
I suppose technically since usb isn't declared const that we haven't promised to modify it; but none of the other device_*_getinfo() functions modify the device struct; I think it would be better to follow suit and use a local variable to get the information from.
However...
Quoted 26 lines
tools/libxl/libxl_device.c +26
-0+ + usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf);
tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }
Basically, starting here, we have information which won't be available if we're using a pvusb driver domain.
This information is nice-to-have, but I don't think this information is directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined to say that if we want to have pvusb driver domains (and I think we do), we should just get rid of this information.
Quoted 68 lines
tools/libxl/libxl_types.idl +46
-0@@ -595,6 +595,35 @@ libxl_device_rdm = Struct("device_rdm", [ ("policy", libxl_rdm_reserve_policy), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type", [ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usbdev_type = Enumeration("usbdev_type", [ + (1, "hostdev"), + ]) + +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", libxl_devid), + ("port", integer), + ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", + [("hostdev", Struct(None, [ + ("hostbus", uint8), + ("hostaddr", uint8)])), + ])), + ]) + libxl_device_dtdev = Struct("device_dtdev", [ ("path", string), ])@@ -627,6 +656,8 @@ libxl_domain_config = Struct("domain_config", [ ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), ("rdms", Array(libxl_device_rdm, "num_rdms")), ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), + ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")), + ("usbs", Array(libxl_device_usb, "num_usbs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),@@ -676,6 +707,32 @@ libxl_vtpminfo = Struct("vtpminfo", [ ("uuid", libxl_uuid), ], dir=DIR_OUT) +libxl_usbctrlinfo = Struct("usbctrlinfo", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("state", integer), + ("evtch", integer), + ("ref_urb", integer), + ("ref_conn", integer), + ], dir=DIR_OUT) +
tools/libxl/libxl_types.idl libxl_vtpminfo = Struct("vtpminfo", [ · line 734
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_usbinfo = Struct("usbinfo", [ + ("ctrl", libxl_devid), + ("port", integer), + ("busnum", uint8), + ("devnum", uint8), + ("idVendor", uint16), + ("idProduct", uint16), + ("prod", string), + ("manuf", string), + ], dir=DIR_OUT)
With the exception of the stuff in libxl_usbinfo we can't get if the backend isn't dom0, the interface looks good to me now.
OK, so I've covered four things:
1. The DEFINE_DEVICE_REMOVE_EXT macro. I think I'd prefer checking in things are as it is, and then have a follow-up patch to refactor everything into a single DEFINE_DEVICE_REMOVE macro as described above.
2. COMPARE_USB. I think this needs to be fixed; but this should be a fairly simple change.
3. The conditional in libxl__device_destroy, the struct copy in libxl_devid_to_device_usbctrl, and the modification of the device in libxl_device_usb_getinfo are minor adjustments that can be discussed and fixed.
4. The pvusb driver domain != dom0 comments. This is somewhat secondary to your primary goal; but at the moment the code will certainly not work. We have a couple of options:
a: Wait until we've fixed the driver domain functionality
b: Check the code in right now, with the driver domain fuctionality explicitly disabled; that is, it will return an error if backend_domain!=0. Get a promise to implement the driver domain functionality properly for 4.7 (on the threat of removing the feature).
c: Take driver domain support out of the interface for now; send follow-up patches to implement it properly.
d. Take driver domain support out of the interface and leave it that way, for simplicity.
I'd probably go with b or c.
Thoughts?
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 19 lines · George Dunlap
Quoted 6 lines
tools/libxl/libxl_pvusb.c new file +6
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx);tools/libxl/libxl_pvusb.c line 421
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &nb); +if (!nb) goto out; + +for (i =0 ; i < nb; i++) { +if (devid == usbctrls[i].devid) { + *usbctrl = usbctrls[i];libxl maintainers: Is this kind of copying OK?
Quoted 3 lines
The analog functions for vtpm and nic both take very different approaches; both call libxl_device_[type]_init() and then fill in individual elements (albeit in different ways).
That depends on the memory lifecycle situation of usbctrls[i] and *usbctrl vis-a-vis the gc and when they are frred.
Cut out of the context here is a
+ libxl_device_usbctrl_list_free(usbctrls, nb);
which is going to free any of the pointers in usbctrls[i] which have been copied to usbctrl. So in this case no it is not ok.
You can't avoid the libxl_device_usbctrl_list_free, since you don't want to leak all the other elements on the list, so copying seems to be the way to go.
The IDL should have generated a copy function which can be used (by the vtpm one too, but it predates the IDL making such things I think).
Quoted 38 lines
Quoted 20 lines
tools/libxl/libxl_pvusb.c new file +15
-0+/* +* USB add +*/ +static int do_usb_add (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usbdev, +libxl__ao_device *aodev) +{ +libxl_ctx *ctx =CTX ; +libxl_usbctrlinfo usbctrlinfo; +libxl_device_usbctrl usbctrl; +int rc; + +libxl_usbctrlinfo_init (&usbctrlinfo); + usbctrl.devid = usbdev->ctrl; + rc = libxl_device_usbctrl_getinfo(ctx, domid, &usbctrl,&usbctrlinfo);
tools/libxl/libxl_pvusb.c new file +3
-0+if (rc) + goto out; +tools/libxl/libxl_pvusb.c line 1159
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+switch (usbctrlinfo.type) { +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : +LOG (ERROR ,"Not supported" ); +break ; +case LIBXL_USBCTRL_TYPE_PV : + rc =libxl__device_usb_add_xenstore (gc, domid, usbdev, + aodev->update_json); +if (rc) goto out; + + rc =usbback_dev_assign (gc, usbdev);This assumes that the usb controller is dom0; but the interface explicitly allows pvusb driver domains.
I think it would be enough here to do this check if the usbctrl device is dom0. We should then assume that a pvusb driver domain will be configured with all usb devices assigned to usbback already.
Quoted 5 lines
I assume that there's a feedback mechanisms for backends for situations where the requested device can't be made, right? For example, if you have a network driver domain and request a non-existent bridge? If so, I think we can let the same mechanism worth for pvusb backends to say "I don't have that device available".
I think the b/e writes an error node in xenstore, which we already pickup iirc.
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to George DunlapQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 10/1/2015 at 01:55 AM, in message <[email protected]>, George
Quoted 111 lines · Dunlap
Quoted 9 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controllers and usb devices
- get information of usb controller and usb device
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Hey Chunyan! This looks pretty close to being ready to check in to me.
There are four basic comments I have. I'm keen to get this series in so that we can start doing more collaborative improvement; so I'll give my comments, and then talk about timing and a plan to get this in as quikcly as possible at the bottom.
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) · line 4193
Quoted 7 lines
tools/libxl/libxl.c +0
-0@@ -4192,11 +4192,54 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)/**************************************************************************** **/
Quoted 18 lines
tools/libxl/libxl.c +17
-0+/* Macro for defining device remove/destroy functions for usbctrl */ +/* Following functions are defined: +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy +*/ + +#define DEFINE_DEVICE_REMOVE_EXT (type, removedestroy, f) \ + int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ + uint32_t domid, libxl_device_##type *type, \ + const libxl_asyncop_how *ao_how) \ + { \ + AO_CREATE(ctx, domid, ao_how); \ + libxl__device *device; \ + libxl__ao_device *aodev; \ + int rc; \ + \ + GCNEW(device); \tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) · line 4221
Quoted 10 lines
tools/libxl/libxl.c +10
-0+ rc = libxl__device_from_##type(gc, domid, type, device); \ + if (rc != 0) goto out; \ + \ + GCNEW(aodev); \ + libxl__prepare_ao_device(ao, aodev); \ + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ + aodev->dev = device; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->force = f; \ + libxl__initiate_device_##type##_remove(egc, aodev); \So this seems to be exactly the same as
DEFINE_DEVICE_REMOVE(), except that you calllibxl__initiate_device_usbctrl_remove()here rather thanlibxl__initiate_device_remove().It seems like it might be better to have a separate patch renaming
libxl__initiate_device_removetolibxl__initiate_device_generic_remove(or something like that), and then add a parameter to the definition above making it so that the definitions above pass in "generic".tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,
Quoted 5 lines
tools/libxl/libxl_device.c +0
-0@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,
libxl__devices_remove_state*drs)tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 683
Quoted 8 lines
tools/libxl/libxl_device.c +4
-0aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; aodev->dev = dev; aodev->force = drs->force; +if (dev->backend_kind ==LIBXL__DEVICE_KIND_VUSB ) { +libxl__initiate_device_usbctrl_remove (egc, aodev); +continue ; + }libxl__initiate_device_remove (egc, aodev);I think this would probably be more clear if you did:
if(dev->backend_kind == LIBXL__DEVICE_KIND_VUSB)
libxl__initiate_device_usbctl_remove()
else
libxl__initiate_device_remove()tools/libxl/libxl_device.c static inline void
Quoted 1 line
tools/libxl/libxl_device.c +0
-0@@ -3951,7 +3966,10 @@ static inline voidlibxl__update_config_vtpm(libxl__gc *gc,
tools/libxl/libxl_device.c static inline void · line 3970
Quoted 6 lines
tools/libxl/libxl_device.c +2
-1#define COMPARE_PCI (a, b) ((a)->func == (b)->func && \ (a)->bus == (b)->bus && \ (a)->dev == (b)->dev) - +#define COMPARE_USB (a, b) ((a)->u.hostdev.hostbus == (b)->u.hostdev.hostbus && \ + (a)->u.hostdev.hostaddr == (b)->u.hostdev.hostaddr)Hmm...
COMPARE_USBis used in three places:1. Used in libxl.c:libxl_retrieve_domain_configuration() to de-duplicate JSON and xenstore configuration
2. Used in libxl_pvusb.c:libxl__device_usb_add_xentore() to avoid adding the same device twice
3. Used in libxl_pvusb.c:is_usbdev_in_array() to avoid assigning the same host device
For #3, we pretty clearly want to be comparing hostbus/hostaddr. (In fact, you didn't use the
COMPARE_USBmacro until I suggested it in v3.)
Quoted 8 lines
But for #1 and #2, is that what we want? Should we be comparing <ctrl,port> instead?
In fact, after thinking about pvusb backends more, I think I want to assert that we do want to compare <ctrl,port> instead: <crtl,port> is guaranteed to be unique for a domain, but it's entirely possible to have two different devices, from two different backend domains, with the same bus.addr.
Considering usb driver domain, <bus.addr> does have problem. I agree it should compare <ctrl, port>, I'll update the MACRO.
For #3, I won't use COMAPRE_USB macro then but extend codes to compare bus.addr directly.
Quoted 20 lines
Quoted 7 lines
tools/libxl/libxl_device.c +6
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx);tools/libxl/libxl_device.c static inline void
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &nb); +if (!nb) goto out; + +for (i =0 ; i < nb; i++) { +if (devid == usbctrls[i].devid) { + *usbctrl = usbctrls[i];libxl maintainers: Is this kind of copying OK?
Quoted 3 lines
The analog functions for vtpm and nic both take very different approaches; both call libxl_device_[type]_init() and then fill in individual elements (albeit in different ways).
As Ian replied, it depends on the free time. To be strict, since we have libxl_device_usbctrl_list_free() soon
later, it is not OK. But since in libxl_device_usbctrl struct, except for backend_domname, all others are int type, since backend_domname won't be called in later work, so it won't be affected after libxl_device_usbctrl_list_freei.
Anyway, I'll update to follow vtpm and nic ways to copy individule elements.
- Chunyan
~
Quoted 322 lines
Quoted 19 lines
tools/libxl/libxl_device.c +18
-0+/* +* USB add +*/ +static int do_usb_add (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usbdev, +libxl__ao_device *aodev) +{ +libxl_ctx *ctx =CTX ; +libxl_usbctrlinfo usbctrlinfo; +libxl_device_usbctrl usbctrl; +int rc; + +libxl_usbctrlinfo_init (&usbctrlinfo); + usbctrl.devid = usbdev->ctrl; + rc =libxl_device_usbctrl_getinfo (ctx, domid, &usbctrl, &usbctrlinfo); +if (rc) + goto out; +tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+switch (usbctrlinfo.type) { +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : +LOG (ERROR ,"Not supported" ); +break ; +case LIBXL_USBCTRL_TYPE_PV : + rc =libxl__device_usb_add_xenstore (gc, domid, usbdev, + aodev->update_json); +if (rc) goto out; + + rc =usbback_dev_assign (gc, usbdev);This assumes that the usb controller is dom0; but the interface explicitly allows pvusb driver domains.
I think it would be enough here to do this check if the usbctrl device is dom0. We should then assume that a pvusb driver domain will be configured with all usb devices assigned to usbback already.
I assume that there's a feedback mechanisms for backends for situations where the requested device can't be made, right? For example, if you have a network driver domain and request a non-existent bridge? If so, I think we can let the same mechanism worth for pvusb backends to say "I don't have that device available".
Quoted 41 lines
tools/libxl/libxl_device.c +41
-0+if (rc) { +libxl__device_usb_remove_xenstore (gc, domid, usbdev); + goto out; + } +break ; +default : + rc =ERROR_FAIL ; + goto out; + } + +out: +libxl_usbctrlinfo_dispose (&usbctrlinfo); +return rc; +} + +/* AO operation to add a usb device. +* +* Generally, it does: +* 1) check if the usb device type is assignable +* 2) check if the usb device is already assigned to a domain +* 3) add 'busid' of the usb device to xenstore contoller/port/. +* (PVUSB driver watches the xenstore changes and will detect that.) +* 4) unbind usb device from original driver and bind to usbback. +* If usb device has many interfaces, then: +* - unbind each interface from its original driver and bind to usbback. +* - store the original driver to xenstore for later rebinding when +* detaching the device. +*/ +void libxl__device_usb_add (libxl__egc *egc,uint32_t domid, +libxl_device_usb *usb, +libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +int rc =ERROR_FAIL ; +char *busid =NULL ; +libxl_device_usb *assigned; +int num_assigned; + +assert (usb->u.hostdev.hostbus >0 && usb->u.hostdev.hostaddr >0 ); + + busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ usb->u.hostdev.hostaddr); +if (!busid) { +LOG (ERROR ,"USB device doesn't exist in sysfs" ); + goto out; + } + +if (!is_usb_assignable (gc, usb)) { +LOG (ERROR ,"USB device is not assignable." ); + goto out; + }Similar issue with pvusb driver domains: we can't do this check for driver domains.
I wonder if we should do this check instead down on the
usbback_assign_path().If we assume that for pvusb driver domains:
1. All assignable devices will be assigned to usbback
2. No controllers will be assigned (since they can't be)
3. pvusb can say "no such device" for unassigned devices then we can safely ignore the check for pvusb driver domainsQuoted 4 lines
+
tools/libxl/libxl_device.c +3
-0+/* check usb device is already assigned */ + rc =get_assigned_devices (gc, &assigned, &num_assigned); +if (rc) {tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+LOG (ERROR ,"cannot determine if device is assigned," +" refusing to continue" ); + goto out; + } + +if (is_usbdev_in_array (assigned, num_assigned, usb)) { +LOG (ERROR ,"USB device already attached to a domain" ); + rc =ERROR_FAIL ; + goto out; + }WRT driver domains: Since we're looking inside xenstore instead of sysfs, we *can* actually do these checks.
However, the "bus.addr" space is defined by the driver domain kernel, and is not unique across all driver domains: If we have one usb controller assigned to domain 0, and another assigned to a driver domain, two distinct devices are likely to end up with the same bus.addr.
So to be compatible with driver domains, we'd need to have
get_assigned_devices()only get devices with the samebackend_domidas the controller we're checking.Quoted 8 lines
tools/libxl/libxl_device.c +8
-0+int libxl_device_usb_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx); +char *filename; +char *busid; +void *buf =NULL ;tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+int buflen, rc; + + usbinfo->ctrl = usb->ctrl; + usbinfo->port = usb->port; + +if (libxl_ctrlport_to_device_usb (ctx, domid, + usb->ctrl, usb->port, usb) <0 ) { + rc =ERROR_FAIL ; + goto out; + }I suppose technically since usb isn't declared const that we haven't promised to modify it; but none of the other device_*_getinfo() functions modify the device struct; I think it would be better to follow suit and use a local variable to get the information from.
However...
Quoted 26 lines
+
tools/libxl/libxl_device.c +25
-0+ usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf);tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Basically, starting here, we have information which won't be available if we're using a pvusb driver domain.
This information is nice-to-have, but I don't think this information is directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined to say that if we want to have pvusb driver domains (and I think we do), we should just get rid of this information.
Quoted 68 lines
tools/libxl/libxl_types.idl +46
-0@@ -595,6 +595,35 @@ libxl_device_rdm = Struct("device_rdm", [ ("policy", libxl_rdm_reserve_policy), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type", [ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usbdev_type = Enumeration("usbdev_type", [ + (1, "hostdev"), + ]) + +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", libxl_devid), + ("port", integer), + ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", + [("hostdev", Struct(None, [ + ("hostbus", uint8), + ("hostaddr", uint8)])), + ])), + ]) + libxl_device_dtdev = Struct("device_dtdev", [ ("path", string), ])@@ -627,6 +656,8 @@ libxl_domain_config = Struct("domain_config", [ ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), ("rdms", Array(libxl_device_rdm, "num_rdms")), ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), + ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")), + ("usbs", Array(libxl_device_usb, "num_usbs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),@@ -676,6 +707,32 @@ libxl_vtpminfo = Struct("vtpminfo", [ ("uuid", libxl_uuid), ], dir=DIR_OUT) +libxl_usbctrlinfo = Struct("usbctrlinfo", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("state", integer), + ("evtch", integer), + ("ref_urb", integer), + ("ref_conn", integer), + ], dir=DIR_OUT) +tools/libxl/libxl_types.idl libxl_vtpminfo = Struct("vtpminfo", [ · line 734
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_usbinfo = Struct("usbinfo", [ + ("ctrl", libxl_devid), + ("port", integer), + ("busnum", uint8), + ("devnum", uint8), + ("idVendor", uint16), + ("idProduct", uint16), + ("prod", string), + ("manuf", string), + ], dir=DIR_OUT)With the exception of the stuff in
libxl_usbinfowe can't get if the backend isn't dom0, the interface looks good to me now.OK, so I've covered four things:
1. The
DEFINE_DEVICE_REMOVE_EXTmacro. I think I'd prefer checking in things are as it is, and then have a follow-up patch to refactor everything into a singleDEFINE_DEVICE_REMOVEmacro as described above.2.
COMPARE_USB. I think this needs to be fixed; but this should be a fairly simple change.3. The conditional in
libxl__device_destroy, the struct copy inlibxl_devid_to_device_usbctrl, and the modification of the device inlibxl_device_usb_getinfoare minor adjustments that can be discussed and fixed.4. The pvusb driver domain != dom0 comments. This is somewhat secondary to your primary goal; but at the moment the code will certainly not work. We have a couple of options:
a: Wait until we've fixed the driver domain functionality
b: Check the code in right now, with the driver domain fuctionality explicitly disabled; that is, it will return an error if backend_domain!=0. Get a promise to implement the driver domain functionality properly for 4.7 (on the threat of removing the feature).
c: Take driver domain support out of the interface for now; send follow-up patches to implement it properly.
d. Take driver domain support out of the interface and leave it that way, for simplicity.I'd probably go with b or c.
Thoughts?
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to George DunlapQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 10/1/2015 at 01:55 AM, in message <[email protected]>, George
Quoted 291 lines · Dunlap
Quoted 9 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controllers and usb devices
- get information of usb controller and usb device
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Hey Chunyan! This looks pretty close to being ready to check in to me.
There are four basic comments I have. I'm keen to get this series in so that we can start doing more collaborative improvement; so I'll give my comments, and then talk about timing and a plan to get this in as quikcly as possible at the bottom.
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) · line 4193
Quoted 7 lines
tools/libxl/libxl.c +0
-0@@ -4192,11 +4192,54 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)/**************************************************************************** **/
Quoted 18 lines
tools/libxl/libxl.c +17
-0+/* Macro for defining device remove/destroy functions for usbctrl */ +/* Following functions are defined: +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy +*/ + +#define DEFINE_DEVICE_REMOVE_EXT (type, removedestroy, f) \ + int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ + uint32_t domid, libxl_device_##type *type, \ + const libxl_asyncop_how *ao_how) \ + { \ + AO_CREATE(ctx, domid, ao_how); \ + libxl__device *device; \ + libxl__ao_device *aodev; \ + int rc; \ + \ + GCNEW(device); \tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) · line 4221
Quoted 10 lines
tools/libxl/libxl.c +10
-0+ rc = libxl__device_from_##type(gc, domid, type, device); \ + if (rc != 0) goto out; \ + \ + GCNEW(aodev); \ + libxl__prepare_ao_device(ao, aodev); \ + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ + aodev->dev = device; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->force = f; \ + libxl__initiate_device_##type##_remove(egc, aodev); \So this seems to be exactly the same as
DEFINE_DEVICE_REMOVE(), except that you calllibxl__initiate_device_usbctrl_remove()here rather thanlibxl__initiate_device_remove().It seems like it might be better to have a separate patch renaming
libxl__initiate_device_removetolibxl__initiate_device_generic_remove(or something like that), and then add a parameter to the definition above making it so that the definitions above pass in "generic".tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,
Quoted 5 lines
tools/libxl/libxl_device.c +0
-0@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,
libxl__devices_remove_state*drs)tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 683
Quoted 8 lines
tools/libxl/libxl_device.c +4
-0aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; aodev->dev = dev; aodev->force = drs->force; +if (dev->backend_kind ==LIBXL__DEVICE_KIND_VUSB ) { +libxl__initiate_device_usbctrl_remove (egc, aodev); +continue ; + }libxl__initiate_device_remove (egc, aodev);I think this would probably be more clear if you did:
if(dev->backend_kind == LIBXL__DEVICE_KIND_VUSB)
libxl__initiate_device_usbctl_remove()
else
libxl__initiate_device_remove()tools/libxl/libxl_device.c static inline void
Quoted 1 line
tools/libxl/libxl_device.c +0
-0@@ -3951,7 +3966,10 @@ static inline voidlibxl__update_config_vtpm(libxl__gc *gc,
tools/libxl/libxl_device.c static inline void · line 3970
Quoted 6 lines
tools/libxl/libxl_device.c +2
-1#define COMPARE_PCI (a, b) ((a)->func == (b)->func && \ (a)->bus == (b)->bus && \ (a)->dev == (b)->dev) - +#define COMPARE_USB (a, b) ((a)->u.hostdev.hostbus == (b)->u.hostdev.hostbus && \ + (a)->u.hostdev.hostaddr == (b)->u.hostdev.hostaddr)Hmm...
COMPARE_USBis used in three places:1. Used in libxl.c:libxl_retrieve_domain_configuration() to de-duplicate JSON and xenstore configuration
2. Used in libxl_pvusb.c:libxl__device_usb_add_xentore() to avoid adding the same device twice
3. Used in libxl_pvusb.c:is_usbdev_in_array() to avoid assigning the same host device
For #3, we pretty clearly want to be comparing hostbus/hostaddr. (In fact, you didn't use the
COMPARE_USBmacro until I suggested it in v3.)But for #1 and #2, is that what we want? Should we be comparing <ctrl,port> instead?
In fact, after thinking about pvusb backends more, I think I want to assert that we do want to compare <ctrl,port> instead: <crtl,port> is guaranteed to be unique for a domain, but it's entirely possible to have two different devices, from two different backend domains, with the same bus.addr.
Quoted 6 lines
tools/libxl/libxl_device.c +6
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx);tools/libxl/libxl_device.c static inline void
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &nb); +if (!nb) goto out; + +for (i =0 ; i < nb; i++) { +if (devid == usbctrls[i].devid) { + *usbctrl = usbctrls[i];libxl maintainers: Is this kind of copying OK?
The analog functions for vtpm and nic both take very different approaches; both call libxl_device_[type]_init() and then fill in individual elements (albeit in different ways).
Quoted 18 lines
tools/libxl/libxl_device.c +18
-0+/* +* USB add +*/ +static int do_usb_add (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usbdev, +libxl__ao_device *aodev) +{ +libxl_ctx *ctx =CTX ; +libxl_usbctrlinfo usbctrlinfo; +libxl_device_usbctrl usbctrl; +int rc; + +libxl_usbctrlinfo_init (&usbctrlinfo); + usbctrl.devid = usbdev->ctrl; + rc =libxl_device_usbctrl_getinfo (ctx, domid, &usbctrl, &usbctrlinfo); +if (rc) + goto out; +tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+switch (usbctrlinfo.type) { +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : +LOG (ERROR ,"Not supported" ); +break ; +case LIBXL_USBCTRL_TYPE_PV : + rc =libxl__device_usb_add_xenstore (gc, domid, usbdev, + aodev->update_json); +if (rc) goto out; + + rc =usbback_dev_assign (gc, usbdev);This assumes that the usb controller is dom0; but the interface explicitly allows pvusb driver domains.
I think it would be enough here to do this check if the usbctrl device is dom0. We should then assume that a pvusb driver domain will be configured with all usb devices assigned to usbback already.
I assume that there's a feedback mechanisms for backends for situations where the requested device can't be made, right? For example, if you have a network driver domain and request a non-existent bridge? If so, I think we can let the same mechanism worth for pvusb backends to say "I don't have that device available".
Quoted 41 lines
tools/libxl/libxl_device.c +41
-0+if (rc) { +libxl__device_usb_remove_xenstore (gc, domid, usbdev); + goto out; + } +break ; +default : + rc =ERROR_FAIL ; + goto out; + } + +out: +libxl_usbctrlinfo_dispose (&usbctrlinfo); +return rc; +} + +/* AO operation to add a usb device. +* +* Generally, it does: +* 1) check if the usb device type is assignable +* 2) check if the usb device is already assigned to a domain +* 3) add 'busid' of the usb device to xenstore contoller/port/. +* (PVUSB driver watches the xenstore changes and will detect that.) +* 4) unbind usb device from original driver and bind to usbback. +* If usb device has many interfaces, then: +* - unbind each interface from its original driver and bind to usbback. +* - store the original driver to xenstore for later rebinding when +* detaching the device. +*/ +void libxl__device_usb_add (libxl__egc *egc,uint32_t domid, +libxl_device_usb *usb, +libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +int rc =ERROR_FAIL ; +char *busid =NULL ; +libxl_device_usb *assigned; +int num_assigned; + +assert (usb->u.hostdev.hostbus >0 && usb->u.hostdev.hostaddr >0 ); + + busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ usb->u.hostdev.hostaddr); +if (!busid) { +LOG (ERROR ,"USB device doesn't exist in sysfs" ); + goto out; + } + +if (!is_usb_assignable (gc, usb)) { +LOG (ERROR ,"USB device is not assignable." ); + goto out; + }Similar issue with pvusb driver domains: we can't do this check for driver domains.
I wonder if we should do this check instead down on the
usbback_assign_path().If we assume that for pvusb driver domains:
1. All assignable devices will be assigned to usbback
2. No controllers will be assigned (since they can't be)
3. pvusb can say "no such device" for unassigned devices then we can safely ignore the check for pvusb driver domainsQuoted 4 lines
+
tools/libxl/libxl_device.c +3
-0+/* check usb device is already assigned */ + rc =get_assigned_devices (gc, &assigned, &num_assigned); +if (rc) {tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+LOG (ERROR ,"cannot determine if device is assigned," +" refusing to continue" ); + goto out; + } + +if (is_usbdev_in_array (assigned, num_assigned, usb)) { +LOG (ERROR ,"USB device already attached to a domain" ); + rc =ERROR_FAIL ; + goto out; + }WRT driver domains: Since we're looking inside xenstore instead of sysfs, we *can* actually do these checks.
However, the "bus.addr" space is defined by the driver domain kernel, and is not unique across all driver domains: If we have one usb controller assigned to domain 0, and another assigned to a driver domain, two distinct devices are likely to end up with the same bus.addr.
So to be compatible with driver domains, we'd need to have
get_assigned_devices()only get devices with the samebackend_domidas the controller we're checking.Quoted 15 lines
tools/libxl/libxl_device.c +15
-0+int libxl_device_usb_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx); +char *filename; +char *busid; +void *buf =NULL ; +int buflen, rc; + + usbinfo->ctrl = usb->ctrl; + usbinfo->port = usb->port; + +if (libxl_ctrlport_to_device_usb (ctx, domid, + usb->ctrl, usb->port, usb) <0 ) {
Quoted 8 lines
tools/libxl/libxl_device.c
Quoted 3 lines
tools/libxl/libxl_device.c +3
-0+ rc =ERROR_FAIL ; + goto out; + }I suppose technically since usb isn't declared const that we haven't promised to modify it; but none of the other device_*_getinfo() functions modify the device struct; I think it would be better to follow suit and use a local variable to get the information from.
Take it.
Quoted 40 lines
However...
Quoted 26 lines
+
tools/libxl/libxl_device.c +25
-0+ usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf);tools/libxl/libxl_device.c
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+ } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }
Quoted 8 lines
Basically, starting here, we have information which won't be available if we're using a pvusb driver domain.
This information is nice-to-have, but I don't think this information is directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined to say that if we want to have pvusb driver domains (and I think we do), we should just get rid of this information.
For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
I think we can keep the function, since every other device type has the function XXX_getinfo. But here we could check backend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting those information. Can add code in future.)
Quoted 97 lines
Quoted 69 lines
tools/libxl/libxl_types.idl +46
-0@@ -595,6 +595,35 @@ libxl_device_rdm = Struct("device_rdm", [ ("policy", libxl_rdm_reserve_policy), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type", [ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usbdev_type = Enumeration("usbdev_type", [ + (1, "hostdev"), + ]) + +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", libxl_devid), + ("port", integer), + ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", + [("hostdev", Struct(None, [ + ("hostbus", uint8), + ("hostaddr", uint8)])), + ])), + ]) + libxl_device_dtdev = Struct("device_dtdev", [ ("path", string), ])@@ -627,6 +656,8 @@ libxl_domain_config = Struct("domain_config", [ ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), ("rdms", Array(libxl_device_rdm, "num_rdms")), ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), + ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")), + ("usbs", Array(libxl_device_usb, "num_usbs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),@@ -676,6 +707,32 @@ libxl_vtpminfo = Struct("vtpminfo", [ ("uuid", libxl_uuid), ], dir=DIR_OUT) +libxl_usbctrlinfo = Struct("usbctrlinfo", [ + ("type", libxl_usbctrl_type), + ("devid", libxl_devid), + ("version", integer), + ("ports", integer), + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("state", integer), + ("evtch", integer), + ("ref_urb", integer), + ("ref_conn", integer), + ], dir=DIR_OUT) +tools/libxl/libxl_types.idl libxl_vtpminfo = Struct("vtpminfo", [ · line 734
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_usbinfo = Struct("usbinfo", [ + ("ctrl", libxl_devid), + ("port", integer), + ("busnum", uint8), + ("devnum", uint8), + ("idVendor", uint16), + ("idProduct", uint16), + ("prod", string), + ("manuf", string), + ], dir=DIR_OUT)With the exception of the stuff in
libxl_usbinfowe can't get if the backend isn't dom0, the interface looks good to me now.OK, so I've covered four things:
1. The
DEFINE_DEVICE_REMOVE_EXTmacro. I think I'd prefer checking in things are as it is, and then have a follow-up patch to refactor everything into a singleDEFINE_DEVICE_REMOVEmacro as described above.2.
COMPARE_USB. I think this needs to be fixed; but this should be a fairly simple change.3. The conditional in
libxl__device_destroy, the struct copy inlibxl_devid_to_device_usbctrl, and the modification of the device inlibxl_device_usb_getinfoare minor adjustments that can be discussed and fixed.
Quoted 8 lines
4. The pvusb driver domain != dom0 comments. This is somewhat secondary to your primary goal; but at the moment the code will certainly not work. We have a couple of options:
a: Wait until we've fixed the driver domain functionality
b: Check the code in right now, with the driver domain fuctionality explicitly disabled; that is, it will return an error if backend_domain!=0. Get a promise to implement the driver domain functionality properly for 4.7 (on the threat of removing the feature).
I'll check the codes and add backend_domain check in related functions.
Thanks,
Chunyan
Quoted 12 lines
c: Take driver domain support out of the interface for now; send follow-up patches to implement it properly.
d. Take driver domain support out of the interface and leave it that way, for simplicity.I'd probably go with b or c.
Thoughts?
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 50 lines · Chun Yan Liu
Quoted 37 lines
Quoted 26 lines
+
tools/libxl/libxl_pvusb.c new file +25
-0+ usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf);tools/libxl/libxl_pvusb.c line 1408
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+ } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Quoted 8 lines
Basically, starting here, we have information which won't be available if we're using a pvusb driver domain.
This information is nice-to-have, but I don't think this information is directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined to say that if we want to have pvusb driver domains (and I think we do), we should just get rid of this information.
For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
Quoted 5 lines
I think we can keep the function, since every other device type has the function
XXX_getinfo. But here we could checkbackend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting those information. Can add code in future.)
Does xl need that information? Can't the user get that information from lsusb?
In any case, I can see why it would be *useful* to have in xl. But about having it in libxl, I think this question sort of goes along with the question about the next patch -- whether libxl should be in the business of providing general information about the USB devices it's handling, or whether it should limit itself to doing what is absolutely necessary to talk to usbback.
There's a part of me that sees the point of it: it's not actually that much extra code (at least for Linux), and it makes it easy to add some very useful features to xl.
On the other hand, it's not portable to other OSes. At the moment of course pvusb isn't portable either, but once we have qemu USB (providing either emulated or PV usb) then I *think* most of the other functionality will Just Work on any platform that can compile qemu (incl. FreeBSD, NetBSD, &c), won't it? The code you're introducing here would have to be re-implented for those platforms, and for every new platform that wanted to include this functionality, wouldn't it?
The libusb interface does look a bit clunky; it would certainly be more convenient for developers to use the interface you've provided here.
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 69 lines · George Dunlap
Quoted 49 lines · Chun Yan Liu
Quoted 40 lines
Quoted 26 lines
tools/libxl/libxl_pvusb.c new file +26
-0+ + usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf);tools/libxl/libxl_pvusb.c line 1408
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+ } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf, &buflen) && + buflen >0 ) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Basically, starting here, we have information which won't be available if we're using a pvusb driver domain.
Quoted 5 lines
This information is nice-to-have, but I don't think this information is directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined to say that if we want to have pvusb driver domains (and I think we do), we should just get rid of this information.
For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
Quoted 5 lines
I think we can keep the function, since every other device type has the function
XXX_getinfo. But here we could checkbackend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting those information. Can add code in future.)Does xl need that information? Can't the user get that information from lsusb?
In any case, I can see why it would be *useful* to have in xl. But about having it in libxl, I think this question sort of goes along with the question about the next patch -- whether libxl should be in the business of providing general information about the USB devices it's handling, or whether it should limit itself to doing what is absolutely necessary to talk to usbback.
There's a part of me that sees the point of it: it's not actually that much extra code (at least for Linux), and it makes it easy to add some very useful features to xl.
Quoted 7 lines
On the other hand, it's not portable to other OSes. At the moment of course pvusb isn't portable either, but once we have qemu USB (providing either emulated or PV usb) then I *think* most of the other functionality will Just Work on any platform that can compile qemu (incl. FreeBSD, NetBSD, &c), won't it? The code you're introducing here would have to be re-implented for those platforms, and for every new platform that wanted to include this functionality, wouldn't it?
So, about the portability problem, I think it's back to: do need to update code to call libusb instead of reading sysfs now? Except for this function, still have places reading sysfs to get hostbus, hostaddr, vendorId, deviceId. Those are not portable for other platform.
And about getting rid of the function, currently it's only needed in 'xl usb-list' and 'xl usb-assignable-list', if not providing general information, yes, we can remove it.
-Chunyan
Quoted 6 lines
The libusb interface does look a bit clunky; it would certainly be more convenient for developers to use the interface you've provided here.
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 84 lines · Chun Yan Liu
Quoted 74 lines · George Dunlap
Quoted 53 lines · Chun Yan Liu
Quoted 41 lines
Quoted 32 lines
tools/libxl/libxl_pvusb.c new file +21
-0+ + usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c new file +9
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf); + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c line 1408
Quoted 6 lines
tools/libxl/libxl_pvusb.c new file +6
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Basically, starting here, we have information which won't be
available
if we're using a pvusb driver domain.Quoted 8 lines
This information is nice-to-have, but I don't think this
information is
directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined
to say that if we want to have pvusb driver domains (and I think we do),
we should just get rid of this information.For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
Quoted 6 lines
I think we can keep the function, since every other device type has the function
XXX_getinfo. But here we could checkbackend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting
those information. Can add code in future.)Does xl need that information? Can't the user get that information from lsusb?
In any case, I can see why it would be *useful* to have in xl. But about having it in libxl, I think this question sort of goes along with the question about the next patch -- whether libxl should be in the business of providing general information about the USB devices it's handling, or whether it should limit itself to doing what is absolutely necessary to talk to usbback.
There's a part of me that sees the point of it: it's not actually that much extra code (at least for Linux), and it makes it easy to add some very useful features to xl.
Quoted 7 lines
On the other hand, it's not portable to other OSes. At the moment of course pvusb isn't portable either, but once we have qemu USB (providing either emulated or PV usb) then I *think* most of the other functionality will Just Work on any platform that can compile qemu (incl. FreeBSD, NetBSD, &c), won't it? The code you're introducing here would have to be re-implented for those platforms, and for every new platform that wanted to include this functionality, wouldn't it?
Quoted 5 lines
So, about the portability problem, I think it's back to: do need to update code to call libusb instead of reading sysfs now? Except for this function, still have places reading sysfs to get hostbus, hostaddr, vendorId, deviceId. Those are not portable for other platform.
I realize I didn't give you very clear guidance; I guess I was hoping to get an opinion from the tools maintainers. Or perhaps, I was hoping to let them be the "bad guys" and say, "You can't have this feature in libxl", so I wouldn't have to. :-)
In the absence of guidance to the contrary, I suggest that patch series should focus on getting the core pvusb functionality in, without the extra usb-querying bits. Then we can discuss a further series which either adds the usb querying functionality to libxl, or implement it in xl using libusb.
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 96 lines · George Dunlap
Quoted 84 lines · Chun Yan Liu
Quoted 74 lines · George Dunlap
Quoted 53 lines · Chun Yan Liu
Quoted 41 lines
Quoted 32 lines
tools/libxl/libxl_pvusb.c new file +21
-0+ + usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c new file +9
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf); + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c line 1408
Quoted 6 lines
tools/libxl/libxl_pvusb.c new file +6
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Basically, starting here, we have information which won't be
available
if we're using a pvusb driver domain.Quoted 8 lines
This information is nice-to-have, but I don't think this
information is
directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined
to say that if we want to have pvusb driver domains (and I think we do),
we should just get rid of this information.For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
Quoted 6 lines
I think we can keep the function, since every other device type has the function
XXX_getinfo. But here we could checkbackend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting
those information. Can add code in future.)Does xl need that information? Can't the user get that information from lsusb?
In any case, I can see why it would be *useful* to have in xl. But about having it in libxl, I think this question sort of goes along with the question about the next patch -- whether libxl should be in the business of providing general information about the USB devices it's handling, or whether it should limit itself to doing what is absolutely necessary to talk to usbback.
There's a part of me that sees the point of it: it's not actually that much extra code (at least for Linux), and it makes it easy to add some very useful features to xl.
Quoted 7 lines
On the other hand, it's not portable to other OSes. At the moment of course pvusb isn't portable either, but once we have qemu USB (providing either emulated or PV usb) then I *think* most of the other functionality will Just Work on any platform that can compile qemu (incl. FreeBSD, NetBSD, &c), won't it? The code you're introducing here would have to be re-implented for those platforms, and for every new platform that wanted to include this functionality, wouldn't it?
Quoted 5 lines
So, about the portability problem, I think it's back to: do need to update code to call libusb instead of reading sysfs now? Except for this function, still have places reading sysfs to get hostbus, hostaddr, vendorId, deviceId. Those are not portable for other platform.
I realize I didn't give you very clear guidance; I guess I was hoping to get an opinion from the tools maintainers. Or perhaps, I was hoping to let them be the "bad guys" and say, "You can't have this feature in libxl", so I wouldn't have to. :-)
Quoted 5 lines
In the absence of guidance to the contrary, I suggest that patch series should focus on getting the core pvusb functionality in, without the extra usb-querying bits. Then we can discuss a further series which either adds the usb querying functionality to libxl, or implement it in xl using libusb.
Just to be clear: Reading sysfs to actually implement the core pvusb protocol is fine, because at the moment there *is* only a Linux backend.
You should be able to get the core pvusb functionality in without
resorting to libusb. It's just the additional usb information that we may want to use libusb for, to avoid having to duplicate that for other platforms once we have qemu-usb enabled.
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to George DunlapQuoted 5 lines · George Dunlap
In the absence of guidance to the contrary, I suggest that patch series should focus on getting the core pvusb functionality in, without the extra usb-querying bits. Then we can discuss a further series which either adds the usb querying functionality to libxl, or implement it in xl using libusb.
That would seem sensible to me. Lets get the (hopefully) uncontroversial core functionality done and then worry about any extras etc, since they seem to be preventing us from making forward progress at the moment.
Ian.
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to George DunlapQuoted 94 lines · George Dunlap
Quoted 83 lines · Chun Yan Liu
Quoted 74 lines · George Dunlap
Quoted 53 lines · Chun Yan Liu
Quoted 41 lines
Quoted 32 lines
tools/libxl/libxl_pvusb.c new file +21
-0+ + usbinfo->devnum = usb->u.hostdev.hostaddr; + usbinfo->busnum = usb->u.hostdev.hostbus; + + busid =usb_busaddr_to_busid (gc, usb->u.hostdev.hostbus, + usb->u.hostdev.hostaddr); +if (!busid) { + rc =ERROR_FAIL ; + goto out; + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idVendor" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idVendor); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/idProduct" , busid); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%" SCNx16, &usbinfo->idProduct); + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/manufacturer" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c new file +9
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->manuf =libxl__strdup (NOGC , buf); + } + + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/product" , busid); + if (!libxl_read_sysfs_file_contents(ctx, filename, &buf,&buflen) &&
tools/libxl/libxl_pvusb.c line 1408
Quoted 6 lines
tools/libxl/libxl_pvusb.c new file +6
-0+ buflen > 0) { +/* replace \n to \0 */ +if (((char *)buf)[buflen -1 ] =='\n' ) + ((char *)buf)[buflen -1 ] ='\0' ; + usbinfo->prod =libxl__strdup (NOGC , buf); + }Basically, starting here, we have information which won't be
available
if we're using a pvusb driver domain.Quoted 8 lines
This information is nice-to-have, but I don't think this
information is
directly relevant to libxl or xl; the funcitonality to get this information is available from other libraries like libusb. I'm inclined
to say that if we want to have pvusb driver domains (and I think we do),
we should just get rid of this information.For command 'xl usb-list', those information should be reported to user. Do you mean we could call libusb to get thoes information directly in xl toolstack and get rid of this function?
Quoted 6 lines
I think we can keep the function, since every other device type has the function
XXX_getinfo. But here we could checkbackend_domid, for backend=dom0, doing above work; for backend!=dom0 (e.g. pvusb driver domain, no matter how, it should also be able to let users getting
those information. Can add code in future.)Does xl need that information? Can't the user get that information from lsusb?
In any case, I can see why it would be *useful* to have in xl. But about having it in libxl, I think this question sort of goes along with the question about the next patch -- whether libxl should be in the business of providing general information about the USB devices it's handling, or whether it should limit itself to doing what is absolutely necessary to talk to usbback.
There's a part of me that sees the point of it: it's not actually that much extra code (at least for Linux), and it makes it easy to add some very useful features to xl.
Quoted 7 lines
On the other hand, it's not portable to other OSes. At the moment of course pvusb isn't portable either, but once we have qemu USB (providing either emulated or PV usb) then I *think* most of the other functionality will Just Work on any platform that can compile qemu (incl. FreeBSD, NetBSD, &c), won't it? The code you're introducing here would have to be re-implented for those platforms, and for every new platform that wanted to include this functionality, wouldn't it?
Quoted 5 lines
So, about the portability problem, I think it's back to: do need to update code to call libusb instead of reading sysfs now? Except for this function, still have places reading sysfs to get hostbus, hostaddr, vendorId, deviceId. Those are not portable for other platform.
I realize I didn't give you very clear guidance; I guess I was hoping to get an opinion from the tools maintainers. Or perhaps, I was hoping to let them be the "bad guys" and say, "You can't have this feature in libxl", so I wouldn't have to. :-)
Quoted 5 lines
In the absence of guidance to the contrary, I suggest that patch series should focus on getting the core pvusb functionality in, without the extra usb-querying bits. Then we can discuss a further series which either adds the usb querying functionality to libxl, or implement it in xl using libusb.
OK. Got it. Thanks.
-Chunyan
Quoted 3 lines
-George
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to Chunyan LiuChunyan Liu writes ("[PATCH V7 3/7] libxl: add pvusb API"):
Quoted 1 line
Add pvusb APIs, including:
...
tools/libxl/libxl_pvusb.c line 32
Quoted 8 lines
tools/libxl/libxl_pvusb.c new file +8
-0+/* Utility to read backend xenstore keys */ +#define READ_BACKEND (tgc, subpath) \ + libxl__xs_read(tgc, XBT_NULL, GCSPRINTF("%s/" subpath, be_path)) + +/* Utility to read frontend xenstore keys */ +#define READ_FRONTEND (tgc, subpath) \ + libxl__xs_read(tgc, XBT_NULL, GCSPRINTF("%s/" subpath, fe_path)) +
Thanks for trying to reduce repetition. But I think these macros need to be improved. I'm am not particularly keen on them in this form, for a number of reasons.
* They implicitly rely on variables (be_path and fe_path) being in scope but there is no associated doc comment. That would be OK if they were macros defined within a single function and #undef'd before the function end.
* Their functionality is not really usb-specific. If this is a good thing to do they should be in libxl_internal.h.
* They should use libxl__xs_read_checked. That means they should probably also implicitly assume that rc is in scope, and `goto out' on error. (There are many calls to libxl__xs_read here to which the same observation applies.)
* I think there is no reason for these to take a tgc' parameter. All of the call sites pass exactly gc'. If these macros are going to make assumptions about what's in their scope, `gc' is a very good candidate (which many existing macros rely on).
You can go two routes with this: make much more local macros, and #undef them. Or formalise these macros and widen their scope to the whole of libxl. I think the latter would probably be best.
Perhaps something like:
/*
* const char *READ_SUBPATH(const char *febe_path, const char *subpath); *
* Expects in scope:
* int rc; * libxl__gc *gc; * out:
*
* Reads febe_path/subpath from xenstore. Does not use a transaction.
* On xenstore errors, sets rc and does `goto out'.
* If the path does not exist, returns NULL.
*/
#define READ_SUBPATH(febe_path, subpath) ...
What do you think ?
Quoted 40 lines
tools/libxl/libxl_pvusb.c new file +40
-0+/* AO operation to add a usb controller. +* +* Generally, it does: +* 1) fill in necessary usb controler information with default value +* 2) write usb controller frontend/backend info to xenstore, update json +* config file if necessary. +* 3) wait for device connection. PVUSB frontend and backend driver will +* probe xenstore paths and build connection between frontend and backend. +*/ +void libxl__device_usbctrl_add (libxl__egc *egc,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +libxl__device *device; +int rc; + + rc =libxl__device_usbctrl_setdefault (gc, domid, usbctrl); +if (rc <0 ) goto out; + +if (usbctrl->devid ==-1 ) { + usbctrl->devid =libxl__device_nextid (gc, domid,"vusb" ); +if (usbctrl->devid <0 ) { + rc =ERROR_FAIL ; + goto out; + } + } + +if (usbctrl->type !=LIBXL_USBCTRL_TYPE_PV ) { +LOG (ERROR ,"Unsupported USB controller type" ); + rc =ERROR_FAIL ; + goto out; + } + + rc =libxl__device_usbctrl_add_xenstore (gc, domid, usbctrl, + aodev->update_json); +if (rc) goto out; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device);
tools/libxl/libxl_pvusb.c line 217
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+if (rc) goto out; + + aodev->dev = device; + aodev->action =LIBXL__DEVICE_ACTION_ADD ; +libxl__wait_device_connection (egc, aodev); + rc =0 ; + +out: + aodev->rc = rc; +if (rc) aodev->callback (egc, aodev);
This is wrong (even though it works with the remaining code as it stands), I'm afraid.
The right pattern is to `return 0' after libxl__wait_device_connection, because libxl__wait_device_connection will always make a callback.
Also the doc comment for this function should make it clear which of the fields in aodev must be filled in by the caller. After you do that you should make sure that the call site obeys the rules. (This is not something I have checked right now because the rules aren't stated.)
Both of these observations apply to the remove path as well.
tools/libxl/libxl_pvusb.c line 237
Quoted 9 lines
tools/libxl/libxl_pvusb.c new file +9
-0+/* AO function to remove a usb controller. +* +* Generally, it does: +* 1) check if the usb controller exists or not +* 2) remove all usb devices under controller +* 3) remove usb controller information from xenstore +*/ +void libxl__initiate_device_usbctrl_remove (libxl__egc *egc, +libxl__ao_device *aodev)
What happens if this functionality is running to try to remove the controller, at the same time as another process is trying to remove a device from the controller, or (worse) add a device to the controller ? Obviously I don't expect 100% successful outcomes, but I want to know that the severity of the consequences is limited.
tools/libxl/libxl_pvusb.c line 293
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+libxl_device_usbctrl * +libxl_device_usbctrl_list (libxl_ctx *ctx,uint32_t domid,int *num) +{
This function should return an rc, and the list should come in an out parameter.
Quoted 1 line
+ dir =
libxl__xs_directory(gc, XBT_NULL, path, &ndirs);
The variables dir' and ndirs' should be entry' and nentries'.
tools/libxl/libxl_pvusb.c line 310
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+if (dir && ndirs) { + usbctrls =libxl__zalloc (NOGC ,sizeof (*usbctrls) * ndirs); +libxl_device_usbctrl *usbctrl; +libxl_device_usbctrl *end = usbctrls + ndirs; +for (usbctrl = usbctrls; usbctrl < end; usbctrl++, dir++, (*num)++) {
This line would be better wrapped at the semicolons, IMO.
Quoted 7 lines
tools/libxl/libxl_pvusb.c new file +7
-0+const char *tmp, *be_path; +const char *fe_path =GCSPRINTF ("%s/%s" , path, *dir); + +libxl_device_usbctrl_init (usbctrl); + usbctrl->devid =atoi (*dir); + + tmp =READ_FRONTEND (gc,"backend-id" );
tools/libxl/libxl_pvusb.c line 330
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+if (!tmp) goto outerr; + usbctrl->backend_domid =atoi (tmp); + + tmp =READ_BACKEND (gc,"usb-ver" ); +if (!tmp) goto outerr; + usbctrl->version =atoi (tmp); + + tmp =READ_BACKEND (gc,"num-ports" ); +if (!tmp) goto outerr; + usbctrl->ports =atoi (tmp);
There are 4 nearly identical stanzas here. I think a more comprehensive would be helpful. Maybe a global macro READ_SUBPATH_INT along the lines of my READ_SUBPATH, above, would be useful, and then:
usbctrl->ports = READ_SUBPATH_INT(be_path, "num-ports");
and there would be no need for any open-coded error handling.
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+int libxl_device_usbctrl_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl_usbctrlinfo *usbctrlinfo)
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ tmp = READ_FRONTEND(gc, "backend-id"); + usbctrlinfo->backend_id = tmp ? strtoul(tmp, NULL, 10) : -1;
Under what circumstances can these be validly missing ? I'm not very happy with the idea of filling in the struct with -1.
tools/libxl/libxl_pvusb.c line 414
Quoted 9 lines
tools/libxl/libxl_pvusb.c new file +9
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx); +libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ;
Initialising rc like this is a bad idea. Instead, it should be set explicitly on each error path. That alllows the compiler to spot error paths that do not set rc. Also rc=-1 is not permitted because rc ought to be a libxl error code. You probably want ERROR_NOTFOUND.
tools/libxl/libxl_pvusb.c line 457
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+static char *usb_busaddr_to_busid (libxl__gc *gc,int bus,int addr) +{ + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/devnum" , de->d_name); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%d" , &devnum);
If the file contents are invalid, devnum will be left uninitialised. Why using sscanf rather than atoi (if you don't want to check for unexpected data) or strtoul (if you do) ? (Same thing later in usb_busaddr_from_busid.)
tools/libxl/libxl_pvusb.c line 465
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+if (bus == busnum && addr == devnum) { + busid =libxl__strdup (NOGC , de->d_name); +break ;
This allocates non-gc'd memory but (a) this is not documented contrary to the rules in libxl_internal.h and (b) some of its callers do not want non-gc'd memory.
tools/libxl/libxl_pvusb.c line 474
Quoted 2 lines
tools/libxl/libxl_pvusb.c new file +2
-0+static void usb_busaddr_from_busid (libxl__gc *gc,char *busid, +uint8_t *bus,uint8_t *addr)
Lack of const-correctness: busid should be const char *.
Quoted 1 line
+ assert(busid);
This is not necessary. Please drop it. If it's NULL, we'll crash in snprintf soon enough.
I think that many of my comments can be generalised to the rest of this patch. I think it would be better for me to stop reading now and await a new version. (I'm finding it difficult to see the overall structure of the code, and to remember the things I'm trying to look out for along with the things I'm trying to disregard because I have already mentioned them.)
Specifically, can you please make sure to take every one of my comments above, and treat it as relevant everywhere that it (or an analagous comment) is applicable in your code.
Thanks,
Ian.
Re: [PATCH V7 3/7] libxl: add pvusb API
Quoted 6 lines · Ian Jackson
tools/libxl/libxl_pvusb.c line 293
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+libxl_device_usbctrl * +libxl_device_usbctrl_list (libxl_ctx *ctx,uint32_t domid,int *num) +{This function should return an rc, and the list should come in an out parameter.
For better of worse libxl.h defines the general form of a device API to include list looking like this (search for "Querying").
If this were for an actual device I'd be adamant that it should follow that pattern.
Since this is part of a new "controller" abstraction we do in theory have the freedom to do things differently, but it seems to me that having something as basic as the list operation differ for devices vs. controller would do more harm than good even if the controller interface is strictly better. IOW I'm willing to be convinced otherwise but right now I'm pretty sure how it is above is the preferable extension to our API.
Quoted 12 lines
Quoted 12 lines
tools/libxl/libxl_pvusb.c new file +12
-0+const char *tmp, *be_path; +const char *fe_path =GCSPRINTF ("%s/%s" , path, *dir); + +libxl_device_usbctrl_init (usbctrl); + usbctrl->devid =atoi (*dir); + + tmp =READ_FRONTEND (gc,"backend-id" ); +if (!tmp) goto outerr; + usbctrl->backend_domid =atoi (tmp); + + tmp =READ_BACKEND (gc,"usb-ver" ); +if (!tmp) goto outerr;
Quoted 8 lines
tools/libxl/libxl_pvusb.c line 330
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+ usbctrl->version =atoi (tmp); + + tmp =READ_BACKEND (gc,"num-ports" ); +if (!tmp) goto outerr; + usbctrl->ports =atoi (tmp);There are 4 nearly identical stanzas here. I think a more comprehensive would be helpful. Maybe a global macro
READ_SUBPATH_INT
^MACRO?
Ian.
Re: [PATCH V7 3/7] libxl: add pvusb API
Ian Campbell writes ("Re: [PATCH V7 3/7] libxl: add pvusb API"):
Quoted 6 lines
Since this is part of a new "controller" abstraction we do in theory have the freedom to do things differently, but it seems to me that having something as basic as the list operation differ for devices vs. controller would do more harm than good even if the controller interface is strictly better. IOW I'm willing to be convinced otherwise but right now I'm pretty sure how it is above is the preferable extension to our API.
Hrm. OK, I guess :-/.
Quoted 7 lines
Quoted 6 lines
tools/libxl/libxl_pvusb.c line 330
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+ tmp =READ_BACKEND (gc,"num-ports" ); +if (!tmp) goto outerr; + usbctrl->ports =atoi (tmp);There are 4 nearly identical stanzas here. I think a more comprehensive would be helpful. Maybe a global macro
READ_SUBPATH_INT^MACRO?
Yes.
Ian.
Re: [PATCH V7 3/7] libxl: add pvusb API
In reply to Ian JacksonQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 10/8/2015 at 10:41 PM, in message
<[email protected]>, Ian Jackson
Quoted 32 lines · <[email protected]> wrote:
Chunyan Liu writes ("[PATCH V7 3/7] libxl: add pvusb API"):
Quoted 1 line
Add pvusb APIs, including:
...
tools/libxl/libxl_pvusb.c
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+/* Utility to read backend xenstore keys */ +#define READ_BACKEND (tgc, subpath) \ + libxl__xs_read(tgc, XBT_NULL, GCSPRINTF("%s/" subpath,
be_path))tools/libxl/libxl_pvusb.c
Quoted 4 lines
+
tools/libxl/libxl_pvusb.c new file +3
-0+/* Utility to read frontend xenstore keys */ +#define READ_FRONTEND (tgc, subpath) \ + libxl__xs_read(tgc, XBT_NULL, GCSPRINTF("%s/" subpath,
fe_path))Quoted 1 line
+
Thanks for trying to reduce repetition. But I think these macros need to be improved. I'm am not particularly keen on them in this form, for a number of reasons.
* They implicitly rely on variables (
be_pathandfe_path) being in scope but there is no associated doc comment. That would be OK if they were macros defined within a single function and #undef'd before the function end.* Their functionality is not really usb-specific. If this is a good thing to do they should be in
libxl_internal.h.* They should use
libxl__xs_read_checked. That means they should probably also implicitly assume that rc is in scope, and `goto out' on error. (There are many calls tolibxl__xs_readhere to which the same observation applies.)
Quoted 8 lines
* I think there is no reason for these to take a
tgc' parameter. All of the call sites pass exactlygc'. If these macros are going to make assumptions about what's in their scope, `gc' is a very good candidate (which many existing macros rely on).You can go two routes with this: make much more local macros, and #undef them. Or formalise these macros and widen their scope to the whole of libxl. I think the latter would probably be best.
Sorry for replying late, the mail server were exchanged and had some issues these days.
For the macro, I think maybe it's better to use local macros within function. The macro itself doesn't do much work but a libxl__xs_read. Local macro can have more flexibility, like can adding extra 'goto out' or error handling or other repeated codes to the macro according to specific function.
Quoted 76 lines
Perhaps something like:
/*
* const char *READ_SUBPATH(const char*febe_path, const char *subpath); *
* Expects in scope:* int rc; * libxl__gc *gc; * out:*
* Reads febe_path/subpath from xenstore. Does not use a transaction.
* On xenstore errors, sets rc and does `goto out'.
* If the path does not exist, returns NULL.
*/
#defineREAD_SUBPATH(febe_path, subpath)...What do you think ?
Quoted 8 lines
+/* AO operation to add a usb controller.
+ *
+ * Generally, it does:
+ * 1) fill in necessary usb controler information with default value
+ * 2) write usb controller frontend/backend info to xenstore, update json
+ * config file if necessary.
+ * 3) wait for device connection. PVUSB frontend and backend driver will
+ * probe xenstore paths and build connection between frontend and ibackend.
Quoted 32 lines
+ */
tools/libxl/libxl_pvusb.c new file +31
-0+void libxl__device_usbctrl_add (libxl__egc *egc,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +libxl__device *device; +int rc; + + rc =libxl__device_usbctrl_setdefault (gc, domid, usbctrl); +if (rc <0 ) goto out; + +if (usbctrl->devid ==-1 ) { + usbctrl->devid =libxl__device_nextid (gc, domid,"vusb" ); +if (usbctrl->devid <0 ) { + rc =ERROR_FAIL ; + goto out; + } + } + +if (usbctrl->type !=LIBXL_USBCTRL_TYPE_PV ) { +LOG (ERROR ,"Unsupported USB controller type" ); + rc =ERROR_FAIL ; + goto out; + } + + rc =libxl__device_usbctrl_add_xenstore (gc, domid, usbctrl, + aodev->update_json); +if (rc) goto out; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device);tools/libxl/libxl_pvusb.c line 217
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+if (rc) goto out; + + aodev->dev = device; + aodev->action =LIBXL__DEVICE_ACTION_ADD ; +libxl__wait_device_connection (egc, aodev); + rc =0 ; + +out: + aodev->rc = rc; +if (rc) aodev->callback (egc, aodev);This is wrong (even though it works with the remaining code as it stands), I'm afraid.
Quoted 3 lines
The right pattern is to `return 0' after
libxl__wait_device_connection, becauselibxl__wait_device_connectionwill always make a callback.
It's OK to 'return 0' directly fater libxl__wait_device_connection since we don't need to do cleanup work. Here the code follows the code format of libxl__device_disk_add and libxl__device_nic_add, I think it doesn't harm.
Quoted 6 lines
Also the doc comment for this function should make it clear which of the fields in aodev must be filled in by the caller. After you do that you should make sure that the call site obeys the rules. (This is not something I have checked right now because the rules aren't stated.)
The libxl__device_usbctrl_add follows the same rule as libxl__device_disk_add and libxl__device_nic_add, call sites including DEFINE_DEVICE_ADD(usbctrl) and domcreate time also follow the same rule as disk type and nic type. Do we need to add doc comment to the parameters of this API separately?
Quoted 18 lines
Both of these observations apply to the remove path as well.
tools/libxl/libxl_pvusb.c line 237
Quoted 9 lines
tools/libxl/libxl_pvusb.c new file +9
-0+/* AO function to remove a usb controller. +* +* Generally, it does: +* 1) check if the usb controller exists or not +* 2) remove all usb devices under controller +* 3) remove usb controller information from xenstore +*/ +void libxl__initiate_device_usbctrl_remove (libxl__egc *egc, +libxl__ao_device *aodev)What happens if this functionality is running to try to remove the controller, at the same time as another process is trying to remove a device from the controller, or (worse) add a device to the controller ? Obviously I don't expect 100% successful outcomes, but I want to know that the severity of the consequences is limited.
I'm not quite clear about the whole lock mechanism in libxl code. But I think here the risk is perhaps similar to one process doing domain destroy and at the same time another process is trying to add a disk device. I didn't add extra lock in the usbctrl add/remove and usb add/remove (should we??).
So, when one process removing usbctrl, another process is trying to add a device, one case could be: the latter would fail to write xenstore if the former process already removes xenstore entries and then report fail, but the former process could succeed.
or could be: the latter process succeeds to write xenstore and assign usb device to usbback and report success, but actually user cannot see the device, since former process will remove everything under the controller soon.
For one process removing usbctrl, another removing usb device, it could be:
the latter one found the usb device doesn't exist any more and report error, but the former one can succeed. or: the former one lists usb devices under the controller, and trying to remove one by one; during that process, the latter removes some usb device; then the former process will fail to remove that usb device again, and then will report error.
Quoted 40 lines
tools/libxl/libxl_pvusb.c line 293
Quoted 4 lines
tools/libxl/libxl_pvusb.c new file +3
-0+libxl_device_usbctrl * +libxl_device_usbctrl_list (libxl_ctx *ctx,uint32_t domid,int *num) +{This function should return an rc, and the list should come in an out is not something I have checked right now because the rules aren't stated.)
Quoted 1 line
+ dir =
libxl__xs_directory(gc, XBT_NULL, path, &ndirs);The variables
dir' andndirs' should beentry' andnentries'.tools/libxl/libxl_pvusb.c
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+if (dir && ndirs) { + usbctrls =libxl__zalloc (NOGC ,sizeof (*usbctrls) * ndirs); +libxl_device_usbctrl *usbctrl; +libxl_device_usbctrl *end = usbctrls + ndirs; +for (usbctrl = usbctrls; usbctrl < end; usbctrl++, dir++, (*num)++){
This line would be better wrapped at the semicolons, IMO.
Quoted 7 lines
tools/libxl/libxl_pvusb.c new file +7
-0+const char *tmp, *be_path; +const char *fe_path =GCSPRINTF ("%s/%s" , path, *dir); + +libxl_device_usbctrl_init (usbctrl); + usbctrl->devid =atoi (*dir); + + tmp =READ_FRONTEND (gc,"backend-id" );tools/libxl/libxl_pvusb.c line 330
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+if (!tmp) goto outerr; + usbctrl->backend_domid =atoi (tmp); + + tmp =READ_BACKEND (gc,"usb-ver" ); +if (!tmp) goto outerr; + usbctrl->version =atoi (tmp); + + tmp =READ_BACKEND (gc,"num-ports" ); +if (!tmp) goto outerr; + usbctrl->ports =atoi (tmp);
Quoted 3 lines
There are 4 nearly identical stanzas here. I think a more comprehensive would be helpful. Maybe a global macro
READ_SUBPATH_INTalong the lines of myREAD_SUBPATH, above, would be useful, and then:
Defining local macro within function may be better, can include more repeated codes into the macro according to need.
Quoted 8 lines
usbctrl->ports = READ_SUBPATH_INT(be_path, "num-ports");and there would be no need for any open-coded error handling.
tools/libxl/libxl_pvusb.c line 353
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +3
-0+int libxl_device_usbctrl_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl_usbctrlinfo *usbctrlinfo)
Quoted 6 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ tmp = READ_FRONTEND(gc, "backend-id"); + usbctrlinfo->backend_id = tmp ? strtoul(tmp, NULL, 10) : -1;Under what circumstances can these be validly missing ? I'm not very happy with the idea of filling in the struct with -1.
In theory that should not happen.
Quoted 13 lines
tools/libxl/libxl_pvusb.c line 414
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +9
-0+int libxl_devid_to_device_usbctrl (libxl_ctx *ctx, +uint32_t domid, +int devid, +libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx); +libxl_device_usbctrl *usbctrls; +int nb =0 ; +int i, rc =-1 ;Initialising rc like this is a bad idea. Instead, it should be set explicitly on each error path.
OK. Take it.
Quoted 4 lines
That alllows the compiler to spot
error paths that do not set rc. Also rc=-1 is not permitted because rc ought to be a libxl error code. You probably wantERROR_NOTFOUND.
Quoted 10 lines
tools/libxl/libxl_pvusb.c line 457
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+static char *usb_busaddr_to_busid (libxl__gc *gc,int bus,int addr) +{ + filename =GCSPRINTF (SYSFS_USB_DEV "/%s/devnum" , de->d_name); +if (!libxl_read_sysfs_file_contents (ctx, filename, &buf,NULL )) +sscanf (buf,"%d" , &devnum);If the file contents are invalid, devnum will be left uninitialised. Why using sscanf rather than atoi (if you don't want to check for unexpected data) or strtoul (if you do) ? (Same thing later in
usb_busaddr_from_busid.)
No special reason, just to keep consistent to use the same code everywhere getting sysfs info.
Quoted 8 lines
tools/libxl/libxl_pvusb.c line 465
Quoted 4 lines
tools/libxl/libxl_pvusb.c new file +3
-0+if (bus == busnum && addr == devnum) { + busid =libxl__strdup (NOGC , de->d_name); +break ;This allocates non-gc'd memory but (a) this is not documented contrary to the rules in
libxl_internal.hand (b) some of its callers do not want non-gc'd memory.
I'll have a look and add document if really need non-gc'd memory.
- Chunyan
Quoted 27 lines
tools/libxl/libxl_pvusb.c line 474
Quoted 3 lines
tools/libxl/libxl_pvusb.c new file +2
-0+static void usb_busaddr_from_busid (libxl__gc *gc,char *busid, +uint8_t *bus,uint8_t *addr)Lack of const-correctness: busid should be const char *.
Quoted 1 line
+ assert(busid);
This is not necessary. Please drop it. If it's NULL, we'll crash in snprintf soon enough.
I think that many of my comments can be generalised to the rest of this patch. I think it would be better for me to stop reading now and await a new version. (I'm finding it difficult to see the overall structure of the code, and to remember the things I'm trying to look out for along with the things I'm trying to disregard because I have already mentioned them.)
Specifically, can you please make sure to take every one of my comments above, and treat it as relevant everywhere that it (or an analagous comment) is applicable in your code.
Thanks,
Ian.
PATCH v7 4/7 libxl: add libxl_device_usb_assignable_list API
In reply to Chunyan LiuAdd 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.
---
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.
tools/libxl/libxl.h | 3 +++ tools/libxl/libxl_pvusb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
tools/libxl/libxl.h +3 -0
@@ -1450,6 +1450,9 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_usbctrlinfo *usbctrlinfo);/* USB Devices */ +libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num); + int libxl_device_usb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usb *usb, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY;
tools/libxl/libxl_pvusb.c +55 -0
61 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH V7 4/7] libxl: add libxl_device_usb_assignable_list API
Quoted 66 lines · Chunyan Liu
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 <[email protected]>---
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.tools/libxl/libxl.h | 3 +++ tools/libxl/libxl_pvusb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)tools/libxl/libxl.h +3
-0@@ -1450,6 +1450,9 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_usbctrlinfo *usbctrlinfo);/* USB Devices */ +libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num); + int libxl_device_usb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usb *usb, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY;tools/libxl/libxl_pvusb.c +30
-0@@ -573,6 +573,61 @@ static bool is_usb_assignable(libxl__gc *gc, libxl_device_usb *usb)return classcode !=USBHUB_CLASS_CODE ; } +libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num) +{ +GC_INIT (ctx); +libxl_device_usb *usbs =NULL ; +libxl_device_usb *assigned; +int num_assigned; +struct dirent *de; +DIR *dir; + + *num =0 ; + +if (get_assigned_devices (gc, &assigned, &num_assigned) <0 ) { +LOG (ERROR ,"cannot determine if device is assigned" ); + goto out; + } + +if (!(dir =opendir (SYSFS_USB_DEV ))) + goto out; + +while ((de =readdir (dir))) { +libxl_device_usb *usb; +uint8_t bus =-1 , addr =-1 ; + +if (!de->d_name) +continue ; + +usb_busaddr_from_busid (gc, de->d_name, &bus, &addr); +if (bus <1 || addr <1 ) +continue ;
tools/libxl/libxl_pvusb.c static bool is_usb_assignable(libxl__gc *gc, libxl_device_usb *usb) · line 615
Quoted 10 lines
tools/libxl/libxl_pvusb.c +10
-0+ +GCNEW (usb); + usb->u.hostdev.hostbus = bus; + usb->u.hostdev.hostaddr = addr; + +if (!is_usb_assignable (gc, usb)) +continue ; + +if (is_usbdev_in_array (assigned, num_assigned, usb)) +continue ;
Why are we allocating a new usb struct every loop, and then never using it again? Why not just put it on the stack and re-use it?
Other than that, looks OK.
-George
PATCH v7 5/7 xl: add pvusb commands
In reply to Chunyan LiuAdd 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 0 1
will detach USB device under controller 0 port 1.
#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.
--- docs/man/xl.pod.1 | 40 ++++++++ tools/libxl/xl.h | 5 + tools/libxl/xl_cmdimpl.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 25 +++++ 4 files changed, 302 insertions(+)
docs/man/xl.pod.1 +40 -0
@@ -1345,6 +1345,46 @@ List pass-through pci devices for a domain. =back +=head1 USB PASS-THROUGH + +=over 4 + +=item B<usb-ctrl-attach> I<domain-id> I[<type=val>] [I<version=val>] [I<ports=number>] + +Create a new USB controller for the specified domain. +B<type=val> is the usb controller type, currently only support 'pv'. +B<version=val> is the usb controller version, could be 1 (USB1.1) or 2 (USB2.0). +B<ports=number> is the total ports of the usb controller. +By default, it will create a USB2.0 controller with 8 ports. + +=item B<usb-ctrl-detach> I<domain-id> I<devid> + +Destroy a USB controller from the specified domain. +B<devid> is devid of the USB controller. + +If B<-f> is specified, B<xl> is going to forcefully remove the device even +without guest's collaboration. + +=item B<usb-attach> I<domain-id> I<bus.addr> [I<controller=devid> [I<port=number>]] + +Hot-plug a new pass-through USB device to the specified domain. +B<bus.addr> is the busnum.devnum of the physical USB device to pass-through. +B<controller=devid> B<port=number> is the USB controller:port to hotplug the +USB device to. By default, it will find the first available controller:port +and use it; if there is no controller, it will create one. + +=item B<usb-detach> I<domain-id> I<controller=devid> I<port=number> + +Hot-unplug a previously assigned USB device from a domain. +B<controller=devid> and B<port=number> is USB controller:port in guest where the +USB device is attached to. + +=item B<usb-list> I<domain-id> + +List pass-through usb devices for a domain. + +=back + =head1 TMEM =over 4
tools/libxl/xl.h +5 -0
@@ -85,6 +85,11 @@ int main_blockdetach(int argc, char **argv);int main_vtpmattach (int argc,char **argv);int main_vtpmlist (int argc,char **argv);int main_vtpmdetach (int argc,char **argv); +int main_usbctrl_attach (int argc,char **argv); +int main_usbctrl_detach (int argc,char **argv); +int main_usbattach (int argc,char **argv); +int main_usbdetach (int argc,char **argv); +int main_usblist (int argc,char **argv);int main_uptime (int argc,char **argv);int main_claims (int argc,char **argv);int main_tmem_list (int argc,char **argv);
tools/libxl/xl_cmdimpl.c +232 -0
238 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +25 -0
@@ -551,6 +551,31 @@ struct cmd_spec cmd_table[] = { },#endif + {"usb-ctrl-attach" , + &main_usbctrl_attach,0 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [type=pv] [version=<version>] [ports=<number>]" , + }, + { "usb-ctrl-detach", + &main_usbctrl_detach,0 ,1 , +"Remove the virtual USB controller specified by <DevId> for a domain" , +"<Domain> <DevId>" , + }, + { "usb-attach", + &main_usbattach,0 ,1 , +"Attach a USB device to a domain" , +"<Domain> <bus.addr> [controller=<DevId> [port=<port>]]" , + }, + { "usb-detach", + &main_usbdetach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <controller> <port>" , + }, + { "usb-list", + &main_usblist,0 ,0 , +"List information about USB devices for a domain" , + "<Domain>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Signature · 1 line
2.1.4
Re: [PATCH V7 5/7] xl: add pvusb commands
Quoted 7 lines · Chunyan Liu
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_vmversion=1 num_ports=8
So all the way back in v2 of this series, I suggested making the arguments for usb-ctrl-attach and usb-attach mirror the format that is found in the config file[1], at which point you replied "That could be, I can update". But you didn't change the interface in v3, so I suggested it again[2], and there was no argument or discussion about it.
(There was a long back-and-forth with Juergen at that point about usb-assignable-list, so [2] may have gotten lost in the noise.)
I still think that's the best interface to use. Do you have reasons to favor the interface you propose here?
-George
[1] marc.info/?i=<CAFLBxZb1N3_9PVvg-yC8dyVaiySZVRA3H2e8496vHNEfvrm6Zg@mail.gmail.com>
[2] marc.info/?i=<CAFLBxZbJcdFi2cXOvQRncbdV0HBL73d8sjXKry+VaRjvkQtRwA@mail.gmail.com>
Quoted 372 lines
#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-attach
test_vm1.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_vm0 1
will detach USB device under controller 0 port 1.#xl usb-ctrl-detach
test_vmdev_id
will destroy the controller with specifieddev_id.Dev_idcan be traced in usb-list info.Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- docs/man/xl.pod.1 | 40 ++++++++ tools/libxl/xl.h | 5 + tools/libxl/xl_cmdimpl.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 25 +++++ 4 files changed, 302 insertions(+)docs/man/xl.pod.1 +40
-0@@ -1345,6 +1345,46 @@ List pass-through pci devices for a domain. =back +=head1 USB PASS-THROUGH + +=over 4 + +=item B<usb-ctrl-attach> I<domain-id> I[<type=val>] [I<version=val>] [I<ports=number>] + +Create a new USB controller for the specified domain. +B<type=val> is the usb controller type, currently only support 'pv'. +B<version=val> is the usb controller version, could be 1 (USB1.1) or 2 (USB2.0). +B<ports=number> is the total ports of the usb controller. +By default, it will create a USB2.0 controller with 8 ports. + +=item B<usb-ctrl-detach> I<domain-id> I<devid> + +Destroy a USB controller from the specified domain. +B<devid> is devid of the USB controller. + +If B<-f> is specified, B<xl> is going to forcefully remove the device even +without guest's collaboration. + +=item B<usb-attach> I<domain-id> I<bus.addr> [I<controller=devid> [I<port=number>]] + +Hot-plug a new pass-through USB device to the specified domain. +B<bus.addr> is the busnum.devnum of the physical USB device to pass-through. +B<controller=devid> B<port=number> is the USB controller:port to hotplug the +USB device to. By default, it will find the first available controller:port +and use it; if there is no controller, it will create one. + +=item B<usb-detach> I<domain-id> I<controller=devid> I<port=number> + +Hot-unplug a previously assigned USB device from a domain. +B<controller=devid> and B<port=number> is USB controller:port in guest where the +USB device is attached to. + +=item B<usb-list> I<domain-id> + +List pass-through usb devices for a domain. + +=back + =head1 TMEM =over 4tools/libxl/xl.h +5
-0@@ -85,6 +85,11 @@ int main_blockdetach(int argc, char **argv);int main_vtpmattach (int argc,char **argv);int main_vtpmlist (int argc,char **argv);int main_vtpmdetach (int argc,char **argv); +int main_usbctrl_attach (int argc,char **argv); +int main_usbctrl_detach (int argc,char **argv); +int main_usbattach (int argc,char **argv); +int main_usbdetach (int argc,char **argv); +int main_usblist (int argc,char **argv);int main_uptime (int argc,char **argv);int main_claims (int argc,char **argv);int main_tmem_list (int argc,char **argv);tools/libxl/xl_cmdimpl.c +232
-0@@ -3367,6 +3367,238 @@ int main_cd_insert(int argc, char **argv)return 0 ; } +int main_usbctrl_attach (int argc,char **argv) +{ +uint32_t domid; +int opt, rc =1 ; +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 ("type" , argv[optind], oparg)) { +if (!strcmp (oparg,"pv" )) { + usbctrl.type =LIBXL_USBCTRL_TYPE_PV ; + }else { +fprintf (stderr,"unsupported type `%s'\n" , oparg); + goto out; + } + }else if (MATCH_OPTION ("version" , argv[optind], oparg)) { + usbctrl.version =atoi (oparg); +if (usbctrl.version !=1 && usbctrl.version !=2 ) { +fprintf (stderr,"unsupported version `%s'\n" , oparg); + goto out; + } + }else if (MATCH_OPTION ("ports" , argv[optind], oparg)) { + usbctrl.ports =atoi (oparg); +if (usbctrl.ports <1 || usbctrl.ports >31 ) { +fprintf (stderr,"unsupported ports `%s'\n" , oparg); + goto out; + } + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); + goto out; + } + optind++; + } + + rc =libxl_device_usbctrl_add (ctx, domid, &usbctrl,0 ); +if (rc) +fprintf (stderr,"libxl_device_usbctrl_add failed.\n" ); + +out: +libxl_device_usbctrl_dispose (&usbctrl); +return rc; +} + +int main_usbctrl_detach (int argc,char **argv) +{ +uint32_t domid; +int opt, devid, rc; +libxl_device_usbctrl usbctrl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-ctrl-detach", 2) { +/* No options */ + } + + domid =find_domain (argv[optind]); + devid =atoi (argv[optind+1 ]); + +libxl_device_usbctrl_init (&usbctrl); +if (libxl_devid_to_device_usbctrl (ctx, domid, devid, &usbctrl)) { +fprintf (stderr,"Unknown device %s.\n" , argv[optind+1 ]); +return 1 ; + } + + rc =libxl_device_usbctrl_remove (ctx, domid, &usbctrl,0 ); +if (rc) +fprintf (stderr,"libxl_device_usbctrl_remove failed.\n" ); + +libxl_device_usbctrl_dispose (&usbctrl); +return rc; + +} + +int main_usbattach (int argc,char **argv) +{ +uint32_t domid; +char *devname, *p; +int opt, rc =1 ; +char *oparg; +libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) { +/* No options */ + } + +libxl_device_usb_init (&usb); + + domid =find_domain (argv[optind++]); + devname = argv[optind++]; + p =strchr (devname,'.' ); +if (p) { + usb.u.hostdev.hostbus =strtoul (devname,NULL ,0 ); + usb.u.hostdev.hostaddr =strtoul (p +1 ,NULL ,0 ); + } + +if (usb.u.hostdev.hostbus <1 || usb.u.hostdev.hostaddr <1 ) { +fprintf (stderr,"Invalid usb device.\n" ); + goto out; + } + +while (argc > optind) { +if (MATCH_OPTION ("controller" , argv[optind], oparg)) { + usb.ctrl =atoi (oparg); + }else if (MATCH_OPTION ("port" , argv[optind], oparg)) { + usb.port =atoi (oparg); + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); + goto out; + } + optind++; + } + + rc =libxl_device_usb_add (ctx, domid, &usb,0 ); +if (rc) +fprintf (stderr,"libxl_device_usb_add failed.\n" ); + +out: +libxl_device_usb_dispose (&usb); +return rc; +} + +int main_usbdetach (int argc,char **argv) +{ +uint32_t domid; +int ctrl, port; +int opt, rc =1 ; +libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 3) { +/* No options */ + } + + domid =find_domain (argv[optind]); + ctrl =atoi (argv[optind+1 ]); + port =atoi (argv[optind+2 ]); + +if (argc - optind >3 ) { +fprintf (stderr,"Invalid arguments.\n" ); + goto out; + } + +libxl_device_usb_init (&usb); +if (libxl_ctrlport_to_device_usb (ctx, domid, ctrl, port, &usb)) { +fprintf (stderr,"Unknown device at controller %d port %d.\n" , + ctrl, port); + goto out; + } + + rc =libxl_device_usb_remove (ctx, domid, &usb,0 ); +if (rc) +fprintf (stderr,"libxl_device_usb_remove failed.\n" ); + +out: +libxl_device_usb_dispose (&usb); +return rc; +} + +int main_usblist (int argc,char **argv) +{ +uint32_t domid; +libxl_device_usbctrl *usbctrls; +libxl_usbctrlinfo usbctrlinfo; +int numctrl, i, j, opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-list", 1) { +/* No options */ + } + + domid =find_domain (argv[optind++]); + +if (argc > optind) { +fprintf (stderr,"Invalid arguments.\n" ); +exit (-1 ); + } + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &numctrl); +if (!usbctrls) { +return 0 ; + } + +for (i =0 ; i < numctrl; ++i) { +printf ("%-6s %-6s %-3s %-5s %-7s %-5s %-30s\n" , +"Devid" ,"Type" ,"BE" ,"state" ,"usb-ver" ,"ports" ,"BE-path" ); + +libxl_usbctrlinfo_init (&usbctrlinfo); + +if (!libxl_device_usbctrl_getinfo (ctx, domid, + &usbctrls[i], &usbctrlinfo)) { +printf ("%-6d %-6s %-3d %-5d %-7d %-5d %-30s\n" , + usbctrlinfo.devid, +libxl_usbctrl_type_to_string (usbctrlinfo.type), + usbctrlinfo.backend_id, usbctrlinfo.state, + usbctrlinfo.version, usbctrlinfo.ports, + usbctrlinfo.backend); + +for (j =1 ; j <= usbctrlinfo.ports; j++) { +libxl_device_usb usb; +libxl_usbinfo usbinfo; + +libxl_device_usb_init (&usb); +libxl_usbinfo_init (&usbinfo); + +printf (" Port %d:" , j); + + usb.ctrl = usbctrlinfo.devid; + usb.port = j; +if (!libxl_device_usb_getinfo (ctx, domid, &usb, &usbinfo)) { +printf (" Bus %03x Device %03x: ID %04x:%04x %s %s\n" , + usbinfo.busnum, usbinfo.devnum, + usbinfo.idVendor, usbinfo.idProduct, + usbinfo.manuf ?:"" , usbinfo.prod ?:"" ); + }else { +printf ("\n" ); + } +libxl_usbinfo_dispose (&usbinfo); +libxl_device_usb_dispose (&usb); + } + } + +libxl_usbctrlinfo_dispose (&usbctrlinfo); + } + +libxl_device_usbctrl_list_free (usbctrls, numctrl); +return 0 ; +} +int main_console (int argc,char **argv) {uint32_t domid;tools/libxl/xl_cmdtable.c +25
-0@@ -551,6 +551,31 @@ struct cmd_spec cmd_table[] = { },#endif + {"usb-ctrl-attach" , + &main_usbctrl_attach,0 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [type=pv] [version=<version>] [ports=<number>]" , + }, + { "usb-ctrl-detach", + &main_usbctrl_detach,0 ,1 , +"Remove the virtual USB controller specified by <DevId> for a domain" , +"<Domain> <DevId>" , + }, + { "usb-attach", + &main_usbattach,0 ,1 , +"Attach a USB device to a domain" , +"<Domain> <bus.addr> [controller=<DevId> [port=<port>]]" , + }, + { "usb-detach", + &main_usbdetach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <controller> <port>" , + }, + { "usb-list", + &main_usblist,0 ,0 , +"List information about USB devices for a domain" , + "<Domain>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Re: [PATCH V7 5/7] xl: add pvusb commands
Quoted 9 lines · George Dunlap
Quoted 7 lines · Chunyan Liu
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_vmversion=1 num_ports=8
Quoted 7 lines
So all the way back in v2 of this series, I suggested making the arguments for usb-ctrl-attach and usb-attach mirror the format that is found in the config file[1]
[...]
[1]
marc.info/?i=< CAFLBxZb1N3_9PVvg-yC8dyVaiySZVRA3H2e8496vHNEfvrm6Zg@mail.gmail.com>
Re: xl usb-ctrl-attach test_vm name=pv-1,type=pv,version=1,ports=8
FWIW I think most of the existing ones allow (but don't require) a slight difference in the cli version, which is that they allow space spearated lists as well as command separate, which ends up a bit more natural:
xl usb-ctrl-attach test_vm name=pv-1 type=pv version=1 ports=8
I also agree that we should try and do something similar here unless there is a compelling reason we can't.
Ian.
Re: [PATCH V7 5/7] xl: add pvusb commands
Quoted 20 lines · Ian Campbell
Quoted 9 lines · George Dunlap
Quoted 7 lines · Chunyan Liu
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_vmversion=1 num_ports=8Quoted 7 lines
So all the way back in v2 of this series, I suggested making the arguments for usb-ctrl-attach and usb-attach mirror the format that is found in the config file[1]
[...]
[1]
marc.info/?i=< CAFLBxZb1N3_9PVvg-yC8dyVaiySZVRA3H2e8496vHNEfvrm6Zg@mail.gmail.com>Re: xl usb-ctrl-attach
test_vmname=pv-1,type=pv,version=1,ports=8
Quoted 8 lines
FWIW I think most of the existing ones allow (but don't require) a slight difference in the cli version, which is that they allow space spearated lists as well as command separate, which ends up a bit more natural:
xl usb-ctrl-attach
test_vmname=pv-1 type=pv version=1 ports=8I also agree that we should try and do something similar here unless there is a compelling reason we can't.
I didn't realize that. +1
-George
Re: [PATCH V7 5/7] xl: add pvusb commands
Quoted 23 lines · George Dunlap
Quoted 21 lines · Ian Campbell
Quoted 9 lines · George Dunlap
Quoted 7 lines · Chunyan Liu
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_vmversion=1 num_ports=8Quoted 8 lines
So all the way back in v2 of this series, I suggested making the arguments for usb-ctrl-attach and usb-attach mirror the format that is
found in the config file[1]
[...]
[1]
marc.info/?i=< CAFLBxZb1N3_9PVvg-yC8dyVaiySZVRA3H2e8496vHNEfvrm6Zg@mail.gmail.com>Re: xl usb-ctrl-attach
test_vmname=pv-1,type=pv,version=1,ports=8
Quoted 7 lines
Quoted 7 lines
FWIW I think most of the existing ones allow (but don't require) a slight
difference in the cli version, which is that they allow space spearated lists as well as command separate, which ends up a bit more natural:xl usb-ctrl-attach
test_vmname=pv-1 type=pv version=1 ports=8
[...]
BTW this is generally pretty easy to arrange, You have a helper:
parse_foo(const char *s, libxl_foo *foo)
which takes a comma separate list "s" and _incremntally_ updates the object "foo" which it was given.
Then when parsing the cfg file you call parse_foo on the string and when parsing the command line you call parse_foo for every argv (with the same object).
See e.g. parse_nic_config in xl_cmdimpl.c.
Disk does it a bit differently with parse_disk_config and parse_disk_config_multistring, where the latter effectively incorporates the loop over argv.
Ian.
Re: [PATCH V7 5/7] xl: add pvusb commands
In reply to George DunlapQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 10/2/2015 at 01:02 AM, in message <[email protected]>, George
Quoted 15 lines · Dunlap
Quoted 7 lines · Chunyan Liu
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_vmversion=1 num_ports=8So all the way back in v2 of this series, I suggested making the arguments for usb-ctrl-attach and usb-attach mirror the format that is found in the config file[1], at which point you replied "That could be, I can update". But you didn't change the interface in v3, so I suggested it again[2], and there was no argument or discussion about it.
Quoted 5 lines
(There was a long back-and-forth with Juergen at that point about usb-assignable-list, so [2] may have gotten lost in the noise.)
I still think that's the best interface to use. Do you have reasons to favor the interface you propose here?
Sorry for replying late, just back from holiday.
It's my fault not updating it, missing that after a lot of other changes, not favor this or that. Thanks for reminding again.
- Chunyan
Quoted 391 lines
-George
[1] marc.info/?i=<[email protected] om>
[2] marc.info/?i=<[email protected]. com>
Quoted 16 lines
#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-attach
test_vm1.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_vm0 1
will detach USB device under controller 0 port 1.#xl usb-ctrl-detach
test_vmdev_id
will destroy the controller with specifieddev_id.Dev_idcan be traced in usb-list info.Quoted 6 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>---
docs/man/xl.pod.1 | 40 ++++++++ tools/libxl/xl.h | 5 + tools/libxl/xl_cmdimpl.c | 232++++++++++++++++++++++++++++++++++++++++++++++
Quoted 10 lines
tools/libxl/xl_cmdtable.c | 25 +++++ 4 files changed, 302 insertions(+)docs/man/xl.pod.1 +0
-0@@ -1345,6 +1345,46 @@ List pass-through pci devices for a domain. =backdocs/man/xl.pod.1 List pass-through pci devices for a domain. · line 1356
Quoted 10 lines
docs/man/xl.pod.1 +9
-0+=head1 USB PASS-THROUGH + +=over 4 + +=item B<usb-ctrl-attach> I<domain-id> I[<type=val>] [I<version=val>] [I<ports=number>] + +Create a new USB controller for the specified domain. +B<type=val> is the usb controller type, currently only support 'pv'. +B<version=val> is the usb controller version, could be 1 (USB1.1) or 2(USB2.0).
Quoted 7 lines
docs/man/xl.pod.1 +7
-0+B<ports=number> is the total ports of the usb controller. +By default, it will create a USB2.0 controller with 8 ports. + +=item B<usb-ctrl-detach> I<domain-id> I<devid> + +Destroy a USB controller from the specified domain. +B<devid> is devid of the USB controller.docs/man/xl.pod.1 List pass-through pci devices for a domain.
Quoted 10 lines
docs/man/xl.pod.1 +10
-0+ +If B<-f> is specified, B<xl> is going to forcefully remove the device even +without guest's collaboration. + +=item B<usb-attach> I<domain-id> I<bus.addr> [I<controller=devid> [I<port=number>]] + +Hot-plug a new pass-through USB device to the specified domain. +B<bus.addr> is the busnum.devnum of the physical USB device to pass-through. +B<controller=devid> B<port=number> is the USB controller:port to hotplug the +USB device to. By default, it will find the first availablecontroller:port
docs/man/xl.pod.1 List pass-through pci devices for a domain.
Quoted 6 lines
docs/man/xl.pod.1 +6
-0+and use it; if there is no controller, it will create one. + +=item B<usb-detach> I<domain-id> I<controller=devid> I<port=number> + +Hot-unplug a previously assigned USB device from a domain. +B<controller=devid> and B<port=number> is USB controller:port in guest wherethe
Quoted 214 lines
docs/man/xl.pod.1 +8
-0+USB device is attached to. + +=item B<usb-list> I<domain-id> + +List pass-through usb devices for a domain. + +=back + =head1 TMEM =over 4tools/libxl/xl.h +5
-0@@ -85,6 +85,11 @@ int main_blockdetach(int argc, char **argv);int main_vtpmattach (int argc,char **argv);int main_vtpmlist (int argc,char **argv);int main_vtpmdetach (int argc,char **argv); +int main_usbctrl_attach (int argc,char **argv); +int main_usbctrl_detach (int argc,char **argv); +int main_usbattach (int argc,char **argv); +int main_usbdetach (int argc,char **argv); +int main_usblist (int argc,char **argv);int main_uptime (int argc,char **argv);int main_claims (int argc,char **argv);int main_tmem_list (int argc,char **argv);tools/libxl/xl_cmdimpl.c +179
-0@@ -3367,6 +3367,238 @@ int main_cd_insert(int argc, char **argv)return 0 ; } +int main_usbctrl_attach (int argc,char **argv) +{ +uint32_t domid; +int opt, rc =1 ; +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 ("type" , argv[optind], oparg)) { +if (!strcmp (oparg,"pv" )) { + usbctrl.type =LIBXL_USBCTRL_TYPE_PV ; + }else { +fprintf (stderr,"unsupported type `%s'\n" , oparg); + goto out; + } + }else if (MATCH_OPTION ("version" , argv[optind], oparg)) { + usbctrl.version =atoi (oparg); +if (usbctrl.version !=1 && usbctrl.version !=2 ) { +fprintf (stderr,"unsupported version `%s'\n" , oparg); + goto out; + } + }else if (MATCH_OPTION ("ports" , argv[optind], oparg)) { + usbctrl.ports =atoi (oparg); +if (usbctrl.ports <1 || usbctrl.ports >31 ) { +fprintf (stderr,"unsupported ports `%s'\n" , oparg); + goto out; + } + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); + goto out; + } + optind++; + } + + rc =libxl_device_usbctrl_add (ctx, domid, &usbctrl,0 ); +if (rc) +fprintf (stderr,"libxl_device_usbctrl_add failed.\n" ); + +out: +libxl_device_usbctrl_dispose (&usbctrl); +return rc; +} + +int main_usbctrl_detach (int argc,char **argv) +{ +uint32_t domid; +int opt, devid, rc; +libxl_device_usbctrl usbctrl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-ctrl-detach", 2) { +/* No options */ + } + + domid =find_domain (argv[optind]); + devid =atoi (argv[optind+1 ]); + +libxl_device_usbctrl_init (&usbctrl); +if (libxl_devid_to_device_usbctrl (ctx, domid, devid, &usbctrl)) { +fprintf (stderr,"Unknown device %s.\n" , argv[optind+1 ]); +return 1 ; + } + + rc =libxl_device_usbctrl_remove (ctx, domid, &usbctrl,0 ); +if (rc) +fprintf (stderr,"libxl_device_usbctrl_remove failed.\n" ); + +libxl_device_usbctrl_dispose (&usbctrl); +return rc; + +} + +int main_usbattach (int argc,char **argv) +{ +uint32_t domid; +char *devname, *p; +int opt, rc =1 ; +char *oparg; +libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) { +/* No options */ + } + +libxl_device_usb_init (&usb); + + domid =find_domain (argv[optind++]); + devname = argv[optind++]; + p =strchr (devname,'.' ); +if (p) { + usb.u.hostdev.hostbus =strtoul (devname,NULL ,0 ); + usb.u.hostdev.hostaddr =strtoul (p +1 ,NULL ,0 ); + } + +if (usb.u.hostdev.hostbus <1 || usb.u.hostdev.hostaddr <1 ) { +fprintf (stderr,"Invalid usb device.\n" ); + goto out; + } + +while (argc > optind) { +if (MATCH_OPTION ("controller" , argv[optind], oparg)) { + usb.ctrl =atoi (oparg); + }else if (MATCH_OPTION ("port" , argv[optind], oparg)) { + usb.port =atoi (oparg); + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); + goto out; + } + optind++; + } + + rc =libxl_device_usb_add (ctx, domid, &usb,0 ); +if (rc) +fprintf (stderr,"libxl_device_usb_add failed.\n" ); + +out: +libxl_device_usb_dispose (&usb); +return rc; +} + +int main_usbdetach (int argc,char **argv) +{ +uint32_t domid; +int ctrl, port; +int opt, rc =1 ; +libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 3) { +/* No options */ + } + + domid =find_domain (argv[optind]); + ctrl =atoi (argv[optind+1 ]); + port =atoi (argv[optind+2 ]); + +if (argc - optind >3 ) { +fprintf (stderr,"Invalid arguments.\n" ); + goto out; + } + +libxl_device_usb_init (&usb); +if (libxl_ctrlport_to_device_usb (ctx, domid, ctrl, port, &usb)) { +fprintf (stderr,"Unknown device at controller %d port %d.\n" , + ctrl, port); + goto out; + } + + rc =libxl_device_usb_remove (ctx, domid, &usb,0 ); +if (rc) +fprintf (stderr,"libxl_device_usb_remove failed.\n" ); + +out: +libxl_device_usb_dispose (&usb); +return rc; +} + +int main_usblist (int argc,char **argv) +{ +uint32_t domid; +libxl_device_usbctrl *usbctrls; +libxl_usbctrlinfo usbctrlinfo; +int numctrl, i, j, opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-list", 1) { +/* No options */ + } + + domid =find_domain (argv[optind++]); + +if (argc > optind) { +fprintf (stderr,"Invalid arguments.\n" ); +exit (-1 );tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3558
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+ } + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &numctrl); +if (!usbctrls) { +return 0 ; + } + +for (i =0 ; i < numctrl; ++i) { + printf("%-6s %-6s %-3s %-5s %-7s %-5s %-30s\n", + "Devid", "Type", "BE", "state", "usb-ver", "ports","BE-path");
Quoted 83 lines
tools/libxl/xl_cmdimpl.c +43
-0+ +libxl_usbctrlinfo_init (&usbctrlinfo); + +if (!libxl_device_usbctrl_getinfo (ctx, domid, + &usbctrls[i], &usbctrlinfo)) { +printf ("%-6d %-6s %-3d %-5d %-7d %-5d %-30s\n" , + usbctrlinfo.devid, +libxl_usbctrl_type_to_string (usbctrlinfo.type), + usbctrlinfo.backend_id, usbctrlinfo.state, + usbctrlinfo.version, usbctrlinfo.ports, + usbctrlinfo.backend); + +for (j =1 ; j <= usbctrlinfo.ports; j++) { +libxl_device_usb usb; +libxl_usbinfo usbinfo; + +libxl_device_usb_init (&usb); +libxl_usbinfo_init (&usbinfo); + +printf (" Port %d:" , j); + + usb.ctrl = usbctrlinfo.devid; + usb.port = j; +if (!libxl_device_usb_getinfo (ctx, domid, &usb, &usbinfo)) { +printf (" Bus %03x Device %03x: ID %04x:%04x %s %s\n" , + usbinfo.busnum, usbinfo.devnum, + usbinfo.idVendor, usbinfo.idProduct, + usbinfo.manuf ?:"" , usbinfo.prod ?:"" ); + }else { +printf ("\n" ); + } +libxl_usbinfo_dispose (&usbinfo); +libxl_device_usb_dispose (&usb); + } + } + +libxl_usbctrlinfo_dispose (&usbctrlinfo); + } + +libxl_device_usbctrl_list_free (usbctrls, numctrl); +return 0 ; +} +int main_console (int argc,char **argv) {uint32_t domid;tools/libxl/xl_cmdtable.c +25
-0@@ -551,6 +551,31 @@ struct cmd_spec cmd_table[] = { },#endif + {"usb-ctrl-attach" , + &main_usbctrl_attach,0 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [type=pv] [version=<version>] [ports=<number>]" , + }, + { "usb-ctrl-detach", + &main_usbctrl_detach,0 ,1 , +"Remove the virtual USB controller specified by <DevId> for a domain" , +"<Domain> <DevId>" , + }, + { "usb-attach", + &main_usbattach,0 ,1 , +"Attach a USB device to a domain" , +"<Domain> <bus.addr> [controller=<DevId> [port=<port>]]" , + }, + { "usb-detach", + &main_usbdetach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <controller> <port>" , + }, + { "usb-list", + &main_usblist,0 ,0 , +"List information about USB devices for a domain" , + "<Domain>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH v7 6/7 xl: add usb-assignable-list command
In reply to Chunyan LiuAdd xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
---
Same as "libxl: add libxl_device_usb_assignable_list API" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.
tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 27 +++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 4 ++++ 3 files changed, 32 insertions(+)
tools/libxl/xl.h +1 -0
@@ -85,6 +85,7 @@ int main_blockdetach(int argc, char **argv);int main_vtpmattach (int argc,char **argv);int main_vtpmlist (int argc,char **argv);int main_vtpmdetach (int argc,char **argv); +int main_usbassignable_list (int argc,char **argv);int main_usbctrl_attach (int argc,char **argv);int main_usbctrl_detach (int argc,char **argv);int main_usbattach (int argc,char **argv);
tools/libxl/xl_cmdimpl.c +27 -0
@@ -3367,6 +3367,33 @@ int main_cd_insert(int argc, char **argv)return 0 ; } +static void usb_assignable_list (void ) +{ +libxl_device_usb *usbs; +int num, i; + + usbs =libxl_device_usb_assignable_list (ctx, &num); + +for (i =0 ; i < num; i++) { +printf ("%d.%d\n" , usbs[i].u.hostdev.hostbus, + usbs[i].u.hostdev.hostaddr); + } + +libxl_device_usb_list_free (usbs, num); +} + +int main_usbassignable_list (int argc,char **argv) +{ +int opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-assignable-list", 0) { +/* No options */ + } + +usb_assignable_list (); +return 0 ; +} +int main_usbctrl_attach (int argc,char **argv) {uint32_t domid;
tools/libxl/xl_cmdtable.c +4 -0
@@ -576,6 +576,10 @@ struct cmd_spec cmd_table[] = { "List information about USB devices for a domain", "<Domain>", }, + { "usb-assignable-list", + &main_usbassignable_list, 0, 0, + "List all assignable USB devices", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Signature · 1 line
2.1.4
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
This command will list all USB devices in dom0 that are not assigned to VMs.
Juergen and I had a long back-and-forth about it around v3. I thought having slightly different semantics might be confusing, and Juergen thought the functionality was important to include. We didn't really come to a conclusion and none of the tools maintainers expressed an opinion.
I don't feel like arguing about it anymore, so I won't oppose the naming; but I think whoever gives final approval should at least be aware of the slight functional difference between {pci,usb}-assignable-list.
Other than that, the patch looks good to me.
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 13 lines · George Dunlap
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.
Quoted 4 lines
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".
OOI how does xl pci-assignable-list compare to xm pci-assignable-list.
Quoted 6 lines
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
Quoted 8 lines
This command will list all USB devices in dom0 that are not assigned to VMs.
Juergen and I had a long back-and-forth about it around v3. I thought having slightly different semantics might be confusing, and Juergen thought the functionality was important to include. We didn't really come to a conclusion and none of the tools maintainers expressed an opinion.
TBH I couldn't follow precisely what that discussion was about, so thanks for your summary. IMHO you both make good points.
However given that xend was now removed 2 releases ago I think the time for strictly mimicking xm behaviour purely for the sake of that compatibility/transition has passed.
Obviously if the xm interface was fine we shouldn't deviate from it just to be contrary, but similarly if the xm interface was bad in some way or doesn't fit in with the direction xl has taken since the two coexisted then we shouldn't feel bound to follow xm.
In this case and at this point in time I think I find the argument that xl subcommands should, where possible, behave similarly to each other more compelling than they should match their xm counterparts. (maybe if we'd been aware of it we would have implemented pci-assignable-list differently, but that ship has sailed).
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
However I think --all/full/host is an optional extra.
/me wonders if xl ought to adjust it's behaviour in various ways when called with $0==xm.
/me beats himself with sticks.
Ian.
Quoted 1 line
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 14 lines · Ian Campbell
Quoted 13 lines · George Dunlap
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.
Quoted 12 lines
Quoted 4 lines
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".OOI how does xl pci-assignable-list compare to xm pci-assignable-list.
Quoted 5 lines
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
Assigning a PCI device to pciback is a necessary step to be able to attach it to a domain.
Quoted 2 lines
Quoted 2 lines
This command will list all USB devices in dom0 that are not assigned to VMs.
Attaching a USB device to a domain works by detaching it from it's normal driver and attaching it to the pvUSB backend. And this backend is per domain (qemu), so it's not possible to prepare this step by attaching the device to "the" pvUSB backend.
And just detaching the device from it's driver is no solution either, as the driver can grab it again at any time, as all drivers are queried for all unassigned devices when a new USB device shows up.
And you'd need another command to move a USB-device to the assignable state.
Quoted 18 lines
Quoted 5 lines
Juergen and I had a long back-and-forth about it around v3. I thought having slightly different semantics might be confusing, and Juergen thought the functionality was important to include. We didn't really come to a conclusion and none of the tools maintainers expressed an opinion.
TBH I couldn't follow precisely what that discussion was about, so thanks for your summary. IMHO you both make good points.
However given that xend was now removed 2 releases ago I think the time for strictly mimicking xm behaviour purely for the sake of that compatibility/transition has passed.
Obviously if the xm interface was fine we shouldn't deviate from it just to be contrary, but similarly if the xm interface was bad in some way or doesn't fit in with the direction xl has taken since the two coexisted then we shouldn't feel bound to follow xm.
Quoted 8 lines
In this case and at this point in time I think I find the argument that xl subcommands should, where possible, behave similarly to each other more compelling than they should match their xm counterparts. (maybe if we'd been aware of it we would have implemented pci-assignable-list differently, but that ship has sailed).
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
As stated above: this will have weird consequences or you need some kind of placeholder backend just for this functionality. Is this really worth the effort?
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 31 lines · Juergen Gross
Quoted 14 lines · Ian Campbell
Quoted 13 lines · George Dunlap
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.Quoted 12 lines
Quoted 4 lines
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".OOI how does xl pci-assignable-list compare to xm pci-assignable-list.
Quoted 5 lines
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
Assigning a PCI device to pciback is a necessary step to be able to attach it to a domain.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
This command will list all USB devices in dom0 that are not assigned to
VMs.Attaching a USB device to a domain works by detaching it from it's normal driver and attaching it to the pvUSB backend. And this backend is per domain (qemu), so it's not possible to prepare this step by attaching the device to "the" pvUSB backend.
Thanks, this is useful information which wasn't in the summary and which gives me cause to reconsider.
Quoted 4 lines
[...]
As stated above: this will have weird consequences or you need some kind of placeholder backend just for this functionality. Is this really worth the effort?
Right. I don't think we want to invent some sort of usb placeholder backend just for the sake of having this command work.
So it seems the question is not so much "should xl usb-assignable-list behave like xl pci-assignable-list or not" but it is rather "what is usb -assignable-list useful for which isn't covered by lsusb and the xl commands for listing attached devices".
What are the intended semantics for xl usb-assignable-list wrt devices which are currently attached to domains?
Ian.
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Ian CampbellQuoted 14 lines · Ian Campbell
Quoted 13 lines · George Dunlap
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.
Quoted 6 lines
Quoted 4 lines
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".OOI how does xl pci-assignable-list compare to xm pci-assignable-list.
xm doesn't have such a command -- more on that below.
Quoted 28 lines
Quoted 7 lines
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
Quoted 8 lines
This command will list all USB devices in dom0 that are not assigned to VMs.
Juergen and I had a long back-and-forth about it around v3. I thought having slightly different semantics might be confusing, and Juergen thought the functionality was important to include. We didn't really come to a conclusion and none of the tools maintainers expressed an opinion.
TBH I couldn't follow precisely what that discussion was about, so thanks for your summary. IMHO you both make good points.
However given that xend was now removed 2 releases ago I think the time for strictly mimicking xm behaviour purely for the sake of that compatibility/transition has passed.
Obviously if the xm interface was fine we shouldn't deviate from it just to be contrary, but similarly if the xm interface was bad in some way or doesn't fit in with the direction xl has taken since the two coexisted then we shouldn't feel bound to follow xm.
Quoted 8 lines
In this case and at this point in time I think I find the argument that xl subcommands should, where possible, behave similarly to each other more compelling than they should match their xm counterparts. (maybe if we'd been aware of it we would have implemented pci-assignable-list differently, but that ship has sailed).
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
I don't think that's really suitable.
Let me try to add in a little more detail (trying to keep it as concise as possible).
In both pci and usb, devices in dom0 will begin assigned to the normal device driver for the device. In order to assign a device to a guest via the PV protocol, the device needs to be detached from its normal driver and assigned to {pci,usb}back.
In USB, this has always been done in one step as part of the
assignment: when you did "xm usb-attach", xm expected the device to be assigned to the normal driver; it would then detach it from the current driver, attach it to usbback, and then assign it to the guest. The "xl usb-attach" Chunyan has submitted behaves the same way.
In PCI, this has always been done in two steps. In xm, there was no way *with xm* to detach the device from the current driver and attach it to pciback: you had to either set kernel parameters so that the device was assigned to pciback at boot, or manually frob around with sysfs nodes. "xm pci-attach" expected the device to already be assigned to pciback; it would then assign it to the guest. "xl pci-attach" behaves the same way.
To avoid the user having to manually frob around with sysfs nodes, I made it possible for xl to do it instaed. But rather than make "xl pci-attach" do everything, I left it in two steps; and the state of being attached to pciback but not yet assigned to a VM I called "assignable". So for pci devices, you can use "lspci" to find the device you want, then use "pci-assignable-add" to detach it from the current driver and attach it to pciback, and then "pci-attach" to assign it to a VM. "pci-assignable-list" will give you the pci devices currently in this "assignable" state. (I wasn't aware of "xm usb-assignable-list" when I came up with that command.)
There is also an option, "seize", which will do the whole thing at once in "pci-attach"; this is off by default.
The reason I left the two-stage thing for pci devices was that I was afraid that setting "seize=1" by default would be too dangerous: it would be to easy for a missed keystroke or a typo to bring down the system.
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Quoted 7 lines
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 4 lines · George Dunlap
The reason I left the two-stage thing for pci devices was that I was afraid that setting "seize=1" by default would be too dangerous: it would be to easy for a missed keystroke or a typo to bring down the system.
And as I've said before, "present me" isn't sure he really agrees with "past me" anymore; if I were to implement this again, I think I might well just make pci-attach behave like usb-attach, and get rid of the whole "assignable" state altogether.
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to George DunlapQuoted 116 lines · George Dunlap
Quoted 14 lines · Ian Campbell
Quoted 13 lines · George Dunlap
Quoted 11 lines · Chunyan Liu
Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.
Signed-off-by Chunyan Liu <[email protected]>---
Same as "libxl: addlibxl_device_usb_assignable_listAPI" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.Quoted 6 lines
Quoted 4 lines
I think it's worth pointing out to other reviewers that the "usb-assignable-list" command introduced here:
1. Has identical behavior to "xm usb-assignable-list", but
2. Has different behavior than "xl pci-assignable-list".OOI how does xl pci-assignable-list compare to xm pci-assignable-list.
xm doesn't have such a command -- more on that below.
Quoted 28 lines
Quoted 7 lines
Namely:
xl pci-assignable-list will list PCI devices which have been detached from their normal driver and have been assigned to pciback (in preparation for being attached to a domain).
Quoted 8 lines
This command will list all USB devices in dom0 that are not assigned to VMs.
Juergen and I had a long back-and-forth about it around v3. I thought having slightly different semantics might be confusing, and Juergen thought the functionality was important to include. We didn't really come to a conclusion and none of the tools maintainers expressed an opinion.
TBH I couldn't follow precisely what that discussion was about, so thanks for your summary. IMHO you both make good points.
However given that xend was now removed 2 releases ago I think the time for strictly mimicking xm behaviour purely for the sake of that compatibility/transition has passed.
Obviously if the xm interface was fine we shouldn't deviate from it just to be contrary, but similarly if the xm interface was bad in some way or doesn't fit in with the direction xl has taken since the two coexisted then we shouldn't feel bound to follow xm.
Quoted 8 lines
In this case and at this point in time I think I find the argument that xl subcommands should, where possible, behave similarly to each other more compelling than they should match their xm counterparts. (maybe if we'd been aware of it we would have implemented pci-assignable-list differently, but that ship has sailed).
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
I don't think that's really suitable.
Let me try to add in a little more detail (trying to keep it as concise as possible).
In both pci and usb, devices in dom0 will begin assigned to the normal device driver for the device. In order to assign a device to a guest via the PV protocol, the device needs to be detached from its normal driver and assigned to {pci,usb}back.
In USB, this has always been done in one step as part of the
assignment: when you did "xm usb-attach", xm expected the device to be assigned to the normal driver; it would then detach it from the current driver, attach it to usbback, and then assign it to the guest. The "xl usb-attach" Chunyan has submitted behaves the same way.In PCI, this has always been done in two steps. In xm, there was no way *with xm* to detach the device from the current driver and attach it to pciback: you had to either set kernel parameters so that the device was assigned to pciback at boot, or manually frob around with sysfs nodes. "xm pci-attach" expected the device to already be assigned to pciback; it would then assign it to the guest. "xl pci-attach" behaves the same way.
To avoid the user having to manually frob around with sysfs nodes, I made it possible for xl to do it instaed. But rather than make "xl pci-attach" do everything, I left it in two steps; and the state of being attached to pciback but not yet assigned to a VM I called "assignable". So for pci devices, you can use "lspci" to find the device you want, then use "pci-assignable-add" to detach it from the current driver and attach it to pciback, and then "pci-attach" to assign it to a VM. "pci-assignable-list" will give you the pci devices currently in this "assignable" state. (I wasn't aware of "xm usb-assignable-list" when I came up with that command.)
There is also an option, "seize", which will do the whole thing at once in "pci-attach"; this is off by default.
The reason I left the two-stage thing for pci devices was that I was afraid that setting "seize=1" by default would be too dangerous: it would be to easy for a missed keystroke or a typo to bring down the system.
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Quoted 6 lines
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
Quoted 7 lines
Quoted 1 line
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
The main information I'd like to have at my hands is a way to see which USB devices are available for being attached to a domain. The command should list the devices in a way that all information related to the planned use is contained in the output:
- the parameter needed for attaching the device to a domain
- a way to identify the device (e.g. something like the lsusb output)
If this done via an own command or an option of xl usb-list I don't care.
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to George DunlapQuoted 4 lines · George Dunlap
Quoted 2 lines
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
I don't think that's really suitable.
Then I'm terribly confused because I thought that is what you were initially advocating.
[...]
Quoted 5 lines
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Thanks. Jeurgen has also explained this.
Do you agree that adding a dummy usbback driver just for the purposes of adding this extra "assignable" state doesn't make sense?
Quoted 6 lines
Quoted 6 lines
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
Quoted 7 lines
Quoted 1 line
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
If there is no assignable state in usb then I guess I don't really understand what usb-list-assignable would even be for, so I don't really understand why anyone is arguing what semantics it should have (my initial reply was predicated on this state existing and it therefore being useful to discuss how the command should behave).
Given that doing something with usb-list seems most plausible _if_ we need some sort of thing like that at all.
What would "usb-list --all" add over and above using lsusb?
I take it that as things stand in patch #5:
# xl usb-list <vm>
will list the usb devices attached to <vm> and that:
# xl usb-list
will list the usb devices attached to every vm, is that
correct?So the idea would then be to add some way of listing the devices not included in "xl usb-list", which are notionally attached to dom0, but via physical USB and not PV usb.
Ian.
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 9 lines · Ian Campbell
Quoted 4 lines · George Dunlap
Quoted 2 lines
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
I don't think that's really suitable.
Then I'm terribly confused because I thought that is what you were initially advocating.
I think in v3 I was trying to come up with a different name (usb-available-list or something); but my main point was that it *shouldn't* be named similarly but have different functionality.
As I said, for this am I was ready to just let it slide; I just wanted to make sure other people knew what was being let slide. :-)
Quoted 9 lines
[...]
Quoted 5 lines
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Quoted 4 lines
Thanks. Jeurgen has also explained this.
Do you agree that adding a dummy usbback driver just for the purposes of adding this extra "assignable" state doesn't make sense?
Yes, I agree.
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
Quoted 7 lines
Quoted 1 line
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
If there is no assignable state in usb then I guess I don't really understand what usb-list-assignable would even be for, so I don't really understand why anyone is arguing what semantics it should have (my initial reply was predicated on this state existing and it therefore being useful to discuss how the command should behave).
Given that doing something with usb-list seems most plausible _if_ we need some sort of thing like that at all.
What would "usb-list --all" add over and above using lsusb?
Quoted 8 lines
I take it that as things stand in patch #5:
# xl usb-list <vm> will list the usb devices attached to <vm> and that: # xl usb-list will list the usb devices attached to every vm, is that correct?So the idea would then be to add some way of listing the devices not included in "xl usb-list", which are notionally attached to dom0, but via physical USB and not PV usb.
The "usb-assignable-list" that Chunyan has submitted will give you a list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it filters
out devices which have already been assigned to VMs.
In the e-mail you respond to, I was suggesting that
# xl usb-list --all
would show you usb devices attached to every VM, and also USB devices attached to no VM, and that
# xl usb-list --host
would show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be available in some form or other.
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 80 lines · George Dunlap
Quoted 9 lines · Ian Campbell
Quoted 4 lines · George Dunlap
Quoted 2 lines
So IMHO xl usb-assignable-list should behave like pci-assignable-list by default.
I don't think that's really suitable.
Then I'm terribly confused because I thought that is what you were initially advocating.
I think in v3 I was trying to come up with a different name (usb-available-list or something); but my main point was that it *shouldn't* be named similarly but have different functionality.
As I said, for this am I was ready to just let it slide; I just wanted to make sure other people knew what was being let slide. :-)
Quoted 9 lines
[...]
Quoted 5 lines
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Quoted 4 lines
Thanks. Jeurgen has also explained this.
Do you agree that adding a dummy usbback driver just for the purposes of adding this extra "assignable" state doesn't make sense?
Yes, I agree.
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
Now, maybe it should also support some sort of --all or --full or --host option which lists everything, ideally with some indication as to whether they are attached to usbback or not and using syntax which can just be cut -and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).
Quoted 7 lines
Quoted 1 line
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
If there is no assignable state in usb then I guess I don't really understand what usb-list-assignable would even be for, so I don't really understand why anyone is arguing what semantics it should have (my initial reply was predicated on this state existing and it therefore being useful to discuss how the command should behave).
Given that doing something with usb-list seems most plausible _if_ we need some sort of thing like that at all.
What would "usb-list --all" add over and above using lsusb?
Quoted 8 lines
I take it that as things stand in patch #5:
# xl usb-list <vm> will list the usb devices attached to <vm> and that: # xl usb-list will list the usb devices attached to every vm, is that correct?So the idea would then be to add some way of listing the devices not included in "xl usb-list", which are notionally attached to dom0, but via physical USB and not PV usb.
The "usb-assignable-list" that Chunyan has submitted will give you a list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it filters
out devices which have already been assigned to VMs.In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices attached to no VM, and that
Quoted 6 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be available in some form or other.
Exactly.
BTW: I've explained that in another reply, but my mail client has chosen to send it via another account - I've no idea how that happened. So now my wife has some xen-devel history as well. ;-)
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 94 lines · Juergen Gross
Quoted 93 lines · George Dunlap
Quoted 10 lines · Ian Campbell
Quoted 5 lines · George Dunlap
Quoted 3 lines
So IMHO xl usb-assignable-list should behave like
pci-assignable-list by
default.I don't think that's really suitable.
Then I'm terribly confused because I thought that is what you were initially advocating.
I think in v3 I was trying to come up with a different name (usb-available-list or something); but my main point was that it *shouldn't* be named similarly but have different functionality.
As I said, for this am I was ready to just let it slide; I just wanted to make sure other people knew what was being let slide. :-)
Quoted 9 lines
[...]
Quoted 5 lines
For USB, there is no "assignable" stage -- "usb-attach" will take it all the way from being assigned to a driver to being assigned to the guest. (You can think of this as pci-attach with "seize=1" always.) So making "usb-assignable-list" act like "pci-assignable-list" doesn't actually make any sense.
Quoted 4 lines
Thanks. Jeurgen has also explained this.
Do you agree that adding a dummy usbback driver just for the purposes of adding this extra "assignable" state doesn't make sense?
Yes, I agree.
Quoted 38 lines
Quoted 9 lines
Quoted 9 lines
Now, maybe it should also support some sort of --all or --full or --host
option which lists everything, ideally with some indication as to whether
they are attached to usbback or not and using syntax which can just be cut
-and-pasted into a cfg file (without at least one of those it's just a pointless reimplementation of lsusb).Quoted 7 lines
Quoted 1 line
However I think --all/full/host is an optional extra.
Juergen suggested having "usb-list" have an --all option in the v3 discussion. If like me you're concerned about confusing people, then having --all and --host is probably the best option.
Thoughts?
If there is no assignable state in usb then I guess I don't really understand what usb-list-assignable would even be for, so I don't really understand why anyone is arguing what semantics it should have (my initial
reply was predicated on this state existing and it therefore being useful
to discuss how the command should behave).Given that doing something with usb-list seems most plausible _if_ we need
some sort of thing like that at all.What would "usb-list --all" add over and above using lsusb?
I take it that as things stand in patch #5:
# xl usb-list <vm> will list the usb devices attached to <vm> and that: # xl usb-list will list the usb devices attached to every vm, is that correct?Quoted 3 lines
So the idea would then be to add some way of listing the devices not included in "xl usb-list", which are notionally attached to dom0, but via physical USB and not PV usb.
The "usb-assignable-list" that Chunyan has submitted will give you a list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it filters
out devices which have already been assigned to VMs.In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices attached to no VM, and that
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
Quoted 8 lines
Quoted 2 lines
I think it's the second bit if functionality which Juergen is keen be available in some form or other.
Exactly.
BTW: I've explained that in another reply, but my mail client has chosen to send it via another account - I've no idea how that happened. So now my wife has some xen-devel history as well. ;-)
Oh, right -- I wondered where "Christiane" came from. I just figured it was an alternate name you used sometimes (like maybe Juergen was your middle name but the one you normally went by). :-)
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Juergen GrossQuoted 3 lines · Juergen Gross
BTW: I've explained that in another reply, but my mail client has chosen to send it via another account - I've no idea how that happened. So now my wife has some xen-devel history as well. ;-)
It's stuck in moderation (I suppose) and I think I have rights to cancel it if you would like to resend as yourself ;-).
Ian.
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 8 lines · Ian Campbell
Quoted 3 lines · Juergen Gross
BTW: I've explained that in another reply, but my mail client has chosen to send it via another account - I've no idea how that happened. So now my wife has some xen-devel history as well. ;-)
It's stuck in moderation (I suppose) and I think I have rights to cancel it if you would like to resend as yourself ;-).
Too late. Otherwise I wouldn't have noticed it.
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Ian CampbellQuoted 10 lines · Ian Campbell
Quoted 4 lines · Juergen Gross
BTW: I've explained that in another reply, but my mail client has chosen
to send it via another account - I've no idea how that happened. So now my wife has some xen-devel history as well. ;-)It's stuck in moderation (I suppose) and I think I have rights to cancel it
if you would like to resend as yourself ;-).
Scratch that, it's already on the list I just didn't even notice...
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Juergen GrossQuoted 4 lines · Juergen Gross
Quoted 4 lines
The "usb-assignable-list" that Chunyan has submitted will give you a list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it filters
out devices which have already been assigned to VMs.
Right, that does sound like useful enough functionality to justify not just using lsusb.
Quoted 6 lines
Quoted 6 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices attached to no VM, and that
And would "xl usb-list" list all domain attached to every VM but not the unattached ones?
Quoted 8 lines
Quoted 6 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be available in some form or other.
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Ian.
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 26 lines · Ian Campbell
Quoted 4 lines · Juergen Gross
Quoted 4 lines
The "usb-assignable-list" that Chunyan has submitted will give you a list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not just using lsusb.
Quoted 6 lines
Quoted 6 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices attached to no VM, and that
And would "xl usb-list" list all domain attached to every VM but not the unattached ones?
Quoted 7 lines
Quoted 6 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be available in some form or other.
Quoted 7 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 42 lines · Juergen Gross
Quoted 33 lines · Ian Campbell
Quoted 7 lines · Juergen Gross
Quoted 7 lines
The "usb-assignable-list" that Chunyan has submitted will give you a
list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it
filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not just
using lsusb.Quoted 7 lines
Quoted 7 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices
attached to no VM, and thatAnd would "xl usb-list" list all domain attached to every VM but not the
unattached ones?Quoted 8 lines
Quoted 7 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be
available in some form or other.Quoted 7 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Quoted 6 lines
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
Makes sense.
Quoted 3 lines
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
I think "xl usb-list" should list the devices attached to all domains, for sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.
Ian.
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 52 lines · Ian Campbell
Quoted 42 lines · Juergen Gross
Quoted 33 lines · Ian Campbell
Quoted 7 lines · Juergen Gross
Quoted 7 lines
The "usb-assignable-list" that Chunyan has submitted will give you a
list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it
filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not just
using lsusb.Quoted 7 lines
Quoted 7 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices
attached to no VM, and thatAnd would "xl usb-list" list all domain attached to every VM but not the
unattached ones?Quoted 8 lines
Quoted 7 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be
available in some form or other.Quoted 7 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Quoted 6 lines
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
Makes sense.
Quoted 7 lines
Quoted 3 lines
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
I think "xl usb-list" should list the devices attached to all domains, for sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.
I'd go for nuking the --all option. I suppose xl usb-list without specifying a domain will nearly always be used to see the unassigned devices and not "uuh, to which domain did I assign device x?".
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 8 lines · Juergen Gross
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Juergen Gross
BTW: In case you don't have the --host option it would be nice to omit
--all as well and just assume --all when no domain was specified (like
xl list).
Quoted 8 lines
Quoted 4 lines
I think "xl usb-list" should list the devices attached to all domains, for
sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.I'd go for nuking the --all option. I suppose xl usb-list without specifying a domain will nearly always be used to see the unassigned devices and not "uuh, to which domain did I assign device x?".
I think that is probably true.
Ian
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Juergen GrossQuoted 57 lines · Juergen Gross
Quoted 56 lines · Ian Campbell
Quoted 42 lines · Juergen Gross
Quoted 33 lines · Ian Campbell
Quoted 7 lines · Juergen Gross
Quoted 7 lines
The "usb-assignable-list" that Chunyan has submitted will give you a
list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it
filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not just
using lsusb.Quoted 7 lines
Quoted 7 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices
attached to no VM, and thatAnd would "xl usb-list" list all domain attached to every VM but not the
unattached ones?Quoted 8 lines
Quoted 7 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be
available in some form or other.Quoted 7 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Quoted 6 lines
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
Makes sense.
Quoted 3 lines
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
Quoted 8 lines
Quoted 4 lines
I think "xl usb-list" should list the devices attached to all domains, for
sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.I'd go for nuking the --all option. I suppose xl usb-list without specifying a domain will nearly always be used to see the unassigned devices and not "uuh, to which domain did I assign device x?".
I don't know -- if you've assigned a device to one particular domain, then it seems pretty likely that at some point in the future you might want to say, "Wait, what devices do I have assigned where again?"
I think
* people will expect "xl usb-list" to show all VMs but *not* all unassigned host devices
* In this sort of a case, doing what people expect is probably more important than doing what we think is probably more convenient for them.
I'd go for "--all" and "--host", but I think it's not terribly important.
Chunyan, do you have any input / opinions?
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 71 lines · George Dunlap
Quoted 57 lines · Juergen Gross
Quoted 56 lines · Ian Campbell
Quoted 42 lines · Juergen Gross
Quoted 33 lines · Ian Campbell
Quoted 7 lines · Juergen Gross
Quoted 7 lines
The "usb-assignable-list" that Chunyan has submitted will give you a
list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it
filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not just
using lsusb.Quoted 7 lines
Quoted 7 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices
attached to no VM, and thatAnd would "xl usb-list" list all domain attached to every VM but not the
unattached ones?Quoted 8 lines
Quoted 7 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be
available in some form or other.Quoted 7 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming unassigned devices are clearly indicated in the --all output (as they should be).
Quoted 6 lines
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
Makes sense.
Quoted 3 lines
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
Quoted 8 lines
Quoted 4 lines
I think "xl usb-list" should list the devices attached to all domains, for
sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.I'd go for nuking the --all option. I suppose xl usb-list without specifying a domain will nearly always be used to see the unassigned devices and not "uuh, to which domain did I assign device x?".
I don't know -- if you've assigned a device to one particular domain, then it seems pretty likely that at some point in the future you might want to say, "Wait, what devices do I have assigned where again?"
Quoted 5 lines
I think
* people will expect "xl usb-list" to show all VMs but *not* all unassigned host devices
* In this sort of a case, doing what people expect is probably more important than doing what we think is probably more convenient for them.
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
"xl usb-list 0" would be the same then as "xl usb-list --host". "xl usb-list" would be the same as "xl usb-list --all".
Just a thought - I'm fine with either variant.
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 2 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
I think you'd at least want to distinguish USB devices available to dom0 as via a PCI host controller from those which are available via pvusb.
This also doesn't quite work when driver domains are in the picture.
Quoted 8 lines
"xl usb-list 0" would be the same then as "xl usb-list --host". "xl usb-list" would be the same as "xl usb-list --all".
Just a thought - I'm fine with either variant.
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
I think you'd at least want to distinguish USB devices available to dom0 as via a PCI host controller from those which are available via pvusb.
Yeah, the non-pvusb devices should be listed as "assignable" if they are handled by a driver domain.
Quoted 1 line
This also doesn't quite work when driver domains are in the picture.
--host does?
TBH: driver domains seem to be a reason to not support the --host option. So the options are --all or no special option. I'm still fine with both.
BTW: Do Xen concepts allow to assign a USB-device via pvUSB from a driver domain to Dom0?
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 16 lines · Juergen Gross
Quoted 10 lines · Ian Campbell
Quoted 2 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
I think you'd at least want to distinguish USB devices available to dom0 as
via a PCI host controller from those which are available via pvusb.Yeah, the non-pvusb devices should be listed as "assignable" if they are handled by a driver domain.
Quoted 8 lines
Quoted 1 line
This also doesn't quite work when driver domains are in the picture.
--host does?
TBH: driver domains seem to be a reason to not support the --host option. So the options are --all or no special option. I'm still fine with both.
I think the idea is that --host doesn't pretend to. But yes, if we made it clear which devices were *assigned* to dom0 from another VM, and which were *available from* dom0 to be assigned, then actually that could be extended at some point in the future to include devices available *from* driver domains.
Alternately, perhaps we should just have
# xl usb-available [domain]
Which will tell you the usb devices available to be assigned from that domain; or all available usb devices from all driver domains. And of course for the time being it only works on domain 0, but future functionality could implement it for driver domains as well.
Quoted 2 lines
BTW: Do Xen concepts allow to assign a USB-device via pvUSB from a driver domain to Dom0?
Sure, why not?
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 26 lines · George Dunlap
Quoted 16 lines · Juergen Gross
Quoted 10 lines · Ian Campbell
Quoted 2 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
I think you'd at least want to distinguish USB devices available to dom0 as
via a PCI host controller from those which are available via pvusb.Yeah, the non-pvusb devices should be listed as "assignable" if they are handled by a driver domain.
Quoted 8 lines
Quoted 1 line
This also doesn't quite work when driver domains are in the picture.
--host does?
TBH: driver domains seem to be a reason to not support the --host option. So the options are --all or no special option. I'm still fine with both.
Quoted 8 lines
I think the idea is that --host doesn't pretend to. But yes, if we made it clear which devices were *assigned* to dom0 from another VM, and which were *available from* dom0 to be assigned, then actually that could be extended at some point in the future to include devices available *from* driver domains.
Alternately, perhaps we should just have
# xl usb-available [domain]
Would work for me.
Wait, wasn't there a similar command suggested? Something like "xl usb-assignable-list"? ;-)
Quoted 9 lines
Which will tell you the usb devices available to be assigned from that domain; or all available usb devices from all driver domains. And of course for the time being it only works on domain 0, but future functionality could implement it for driver domains as well.
Quoted 2 lines
BTW: Do Xen concepts allow to assign a USB-device via pvUSB from a driver domain to Dom0?
Sure, why not?
With driver domains the picture is becoming more complicated.
The main question now is: What is the real purpose of "xl usb-list"? Should it list the devices which are assigned to a domain, or should it list the devices which are usable by a domain (probably attributed whether the device is assignable to other domains)?
I think I'll always use the --all option in case this variant will be chosen.
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 35 lines · Juergen Gross
Quoted 34 lines · George Dunlap
Quoted 18 lines · Juergen Gross
Quoted 8 lines · Ian Campbell
Quoted 3 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why
not list them there.Quoted 4 lines
I think you'd at least want to distinguish USB devices available to dom0
as
via a PCI host controller from those which are available via pvusb.Yeah, the non-pvusb devices should be listed as "assignable" if they are handled by a driver domain.
Quoted 8 lines
Quoted 1 line
This also doesn't quite work when driver domains are in the picture.
--host does?
TBH: driver domains seem to be a reason to not support the --host option. So the options are --all or no special option. I'm still fine with both.
I think the idea is that --host doesn't pretend to. But yes, if we made it clear which devices were *assigned* to dom0 from another VM, and which were *available from* dom0 to be assigned, then actually that could be extended at some point in the future to include devices available *from* driver domains.
Quoted 7 lines
Quoted 2 lines
Alternately, perhaps we should just have
# xl usb-available [domain]Would work for me.
Wait, wasn't there a similar command suggested? Something like "xl usb-assignable-list"? ;-)
Indeed there was! A very useful command with a very sensible name... unfortunately one with a very *similar* name to another command but with different functionality. And this similarity even confused one of the tools maintainers, so would almost certainly confuse our users. :-)
Quoted 8 lines
Quoted 8 lines
Which will tell you the usb devices available to be assigned from that domain; or all available usb devices from all driver domains. And of course for the time being it only works on domain 0, but future functionality could implement it for driver domains as well.
Quoted 2 lines
BTW: Do Xen concepts allow to assign a USB-device via pvUSB from a driver domain to Dom0?
Quoted 8 lines
Quoted 1 line
Sure, why not?
With driver domains the picture is becoming more complicated.
The main question now is: What is the real purpose of "xl usb-list"? Should it list the devices which are assigned to a domain, or should it list the devices which are usable by a domain (probably attributed whether the device is assignable to other domains)?
For *all* of our other -list commands relating to guest devices -- pci-list, disk-list, network-list, vtpm-list, channel-list, tmem-list -- the list command shows the virtual devices *actually assigned to the
VM*. Based on that, the core information that any user will *expect*
from "usb-list" will be "what usb devices are assigned to this VM".
I'm not opposed to extending usb-list to include extra useful information; but it should be made clear to the user which information is the "core expected" information (i.e., what usb devices are assigned to this VM) and what is "extra" information (i.e., what usb devices are available to be assigned *from* this VM).
So I think we have 3 options that people don't find objectionable:
1. Add --all and --host options to usb-list. (Or perhaps, --available.)
2. Have usb-list also list "available" devices from driver domains, clearly marked distinct from devices *assigned to* that driver domain from another domain, and to begin with only working for dom0.
3. A new command, "usb-available" to list available devices from driver domains, to begin with only working for dom0.
I think I'd go for #3, but mostly I think we need to decide *something* so we can move forward.
-George
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
Quoted 86 lines · George Dunlap
Quoted 35 lines · Juergen Gross
Quoted 34 lines · George Dunlap
Quoted 18 lines · Juergen Gross
Quoted 8 lines · Ian Campbell
Quoted 3 lines · Juergen Gross
Hmm, technically all unassigned USB-devices are usable from Dom0. So why
not list them there.Quoted 4 lines
I think you'd at least want to distinguish USB devices available to dom0
as
via a PCI host controller from those which are available via pvusb.Yeah, the non-pvusb devices should be listed as "assignable" if they are handled by a driver domain.
Quoted 8 lines
Quoted 1 line
This also doesn't quite work when driver domains are in the picture.
--host does?
TBH: driver domains seem to be a reason to not support the --host option. So the options are --all or no special option. I'm still fine with both.
I think the idea is that --host doesn't pretend to. But yes, if we made it clear which devices were *assigned* to dom0 from another VM, and which were *available from* dom0 to be assigned, then actually that could be extended at some point in the future to include devices available *from* driver domains.
Quoted 7 lines
Quoted 2 lines
Alternately, perhaps we should just have
# xl usb-available [domain]Would work for me.
Wait, wasn't there a similar command suggested? Something like "xl usb-assignable-list"? ;-)
Indeed there was! A very useful command with a very sensible name... unfortunately one with a very *similar* name to another command but with different functionality. And this similarity even confused one of the tools maintainers, so would almost certainly confuse our users. :-)
Quoted 8 lines
Quoted 8 lines
Which will tell you the usb devices available to be assigned from that domain; or all available usb devices from all driver domains. And of course for the time being it only works on domain 0, but future functionality could implement it for driver domains as well.
Quoted 2 lines
BTW: Do Xen concepts allow to assign a USB-device via pvUSB from a driver domain to Dom0?
Quoted 8 lines
Quoted 1 line
Sure, why not?
With driver domains the picture is becoming more complicated.
The main question now is: What is the real purpose of "xl usb-list"? Should it list the devices which are assigned to a domain, or should it list the devices which are usable by a domain (probably attributed whether the device is assignable to other domains)?
For *all* of our other -list commands relating to guest devices -- pci-list, disk-list, network-list, vtpm-list, channel-list, tmem-list -- the list command shows the virtual devices *actually assigned to the
VM*. Based on that, the core information that any user will *expect*
from "usb-list" will be "what usb devices are assigned to this VM".I'm not opposed to extending usb-list to include extra useful information; but it should be made clear to the user which information is the "core expected" information (i.e., what usb devices are assigned to this VM) and what is "extra" information (i.e., what usb devices are available to be assigned *from* this VM).
So I think we have 3 options that people don't find objectionable:
1. Add --all and --host options to usb-list. (Or perhaps, --available.)
2. Have usb-list also list "available" devices from driver domains, clearly marked distinct from devices *assigned to* that driver domain from another domain, and to begin with only working for dom0.
Quoted 5 lines
3. A new command, "usb-available" to list available devices from driver domains, to begin with only working for dom0.
I think I'd go for #3, but mostly I think we need to decide *something* so we can move forward.
+1 for both. :-)
Juergen
Re: [PATCH V7 6/7] xl: add usb-assignable-list command
In reply to Juergen GrossQuoted 80 lines · Juergen Gross
Quoted 73 lines · George Dunlap
Quoted 59 lines · Juergen Gross
Quoted 58 lines · Ian Campbell
Quoted 44 lines · Juergen Gross
Quoted 34 lines · Ian Campbell
Quoted 7 lines · Juergen Gross
Quoted 7 lines
The "usb-assignable-list" that Chunyan has submitted will give you a
list of all dom0 USB devices that have not yet been assigned to a guest.
It should be basically equivalent to "lsusb", except that it
filters
out devices which have already been assigned to VMs.Right, that does sound like useful enough functionality to justify not
just
using lsusb.Quoted 7 lines
Quoted 7 lines
In the e-mail you respond to, I was suggesting that
# xl usb-list --allwould show you usb devices attached to every VM, and also USB devices
attached to no VM, and thatAnd would "xl usb-list" list all domain attached to every VM but not the
unattached ones?Quoted 8 lines
Quoted 7 lines
# xl usb-list --hostwould show you only host usb devices not attached to any VM.
I think it's the second bit if functionality which Juergen is keen be
available in some form or other.Quoted 8 lines
Quoted 1 line
Exactly.
I'm happy with this proposal too.
Is the distinction between --host and --all important to you? Assuming
unassigned devices are clearly indicated in the --all output (as they should be).Quoted 6 lines
Depends on how the output would look like.
In case it either isn't containing VMs without any attached USB device or the unassigned devices are listed at the end this would be okay. I just wouldn't want to have to scroll a lot in case of a host with 1000 domains.
Makes sense.
Quoted 3 lines
BTW: In case you don't have the --host option it would be nice to omit --all as well and just assume --all when no domain was specified (like xl list).
Quoted 8 lines
Quoted 4 lines
I think "xl usb-list" should list the devices attached to all domains, for
sure. I'm ambivalent about whether it also lists unattached devices (in which case --all is unnecessary) or if --all is required to get those.I'd go for nuking the --all option. I suppose xl usb-list without specifying a domain will nearly always be used to see the unassigned devices and not "uuh, to which domain did I assign device x?".
I don't know -- if you've assigned a device to one particular domain, then it seems pretty likely that at some point in the future you might want to say, "Wait, what devices do I have assigned where again?"
Quoted 5 lines
I think
* people will expect "xl usb-list" to show all VMs but *not* all unassigned host devices
* In this sort of a case, doing what people expect is probably more important than doing what we think is probably more convenient for them.
Quoted 7 lines
Hmm, technically all unassigned USB-devices are usable from Dom0. So why not list them there.
"xl usb-list 0" would be the same then as "xl usb-list --host". "xl usb-list" would be the same as "xl usb-list --all".
Just a thought - I'm fine with either variant.
Haha -- well, I guess that's one way of looking at it. :-)
dom0 is different from the others, however, in that "xl pci-attach" will automatically remove it from dom0 and give it to another VM. If that was true for all domains, I'd be on board with it. And of course it doesn't work for driver domains.
-George
PATCH v7 7/7 domcreate: support pvusb in configuration file
In reply to Chunyan LiuAdd code to support pvusb in domain config file. One could specify usbctrl and usb in domain's configuration file and create domain, then usb controllers will be created and usb device would be attached to guest automatically.
One could specify usb controllers and usb devices in config file like this:
usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['2.1,controller=0,port=1', ]
--- docs/man/xl.cfg.pod.5 | 75 +++++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 73 ++++++++++++++++++++++++++++-- tools/libxl/libxl_device.c | 4 ++ tools/libxl/libxl_internal.h | 8 ++++ tools/libxl/xl_cmdimpl.c | 105 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 261 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5 +75 -0
@@ -716,6 +716,81 @@ Note this may be overridden by rdm_policy option in PCI device configuration. =back +=item B<usbctrl=[ "USBCTRL_SPEC_STRING", "USBCTRL_SPEC_STRING", ... ]> + +Specifies the USB controllers created for this guest. Each +B<USB_SPEC_STRING> has the form C<KEY=VALUE,KEY=VALUE,...> where: + +=over 4 + +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<type=TYPE> + +Specifies the protocol to implement USB controller, could be "pv" (indicates +PVUSB) or "qemu" (indicates QEMU emulated). Currently only "pv" is supported. + +=item B<version=VERSION> + +Specifies version of the USB controller, could be 1 (USB1.1) or 2 (USB2.0). +Default is 2 (USB2.0). + +=item B<ports=PORTS> + +Specifies port number of the USB controller. Default is 8. + +Each USB controller will have an index starting from 0. On the same +controller, each port will have an index starting from 1. + +E.g. +usbctrl=["version=1,ports=4", "version=2,ports=8",] +The first controller has: +controller index = 0, and port 1,2,3,4. +The second controller has: +controller index = 1, and port 1,2,3,4,5,6,7,8. + +=back + +=back + +=item B<usbdev=[ "USB_SPEC_STRING", "USB_SPEC_STRING", ... ]> + +Specifies the host USB devices to passthrough to this guest. Each +B<USB_SPEC_STRING> has the form C<bus.addr,KEY=VALUE,KEY=VALUE,...> where: + +=over 4 + +=item B<bus.addr> + +Identifies the busnum.devnum of the USB device from the host perspective. +This is the same scheme as used in the output of C<lsusb> for the device in +question. + +=item B<KEY=VALUE> + +Possible B<KEY>s are: + +=over 4 + +=item B<controller=CONTROLLER> + +Specifies USB controller index, to which controller the USB device is attached. + +=item B<port=PORT> + +Specifies USB port index, to which port the USB device is attached. B<port=PORT> +is valid only when B<controller=CONTROLLER> is specified. Without +B<controller=CONTROLLER>, it will find the first available USB controller:port +and use it. If there is no controller at all, it will create one. + +=back + +=back + =item B<pci=[ "PCI_SPEC_STRING", "PCI_SPEC_STRING", ... ]> Specifies the host PCI devices to passthrough to this guest. Each B<PCI_SPEC_STRING>
tools/libxl/libxl_create.c +70 -3
102 lines not on this page · raw message
tools/libxl/libxl_device.c +4 -0
@@ -544,6 +544,8 @@ void libxl__multidev_prepared(libxl__egc *egc,* libxl__add_disks * libxl__add_nics * libxl__add_vtpms +* libxl__add_usbctrls +* libxl__add_usbs */ #define DEFINE_DEVICES_ADD (type) \
@@ -563,6 +565,8 @@ void libxl__multidev_prepared(libxl__egc *egc, DEFINE_DEVICES_ADD(disk) DEFINE_DEVICES_ADD(nic) DEFINE_DEVICES_ADD(vtpm) +DEFINE_DEVICES_ADD(usbctrl) +DEFINE_DEVICES_ADD(usb) #undef DEFINE_DEVICES_ADD
tools/libxl/libxl_internal.h +8 -0
@@ -3296,6 +3296,14 @@ _hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev); +_hidden void libxl__add_usbctrls(libxl__egc *egc, libxl__ao *ao, +uint32_t domid,libxl_domain_config *d_config, +libxl__multidev *multidev); + +_hidden void libxl__add_usbs(libxl__egc *egc, libxl__ao *ao, +uint32_t domid,libxl_domain_config *d_config, +libxl__multidev *multidev); +/*----- device model creation -----*/ /* First layer; wraps libxl__spawn_spawn. */
tools/libxl/xl_cmdimpl.c +104 -1
123 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH V7 7/7] domcreate: support pvusb in configuration file
Quoted 9 lines · Chunyan Liu
Add code to support pvusb in domain config file. One could specify usbctrl and usb in domain's configuration file and create domain, then usb controllers will be created and usb device would be attached to guest automatically.
One could specify usb controllers and usb devices in config file like this:
usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['2.1,controller=0,port=1', ]
I realize you're patterning this after pci, but this syntax assumes that you're always going to want to pass in a host device, which I think we don't want to do. In particular, we want to leave the door open in the future to different ways of being able to specify a particular device based on the pci + usb topology which will be invariant over reboots.
So I think all parameters should have a name.
Two questions; first, the name of the parameter specifying hostbus and hostaddr.
1. "hostspec=", which will automatically use 2.1 for bus.addr, and could in the future be extended to use 2-1 for bus-port, xxxx:yyyy for vendorid:productid, and potentially the udev "pci + usb topology" thing.
2. hostbus=x, hostaddr=y. This is what qemu and libvirt do. It also leaves open the door for adding double-checks or other constraints:
e.g., hostbus=x, hostaddr=y, hostvid=m, hostpid=n would only assign x.y if vendorid:productid match m:n
I'd go for #2.
We should also have a "type" field, of which one option should be "hostdev". I think it's probably OK to assume "hostdev" if we have hostdev-only parameters.
One more comment...
Quoted 16 lines
/* First layer; wraps
libxl__spawn_spawn. */tools/libxl/xl_cmdimpl.c +7
-0@@ -1253,6 +1253,79 @@ static void parse_vnuma_config(const XLU_Config *config,free (vcpu_parsed); } +static void parse_usbctrl_config (libxl_device_usbctrl *usbctrl, +const char *buf) +{ +char *buf2 =strdup (buf); +char *p, *p2; + + p =strtok (buf2,"," );
tools/libxl/xl_cmdimpl.c static void parse_vnuma_config(const XLU_Config *config, · line 1272
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+if (!p) + goto out; + do { + while (*p == ' ') + p++; + if ((p2 = strchr(p, '=')) == NULL) + break; + *p2 = '\0'; + if (!strcmp(p, "type")) { + if (!strcmp(p2 + 1, "pv")) {
I'd probably do "*p2='\0'; p2++" so that then later you can just use p2 as a normal string, rather than p2+1 as you do here.
But what I'd *really* do is copy the parse_nic_config() code, and use MATCH_STRING("type", ...).
And as Ian said, I'd move these parsing functions into the previous patch, and then use them to parse the command-line arguments (again modelled after main_networkattach()).
(I'm not confident in the multidev stuff enough to give a proper review.)
-George