xen pvusb toolstack work
v13 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 V12:
* update error handlings in libxl pvusb API (patch 3/5)
* adjust order of patch 4/5 and 5/5, and in 5/5, reuse documentation generated in 4/5.
V12:
http://lists.xen.org/archives/html/xen-devel/2015-12/msg02697.html
V11:
http://lists.xen.org/archives/html/xen-devel/2015-12/msg01626.html
V10:
http://lists.xen.org/archives/html/xen-devel/2015-12/msg01172.html
V9:
http://lists.xen.org/archives/html/xen-devel/2015-11/msg02744.html
V8:
http://lists.xen.org/archives/html/xen-devel/2015-10/msg02178.html
V7:
http://lists.xen.org/archives/html/xen-devel/2015-09/msg03115.html
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.
*** BLURB HERE ***
Chunyan Liu (5):
libxl: export some functions for pvusb use
libxl_utils: add internal function to read sysfs file contents
libxl: add pvusb API
domcreate: support pvusb in configuration file
xl: add pvusb commands
docs/man/xl.cfg.pod.5 | 84 ++ docs/man/xl.pod.1 | 35 + tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 39 +- tools/libxl/libxl.h | 77 ++ tools/libxl/libxl_create.c | 73 +- tools/libxl/libxl_device.c | 17 +- tools/libxl/libxl_internal.h | 37 +- tools/libxl/libxl_osdeps.h | 13 + tools/libxl/libxl_pvusb.c | 1565 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 46 + tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.c | 92 ++ tools/libxl/libxl_utils.h | 5 + tools/libxl/xl.h | 5 + tools/libxl/xl_cmdimpl.c | 297 ++++++- tools/libxl/xl_cmdtable.c | 25 + 17 files changed, 2393 insertions(+), 20 deletions(-) create mode 100644 tools/libxl/libxl_pvusb.c
Signature · 1 line
2.1.4
PATCH v13 1/5 libxl: export some functions for pvusb use
--- tools/libxl/libxl.c | 5 ++--- tools/libxl/libxl_internal.h | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +2 -3
@@ -2036,7 +2036,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;
@@ -2055,8 +2055,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, -uint32_t *domid) +int libxl__resolve_domid (libxl__gc *gc,const char *name,uint32_t *domid) {if (!name)return 0 ;
tools/libxl/libxl_internal.h +3 -0
@@ -1176,6 +1176,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 v13 2/5 libxl_utils: add internal function to read sysfs file contents
In reply to Chunyan LiuAdd a new function libxl_read_sysfs_file_contents to handle sysfs file specially. It would be used in later pvusb work.
--- tools/libxl/libxl_internal.h | 4 +++ tools/libxl/libxl_utils.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
tools/libxl/libxl_internal.h +4 -0
@@ -4039,6 +4039,10 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,int libxl__count_physical_sockets (libxl__gc *gc,int *sockets); +_hidden int libxl__read_sysfs_file_contents(libxl__gc *gc, +const char *filename, +void **data_r, +int *datalen_r);#define LIBXL_QEMU_USER_PREFIX "xen-qemuuser"#define LIBXL_QEMU_USER_BASE LIBXL_QEMU_USER_PREFIX"-domid"
tools/libxl/libxl_utils.c +74 -0
80 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v13 3/5 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 controller and usb devices
- some other helper functions
---
changes:
* address error handlings
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 34 +- tools/libxl/libxl.h | 77 ++ tools/libxl/libxl_device.c | 13 +- tools/libxl/libxl_internal.h | 22 +- tools/libxl/libxl_osdeps.h | 13 + tools/libxl/libxl_pvusb.c | 1567 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 46 + tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.c | 18 + tools/libxl/libxl_utils.h | 5 + 11 files changed, 1785 insertions(+), 13 deletions(-) create mode 100644 tools/libxl/libxl_pvusb.c
tools/libxl/Makefile +1 -1
@@ -104,7 +104,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 +29 -5
@@ -3204,7 +3204,7 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc, aodev->dev = device; aodev->callback = local_device_detach_cb; aodev->force =0 ; -libxl__initiate_device_remove (egc, aodev); +libxl__initiate_device_generic_remove (egc, aodev);return ; }
@@ -4172,8 +4172,10 @@ out:* libxl_device_vkb_destroy * libxl_device_vfb_remove * libxl_device_vfb_destroy +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy */ -#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ +#define DEFINE_DEVICE_REMOVE_EXT (type, remtype, removedestroy, f) \ int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ uint32_t domid, libxl_device_##type *type, \ const libxl_asyncop_how *ao_how) \
@@ -4193,13 +4195,19 @@ out: aodev->dev = device; \ aodev->callback = device_addrm_aocomplete; \ aodev->force = f; \ -libxl__initiate_device_remove (egc, aodev); \ + libxl__initiate_device_##remtype##_remove(egc, aodev); \ \ out: \ -if (rc)return AO_CREATE_FAIL (rc); \ +if (rc)return AO_CREATE_FAIL (rc); \return AO_INPROGRESS ; \ } +#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f) + +#define DEFINE_DEVICE_REMOVE_CUSTOM (type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, type, removedestroy, f) +/* Define all remove/destroy functions and undef the macro */ /* disk */
@@ -4223,6 +4231,10 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1) DEFINE_DEVICE_REMOVE(vtpm, remove, 0)DEFINE_DEVICE_REMOVE (vtpm, destroy,1 ) +/* usbctrl */ +DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0) +DEFINE_DEVICE_REMOVE_CUSTOM (usbctrl, destroy,1 ) +/* channel/console hotunplug is not implemented. There are 2 possibilities: * 1. add support for secondary consoles to xenconsoled * 2. dynamically add/remove qemu chardevs via qmp messages. */
@@ -4236,6 +4248,8 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)* libxl_device_disk_add * libxl_device_nic_add * libxl_device_vtpm_add +* libxl_device_usbctrl_add +* libxl_device_usbdev_add */ #define DEFINE_DEVICE_ADD (type) \
@@ -4267,6 +4281,12 @@ DEFINE_DEVICE_ADD(nic)/* vtpm */ DEFINE_DEVICE_ADD(vtpm) +/* usbctrl */ +DEFINE_DEVICE_ADD(usbctrl) + +/* usb */ +DEFINE_DEVICE_ADD(usbdev) + #undef DEFINE_DEVICE_ADD /******************************************************************************/
@@ -4432,7 +4452,7 @@ static int remove_device(libxl__egc *egc, libxl__ao *ao, aodev->dev = dev; aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; aodev->callback = device_complete; -libxl__initiate_device_remove (egc, aodev); +libxl__initiate_device_generic_remove (egc, aodev);break ;case LIBXL__DEVICE_KIND_QDISK :if (--dguest->num_qdisks ==0 ) {
@@ -6807,6 +6827,10 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,MERGE (pci, pcidevs,COMPARE_PCI , {}); +MERGE (usbctrl, usbctrls,COMPARE_USBCTRL , {}); + +MERGE (usbdev, usbdevs,COMPARE_USB , {}); +/* Take care of removable device. We maintain invariant in the * insert / remove operation so that: * 1. if xenstore is "empty" while JSON is not, the result
tools/libxl/libxl.h +77 -0
89 lines not on this page · raw message
tools/libxl/libxl_device.c +8 -5
@@ -676,7 +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; -libxl__initiate_device_remove (egc, aodev); +if (dev->backend_kind ==LIBXL__DEVICE_KIND_VUSB ) +libxl__initiate_device_usbctrl_remove (egc, aodev); +else +libxl__initiate_device_generic_remove (egc, aodev); } } }
@@ -775,8 +778,8 @@ out:return ; } -void libxl__initiate_device_remove (libxl__egc *egc, -libxl__ao_device *aodev) +void libxl__initiate_device_generic_remove (libxl__egc *egc, +libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao);xs_transaction_t t =0 ;
@@ -806,7 +809,7 @@ void libxl__initiate_device_remove(libxl__egc *egc, (info.paused || info.dying || info.shutdown)) {/* * TODO: 4.2 Bodge due to QEMU, see comment on top of -* libxl__initiate_device_remove in libxl_internal.h +* libxl__initiate_device_generic_remove in libxl_internal.h */ rc = libxl__ev_time_register_rel(ao, &aodev->timeout, device_qemu_timeout,
@@ -942,7 +945,7 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, !aodev->force) {LOG (DEBUG ,"Timeout reached, initiating forced remove" ); aodev->force =1 ; -libxl__initiate_device_remove (egc, aodev); +libxl__initiate_device_generic_remove (egc, aodev);return ; }
tools/libxl/libxl_internal.h +20 -2
@@ -2583,6 +2583,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_usbdev_add(libxl__egc *egc, uint32_t domid, +libxl_device_usbdev *usbdev, +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);
@@ -2612,8 +2620,15 @@ _hidden void libxl__wait_device_connection(libxl__egc*,* * Once finished, aodev->callback will be executed. */ -_hidden void libxl__initiate_device_remove(libxl__egc *egc, -libxl__ao_device *aodev); +_hidden void libxl__initiate_device_generic_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
@@ -3975,6 +3990,9 @@ 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)->ctrl == (b)->ctrl && \ + (a)->port == (b)->port) +#define COMPARE_USBCTRL (a, b) ((a)->devid == (b)->devid)/* DEVICE_ADD *
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 +1567 -0
1,567 lines not on this page · raw message
tools/libxl/libxl_types.idl +46 -0
64 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 +18 -0
@@ -1311,6 +1311,24 @@ 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_usbdev_list_free (libxl_device_usbdev *list,int nr) +{ +int i; + +for (i =0 ; i < nr; i++) +libxl_device_usbdev_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_usbdev (libxl_ctx *ctx,uint32_t domid, +int ctrl,int port, +libxl_device_usbdev *usbdev);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 V13 3/5] libxl: add pvusb API
Chunyan Liu writes ("[PATCH V13 3/5] libxl: add pvusb API"):
Quoted 5 lines
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controller and usb devices
- some other helper functions
Thanks. This is making progress but I'm afraid we're not quite there yet.
Quoted 2 lines
(quoted diff) +2
-0+static int usbback_dev_unassign(libxl__gc *gc, const char *busid) +{
...
tools/libxl/libxl_pvusb.c line 1208
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+/* Till here, USB device has been unbound from USBBACK and +* removed from xenstore, usb list couldn't show it anymore, +* so no matter removimg driver path successfully or not, +* we will report operation success. +*/
I'm still unconvinced by this and this may mean that the code in this function is in the wrong order. Earlier we had this exchange:
Quoted 4 lines
Quoted 1 line
Ought this function to really report success if these calls fail ?
I think so. Till here, the USB device has already been unbound from usbback and removed from xenstore. usb-list cannot list it any more.
The problem is that I think that if this function fails, it can leave
- debris in xenstore (the usbback path)
- the interface bound to the wrong driver
And then there is no way for the user to get libxl to re-attempt the operation, or clean up. Am I right ?
One way to avoid this kind of problem is to deal with the xenstore path last. That way the device will still appear as attached to the domain.
To do this properly I think bind_usbintf may need to become idempotent even in the face of other callers racing to assign the device. I think that would mean bind_usbif it would have to know what driver to expect to find the device bound to.
George, am I right here ?
I have a few other comments too:
tools/libxl/libxl_pvusb.c line 991
Quoted 10 lines
tools/libxl/libxl_pvusb.c new file +10
-0+/* get original driver path of usb interface, stored in @drvpath */ +static int usbintf_get_drvpath (libxl__gc *gc,const char *intf,char **drvpath) +{ +char *spath, *dp =NULL ; +struct stat st; +int rc; + + spath =GCSPRINTF (SYSFS_USB_DEV "/%s/driver" , intf); + + rc =lstat (spath, &st);
This rc' should be r'. (CODING_STYLE.)
I mentioned this in my review of v12 in the context of sysfs_write_intf. But there is still more than one occurrence in v13 of `rc' for a syscall return value.
Review
Quoted 2 lines
(quoted diff) +2
-0+static int sysfs_write_intf(libxl__gc *gc, const char *intf, const char *path) +{
Last time I wrote:
But there is nothing usb specific about this function. Looking for similar code elsewhere this function seems very similar to libxl_pci.c:sysfs_write_bdf, but I won't ask you to try to refactor these two functions together.
This time I have remembered that libxl_write_exactly exists, and could be used. Sorry for not saing this last time but I think you can probably just get rid of this in favour of libxl_write_exactly. If you think not, please say why.
tools/libxl/libxl_pvusb.c line 1061
Quoted 11 lines
tools/libxl/libxl_pvusb.c new file +11
-0+static int bind_usbintf (libxl__gc *gc,const char *intf,const char *drvpath) +{ +char *path; +struct stat st; + + path =GCSPRINTF ("%s/%s" , drvpath, intf); +/* if already bound, return */ +if (!lstat (path, &st)) +return 0 ; +else if (errno !=ENOENT ) +return ERROR_FAIL ;
This new ERROR_FAIL fails to log anything, and probably should. I think the anomalous style leads to this mistake. You should say
r = lstat...
and adopt the pattern from the rest of libxl.
Thanks,
Ian.
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 28 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 3/5] libxl: add pvusb API"):
Quoted 2 lines
(quoted diff) +2
-0+static int usbback_dev_unassign(libxl__gc *gc, const char *busid) +{...
tools/libxl/libxl_pvusb.c line 1208
Quoted 5 lines
tools/libxl/libxl_pvusb.c new file +5
-0+/* Till here, USB device has been unbound from USBBACK and +* removed from xenstore, usb list couldn't show it anymore, +* so no matter removimg driver path successfully or not, +* we will report operation success. +*/ I'm still unconvinced by this and this may mean that the code in this function is in the wrong order. Earlier we had this exchange:
Quoted 4 lines
Quoted 1 line
Ought this function to really report success if these calls fail ?
I think so. Till here, the USB device has already been unbound from usbback and removed from xenstore. usb-list cannot list it any more.
The problem is that I think that if this function fails, it can leave
- debris in xenstore (the usbback path)
- the interface bound to the wrong driver
And then there is no way for the user to get libxl to re-attempt the operation, or clean up. Am I right ?One way to avoid this kind of problem is to deal with the xenstore path last. That way the device will still appear as attached to the domain.
Quoted 6 lines
To do this properly I think
bind_usbintfmay need to become idempotent even in the face of other callers racing to assign the device. I think that would meanbind_usbifit would have to know what driver to expect to find the device bound to.George, am I right here ?
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Regardless of the state, the USB device is visible to lsusb, and always exists in the usb controller's device heirarchy, regardless of what driver it's assigned to (if any).
As far as sysfs and lspci goes, pci is an exact analog.
For usb, libxl really only has two states: assigned (state 4) and unassigned (states 1 or 2). libxl__device_usbdev_add() will take devices from states 1 or 2 and move them into state 3, then state 4. libxl__device_usbdev_remove() will take devices from state 4, through state 3, and then to state 2 (and then possibly state 1, if it has the appropriate information). usbdev_list will only list things in state 4.
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
For comparison, the libxl pci pass-through code has three states: not assignable (states 1 or 2), assignable (state 3), and assigned (state 4). libxl__device_pci_assignable_add moves it from 1 or 2 to state 3; libxl_device_pci_add moves it from state 3 to 4 (unless the "seize" flag is set, in which case it will call libxl__device_pci_assignable_add if necessary). libxl_device_pci_assignable_list lists things in state 3; libxl_device_pci_list list things in state 4.
pci devices also have analogs called "functions"; but libxl treats each of these separately (i.e., you actually assign a "function" to a VM, not a "device"). If a device has several functions which all need to be assigned, it's up to the user to assign each one individually.
So for removal, we have to consider what to do with a failure at each of the steps.
* 4 -> 3. This is just removing it from xenstore. The xenstore removal is transactional, so (I think) a failure here should mean that it's still in state 4; it should still show up in usb_list, and the user could try removing again if she wants.
* 3 -> 2. At this point, what the code actually does is try to unbind each interface from usbback; if any of the calls to unbind_usbintf() fail, it will give up (leaving any remaining functions bound to usbback).
* 2 -> 1. If we stored a driver path in xenstore (under the /libxl node, not under the pvusb node), we then try to rebind each interface to that driver. If this binding fails, we simply print a warning and continue (i.e., we attempt to re-bind with all interfaces, even if one of them fails).
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
It's not clear to me under what conditions 3->2 might fail, or what could be done about it if it did fail. Perhaps removing the usbback module? Failing that, rebooting the system is the only recovery option I can think of. Certainly trying to assign it back to the guest (i.e., move it back to the previous legal state of '4') isn't a good idea.
I do agree, however, that stopping in the middle here (leaving some interfaces assigned to usbback and some potentially already re-assigned to the original driver) is a bad; as is leaving the original driver for the interface in xenstore.
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Perhaps the best approach code-wise is to change the "goto out" on failure of unbind_usbintf() into a "continue". That way:
1. All interfaces which can be re-assigned are re-assigned (and work as much as possible)
2. All interfaces which can be unbound but not re-assigned are at least unbound (so that reloading the original driver might pick them up)
3. The xenstore paths storing the original driver information are cleaned up.
And we should of course include some useful error messages to give the user a hint as to what they can do to fix things; perhaps:
"ERROR: Unexpected failure, device now in wedged state (partially assigned to usbback), don't know how to recover. Try unloading and reloading the usbback module, or rebooting the system."
"ERROR: Unexpected failure re-assigning device, don't know how to recover. Try unloading and reloading $MODULE, or rebooting the system."
Thoughts?
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 5 lines
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
Quoted 1 line
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Quoted 9 lines
Perhaps the best approach code-wise is to change the "goto out" on failure of
unbind_usbintf()into a "continue". That way:1. All interfaces which can be re-assigned are re-assigned (and work as much as possible)
2. All interfaces which can be unbound but not re-assigned are at least unbound (so that reloading the original driver might pick them up)
I certainly don't mind the software trying to do as much of its task as possible.
Ian.
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 02:11 AM, in message
<[email protected]>, Ian Jackson
Quoted 24 lines · <[email protected]> wrote:
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 2 lines
Regarding Ian's comments:
Quoted 7 lines
Quoted 3 lines
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
Indeed "unassign from usbback, but listed under pvusb xenstore" is a confusing state. usb-list can list it but guest can not see it. What user can do under that state is: reattempt usbdev_remove, if it succeeds, everything is cleaned up, that's the best result; but possibly it still fails (for example, in my testing, always cannot rebind to original driver), in this case, the confusing state will be lasting, and the device could not be removed, this is worse.
Quoted 48 lines
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
Quoted 1 line
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Quoted 6 lines
Perhaps the best approach code-wise is to change the "goto out" on failure of
unbind_usbintf()into a "continue". That way:1. All interfaces which can be re-assigned are re-assigned (and work as much as possible)
Quoted 6 lines
Quoted 3 lines
2. All interfaces which can be unbound but not re-assigned are at least unbound (so that reloading the original driver might pick them up)
I certainly don't mind the software trying to do as much of its task as possible.
Could I understand that this way is acceptable? That means: removing xenstore, and as much as we could (on failure of "unbind from usbback" or "bind to original driver", don't "goto out", just "continue").
Chunyan
Quoted 9 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 37 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 02:11 AM, in message
<[email protected]>, Ian Jackson
Quoted 24 lines · <[email protected]> wrote:
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 2 lines
Regarding Ian's comments:
Quoted 7 lines
Quoted 3 lines
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
Quoted 7 lines
Indeed "unassign from usbback, but listed under pvusb xenstore" is a confusing state. usb-list can list it but guest can not see it. What user can do under that state is: reattempt
usbdev_remove, if it succeeds, everything is cleaned up, that's the best result; but possibly it still fails (for example, in my testing, always cannot rebind to original driver), in this case, the confusing state will be lasting, and the device could not be removed, this is worse.
As I said in my other mail, I think removing the pvusb nodes should be done once it's successfully un-bound from usbback, *even if* the re-bind to the original driver fails. (That is, once it reaches state 2, usb-list should no longer list it.)
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Perhaps the best approach code-wise is to change the "goto out" on failure of
unbind_usbintf()into a "continue". That way:1. All interfaces which can be re-assigned are re-assigned (and work as much as possible)
2. All interfaces which can be unbound but not re-assigned are at least unbound (so that reloading the original driver might pick them up)
Quoted 6 lines
Quoted 2 lines
I certainly don't mind the software trying to do as much of its task as possible.
Could I understand that this way is acceptable? That means: removing xenstore, and as much as we could (on failure of "unbind from usbback" or "bind to original driver", don't "goto out", just "continue").
I think part of it depends on what is *possible*. If it's possible to safely unbind the device from usbback while retaining its place in the pvusb-related xenstore nodes, then I think we should (so that the user can re-try removing it). If it's not possible, then of course we have to remove the pvusb xenstore nodes first, and then we'll just have to deal as gracefully as possible with failure unbinding from usbback.
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 10:38 PM, in message <[email protected]>, George
Quoted 65 lines · Dunlap
Quoted 6 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 02:11 AM, in message
<[email protected]>, Ian Jackson
Quoted 1 line · <[email protected]> wrote:
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb
API"):
Quoted 31 lines
Quoted 23 lines
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 2 lines
Regarding Ian's comments:
Quoted 7 lines
Quoted 3 lines
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
Quoted 7 lines
Indeed "unassign from usbback, but listed under pvusb xenstore" is a confusing state. usb-list can list it but guest can not see it. What user can do under that state is: reattempt
usbdev_remove, if it succeeds, everything is cleaned up, that's the best result; but possibly it still fails (for example, in my testing, always cannot rebind to original driver), in this case, the confusing state will be lasting, and the device could not be removed, this is worse.As I said in my other mail, I think removing the pvusb nodes should be done once it's successfully un-bound from usbback, *even if* the re-bind to the original driver fails. (That is, once it reaches state 2, usb-list should no longer list it.)
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines
Perhaps the best approach code-wise is to change the "goto out" on failure of
unbind_usbintf()into a "continue". That way:1. All interfaces which can be re-assigned are re-assigned (and work as much as possible)
2. All interfaces which can be unbound but not re-assigned are at least unbound (so that reloading the original driver might pick them up)
I certainly don't mind the software trying to do as much of its task as possible.
Quoted 7 lines
Quoted 3 lines
Could I understand that this way is acceptable? That means: removing xenstore, and as much as we could (on failure of "unbind from usbback" or "bind to original driver", don't "goto out", just "continue").
I think part of it depends on what is *possible*. If it's possible to safely unbind the device from usbback while retaining its place in the pvusb-related xenstore nodes, then I think we should (so that the user
Juergen, I think you are the person who can answer the question best. Can you confirm that?
-Chunyan
Quoted 7 lines
can re-try removing it). If it's not possible, then of course we have to remove the pvusb xenstore nodes first, and then we'll just have to deal as gracefully as possible with failure unbinding from usbback.
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
In reply to Ian JacksonQuoted 28 lines · Ian Jackson
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 5 lines
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
Quoted 6 lines
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
That's true. But if the USB device has actually disappeared, the device is in fact "safe" from usbback. I think I might consider state 2 safe to go to, but I definitely wouldn't consider state 1 safe with the xenstore nodes still in place.
Quoted 4 lines
Quoted 2 lines
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
*grumble*
Quoted 6 lines
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
I'm not sure what this means in the context of moving from 3 (assigned to usbback) to 2 (unassigned). usbback will definitely not use the device to mount something in dom0; and I'm pretty sure has no visibility as to whether it's being used as a filesystem in the domU.
(Moving from 1 -> 2 of course would be subject to this sort of thing, but that's a different issue.)
Quoted 7 lines
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 8 lines
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
I was talking here about whether it would be better to have some interfaces assigned to the original drivers and some interfaces left unassigned, or to try to leave all interfaces unassigned if any of the assignments fail.
I agree, it would be better to try to avoid the possibility of having some interfaces bound to usbback and some interfaces bound to the original drivers.
Quoted 10 lines
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Right -- so what about this. When removing a USB device:
* First modify the pvusb xenstore nodes such that 1) it's safe to attempt removing the interfaces from usbback, but 2) they still show up in usb-list. (This may be a noop.)
* Attempt to remove all interfaces from usbback; if any of these fail, stop and report an error. Possible recovery options:
- Re-try the usb_remove command
- Re-load usbback (obviously disruptive to other VMs)
- Reboot the host
- Manually try unbinding with sysfs
* Remove the remaining pvusb xenstore nodes. If this fails, stop and report the error. Possible recovery options:
- Re-try the usb_remove command
= REBIND OPTION 1: Do the best we can without extra commands
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, report an error but continue to try the rest of the interfaces, and remove the xenstore nodes containing information about the original drivers. Possible recovery options for the user:
- Reload the original drivers
- Reboot the host
- Manually try rebinding with sysfs
= REBIND OPTION 2: Include a recovery command, usb-retry-rebind
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, stop immediately and report an error; do not remove the xenstore nodes containing the original drivers of any interfaces that failed to rebind. Possible recovery options for the user:
- Run 'xl usbdev-retry-rebind', which will just execute this step again
- Unload and reload original host drivers
- Reboot the host
Both of these:
1. Will avoid the state of some interfaces bound to usbback, some rebound to the original drivers
2. Give the user a convenient way to re-try unbinding from usbback it failed
3. Give the user out-of-xl ways to attempt to recover the state other than messing around with sysfs.
Rebind option 2 will give the user a convenient way to retry rebinding to the original driver via xl if that step failed.
I'm inclined to suggest rebind option #1 for now, just to keep things simple.
Thoughts?
Chunyan, would the first half of that (removing from usbback before removing the pvusb xenstore nodes) actually work?
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 10:33 PM, in message <[email protected]>, George
Quoted 155 lines · Dunlap
Quoted 1 line · Ian Jackson
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb
API"):
Quoted 27 lines
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 5 lines
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
Quoted 6 lines
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
That's true. But if the USB device has actually disappeared, the device is in fact "safe" from usbback. I think I might consider state 2 safe to go to, but I definitely wouldn't consider state 1 safe with the xenstore nodes still in place.
Quoted 4 lines
Quoted 2 lines
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
*grumble*
Quoted 6 lines
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
I'm not sure what this means in the context of moving from 3 (assigned to usbback) to 2 (unassigned). usbback will definitely not use the device to mount something in dom0; and I'm pretty sure has no visibility as to whether it's being used as a filesystem in the domU.
(Moving from 1 -> 2 of course would be subject to this sort of thing, but that's a different issue.)
Quoted 7 lines
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 8 lines
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
I was talking here about whether it would be better to have some interfaces assigned to the original drivers and some interfaces left unassigned, or to try to leave all interfaces unassigned if any of the assignments fail.
I agree, it would be better to try to avoid the possibility of having some interfaces bound to usbback and some interfaces bound to the original drivers.
Quoted 10 lines
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Right -- so what about this. When removing a USB device:
* First modify the pvusb xenstore nodes such that 1) it's safe to attempt removing the interfaces from usbback, but 2) they still show up in usb-list. (This may be a noop.)
* Attempt to remove all interfaces from usbback; if any of these fail, stop and report an error. Possible recovery options:
- Re-try theusb_removecommand
- Re-load usbback (obviously disruptive to other VMs)
- Reboot the host
- Manually try unbinding with sysfs* Remove the remaining pvusb xenstore nodes. If this fails, stop and report the error. Possible recovery options:
- Re-try theusb_removecommand= REBIND OPTION 1: Do the best we can without extra commands
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, report an error but continue to try the rest of the interfaces, and remove the xenstore nodes containing information about the original drivers. Possible recovery options for the user:
- Reload the original drivers
- Reboot the host
- Manually try rebinding with sysfs= REBIND OPTION 2: Include a recovery command, usb-retry-rebind
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, stop immediately and report an error; do not remove the xenstore nodes containing the original drivers of any interfaces that failed to rebind. Possible recovery options for the user:
- Run 'xl usbdev-retry-rebind', which will just execute this step again
- Unload and reload original host drivers
- Reboot the hostBoth of these:
1. Will avoid the state of some interfaces bound to usbback, some rebound to the original drivers
2. Give the user a convenient way to re-try unbinding from usbback it failed
3. Give the user out-of-xl ways to attempt to recover the state other than messing around with sysfs.
Rebind option 2 will give the user a convenient way to retry rebinding to the original driver via xl if that step failed.
I'm inclined to suggest rebind option #1 for now, just to keep things simple.
Quoted 6 lines
Thoughts?
Chunyan, would the first half of that (removing from usbback before removing the pvusb xenstore nodes) actually work?
From testing, yes, it works. But I am not sure if it is safe though. Juergen
should be very clear about that according to usbback internal codes.
Juergen, could you help to confirm that?
Thanks,
Chunyan
Quoted 4 lines
-George
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 161 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 10:33 PM, in message <[email protected]>, George
Quoted 157 lines · Dunlap
Quoted 1 line · Ian Jackson
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb
API"):
Quoted 27 lines
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 5 lines
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
Quoted 6 lines
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
That's true. But if the USB device has actually disappeared, the device is in fact "safe" from usbback. I think I might consider state 2 safe to go to, but I definitely wouldn't consider state 1 safe with the xenstore nodes still in place.
Quoted 4 lines
Quoted 2 lines
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
*grumble*
Quoted 6 lines
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
I'm not sure what this means in the context of moving from 3 (assigned to usbback) to 2 (unassigned). usbback will definitely not use the device to mount something in dom0; and I'm pretty sure has no visibility as to whether it's being used as a filesystem in the domU.
(Moving from 1 -> 2 of course would be subject to this sort of thing, but that's a different issue.)
Quoted 7 lines
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 8 lines
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
I was talking here about whether it would be better to have some interfaces assigned to the original drivers and some interfaces left unassigned, or to try to leave all interfaces unassigned if any of the assignments fail.
I agree, it would be better to try to avoid the possibility of having some interfaces bound to usbback and some interfaces bound to the original drivers.
Quoted 10 lines
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Right -- so what about this. When removing a USB device:
* First modify the pvusb xenstore nodes such that 1) it's safe to attempt removing the interfaces from usbback, but 2) they still show up in usb-list. (This may be a noop.)
* Attempt to remove all interfaces from usbback; if any of these fail, stop and report an error. Possible recovery options:
- Re-try theusb_removecommand
- Re-load usbback (obviously disruptive to other VMs)
- Reboot the host
- Manually try unbinding with sysfs* Remove the remaining pvusb xenstore nodes. If this fails, stop and report the error. Possible recovery options:
- Re-try theusb_removecommand= REBIND OPTION 1: Do the best we can without extra commands
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, report an error but continue to try the rest of the interfaces, and remove the xenstore nodes containing information about the original drivers. Possible recovery options for the user:
- Reload the original drivers
- Reboot the host
- Manually try rebinding with sysfs= REBIND OPTION 2: Include a recovery command, usb-retry-rebind
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, stop immediately and report an error; do not remove the xenstore nodes containing the original drivers of any interfaces that failed to rebind. Possible recovery options for the user:
- Run 'xl usbdev-retry-rebind', which will just execute this step again
- Unload and reload original host drivers
- Reboot the hostBoth of these:
1. Will avoid the state of some interfaces bound to usbback, some rebound to the original drivers
2. Give the user a convenient way to re-try unbinding from usbback it failed
3. Give the user out-of-xl ways to attempt to recover the state other than messing around with sysfs.
Rebind option 2 will give the user a convenient way to retry rebinding to the original driver via xl if that step failed.
I'm inclined to suggest rebind option #1 for now, just to keep things simple.
Thoughts?
Quoted 7 lines
Quoted 2 lines
Chunyan, would the first half of that (removing from usbback before removing the pvusb xenstore nodes) actually work?
From testing, yes, it works. But I am not sure if it is safe though. Juergen should be very clear about that according to usbback internal codes.
Juergen, could you help to confirm that?
I think it should work.
TBH, I don't think the error handling of driver binding/unbinding should be made too intelligent. In the long run I hope to have a qemu-based pvUSB backend. And in this case driver binding/unbinding will be handled completely by qemu/libusb.
Whether we want to keep the kernel based pvUSB-backend support in xl at the end should be discussed later. I'll either add the qemu based variant or I'll replace the kernel variant with the qemu one as soon as the qemu backend has been accepted.
Juergen
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 177 lines · Juergen Gross
Quoted 161 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 10:33 PM, in message <[email protected]>, George
Quoted 157 lines · Dunlap
Quoted 1 line · Ian Jackson
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb
API"):
Quoted 27 lines
Quoted 10 lines
There are effectively four states a device can be in, from the 'assignment' point of view:
1. Assigned to the normal Linux device driver(s) for the USB device
2. Assigned to no driver
3. Assigned to usbback, but not yet assigned to any guest
4. Assigned to a guest
Thanks for your clear explanation (of which I will snip much).
Quoted 4 lines
Additionally, each USB "device" has one or more "interfaces". To assign a "device" to usbback in the sysfs case means assigning all of the "interfaces". The code seems to assume that different interfaces from the same device can be assigned to different drivers.
It is indeed the case that in principle a single USB device with multiple interfaces can be assigned to multiple different drivers.
Quoted 5 lines
Regarding Ian's comments:
Since "assigned to the guest" and "listed under the pvusb xenstore node" are the same thing, is it even *possible* to (safely) unassign the device from usbback before removing the xenstore nodes?
Quoted 6 lines
It might be possible to remove some of the xenstore nodes but leave others present, so that usbback detaches, but enough information remains for libxl to know that Xen still `owns' the device.
But, surely usbback needs to cope with the notion that the device might disappear. USB devices can disappear at any time.
That's true. But if the USB device has actually disappeared, the device is in fact "safe" from usbback. I think I might consider state 2 safe to go to, but I definitely wouldn't consider state 1 safe with the xenstore nodes still in place.
Quoted 4 lines
Quoted 2 lines
It's not clear to me under what conditions 3->2 might fail,
As an example, someone might press ^C on `xl usb-detach'.
*grumble*
Quoted 6 lines
Quoted 1 line
or what could be done about it if it did fail.
The most obvious reason for it failing is that something somewhere still held onto the device. (For umounting filesystems, and detaching block devices, this happens a lot.) So if the detach from usbback fails would probably be possible to simply retry it.
I'm not sure what this means in the context of moving from 3 (assigned to usbback) to 2 (unassigned). usbback will definitely not use the device to mount something in dom0; and I'm pretty sure has no visibility as to whether it's being used as a filesystem in the domU.
(Moving from 1 -> 2 of course would be subject to this sort of thing, but that's a different issue.)
Quoted 7 lines
Quoted 4 lines
Regarding 2->1, again it's not clear that there's anything libxl can do. Reloading the driver's module might reset it enough to pick up the (now unassigned) USB devices again; other than that, rebooting is probably the best option.
I think re-attempting the bind may work. USB devices can be flaky.
Quoted 8 lines
Quoted 4 lines
It's also not clear to me, if some functions succeed in being reassigned and others fail, whether it's best to just try to assign as many as we can, or better to go back and un-assign all the ones that succeeded.
Unless explicitly requested, I don't think the system should create situations some interfaces are assigned to host drivers and some to usbback.
I was talking here about whether it would be better to have some interfaces assigned to the original drivers and some interfaces left unassigned, or to try to leave all interfaces unassigned if any of the assignments fail.
I agree, it would be better to try to avoid the possibility of having some interfaces bound to usbback and some interfaces bound to the original drivers.
Quoted 10 lines
And, I'm a fan of `crash-only software': in general, if a failure occurs, the situation should just be left as-is. The intermediate state needs to be visible and rectifiable.
This approach to software state machines avoids bugs where the system gets into `impossible' states, recovery from which is impossible because the designers didn't anticipate them.
It would be tolerable if the recovery sometimes involves `lsusb' and echoing things into sysfs, but it would be better if not.
Right -- so what about this. When removing a USB device:
* First modify the pvusb xenstore nodes such that 1) it's safe to attempt removing the interfaces from usbback, but 2) they still show up in usb-list. (This may be a noop.)
* Attempt to remove all interfaces from usbback; if any of these fail, stop and report an error. Possible recovery options:
- Re-try theusb_removecommand
- Re-load usbback (obviously disruptive to other VMs)
- Reboot the host
- Manually try unbinding with sysfs* Remove the remaining pvusb xenstore nodes. If this fails, stop and report the error. Possible recovery options:
- Re-try theusb_removecommand= REBIND OPTION 1: Do the best we can without extra commands
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, report an error but continue to try the rest of the interfaces, and remove the xenstore nodes containing information about the original drivers. Possible recovery options for the user:
- Reload the original drivers
- Reboot the host
- Manually try rebinding with sysfs= REBIND OPTION 2: Include a recovery command, usb-retry-rebind
* Attempt to re-bind the interfaces to the original drivers, as recorded in the libxl usb xenstore nodes. If any of these fail, stop immediately and report an error; do not remove the xenstore nodes containing the original drivers of any interfaces that failed to rebind. Possible recovery options for the user:
- Run 'xl usbdev-retry-rebind', which will just execute this step again
- Unload and reload original host drivers
- Reboot the hostBoth of these:
1. Will avoid the state of some interfaces bound to usbback, some rebound to the original drivers
2. Give the user a convenient way to re-try unbinding from usbback it failed
3. Give the user out-of-xl ways to attempt to recover the state other than messing around with sysfs.
Rebind option 2 will give the user a convenient way to retry rebinding to the original driver via xl if that step failed.
I'm inclined to suggest rebind option #1 for now, just to keep things simple.
Thoughts?
Quoted 7 lines
Quoted 2 lines
Chunyan, would the first half of that (removing from usbback before removing the pvusb xenstore nodes) actually work?
From testing, yes, it works. But I am not sure if it is safe though. Juergen should be very clear about that according to usbback internal codes.
Juergen, could you help to confirm that?
I think it should work.
TBH, I don't think the error handling of driver binding/unbinding should be made too intelligent. In the long run I hope to have a qemu-based pvUSB backend. And in this case driver binding/unbinding will be handled completely by qemu/libusb.
Quoted 4 lines
Whether we want to keep the kernel based pvUSB-backend support in xl at the end should be discussed later. I'll either add the qemu based variant or I'll replace the kernel variant with the qemu one as soon as the qemu backend has been accepted.
There's a difference between "making it intelligent" and "not making it broken". :-) Given that users can potentially cause a number of these things to fail just by pressing Ctrl-C, we need to at least make sure that we don't get into a completely wedged state that the user can't do anything to fix. That requires some careful thought.
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
Quoted 5 lines
There's a difference between "making it intelligent" and "not making it broken". :-) Given that users can potentially cause a number of these things to fail just by pressing Ctrl-C, we need to at least make sure that we don't get into a completely wedged state that the user can't do anything to fix. That requires some careful thought.
Right. There is a useful design principle which can help simplify and
clarify: "crash-only software".[1][2]
The idea is that when an error occurs, it is usually best to simply stop and leave the system in whatever intermediate state. The next run of the software is responsible for discovering, interpreting and if necessary rectifying the situation.
In general these recovery paths are necessary anyway. So the on-error-cleanup doesn't help.
In the context of that series, I think that means:
We observe that there is an ordering of possible states
attached to dom0 driver
unattached
attached to usbback
assigned to a guest
When reconfiguring a device, it will move through these states in order (forwards or backwards, normally).
NB that I don't discuss here what information may be recorded in xenstore and the VM configuration at each stage: so in fact there are various micro-states in between the major states shown above (eg, "attached to usbback and in process of attaching to geust").
To make a coherent design, we need to:
Arrange that each of these states can be seen by the user somehow. (Eg in output from list-assignable.)
Arrange that each intermediate state can be recovered to at least one endpoint state by use of some appropriate command(s).
Arrange that the recording of metadata in xenstore and the domain json config occurs in the right order to support the above (ie, that the micro-states are right). After an approach has been chosen, to show that the design is correct, it is probably easiest to explicitly enumerate all the micro-states.
Ideally I would like to see this aspect of the design covered in a doc comment (or maybe commit messages), in some form or other.
I hope this is of some help.
Thanks,
Ian.
[1] https://www.usenix.org/events/hotos03/tech/full_papers/candea/candea.pdf
[2] https://en.wikipedia.org/wiki/Crash-only_software
Re: [PATCH V13 3/5] libxl: add pvusb API
In reply to Ian JacksonQuoted 5 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 3/5] libxl: add pvusb API"):
Quoted 4 lines
Quoted 1 line
Ought this function to really report success if these calls fail ?
I think so. Till here, the USB device has already been unbound from usbback and removed from xenstore. usb-list cannot list it any more.
Also, I think we probably should return some sort of error, so that scripts &c can at least know something out of the ordinary has happened, even if it doesn't go back to the state we started in when the function was called.
-George
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/3/2016 at 12:48 AM, in message
<CAFLBxZY38HfouhD4eS63+HieQ8dfsza=rY7r_CNGhknmVLowJg@mail.gmail.com>, George
Quoted 11 lines · Dunlap
Quoted 5 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 3/5] libxl: add pvusb API"):
Quoted 4 lines
Quoted 1 line
Ought this function to really report success if these calls fail ?
I think so. Till here, the USB device has already been unbound from usbback and removed from xenstore. usb-list cannot list it any more.
Also, I think we probably should return some sort of error, so that scripts &c can at least know something out of the ordinary has happened, even if it doesn't go back to the state we started in when the function was called.
That makes sense. But do we need to differentiate failure at removing xenstore information step and error in bind/unbind step? Or, treat them as same? That affects doing it within other process (like usbctrl-detach). For the former, xl usb-list can list usb device and one can do usbdev-detach again; and if in a usbctrl-detach process, will stop the process. For the later, one cannot do usbdev-detach, and if in usbctrl-detach process, in current codes, will ignore that.
Chunyan
Quoted 9 lines
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH V13 3/5] libxl: add pvusb API
In reply to Chunyan LiuQuoted 11 lines · Chunyan Liu
+++
b/tools/libxl/libxl.ctools/libxl/libxl.c +1
-1@@ -3204,7 +3204,7 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc, aodev->dev = device; aodev->callback = local_device_detach_cb; aodev->force =0 ; -libxl__initiate_device_remove (egc, aodev); +libxl__initiate_device_generic_remove (egc, aodev);return ; }
tools/libxl/libxl.c out: · line 4176
Quoted 5 lines
tools/libxl/libxl.c +2
-0@@ -4172,8 +4172,10 @@ out:* libxl_device_vkb_destroy * libxl_device_vfb_remove * libxl_device_vfb_destroy +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy
This should be moved down to DEFINE_DEVICE_REMOVE_CUSTOM.
Quoted 18 lines
tools/libxl/libxl.c +3
-3*/ -#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ +#define DEFINE_DEVICE_REMOVE_EXT (type, remtype, removedestroy, f) \ int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ uint32_t domid, libxl_device_##type *type, \ const libxl_asyncop_how *ao_how) \@@ -4193,13 +4195,19 @@ out: aodev->dev = device; \ aodev->callback = device_addrm_aocomplete; \ aodev->force = f; \ -libxl__initiate_device_remove (egc, aodev); \ + libxl__initiate_device_##remtype##_remove(egc, aodev); \ \ out: \ -if (rc)return AO_CREATE_FAIL (rc); \ +if (rc)return AO_CREATE_FAIL (rc); \return AO_INPROGRESS ; \ }
tools/libxl/libxl.c out: · line 4213
Quoted 10 lines
tools/libxl/libxl.c +6
-0+#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f) + +#define DEFINE_DEVICE_REMOVE_CUSTOM (type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, type, removedestroy, f) +/* Define all remove/destroy functions and undef the macro */ /* disk */
If this is the way to move forward, please split this out into a separate change which can be applied to staging independent of any pvusb changes.
I think the patch needs also the #undef.
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vfb, destroy, 1) · line 4240
Quoted 11 lines
tools/libxl/libxl.c +4
-0@@ -4223,6 +4231,10 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1) DEFINE_DEVICE_REMOVE(vtpm, remove, 0)DEFINE_DEVICE_REMOVE (vtpm, destroy,1 ) +/* usbctrl */ +DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0) +DEFINE_DEVICE_REMOVE_CUSTOM (usbctrl, destroy,1 ) +/* channel/console hotunplug is not implemented. There are 2 possibilities: * 1. add support for secondary consoles to xenconsoled * 2. dynamically add/remove qemu chardevs via qmp messages. */
A comment should mention both libxl_device_usbctrl_remove/destroy and libxl__initiate_device_usbctrl_remove/destroy.
Olaf
Re: [PATCH V13 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 1/27/2016 at 12:12 AM, in message <[email protected]>, Olaf
Quoted 50 lines · Hering
Review void
Quoted 2 lines · Chunyan Liu
+++
b/tools/libxl/libxl.c(quoted diff) +0
-0@@ -3204,7 +3204,7 @@ voidlibxl__device_disk_local_initiate_detach(libxl__egc *egc,
Quoted 9 lines
tools/libxl/libxl.c +1
-1aodev->dev = device; aodev->callback = local_device_detach_cb; aodev->force =0 ; -libxl__initiate_device_remove (egc, aodev); +libxl__initiate_device_generic_remove (egc, aodev);return ; }tools/libxl/libxl.c out: · line 4176
Quoted 5 lines
tools/libxl/libxl.c +2
-0@@ -4172,8 +4172,10 @@ out:* libxl_device_vkb_destroy * libxl_device_vfb_remove * libxl_device_vfb_destroy +* libxl_device_usbctrl_remove +* libxl_device_usbctrl_destroy This should be moved down to
DEFINE_DEVICE_REMOVE_CUSTOM.Quoted 7 lines
tools/libxl/libxl.c +1
-1*/ -#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ +#define DEFINE_DEVICE_REMOVE_EXT (type, remtype, removedestroy, f) \ int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ uint32_t domid, libxl_device_##type *type, \ const libxl_asyncop_how *ao_how) \tools/libxl/libxl.c out: · line 4199
Quoted 8 lines
tools/libxl/libxl.c +1
-2@@ -4193,13 +4195,19 @@ out: aodev->dev = device; \ aodev->callback = device_addrm_aocomplete; \ aodev->force = f; \ - libxl__initiate_device_remove(egc, aodev); \ + libxl__initiate_device_##remtype##_remove(egc, aodev); \ \ out: \ -if (rc)return AO_CREATE_FAIL (rc);\
Quoted 12 lines
tools/libxl/libxl.c +7
-0+ if (rc) return AO_CREATE_FAIL(rc); \ return AO_INPROGRESS; \ } +#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f) + +#define DEFINE_DEVICE_REMOVE_CUSTOM (type, removedestroy, f) \ +DEFINE_DEVICE_REMOVE_EXT (type, type, removedestroy, f) +/* Define all remove/destroy functions and undef the macro */
Quoted 9 lines
tools/libxl/libxl.c out: · line 4213
Quoted 1 line
tools/libxl/libxl.c +0
-0/* disk */ If this is the way to move forward, please split this out into a separate change which can be applied to staging independent of any pvusb changes.
I think the patch needs also the #undef.
Got you. Will update.
Quoted 11 lines
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vfb, destroy, 1) · line 4238
Quoted 10 lines
tools/libxl/libxl.c +4
-0@@ -4223,6 +4231,10 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1) DEFINE_DEVICE_REMOVE(vtpm, remove, 0)DEFINE_DEVICE_REMOVE (vtpm, destroy,1 ) +/* usbctrl */ +DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0) +DEFINE_DEVICE_REMOVE_CUSTOM (usbctrl, destroy,1 ) +/* channel/console hotunplug is not implemented. There are 2 possibilities:
Quoted 5 lines
tools/libxl/libxl.c DEFINE_DEVICE_REMOVE(vfb, destroy, 1) · line 4240
Quoted 2 lines
tools/libxl/libxl.c +0
-0* 1. add support for secondary consoles to xenconsoled * 2. dynamically add/remove qemu chardevs via qmp messages. */ A comment should mention both libxl_device_usbctrl_remove/destroy and libxl__initiate_device_usbctrl_remove/destroy.
Will add comments.
Thanks,
Chunyan
Quoted 9 lines
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v13 4/5 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=['hostbus=2, hostaddr=1, controller=0,port=1', ]
---
Changes:
* adjust patch order of this patch and next patch, so that next patch can use docs generated in this patch.
docs/man/xl.cfg.pod.5 | 84 +++++++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 73 +++++++++++++++++++++++++++-- tools/libxl/libxl_device.c | 4 ++ tools/libxl/libxl_internal.h | 8 ++++ tools/libxl/xl_cmdimpl.c | 107 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 272 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5 +84 -0
@@ -722,6 +722,90 @@ 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 usb controller type. Currently only 'pv' and 'auto' +are supported. + +=item B<version=VERSION> + +Specifies the usb controller version. Possible values include +1 (USB1.1) and 2 (USB2.0). Default is 2 (USB2.0). + +=item B<ports=PORTS> + +Specifies the total ports of the usb controller. The maximum +number is 31. Default is 8. + +USB controler ids start from 0. In line with the USB spec, however, +ports on a controller start from 1. + +E.g. +usbctrl=["version=1,ports=4", "version=2,ports=8",] +The first controller has: +controller id = 0, and port 1,2,3,4. +The second controller has: +controller id = 1, and port 1,2,3,4,5,6,7,8. + +=back + +=back + +=item B<usbdev=[ "USB_SPEC_STRING", "USB_SPEC_STRING", ... ]> + +Specifies the USB devices to be attached to the guest at boot. 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<devtype=hostdev> + +Specifies USB device type. Currently only support 'hostdev'. + +=item B<hostbus=busnum> + +Specifies busnum of the USB device from the host perspective. + +=item B<hostaddr=devnum> + +Specifies devnum of the USB device from the host perspective. + +=item B<controller=CONTROLLER> + +Specifies USB controller id, to which controller the USB device is attached. + +=item B<port=PORT> + +Specifies USB port, to which port the USB device is attached. B<port=PORT> +is valid only when B<controller=CONTROLLER> is specified. + +=back + +If no controller is specified, an available controller:port combination +will be used. If there are no available controller:port options, +a new controller will be created. + +=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(usbdev) #undef DEFINE_DEVICES_ADD
tools/libxl/libxl_internal.h +8 -0
@@ -3319,6 +3319,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_usbdevs(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 +106 -1
125 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH V13 4/5] domcreate: support pvusb in configuration file
Chunyan Liu writes ("[PATCH V13 4/5] domcreate: support pvusb in configuration file"):
Quoted 5 lines
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.
Quoted 8 lines
One could specify usb controllers and usb devices in config file like this:
usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['hostbus=2, hostaddr=1, controller=0,port=1', ]Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Reviewed-by George Dunlap <[email protected]>
PATCH v13 5/5 xl: add pvusb commands
In reply to Chunyan LiuAdd pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usbctrl-attach test_vm version=1 ports=8
#xl usb-list test_vm
will show the usb controllers and port usage under the domain.
#xl usbdev-attach test_vm hostbus=1 hostaddr=2 will find the first usable controller:port, and attach usb device whose busnum is 1 and devnum is 6.
One could also specify which <controller> and which <port>.
#xl usbdev-detach test_vm 0 1
will detach USB device under controller 0 port 1.
#xl usbctrl-detach test_vm dev_id
will destroy the controller with specified dev_id. Dev_id can be traced in usb-list info.
---
changes:
* update docs to reuse documentation in xl.cfg
* remove backend patch information from usb-list
docs/man/xl.pod.1 | 35 +++++++++ tools/libxl/xl.h | 5 ++ tools/libxl/xl_cmdimpl.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 25 ++++++ 4 files changed, 255 insertions(+)
docs/man/xl.pod.1 +35 -0
@@ -1345,6 +1345,41 @@ List pass-through pci devices for a domain. =back +=head1 USB PASS-THROUGH + +=over 4 + +=item B<usbctrl-attach> I<domain-id> I<usbctrl-device> + +Create a new USB controller in the domain specified by I<domain-id>, +I<usbctrl-device> describes the device to attach, using the same format +as the B<usbctrl> string in the domain config file. See L<xl.cfg> for +more information. + +=item B<usbctrl-detach> I<domain-id> I<devid> + +Destroy a USB controller from the specified domain. +B<devid> is devid of the USB controller. + +=item B<usbdev-attach> I<domain-id> I<usbdev-device> + +Hot-plug a new pass-through USB device to the domain specified by +I<domain-id>, I<usbdev-device> describes the device to attach, using +the same format as the B<usbdev> string in the domain config file. +See L<xl.cfg> for more information. + +=item B<usbdev-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
@@ -92,6 +92,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_usbdev_attach (int argc,char **argv); +int main_usbdev_detach (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 +190 -0
196 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +25 -0
@@ -553,6 +553,31 @@ struct cmd_spec cmd_table[] = { },#endif + {"usbctrl-attach" , + &main_usbctrl_attach,0 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [type=pv] [version=<version>] [ports=<number>]" , + }, + { "usbctrl-detach", + &main_usbctrl_detach,0 ,1 , +"Remove the virtual USB controller specified by <DevId> for a domain" , +"<Domain> <DevId>" , + }, + { "usbdev-attach", + &main_usbdev_attach,0 ,1 , +"Attach a USB device to a domain" , +"<Domain> hostbus=<busnum> hostaddr=<devnum> [controller=<DevId> [port=<port>]]" , + }, + { "usbdev-detach", + &main_usbdev_detach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <controller> <port>" , + }, + { "usb-list", + &main_usblist,0 ,0 , +"List information about all USB controllers and devices for a domain" , + "<Domain>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Signature · 1 line
2.1.4
Re: [PATCH V13 5/5] xl: add pvusb commands
Chunyan Liu writes ("[PATCH V13 5/5] xl: add pvusb commands"):
Quoted 2 lines
Add pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
Thanks for swapping this with the other patch. It is better now.
Quoted 1 line
+=item B<usbctrl-attach> I<domain-id> I<usbctrl-device>
However, I think you need to explictly state that the user may (and indeed, must) pass multiple settings as separate arguments. AFAICT the parser here doesn't do the ,-splitting.
docs/man/xl.pod.1 List pass-through pci devices for a domain. · line 1357
Quoted 3 lines
docs/man/xl.pod.1 +3
-0+I<usbctrl-device> describes the device to attach, using the same format +as the B<usbctrl> string in the domain config file. See L<xl.cfg> for +more information.
And this, therefore, is not quite true.
To be clear, I think that you should fix the documentation to match the code.
Thanks,
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 9 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 5/5] xl: add pvusb commands"):
Quoted 2 lines
Add pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
Thanks for swapping this with the other patch. It is better now.
Quoted 1 line
+=item B<usbctrl-attach> I<domain-id> I<usbctrl-device>
However, I think you need to explictly state that the user may (and indeed, must) pass multiple settings as separate arguments. AFAICT the parser here doesn't do the ,-splitting.
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
main_networkattach() in tools/libxl/xl_cmdimpl.c doesn't split on the ',', so everything after mac=00:16:3e:xx:yy:zz is ignored. I'd need advice on how to fix this though. Based on xl-network-configuration doc and Xen tool's long history of network-attach supporting that syntax, I'd say main_networkattach() should be changed to split on ','. I could also change the docs. Do tools maintainers have a preference, or alternative option?
Regards,
Jim
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 17 lines · Jim Fehlig
Quoted 9 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 5/5] xl: add pvusb commands"):
Quoted 2 lines
Add pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
Thanks for swapping this with the other patch. It is better now.
Quoted 1 line
+=item B<usbctrl-attach> I<domain-id> I<usbctrl-device>
However, I think you need to explictly state that the user may (and indeed, must) pass multiple settings as separate arguments. AFAICT the parser here doesn't do the ,-splitting.
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
Quoted 7 lines
main_networkattach()intools/libxl/xl_cmdimpl.cdoesn't split on the ',', so everything after mac=00:16:3e:xx:yy:zz is ignored. I'd need advice on how to fix this though. Based on xl-network-configuration doc and Xen tool's long history of network-attach supporting that syntax, I'd saymain_networkattach()should be changed to split on ','. I could also change the docs. Do tools maintainers have a preference, or alternative option?
It is splitting on " " at the moment which is not very desirable.
I think this is a bug. I've added it to my list and will look into fixing it.
Wei.
Quoted 3 lines
Regards,
Jim
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 32 lines · Wei Liu
Quoted 18 lines · Jim Fehlig
Quoted 9 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 5/5] xl: add pvusb commands"):
Quoted 2 lines
Add pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
Thanks for swapping this with the other patch. It is better now.
Quoted 1 line
+=item B<usbctrl-attach> I<domain-id> I<usbctrl-device>
However, I think you need to explictly state that the user may (and indeed, must) pass multiple settings as separate arguments. AFAICT the parser here doesn't do the ,-splitting.
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb:
script: Could
not find bridge device xenbr0Quoted 12 lines
main_networkattach()intools/libxl/xl_cmdimpl.cdoesn't split on the ',', so
everything after mac=00:16:3e:xx:yy:zz is ignored. I'd need advice on how to fix
this though. Based on xl-network-configuration doc and Xen tool's long history
of network-attach supporting that syntax, I'd saymain_networkattach()should be
changed to split on ','. I could also change the docs. Do tools maintainers have
a preference, or alternative option?
Quoted 4 lines
It is splitting on " " at the moment which is not very desirable.
I think this is a bug. I've added it to my list and will look into fixing it.
If you are feeling particularly highly motivated then xl_cmdimpl.c contains quite a lot of adhoc parsing of various comma a space separated lists (often dupped for a given instance into cmdline vs cfg file, which leads to unintentional behavioural differences like above) which could usefully be consolidated into a series of helpers.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 35 lines · Ian Campbell
Quoted 34 lines · Wei Liu
Quoted 18 lines · Jim Fehlig
Quoted 9 lines · Ian Jackson
Chunyan Liu writes ("[PATCH V13 5/5] xl: add pvusb commands"):
Quoted 2 lines
Add pvusb commands: usbctrl-attach, usbctrl-detach, usb-list, usbdev-attach and usbdev-detach.
Thanks for swapping this with the other patch. It is better now.
Quoted 1 line
+=item B<usbctrl-attach> I<domain-id> I<usbctrl-device>
However, I think you need to explictly state that the user may (and indeed, must) pass multiple settings as separate arguments. AFAICT the parser here doesn't do the ,-splitting.
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb:
script: Could
not find bridge device xenbr0Quoted 12 lines
main_networkattach()intools/libxl/xl_cmdimpl.cdoesn't split on the ',', so
everything after mac=00:16:3e:xx:yy:zz is ignored. I'd need advice on how to fix
this though. Based on xl-network-configuration doc and Xen tool's long history
of network-attach supporting that syntax, I'd saymain_networkattach()should be
changed to split on ','. I could also change the docs. Do tools maintainers have
a preference, or alternative option?It is splitting on " " at the moment which is not very desirable.
Quoted 9 lines
Quoted 2 lines
I think this is a bug. I've added it to my list and will look into fixing it.
If you are feeling particularly highly motivated then
xl_cmdimpl.ccontains quite a lot of adhoc parsing of various comma a space separated lists (often dupped for a given instance into cmdline vs cfg file, which leads to unintentional behavioural differences like above) which could usefully be consolidated into a series of helpers.
Or rewrite every adhoc parser with bison/flex or Ocaml / Haskell parsec.
Jokes aside. I will see what I can do. Consolidating them into helper functions is a good start.
Wei.
Quoted 2 lines
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
Wei Liu writes ("Re: [Xen-devel] [PATCH V13 5/5] xl: add pvusb commands"):
Quoted 1 line
Or rewrite every adhoc parser with bison/flex or Ocaml / Haskell parsec.
I endorse this product and/or service.
Quoted 2 lines
Jokes aside. I will see what I can do. Consolidating them into helper functions is a good start.
Yes :-).
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
In reply to Jim FehligJim Fehlig writes ("Re: [Xen-devel] [PATCH V13 5/5] xl: add pvusb commands"):
Quoted 5 lines
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0
This is clearly a bug.
Quoted 2 lines
main_networkattach()intools/libxl/xl_cmdimpl.cdoesn't split on the ',', so everything after mac=00:16:3e:xx:yy:zz is ignored.
That's quite silly, isn't it. Looking at the code it would also accept
mac=00:16:3e:aa:bb:cc:THIS:SHOULD:NOT:BE:HERE
The bug seems to be that the ad-hoc strtoul-based mac address parser in xl_cmdimpl.c:parse_nic_config doesn't notice garbage after its option.
Quoted 5 lines
I'd need advice on how to fix this though. Based on xl-network-configuration doc and Xen tool's long history of network-attach supporting that syntax, I'd say
main_networkattach()should be changed to split on ','. I could also change the docs. Do tools maintainers have a preference, or alternative option?
I don't have a strong opinion, but I would lean towards insisting that on command lines each setting should be in its own argument.
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 19 lines · Ian Jackson
Jim Fehlig writes ("Re: [Xen-devel] [PATCH V13 5/5] xl: add pvusb commands"):
Quoted 5 lines
I just noticed this is the case with network devices as well. E.g.
#xl network-attach hvm-domU mac=00:16:3e:xx:yy:zz,bridge=br0
libxl: error: libxl_device.c:1095:device_hotplug_child_death_cb: script: Could not find bridge device xenbr0This is clearly a bug.
Quoted 2 lines
main_networkattach()intools/libxl/xl_cmdimpl.cdoesn't split on the ',', so everything after mac=00:16:3e:xx:yy:zz is ignored.That's quite silly, isn't it. Looking at the code it would also accept
mac=00:16:3e:aa:bb:cc:THIS:SHOULD:NOT:BE:HEREThe bug seems to be that the ad-hoc strtoul-based mac address parser in xl_cmdimpl.c:parse_nic_config doesn't notice garbage after its option.
Quoted 9 lines
Quoted 5 lines
I'd need advice on how to fix this though. Based on xl-network-configuration doc and Xen tool's long history of network-attach supporting that syntax, I'd say
main_networkattach()should be changed to split on ','. I could also change the docs. Do tools maintainers have a preference, or alternative option?I don't have a strong opinion, but I would lean towards insisting that on command lines each setting should be in its own argument.
We should support both IMHO. Libxlu's disk spec parser is able to do that with parse_disk_config_multistring.
Wei.
Quoted 1 line
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
Wei Liu writes ("Re: [Xen-devel] [PATCH V13 5/5] xl: add pvusb commands"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
I don't have a strong opinion, but I would lean towards insisting that on command lines each setting should be in its own argument.
We should support both IMHO. Libxlu's disk spec parser is able to do that with
parse_disk_config_multistring.
Fine by me. As I say I don't have a strong opinion, so we should do what Wei wants as he does :-).
Ian.
Re: [PATCH V13 5/5] xl: add pvusb commands
In reply to Chunyan LiuQuoted 3 lines · Chunyan Liu
#xl usbctrl-attach
test_vmversion=1 ports=8#xl usbdev-attach
test_vmhostbus=1 hostaddr=2
I think this does not handle the -N knob of xl. Other commands check the global dryrun_only variable.
Olaf
Re: [PATCH V13 5/5] xl: add pvusb commands
n
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 2/17/2016 at 12:56 AM, in message <[email protected]>, Olaf
Quoted 8 lines · Hering
Quoted 3 lines · Chunyan Liu
#xl usbctrl-attach
test_vmversion=1 ports=8#xl usbdev-attach
test_vmhostbus=1 hostaddr=2I think this does not handle the -N knob of xl. Other commands check the global
dryrun_onlyvariable.
Thanks. I'll add.
Quoted 9 lines
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH V13 5/5] xl: add pvusb commands
In reply to Olaf HeringQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/17/2016 at 12:56 AM, in message <[email protected]>, Olaf
Quoted 8 lines · Hering
Quoted 3 lines · Chunyan Liu
#xl usbctrl-attach
test_vmversion=1 ports=8#xl usbdev-attach
test_vmhostbus=1 hostaddr=2I think this does not handle the -N knob of xl. Other commands check the global
dryrun_onlyvariable.
Just sent V14. I tried to add dryrun_only codes but finally gave up. For usbdev-attach, since it will automatically and dynamically create usb controller in some cases, it's hard to print dryrun-only information.
Chunyan
Quoted 3 lines
Olaf
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 8 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 2/17/2016 at 12:56 AM, in message <[email protected]>, Olaf
Quoted 4 lines · Hering
Quoted 1 line · Chunyan Liu
#xl usbctrl-attach
test_vmversion=1 ports=8
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
#xl usbdev-attach
test_vmhostbus=1 hostaddr=2I think this does not handle the -N knob of xl. Other commands check the global
dryrun_onlyvariable.Just sent V14. I tried to add
dryrun_onlycodes but finally gave up. For usbdev-attach, since it will automatically and dynamically create usb controller in some cases, it's hard to print dryrun-only information.
Not sure how to handle it, perhaps exit when xl -N is called?
Olaf
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 1 line · Olaf Hering
Not sure how to handle it, perhaps exit when xl -N is called?
Also the interface is 'xl -N' is not clearly defined. What is it supposed to do with the newly introduced ctrl types? Should it display the json just for the dev, just for the ctrl+dev or the entire ctrl with all existing devs + the new dev?
Who is the consumer of the json output?
xl(1) says just "-N Dry run: do not actually execute the command."
I'm asking this mainly in the context of main_vscsiattach, which right now dumps the enitre ctrl with all existing devs + the new dev.
Olaf
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 11 lines · Olaf Hering
Quoted 1 line · Olaf Hering
Not sure how to handle it, perhaps exit when xl -N is called?
Also the interface is 'xl -N' is not clearly defined. What is it supposed to do with the newly introduced ctrl types? Should it display the json just for the dev, just for the ctrl+dev or the entire ctrl with all existing devs + the new dev?
Who is the consumer of the json output?
xl(1) says just "-N Dry run: do not actually execute the command."
Quoted 3 lines
I'm asking this mainly in the context of
main_vscsiattach, which right now dumps the enitre ctrl with all existing devs + the new dev.
I just turn everything into JSON and print it out?
Say, if you only add a controller, you just print the ctrl JSON. If you add a controller and a bunch of devices, you print all of them. Does this sound plausible?
I tend to think dryrun output is only used by administrator to eye-ball the resulting structure. I'm not sure if it is meant to be stable at all.
Maybe Ian has a second opinion on this.
Wei.
Quoted 1 line
Olaf
Re: [PATCH V13 5/5] xl: add pvusb commands
Quoted 3 lines · Wei Liu
Say, if you only add a controller, you just print the ctrl JSON. If you add a controller and a bunch of devices, you print all of them. Does this sound plausible?
Yes.
Olaf