Skip to contentSkip to conversation

xen pvusb toolstack work

PATCH Superseded Chunyan Liu 7 participants 41 messages Aug 10, 2015 – Sep 29, 2015

v6 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v6 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 V5:
* Address George's comments on libxl API and Ian's comments on libxl_read_sysfs_file_content

V5 is here:
http://lists.xen.org/archives/html/xen-devel/2015-06/msg04052.html

V4 is here:
http://lists.xenproject.org/archives/html/xen-devel/2015-06/msg01327.html

Related Discussion Threads:
http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html
http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html

<<< pvusb work introduction >>>

1. Overview

There are two general methods for passing through individual host devices to a guest. The first is via an emulated USB device controller; the second is PVUSB.

Additionally, there are two ways to add USB devices to a guest: via the config file at domain creation time, and via hot-plug while the VM is running.

* Emulated USB

In emulated USB, the device model (qemu) presents an emulated USB controller to the guest. The device model process then grabs control of the device from domain 0 and and passes the USB commands between the guest OS and the host USB device.

This method is only available to HVM domains, and is not available for domains running with device model stubdomains.

* PVUSB

PVUSB uses a paravirtialized front-end/back-end interface, similar to the traditional Xen PV network and disk protocols. In order to use PVUSB, you need usbfront in your guest OS, and usbback in dom0 (or your USB driver domain).

2. Specifying a host USB device

QEMU qmp commands allows USB devices to be specified either by their bus address (in the form bus.device) or their device tag (in the form vendorid:deviceid).

Each way of specifying has its advantages:

Specifying by device tag will always get the same device,
regardless of where the device ends up in the USB bus topology. However, if there are two identical devices, it will not allow you to specify which one.

Specifying by bus address will always allow you to choose a
specific device, even if you have duplicates. However, the bus address may change depending on which port you plugged the device into, and possibly also after a reboot.

To avoid duplication of vendorid:deviceid, we'll use bus address to specify host USB device in xl toolstack.

You can use lsusb to list the USB devices on the system:

Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 003 Device 002: ID f617:0905
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0424:2640 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 005: ID 0424:4060 Standard Microsystems Corp. Ultra Fast Media Reader
Bus 001 Device 006: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse

To pass through the Logitec mouse, for instance, you could specify 1.6 (remove leading zeroes).

Note: USB hubs can not be assigned to guest.

3. PVUSB toolstack

* Specify USB device in xl config file

You can just specify usb devices, like:
usbdev=['1.6']

Then it will create a USB controller automatically and attach the USB device to the first available USB controller:port.

or, you can explicitly specify usb controllers and usb devices, like:
usbctrl=['verison=1, ports=4', 'version=2, ports=8', ] usbdev=['1.6, controller=0, port=1']

Then it will create two USB controllers as you specified. And if controller and port are specified in usb config, then it will attach the USB device to that controller:port. About the controller and port value:
Each USB controller has a index (or called devid) based on 0. The 1st controller has index 0, the 2nd controller has index 1, ... Under controller, each port has a port number based on 1. In above configuration, the 1st controller will have port 1,2,3,4.

* Hot-Plug USB device

To attach a USB device, you should first create a USB controller. e.g.
xl usb-ctrl-attach domain [version=1|2] [ports=value] By default, it will create a USB2.0 controller with 8 ports.

Then you could attach a USB device.
e.g.
xl usb-attach domain 1.6 [controller=index port=number] By default, it will find the 1st available controller:port to attach the USB device.

You could view USB device status of the domain by usb-list. e.g.
xl usb-list domain
It will list USB controllers and USB devices under each controller.

You could detach a USB device with usb-detach command. e.g.
xl usb-detach domain 1.6

You can also remove the whole USB controller by usb-ctrl-detach command.
e.g.
xl usb-ctrl-detach domain 0
It will remove the USB controller with index 0 and all USB devices under it.

4. PVUSB Libxl implementation

* usb-ctrl-attach
To create a usb controller, we need:
1) generate usb controler related information
2) write usb controller frontend/backend info to xenstore PVUSB frontend and backend driver will probe xenstore paths and build connection between frontend and backend.

* usb-ctrl-detach
To remove a usb controller, we need:
1) check if the usb controller exists or not
2) remove all usb devices under controller
3) remove usb controller info from xenstore

* usb-attach
To attach a usb device, we need:
1) check if the usb device type is assignable
2) check if the usb device is already assigned to a domain
3) add 'busid' of the usb device to xenstore contoller/port/. PVUSB driver watches the xenstore changes and detects that, and needs to use 'busid' to do following work.
4) unbind usb device from original driver and bind to usbback. If usb device has many interfaces, then:
- unbind each interface from its original driver and bind to usbback.
- store the original driver to xenstore for later rebinding when detaching the device.

* usb-detach
To detach a usb device, we need:
1) check if the usb device is assigned to the domain
2) remove the usb device from xenstore controller/port.
3) unbind usb device from usbback and rebind to its original driver. If usb device has many interfaces, do it to each interface.

* usb-list
List all USB controllers and USB devices under each controller.

5. PVUSB xenstore information

PVUSB xenstore information includes three parts: frontend, backend and /libxl part.

A USB controller is corresponding to a "vusb" device in xenstore. Adding a USB controller will add a new "vusb" device, removing a USB controller will delete the related "vusb" device.

Following is an example xenstore values of a USB controller. Backend:
backend = ""

    vusb = ""
     1 = ""
      0 = ""
       frontend = "/local/domain/1/device/vusb/0"
       frontend-id = "1"
       online = "1"
       state = "4"
       type = "pv"
       usb-ver = "1"
       num-ports = "4"
       port = ""
        1 = ""
        2 = ""
        3 = ""
        4 = ""

Frontend:
device = ""

    vusb = ""
     0 = ""
      backend = "/local/domain/0/backend/vusb/1/0"
      backend-id = "0"
      state = "4"
      urb-ring-ref = "348"
      conn-ring-ref = "346"
      event-channel = "20"

Adding a USB device won't create a new "vusb" device, but only write the USB device busid to one port of USB controller.
For example, attaching a USB device (busid is 2-1.6) to above USB controller port 1, it only need write 2-1.6 to port 1 of this USB controller:
Backend:
backend = ""

    vusb = ""
     1 = ""
      0 = ""
       frontend = "/local/domain/1/device/vusb/0"
       frontend-id = "1"
       online = "1"
       state = "4"
       type = "pv"
       usb-ver = "1"
       num-ports = "4"
       port = ""
        1 = "2-1.6"
        2 = ""
        3 = ""
        4 = ""

Frontend doesn't change.

Since assign a host USB device to guest, we'll unbind USB interfaces from their original drivers and bind them to usbback. After detaching this USB device from guest, one would hope the USB interfaces could be rebind to their original drivers, so there should some place to get the original driver info. To support that, when attaching a USB device to guest, we'll save the original driver info in xenstore too, the place is /libxl/usbback, for example:
libxl = ""
1 = ""
dm-version = "qemu_xen"
usbback = ""
3-11 = ""
3-11-1_0 = ""
driver_path = "/sys/bus/usb/drivers/btusb"

In this example, USB device (busid is 3-11, /sys/bus/usb/devices/3-11). It has interface 3-11:1.0, whose original dirver is btusb. Since xenstore doesn't allow ':' and '.' in a key, so we encode the interface by changing ':' to '-' and changing '.' to '_'.

When detaching the USB device from guest, we can rebind 3-11:1.0 to btusb driver.

Chunyan Liu (7):
libxl: export some functions for pvusb use
libxl_read_file_contents: add new entry to read sysfs file
libxl: add pvusb API
libxl: add libxl_device_usb_assignable_list API
xl: add pvusb commands
xl: add usb-assignable-list command
domcreate: support pvusb in configuration file

 docs/man/xl.cfg.pod.5                |   75 ++
 docs/man/xl.pod.1                    |   40 +
 tools/libxl/Makefile                 |    2 +-
 tools/libxl/libxl.c                  |   57 +-
 tools/libxl/libxl.h                  |   68 ++
 tools/libxl/libxl_create.c           |   73 +-
 tools/libxl/libxl_device.c           |    8 +
 tools/libxl/libxl_internal.h         |   33 +-
 tools/libxl/libxl_osdeps.h           |   13 +
 tools/libxl/libxl_pvusb.c            | 1373 ++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl          |   59 ++
 tools/libxl/libxl_types_internal.idl |    1 +
 tools/libxl/libxl_utils.c            |   67 +-
 tools/libxl/libxl_utils.h            |    5 +
 tools/libxl/xl.h                     |    6 +
 tools/libxl/xl_cmdimpl.c             |  369 ++++++++-
 tools/libxl/xl_cmdtable.c            |   29 +
 17 files changed, 2259 insertions(+), 19 deletions(-)
 create mode 100644 tools/libxl/libxl_pvusb.c
Signature · 1 line
2.1.4
#1 lore raw

PATCH v6 1/7 libxl: export some functions for pvusb use

---
 tools/libxl/libxl.c          | 4 ++--
 tools/libxl/libxl_internal.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +2 -2
index 083f099..006e8da 100644
@@ -1995,7 +1995,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;
@@ -2014,7 +2014,7 @@ static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device)
     return nextid;
 }
 
-static int libxl__resolve_domid(libxl__gc *gc, const char *name,
+int libxl__resolve_domid(libxl__gc *gc, const char *name,
                                 uint32_t *domid)
 {
     if (!name)
tools/libxl/libxl_internal.h +3 -0
index 6ea6c83..6013628 100644
@@ -1152,6 +1152,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
Acked-by on v6 1/7
#2 lore raw

Re: [PATCH V6 1/7] libxl: export some functions for pvusb use

Quoted 2 lines · Chunyan Liu
Quoted 20 lines
---
 tools/libxl/libxl.c          | 4 ++--
 tools/libxl/libxl_internal.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +1 -1
index 083f099..006e8da 100644
@@ -1995,7 +1995,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;

tools/libxl/libxl.c static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device) · line 2018

Quoted 6 lines
tools/libxl/libxl.c +1 -1
@@ -2014,7 +2014,7 @@ static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device)
     return nextid;
 }
 
-static int libxl__resolve_domid(libxl__gc *gc, const char *name,
+int libxl__resolve_domid(libxl__gc *gc, const char *name,
                                 uint32_t *domid)

Nit: please adjust indentation.

Quoted 18 lines
tools/libxl/libxl.c +0 -0
 {
     if (!name)
tools/libxl/libxl_internal.h +3 -0
index 6ea6c83..6013628 100644
@@ -1152,6 +1152,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
#3 lore raw

PATCH v6 2/7 libxl_read_file_contents: add new entry to read sysfs file

In reply to Chunyan Liu

Sysfs file has size=4096 but actual file content is less than that. Current libxl_read_file_contents will treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.

Add a new entry libxl_read_sysfs_file_contents to handle sysfs file specially. It would be used in later pvusb work.

---
Changes:
- read one more byte to check bigger size problem.

 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_utils.c    | 51 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 42 insertions(+), 11 deletions(-)
tools/libxl/libxl_internal.h +2 -0
index 6013628..f98f089 100644
@@ -4001,6 +4001,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
 
 int libxl__count_physical_sockets(libxl__gc *gc, int *sockets);
 #endif
+_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename,
+                                   void **data_r, int *datalen_r);
 
 /*
  * Local variables:
tools/libxl/libxl_utils.c +40 -11

74 lines not on this page · raw message

Signature · 1 line
2.1.4
#4 lore raw

Re: [PATCH V6 2/7] libxl_read_file_contents: add new entry to read sysfs file

Quoted 23 lines · Chunyan Liu

Sysfs file has size=4096 but actual file content is less than that. Current libxl_read_file_contents will treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.

Add a new entry libxl_read_sysfs_file_contents to handle sysfs file specially. It would be used in later pvusb work.

---
Changes:
- read one more byte to check bigger size problem.

 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_utils.c    | 51 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 42 insertions(+), 11 deletions(-)
tools/libxl/libxl_internal.h +0 -0
index 6013628..f98f089 100644

tools/libxl/libxl_internal.h void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, · line 4005

Quoted 5 lines
tools/libxl/libxl_internal.h +2 -0
@@ -4001,6 +4001,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
 
 int libxl__count_physical_sockets(libxl__gc *gc, int *sockets);
 #endif
+_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename,
+                                   void **data_r, int *datalen_r);

Indentation looks wrong.

Quoted 48 lines
tools/libxl/libxl_internal.h +0 -0
 /*
  * Local variables:
tools/libxl/libxl_utils.c +17 -10
index bfc9699..9234efb 100644
@@ -322,8 +322,10 @@ out:
     return rc;
 }
 
-int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
-                             void **data_r, int *datalen_r) {
+static int libxl_read_file_contents_core(libxl_ctx *ctx, const char *filename,
+                                         void **data_r, int *datalen_r,
+                                         bool tolerate_shrinking_file)
+{
     GC_INIT(ctx);
     FILE *f = 0;
     uint8_t *data = 0;
@@ -359,20 +361,34 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
     datalen = stab.st_size;
 
     if (stab.st_size && data_r) {
-        data = malloc(datalen);
+        data = malloc(datalen + 1);
         if (!data) goto xe;
 
-        rs = fread(data, 1, datalen, f);
-        if (rs != datalen) {
-            if (ferror(f))
+        rs = fread(data, 1, datalen + 1, f);
+        if (rs > datalen) {
+            LOG(ERROR, "%s increased size while we were reading it",
+                filename);
+            goto xe;
+        }
+
+        if (rs < datalen) {
+            if (ferror(f)) {
                 LOGE(ERROR, "failed to read %s", filename);
-            else if (feof(f))
-                LOG(ERROR, "%s changed size while we were reading it",
-		    filename);
-            else
+                goto xe;
+            } else if (feof(f)) {
+                if (tolerate_shrinking_file) {

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 388

Quoted 10 lines
tools/libxl/libxl_utils.c +8 -1
+                    datalen = rs;
+                } else {
+                    LOG(ERROR, "%s shrunk size while we were reading it",
+                        filename);
+                    goto xe;
+                }
+            } else {
                 abort();
-            goto xe;
+            }

This is a bit bikeshedding, but you can leave "goto xe" out of two `if' to reduce patch size.

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 391

Quoted 3 lines
tools/libxl/libxl_utils.c +2 -0
         }
+
+        data = realloc(data, datalen);

Should check return value of realloc.

The logic of this function reflects what has been discussed so far.

Wei.

Quoted 25 lines
tools/libxl/libxl_utils.c +13 -0
     }
 
     if (fclose(f)) {
@@ -396,6 +412,19 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
     return e;
 }
 
+int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
+                             void **data_r, int *datalen_r)
+{
+    return libxl_read_file_contents_core(ctx, filename, data_r, datalen_r, 0);
+}
+
+int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename,
+                                   void **data_r, int *datalen_r)
+{
+    return libxl_read_file_contents_core(ctx, filename, data_r, datalen_r, 1);
+}
+
+
 #define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata)                    \
                                                                           \
   int libxl_##rw##_exactly(libxl_ctx *ctx, int fd,                 \
Signature · 1 line
2.1.4
#5 lore raw

Re: [PATCH V6 2/7] libxl_read_file_contents: add new entry to read sysfs file

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/11/2015 at 07:26 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 89 lines · wrote:

tools/libxl/libxl_internal.h void libxl__bitmap_copy_best_effort(libxl__gc *gc,

Quoted 23 lines · Chunyan Liu

Sysfs file has size=4096 but actual file content is less than that. Current libxl_read_file_contents will treat it as error when file size and actual file content differs, so reading sysfs file content with this function always fails.

Add a new entry libxl_read_sysfs_file_contents to handle sysfs file specially. It would be used in later pvusb work.

---
Changes:
- read one more byte to check bigger size problem.

 tools/libxl/libxl_internal.h |  2 ++ 
 tools/libxl/libxl_utils.c    | 51 ++++++++++++++++++++++++++++++++++---------- 
 2 files changed, 42 insertions(+), 11 deletions(-) 
tools/libxl/libxl_internal.h +0 -0
index 6013628..f98f089 100644 
@@ -4001,6 +4001,8 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc,  

libxl_bitmap *dptr,

tools/libxl/libxl_internal.h void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 int libxl__count_physical_sockets(libxl__gc *gc, int *sockets); 
 #endif 
+_hidden int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char  

*filename,

tools/libxl/libxl_internal.h void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, · line 4005

Quoted 1 line
tools/libxl/libxl_internal.h +1 -0
+                                   void **data_r, int *datalen_r); 

Indentation looks wrong.

Quoted 8 lines
tools/libxl/libxl_internal.h +0 -0
 /* 
  * Local variables: 
tools/libxl/libxl_utils.c +0 -0
index bfc9699..9234efb 100644 

tools/libxl/libxl_utils.c out: · line 325

Quoted 6 lines
tools/libxl/libxl_utils.c +1 -2
@@ -322,8 +322,10 @@ out: 
     return rc; 
 } 
 
-int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, 
-                             void **data_r, int *datalen_r) { 
+static int libxl_read_file_contents_core(libxl_ctx *ctx, const char  

*filename,

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const

Quoted 7 lines
tools/libxl/libxl_utils.c +3 -0
+                                         void **data_r, int *datalen_r, 
+                                         bool tolerate_shrinking_file) 
+{ 
     GC_INIT(ctx); 
     FILE *f = 0; 
     uint8_t *data = 0; 
@@ -359,20 +361,34 @@ int libxl_read_file_contents(libxl_ctx *ctx, const  

char *filename,

Quoted 32 lines
tools/libxl/libxl_utils.c +18 -8
     datalen = stab.st_size; 
 
     if (stab.st_size && data_r) { 
-        data = malloc(datalen); 
+        data = malloc(datalen + 1); 
         if (!data) goto xe; 
 
-        rs = fread(data, 1, datalen, f); 
-        if (rs != datalen) { 
-            if (ferror(f)) 
+        rs = fread(data, 1, datalen + 1, f); 
+        if (rs > datalen) { 
+            LOG(ERROR, "%s increased size while we were reading it", 
+                filename); 
+            goto xe; 
+        } 
+ 
+        if (rs < datalen) { 
+            if (ferror(f)) { 
                 LOGE(ERROR, "failed to read %s", filename); 
-            else if (feof(f)) 
-                LOG(ERROR, "%s changed size while we were reading it", 
-		    filename); 
-            else 
+                goto xe; 
+            } else if (feof(f)) { 
+                if (tolerate_shrinking_file) { 
+                    datalen = rs; 
+                } else { 
+                    LOG(ERROR, "%s shrunk size while we were reading it", 
+                        filename); 
+                    goto xe; 
Quoted 8 lines

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 388

Quoted 5 lines
tools/libxl/libxl_utils.c +3 -1
+                } 
+            } else { 
                 abort(); 
-            goto xe; 
+            } 

This is a bit bikeshedding, but you can leave "goto xe" out of two `if' to reduce patch size.

I guess you mean if (ferror(f)) and if (feof(f)) ? We can't leave 'goto xe' outside, since in if (feof(f)) && if (tolerate_shrinking_file), it's not error but an expected result in sysfs case.

Quoted 5 lines

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 391

Quoted 3 lines
tools/libxl/libxl_utils.c +2 -0
         } 
+ 
+        data = realloc(data, datalen); 

Should check return value of realloc.

Will add a check:
if (!data) goto xe;

Thanks,
Chunyan

Quoted 37 lines

The logic of this function reflects what has been discussed so far.

Wei.

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char

Quoted 4 lines
tools/libxl/libxl_utils.c +0 -0
     } 
 
     if (fclose(f)) { 
@@ -396,6 +412,19 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char  

*filename,

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,

Quoted 7 lines
tools/libxl/libxl_utils.c +4 -0
     return e; 
 } 
 
+int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, 
+                             void **data_r, int *datalen_r) 
+{ 
+    return libxl_read_file_contents_core(ctx, filename, data_r, datalen_r,  

0);

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,

Quoted 6 lines
tools/libxl/libxl_utils.c +6 -0
+} 
+ 
+int libxl_read_sysfs_file_contents(libxl_ctx *ctx, const char *filename, 
+                                   void **data_r, int *datalen_r) 
+{ 
+    return libxl_read_file_contents_core(ctx, filename, data_r, datalen_r,  

1);

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,

Quoted 4 lines
tools/libxl/libxl_utils.c +3 -0
+} 
+ 
+ 
 #define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata)                     

\

Quoted 1 line

\

Quoted 3 lines
   int libxl_##rw##_exactly(libxl_ctx *ctx, int fd,                 \ 
Signature · 1 line
2.1.4 
#6 lore raw

Re: [PATCH V6 2/7] libxl_read_file_contents: add new entry to read sysfs file

On Tue, Aug 11, 2015 at 08:37:09PM -0600, Chun Yan Liu wrote:
[...]

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines

+

tools/libxl/libxl_utils.c +10 -4
+        if (rs < datalen) { 
+            if (ferror(f)) { 
                 LOGE(ERROR, "failed to read %s", filename); 
-            else if (feof(f)) 
-                LOG(ERROR, "%s changed size while we were reading it", 
-		    filename); 
-            else 
+                goto xe; 
+            } else if (feof(f)) { 
+                if (tolerate_shrinking_file) { 
+                    datalen = rs; 
+                } else { 
+                    LOG(ERROR, "%s shrunk size while we were reading it", 
+                        filename); 
+                    goto xe; 
Quoted 8 lines

tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, · line 388

Quoted 5 lines
tools/libxl/libxl_utils.c +3 -1
+                } 
+            } else { 
                 abort(); 
-            goto xe; 
+            } 

This is a bit bikeshedding, but you can leave "goto xe" out of two `if' to reduce patch size.

Quoted 4 lines

I guess you mean if (ferror(f)) and if (feof(f)) ? We can't leave 'goto xe' outside, since in if (feof(f)) && if (tolerate_shrinking_file), it's not error but an expected result in sysfs case.

Oh, right. I missed that tolerate_shrinking_file check. Sorry for the noise.

Wei.

#7 lore raw

PATCH v6 3/7 libxl: add pvusb API

In reply to Chunyan Liu

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

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.
* Add USB 'devtype' union, currently only includes "hostdev"

 tools/libxl/Makefile                 |    2 +-
 tools/libxl/libxl.c                  |   53 ++
 tools/libxl/libxl.h                  |   65 ++
 tools/libxl/libxl_device.c           |    4 +
 tools/libxl/libxl_internal.h         |   20 +-
 tools/libxl/libxl_osdeps.h           |   13 +
 tools/libxl/libxl_pvusb.c            | 1320 ++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl          |   59 ++
 tools/libxl/libxl_types_internal.idl |    1 +
 tools/libxl/libxl_utils.c            |   16 +
 tools/libxl/libxl_utils.h            |    5 +
 11 files changed, 1556 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_pvusb.c
tools/libxl/Makefile +1 -1
index 9036076..cdb50fe 100644
@@ -103,7 +103,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_stream_read.o libxl_stream_write.o \
 			libxl_save_callout.o _libxl_save_msgs_callout.o \
 			libxl_qmp.o libxl_event.o libxl_fork.o \
-			libxl_dom_suspend.o $(LIBXL_OBJS-y)
+			libxl_dom_suspend.o libxl_pvusb.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
tools/libxl/libxl.c +53 -0

76 lines not on this page · raw message

tools/libxl/libxl.h +65 -0

77 lines not on this page · raw message

tools/libxl/libxl_device.c +4 -0
index bee5ed5..935f25b 100644
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
                 aodev->dev = dev;
                 aodev->force = drs->force;
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) {
+                    libxl__initiate_device_usbctrl_remove(egc, aodev);
+                    continue;
+                }
                 libxl__initiate_device_remove(egc, aodev);
             }
         }
tools/libxl/libxl_internal.h +19 -1
index f98f089..5be3b3a 100644
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_vtpm *vtpm,
                                    libxl__ao_device *aodev);
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
+                                       libxl_device_usbctrl *usbctrl,
+                                       libxl__ao_device *aodev);
+
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_usb *usb,
+                                   libxl__ao_device *aodev);
+
 /* Internal function to connect a vkb device */
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
                                   libxl_device_vkb *vkb);
@@ -2585,6 +2593,13 @@ _hidden void libxl__wait_device_connection(libxl__egc*,
 _hidden void libxl__initiate_device_remove(libxl__egc *egc,
                                            libxl__ao_device *aodev);
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
+                                       libxl_device_usbctrl *usbctrl,
+                                       libxl__device *device);
+
+_hidden void libxl__initiate_device_usbctrl_remove(libxl__egc *egc,
+                                                   libxl__ao_device *aodev);
+
 /*
  * libxl__get_hotplug_script_info returns the args and env that should
  * be passed to the hotplug script for the requested device.
@@ -3937,7 +3952,10 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
 #define COMPARE_PCI(a, b) ((a)->func == (b)->func &&    \
                            (a)->bus == (b)->bus &&      \
                            (a)->dev == (b)->dev)
-
+#define COMPARE_USB(a, b) ((a)->u.hostdev.hostbus == (b)->u.hostdev.hostbus && \
+                           (a)->u.hostdev.hostaddr == (b)->u.hostdev.hostaddr)
+#define COMPARE_USBCTRL(a, b) ((a)->devid == (b)->devid)
+ 
 /* DEVICE_ADD
  *
  * Add a device in libxl_domain_config structure
tools/libxl/libxl_osdeps.h +13 -0
index d9661c9..802c762 100644
@@ -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 +1320 -0

1,320 lines not on this page · raw message

tools/libxl/libxl_types.idl +59 -0

77 lines not on this page · raw message

tools/libxl/libxl_types_internal.idl +1 -0
index 5e55685..696f5f8 100644
@@ -22,6 +22,7 @@ libxl__device_kind = Enumeration("device_kind", [
     (6, "VKBD"),
     (7, "CONSOLE"),
     (8, "VTPM"),
+    (9, "VUSB"),
     ])
 
 libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_utils.c +16 -0
index 9234efb..b196203 100644
@@ -1241,6 +1241,22 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len)
     return ret;
 }
 
+void libxl_device_usbctrl_list_free(libxl_device_usbctrl* list, int nr)
+{
+   int i;
+   for (i = 0; i < nr; i++)
+      libxl_device_usbctrl_dispose(&list[i]);
+   free(list);
+}
+
+void libxl_device_usb_list_free(libxl_device_usb* list, int nr)
+{
+   int i;
+   for (i = 0; i < nr; i++)
+      libxl_device_usb_dispose(&list[i]);
+   free(list);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_utils.h +5 -0
index 1e5ca8a..ef049e3 100644
@@ -76,6 +76,11 @@ int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
                                libxl_uuid *uuid, libxl_device_vtpm *vtpm);
 int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
                                int devid, libxl_device_vtpm *vtpm);
+int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid,
+                                  int devid, libxl_device_usbctrl *usbctrl);
+int libxl_ctrlport_to_device_usb(libxl_ctx *ctx, uint32_t domid,
+                                 int ctrl, int port,
+                                 libxl_device_usb *usb);
 
 int libxl_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *bitmap, int n_bits);
     /* Allocated bimap is from malloc, libxl_bitmap_dispose() to be
Signature · 1 line
2.1.4
#8 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 9 lines · Chunyan Liu

Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list usb controller and usb devices
- some other helper functions

Quoted 10 lines

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.
* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

Quoted 13 lines
tools/libxl/libxl.h +5 -0
+
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid,
+                             libxl_device_usb *usb,
+                             libxl_usbinfo *usbinfo);
+
 /* Network Interfaces */
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
                          const libxl_asyncop_how *ao_how)
tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 682

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
                 aodev->dev = dev;
                 aodev->force = drs->force;
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) {
+                    libxl__initiate_device_usbctrl_remove(egc, aodev);
+                    continue;
+                }

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

Quoted 27 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev);
             }
         }
tools/libxl/libxl_internal.h +9 -0
index f98f089..5be3b3a 100644
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_vtpm *vtpm,
                                    libxl__ao_device *aodev);
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
+                                       libxl_device_usbctrl *usbctrl,
+                                       libxl__ao_device *aodev);
+
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_usb *usb,
+                                   libxl__ao_device *aodev);
+
 /* Internal function to connect a vkb device */
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
                                   libxl_device_vkb *vkb);
@@ -2585,6 +2593,13 @@ _hidden void libxl__wait_device_connection(libxl__egc*,
 _hidden void libxl__initiate_device_remove(libxl__egc *egc,
                                            libxl__ao_device *aodev);
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,

[...]

Quoted 34 lines
tools/libxl/libxl_internal.h +34 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,
+                           libxl_device_usb *usb,
+                           libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    int rc = -1;
+    char *busid = NULL;
+
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0);
+
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,
+                                 usb->u.hostdev.hostaddr);
+    if (!busid) {
+        LOG(ERROR, "USB device doesn't exist in sysfs");
+        goto out;
+    }
+
+    if (!is_usb_assignable(gc, usb)) {
+        LOG(ERROR, "USB device is not assignable.");
+        goto out;
+    }
+
+    /* check usb device is already assigned */
+    if (is_usb_assigned(gc, usb)) {
+        LOG(ERROR, "USB device is already attached to a domain.");
+        goto out;
+    }
+
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json);
+    if (rc) goto out;
+
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb, aodev->update_json);
+    if (rc) goto out;
+

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+    rc = usbback_dev_assign(gc, usb);
+    if (rc) {
+        libxl__device_usb_remove_xenstore(gc, domid, usb);
+        goto out;
+    }
+
+    libxl__ao_complete(egc, ao, 0);
+    rc = 0;
+
+out:

You forget to complete ao in failure path.

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

#9 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/11/2015 at 07:27 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 50 lines · wrote:
Quoted 9 lines · Chunyan Liu

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

Quoted 10 lines

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.
* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,

Quoted 7 lines

+

tools/libxl/libxl.h +4 -0
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid, 
+                             libxl_device_usb *usb, 
+                             libxl_usbinfo *usbinfo); 
+ 
 /* Network Interfaces */ 
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic  

*nic,

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,

Quoted 6 lines

const libxl_asyncop_how *ao_how)

tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644 
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,  

libxl__devices_remove_state *drs)

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 682

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE; 
                 aodev->dev = dev; 
                 aodev->force = drs->force; 
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) { 
+                    libxl__initiate_device_usbctrl_remove(egc, aodev); 
+                    continue; 
+                } 
Quoted 2 lines

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

You mean races with other device removal (like 'vbd') ? Yes, it is idempotent. Only for 'vusb' (corresponding to USB controller), before removing USB controller it will first removing all USB devices under it.

Quoted 69 lines

tools/libxl/libxl_internal.h _hidden void libxl__device_vtpm_add(libxl__egc *egc,

Quoted 9 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev); 
             } 
         } 
tools/libxl/libxl_internal.h +0 -0
index f98f089..5be3b3a 100644 
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc,  

uint32_t domid,

tools/libxl/libxl_internal.h _hidden void

Quoted 15 lines
tools/libxl/libxl_internal.h +8 -0
                                    libxl_device_vtpm *vtpm, 
                                    libxl__ao_device *aodev); 
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, 
+                                       libxl_device_usbctrl *usbctrl, 
+                                       libxl__ao_device *aodev); 
+ 
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                                   libxl_device_usb *usb, 
+                                   libxl__ao_device *aodev); 
+ 
 /* Internal function to connect a vkb device */ 
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid, 
                                   libxl_device_vkb *vkb); 
@@ -2585,6 +2593,13 @@ _hidden void  

libxl__wait_device_connection(libxl__egc*,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 _hidden void libxl__initiate_device_remove(libxl__egc *egc, 
                                            libxl__ao_device *aodev); 
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, 

[...]

Quoted 38 lines
tools/libxl/libxl_internal.h +38 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                           libxl_device_usb *usb, 
+                           libxl__ao_device *aodev) 
+{ 
+    STATE_AO_GC(aodev->ao); 
+    int rc = -1; 
+    char *busid = NULL; 
+ 
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0); 
+ 
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus, 
+                                 usb->u.hostdev.hostaddr); 
+    if (!busid) { 
+        LOG(ERROR, "USB device doesn't exist in sysfs"); 
+        goto out; 
+    } 
+ 
+    if (!is_usb_assignable(gc, usb)) { 
+        LOG(ERROR, "USB device is not assignable."); 
+        goto out; 
+    } 
+ 
+    /* check usb device is already assigned */ 
+    if (is_usb_assigned(gc, usb)) { 
+        LOG(ERROR, "USB device is already attached to a domain."); 
+        goto out; 
+    } 
+ 
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 
+    rc = usbback_dev_assign(gc, usb); 
+    if (rc) { 
+        libxl__device_usb_remove_xenstore(gc, domid, usb); 
+        goto out; 
Quoted 8 lines

tools/libxl/libxl_internal.h

Quoted 6 lines
tools/libxl/libxl_internal.h +6 -0
+    } 
+ 
+    libxl__ao_complete(egc, ao, 0); 
+    rc = 0; 
+ 
+out: 

You forget to complete ao in failure path.

It will complete ao in aodev->callback(egc, aodev) in "out:" section, here:
if (rc) aodev->callback(egc, aodev);

Thanks,
Chunyan

Quoted 7 lines

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

#10 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 55 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/11/2015 at 07:27 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 50 lines · wrote:
Quoted 9 lines · Chunyan Liu

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

Quoted 10 lines

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.
* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,

Quoted 7 lines

+

tools/libxl/libxl.h +4 -0
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid, 
+                             libxl_device_usb *usb, 
+                             libxl_usbinfo *usbinfo); 
+ 
 /* Network Interfaces */ 
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic  

*nic,

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,

Quoted 6 lines

const libxl_asyncop_how *ao_how)

tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644 
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,  

libxl__devices_remove_state *drs)

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE; 
                 aodev->dev = dev; 
                 aodev->force = drs->force; 
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) { 
+                    libxl__initiate_device_usbctrl_remove(egc, aodev); 
+                    continue; 
+                } 
Quoted 7 lines
Quoted 2 lines

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

You mean races with other device removal (like 'vbd') ? Yes, it is idempotent. Only for 'vusb' (corresponding to USB controller), before removing USB controller it will first removing all USB devices under it.

No. What I mean is, the removal of usbctrl triggers removal of all assigned usb devices. And then this function initiates removal of assigned usb devices again. Is this a possible scenario?

Quoted 78 lines
Quoted 69 lines

tools/libxl/libxl_internal.h _hidden void libxl__device_vtpm_add(libxl__egc *egc,

Quoted 9 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev); 
             } 
         } 
tools/libxl/libxl_internal.h +0 -0
index f98f089..5be3b3a 100644 
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc,  

uint32_t domid,

tools/libxl/libxl_internal.h _hidden void

Quoted 15 lines
tools/libxl/libxl_internal.h +8 -0
                                    libxl_device_vtpm *vtpm, 
                                    libxl__ao_device *aodev); 
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, 
+                                       libxl_device_usbctrl *usbctrl, 
+                                       libxl__ao_device *aodev); 
+ 
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                                   libxl_device_usb *usb, 
+                                   libxl__ao_device *aodev); 
+ 
 /* Internal function to connect a vkb device */ 
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid, 
                                   libxl_device_vkb *vkb); 
@@ -2585,6 +2593,13 @@ _hidden void  

libxl__wait_device_connection(libxl__egc*,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 _hidden void libxl__initiate_device_remove(libxl__egc *egc, 
                                            libxl__ao_device *aodev); 
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, 

[...]

Quoted 38 lines
tools/libxl/libxl_internal.h +38 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                           libxl_device_usb *usb, 
+                           libxl__ao_device *aodev) 
+{ 
+    STATE_AO_GC(aodev->ao); 
+    int rc = -1; 
+    char *busid = NULL; 
+ 
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0); 
+ 
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus, 
+                                 usb->u.hostdev.hostaddr); 
+    if (!busid) { 
+        LOG(ERROR, "USB device doesn't exist in sysfs"); 
+        goto out; 
+    } 
+ 
+    if (!is_usb_assignable(gc, usb)) { 
+        LOG(ERROR, "USB device is not assignable."); 
+        goto out; 
+    } 
+ 
+    /* check usb device is already assigned */ 
+    if (is_usb_assigned(gc, usb)) { 
+        LOG(ERROR, "USB device is already attached to a domain."); 
+        goto out; 
+    } 
+ 
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 
+    rc = usbback_dev_assign(gc, usb); 
+    if (rc) { 
+        libxl__device_usb_remove_xenstore(gc, domid, usb); 
+        goto out; 
Quoted 8 lines

tools/libxl/libxl_internal.h

Quoted 6 lines
tools/libxl/libxl_internal.h +6 -0
+    } 
+ 
+    libxl__ao_complete(egc, ao, 0); 
+    rc = 0; 
+ 
+out: 

You forget to complete ao in failure path.

Quoted 3 lines

It will complete ao in aodev->callback(egc, aodev) in "out:" section, here:

   if (rc) aodev->callback(egc, aodev);

I'm still confused by the way it is structured. If aodev->callback completes the AO nonetheless, why don't you just call that unconditionally?

Wei.

Quoted 10 lines

Thanks,
Chunyan

Quoted 7 lines

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

#11 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/13/2015 at 05:09 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 58 lines · wrote:
Quoted 40 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/11/2015 at 07:27 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 35 lines · wrote:
Quoted 18 lines · Chunyan Liu

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

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.

Quoted 2 lines

* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

Quoted 7 lines
tools/libxl/libxl.h +5 -0
+  
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid,  
+                             libxl_device_usb *usb,  
+                             libxl_usbinfo *usbinfo);  
+  
 /* Network Interfaces */  
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid,  

libxl_device_nic

Quoted 16 lines
Quoted 16 lines

*nic,

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,

Quoted 6 lines

const libxl_asyncop_how *ao_how)

tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644  
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,   

libxl__devices_remove_state *drs)

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE;  
                 aodev->dev = dev;  
                 aodev->force = drs->force;  
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) {  
+                    libxl__initiate_device_usbctrl_remove(egc, aodev);  
+                    continue;  
+                }  
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

You mean races with other device removal (like 'vbd') ? Yes, it is

idempotent.

Quoted 1 line

Only for 'vusb' (corresponding to USB controller), before removing USB

controller

Quoted 1 line

it will first removing all USB devices under it.

h >

Quoted 4 lines

No. What I mean is, the removal of usbctrl triggers removal of all assigned usb devices. And then this function initiates removal of assigned usb devices again. Is this a possible scenario?

No, it's not possible. libxl__devices_destroy is used in domain destroy, it's trying to scan each device type in xenstore and destroy them. Since USB device is NOT presented as a separate device type but inside USB controller (which is represented by a 'vusb' device in xenstore), so when scanning 'vusb' type, it tries to destroy USB controller, within that it will destroy all USB devices under that controller. No entry to remove USB device alone.

Thanks,
Chunyan

Quoted 105 lines
Quoted 10 lines
Quoted 10 lines

tools/libxl/libxl_internal.h _hidden void libxl__device_vtpm_add(libxl__egc

Quoted 10 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev);  
             }  
         }  
tools/libxl/libxl_internal.h +0 -0
index f98f089..5be3b3a 100644  
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc  

*egc,

Quoted 52 lines
Quoted 51 lines

uint32_t domid,

tools/libxl/libxl_internal.h _hidden void

Quoted 15 lines
tools/libxl/libxl_internal.h +8 -0
                                    libxl_device_vtpm *vtpm,  
                                    libxl__ao_device *aodev);  
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,  
+                                       libxl_device_usbctrl *usbctrl,  
+                                       libxl__ao_device *aodev);  
+  
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,  
+                                   libxl_device_usb *usb,  
+                                   libxl__ao_device *aodev);  
+  
 /* Internal function to connect a vkb device */  
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,  
                                   libxl_device_vkb *vkb);  
@@ -2585,6 +2593,13 @@ _hidden void   

libxl__wait_device_connection(libxl__egc*,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 _hidden void libxl__initiate_device_remove(libxl__egc *egc,  
                                            libxl__ao_device *aodev);  
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,  

[...]

Quoted 29 lines
tools/libxl/libxl_internal.h +29 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,  
+                           libxl_device_usb *usb,  
+                           libxl__ao_device *aodev)  
+{  
+    STATE_AO_GC(aodev->ao);  
+    int rc = -1;  
+    char *busid = NULL;  
+  
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0);  
+  
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,  
+                                 usb->u.hostdev.hostaddr);  
+    if (!busid) {  
+        LOG(ERROR, "USB device doesn't exist in sysfs");  
+        goto out;  
+    }  
+  
+    if (!is_usb_assignable(gc, usb)) {  
+        LOG(ERROR, "USB device is not assignable.");  
+        goto out;  
+    }  
+  
+    /* check usb device is already assigned */  
+    if (is_usb_assigned(gc, usb)) {  
+        LOG(ERROR, "USB device is already attached to a domain.");  
+        goto out;  
+    }  
+  
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json);  
Quoted 3 lines
Quoted 3 lines

tools/libxl/libxl_internal.h

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    if (rc) goto out;  
+  
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb,  

aodev->update_json);

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
tools/libxl/libxl_internal.h +12 -0
+    if (rc) goto out;  
+  
+    rc = usbback_dev_assign(gc, usb);  
+    if (rc) {  
+        libxl__device_usb_remove_xenstore(gc, domid, usb);  
+        goto out;  
+    }  
+  
+    libxl__ao_complete(egc, ao, 0);  
+    rc = 0;  
+  
+out:  
Quoted 5 lines
Quoted 1 line

You forget to complete ao in failure path.

It will complete ao in aodev->callback(egc, aodev) in "out:" section, here:

   if (rc) aodev->callback(egc, aodev); 

I'm still confused by the way it is structured. If aodev->callback completes the AO nonetheless, why don't you just call that unconditionally?

Wei.

Quoted 10 lines

Thanks,
Chunyan

Quoted 7 lines

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

#12 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Wei Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/13/2015 at 05:09 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 153 lines · wrote:
Quoted 40 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 8/11/2015 at 07:27 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 35 lines · wrote:
Quoted 18 lines · Chunyan Liu

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

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.

Quoted 2 lines

* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

Quoted 7 lines
tools/libxl/libxl.h +5 -0
+  
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid,  
+                             libxl_device_usb *usb,  
+                             libxl_usbinfo *usbinfo);  
+  
 /* Network Interfaces */  
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid,  

libxl_device_nic

Quoted 16 lines
Quoted 16 lines

*nic,

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,

Quoted 6 lines

const libxl_asyncop_how *ao_how)

tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644  
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,   

libxl__devices_remove_state *drs)

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE;  
                 aodev->dev = dev;  
                 aodev->force = drs->force;  
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) {  
+                    libxl__initiate_device_usbctrl_remove(egc, aodev);  
+                    continue;  
+                }  
Quoted 4 lines
Quoted 2 lines

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

You mean races with other device removal (like 'vbd') ? Yes, it is

idempotent.

Quoted 1 line

Only for 'vusb' (corresponding to USB controller), before removing USB

controller

Quoted 2 lines

it will first removing all USB devices under it.

No. What I mean is, the removal of usbctrl triggers removal of all assigned usb devices. And then this function initiates removal of assigned usb devices again. Is this a possible scenario?

Quoted 9 lines
Quoted 9 lines

tools/libxl/libxl_internal.h _hidden void libxl__device_vtpm_add(libxl__egc

Quoted 9 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev);  
             }  
         }  
tools/libxl/libxl_internal.h +0 -0
index f98f089..5be3b3a 100644  
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc  

*egc,

Quoted 52 lines
Quoted 51 lines

uint32_t domid,

tools/libxl/libxl_internal.h _hidden void

Quoted 15 lines
tools/libxl/libxl_internal.h +8 -0
                                    libxl_device_vtpm *vtpm,  
                                    libxl__ao_device *aodev);  
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,  
+                                       libxl_device_usbctrl *usbctrl,  
+                                       libxl__ao_device *aodev);  
+  
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,  
+                                   libxl_device_usb *usb,  
+                                   libxl__ao_device *aodev);  
+  
 /* Internal function to connect a vkb device */  
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,  
                                   libxl_device_vkb *vkb);  
@@ -2585,6 +2593,13 @@ _hidden void   

libxl__wait_device_connection(libxl__egc*,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 _hidden void libxl__initiate_device_remove(libxl__egc *egc,  
                                            libxl__ao_device *aodev);  
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,  

[...]

Quoted 29 lines
tools/libxl/libxl_internal.h +29 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid,  
+                           libxl_device_usb *usb,  
+                           libxl__ao_device *aodev)  
+{  
+    STATE_AO_GC(aodev->ao);  
+    int rc = -1;  
+    char *busid = NULL;  
+  
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0);  
+  
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus,  
+                                 usb->u.hostdev.hostaddr);  
+    if (!busid) {  
+        LOG(ERROR, "USB device doesn't exist in sysfs");  
+        goto out;  
+    }  
+  
+    if (!is_usb_assignable(gc, usb)) {  
+        LOG(ERROR, "USB device is not assignable.");  
+        goto out;  
+    }  
+  
+    /* check usb device is already assigned */  
+    if (is_usb_assigned(gc, usb)) {  
+        LOG(ERROR, "USB device is already attached to a domain.");  
+        goto out;  
+    }  
+  
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json);  
Quoted 3 lines
Quoted 3 lines

tools/libxl/libxl_internal.h

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    if (rc) goto out;  
+  
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb,  

aodev->update_json);

Quoted 15 lines
Quoted 14 lines

tools/libxl/libxl_internal.h

Quoted 12 lines
tools/libxl/libxl_internal.h +12 -0
+    if (rc) goto out;  
+  
+    rc = usbback_dev_assign(gc, usb);  
+    if (rc) {  
+        libxl__device_usb_remove_xenstore(gc, domid, usb);  
+        goto out;  
+    }  
+  
+    libxl__ao_complete(egc, ao, 0);  
+    rc = 0;  
+  
+out:  

You forget to complete ao in failure path.

Quoted 7 lines
Quoted 3 lines

It will complete ao in aodev->callback(egc, aodev) in "out:" section, here:

   if (rc) aodev->callback(egc, aodev); 

I'm still confused by the way it is structured. If aodev->callback completes the AO nonetheless, why don't you just call that unconditionally?

In general case, it won't call libxl__ao_complete directly. In correct path, it will call libxl__wait_device_connection (it will wait for front/backend driver status change and deal with hotplug script, and then call callback function 'addrmcompelte' or in some path call libxl__ao_compelete to complete the ao); in error path, it will call aodev->callback function 'addrmcomplete' to complete the ao.

Here, we try to follow the general routine, so keep the error path handling; but for correct path, since there is no need to wait for device, so we explicitly call libxl__ao_compelte to complete ao. That may keep the function easier to read? (since it keeps the same framework as others.) I see the pending scsi patch series when adding scsi device does in the same way.

Thanks,
Chunyan

Quoted 21 lines

Wei.

Quoted 10 lines

Thanks,
Chunyan

Quoted 7 lines

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Wei Liu

Ian and George, could I have your comments?

Thanks,
Chunyan

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 8/11/2015 at 07:27 PM, in message

<[email protected]>, Wei Liu <[email protected]>

Quoted 141 lines · wrote:
Quoted 9 lines · Chunyan Liu

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

Quoted 10 lines

---
changes:
- Address George's comments:
* Update libxl_device_usb_getinfo to read ctrl/port only and get other information.
* Update backend path according to xenstore frontend 'xxx/backend' entry instead of using TOOLSTACK_DOMID.
* Use 'type' to indicate qemu/pv instead of previous naming 'protocol'.
* Add USB 'devtype' union, currently only includes "hostdev"

I will leave this to Ian and George since they had strong opinions on this.

I only skimmed this patch. Some comments below.

[...]

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,

Quoted 7 lines

+

tools/libxl/libxl.h +4 -0
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid, 
+                             libxl_device_usb *usb, 
+                             libxl_usbinfo *usbinfo); 
+ 
 /* Network Interfaces */ 
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic  

*nic,

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc,

Quoted 6 lines

const libxl_asyncop_how *ao_how)

tools/libxl/libxl_device.c +0 -0
index bee5ed5..935f25b 100644 
@@ -676,6 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc,  

libxl__devices_remove_state *drs)

tools/libxl/libxl_device.c void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) · line 682

Quoted 7 lines
tools/libxl/libxl_device.c +4 -0
                 aodev->action = LIBXL__DEVICE_ACTION_REMOVE; 
                 aodev->dev = dev; 
                 aodev->force = drs->force; 
+                if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB) { 
+                    libxl__initiate_device_usbctrl_remove(egc, aodev); 
+                    continue; 
+                } 

Is there a risk that this races with individual device removal? I think you get away with it because removal of individual device is idempotent?

tools/libxl/libxl_internal.h _hidden void libxl__device_vtpm_add(libxl__egc *egc,

Quoted 8 lines
tools/libxl/libxl_device.c +0 -0
                 libxl__initiate_device_remove(egc, aodev); 
             } 
         } 
tools/libxl/libxl_internal.h +0 -0
index f98f089..5be3b3a 100644 
@@ -2553,6 +2553,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc,  

uint32_t domid,

tools/libxl/libxl_internal.h _hidden void

Quoted 15 lines
tools/libxl/libxl_internal.h +8 -0
                                    libxl_device_vtpm *vtpm, 
                                    libxl__ao_device *aodev); 
 
+_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, 
+                                       libxl_device_usbctrl *usbctrl, 
+                                       libxl__ao_device *aodev); 
+ 
+_hidden void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                                   libxl_device_usb *usb, 
+                                   libxl__ao_device *aodev); 
+ 
 /* Internal function to connect a vkb device */ 
 _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid, 
                                   libxl_device_vkb *vkb); 
@@ -2585,6 +2593,13 @@ _hidden void  

libxl__wait_device_connection(libxl__egc*,

Quoted 4 lines
tools/libxl/libxl_internal.h +1 -0
 _hidden void libxl__initiate_device_remove(libxl__egc *egc, 
                                            libxl__ao_device *aodev); 
 
+_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, 

[...]

Quoted 34 lines
tools/libxl/libxl_internal.h +34 -0
+void libxl__device_usb_add(libxl__egc *egc, uint32_t domid, 
+                           libxl_device_usb *usb, 
+                           libxl__ao_device *aodev) 
+{ 
+    STATE_AO_GC(aodev->ao); 
+    int rc = -1; 
+    char *busid = NULL; 
+ 
+    assert(usb->u.hostdev.hostbus > 0 && usb->u.hostdev.hostaddr > 0); 
+ 
+    busid = usb_busaddr_to_busid(gc, usb->u.hostdev.hostbus, 
+                                 usb->u.hostdev.hostaddr); 
+    if (!busid) { 
+        LOG(ERROR, "USB device doesn't exist in sysfs"); 
+        goto out; 
+    } 
+ 
+    if (!is_usb_assignable(gc, usb)) { 
+        LOG(ERROR, "USB device is not assignable."); 
+        goto out; 
+    } 
+ 
+    /* check usb device is already assigned */ 
+    if (is_usb_assigned(gc, usb)) { 
+        LOG(ERROR, "USB device is already attached to a domain."); 
+        goto out; 
+    } 
+ 
+    rc = libxl__device_usb_setdefault(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 
+    rc = libxl__device_usb_add_xenstore(gc, domid, usb, aodev->update_json); 
+    if (rc) goto out; 
+ 

tools/libxl/libxl_internal.h

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+    rc = usbback_dev_assign(gc, usb); 
+    if (rc) { 
+        libxl__device_usb_remove_xenstore(gc, domid, usb); 
+        goto out; 
+    } 
+ 
+    libxl__ao_complete(egc, ao, 0); 
+    rc = 0; 
+ 
+out: 

You forget to complete ao in failure path.

But I'm not very familiar with the AO machinery, I will let Ian comment on this.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Chunyan Liu

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

tools/libxl/libxl.h line 126

Quoted 9 lines
tools/libxl/libxl.h +1 -0
index 5f9047c..05b6331 100644
@@ -123,6 +123,23 @@
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1
 
 /*
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of

And cold-plug, no?

tools/libxl/libxl.h line 137

Quoted 11 lines
tools/libxl/libxl.h +11 -0
+ * USB devices through pvusb.
+ *
+ * With this functionality, one can add/remove USB controllers to/from
+ * guest, and attach/detach USB devices to/from USB controllers. To add
+ * USB controllers and USB devices, one can either adding USB controllers
+ * first and then attaching USB devices to some USB controller, or adding
+ * USB devices to guest directly, it will automatically create a USB
+ * controller for USB devices to attach. To remove USB controllers or USB
+ * devices, one can either remove USB devices under USB controller one by
+ * one and then remove USB controller, or remove USB controller directly,
+ * it will remove all USB devices under it automatically.

I think this API documentation belongs alongside the API declarations (i.e the prototypes) rather than hidden away next to the feature flag.

Quoted 9 lines
tools/libxl/libxl.h +5 -0
+ *
+ */
+#define LIBXL_HAVE_PVUSB 1
+
+/*
  * LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE indicates that the
  * libxl_vendor_device field is present in the hvm sections of
  * libxl_domain_build_info. This field tells libxl which

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t · line 1411

Quoted 6 lines
tools/libxl/libxl.h +1 -0
@@ -1389,6 +1406,54 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t
 domid, libxl_device_disk *disk,
                        const libxl_asyncop_how *ao_how)
                        LIBXL_EXTERNAL_CALLERS_ONLY;
 
+/* USB Controllers*/
 

[....]

Seem fine.

Quoted 6 lines
tools/libxl/libxl.h +6 -0
+
+/* USB Devices */
+int libxl_device_usb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usb *usb,
+                         const libxl_asyncop_how *ao_how)
+                         LIBXL_EXTERNAL_CALLERS_ONLY;
+

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, · line 1449

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+int libxl_device_usb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_usb *usb,
+                            const libxl_asyncop_how *ao_how)
+                            LIBXL_EXTERNAL_CALLERS_ONLY;
+
+libxl_device_usb *
+libxl_device_usb_list(libxl_ctx *ctx, uint32_t domid, int *num);
+
+libxl_device_usb *
+libxl_device_usb_list_per_usbctrl(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_devid usbctrl, int *num);

I'd probably say "..._for_usbctrl" or "..._by_usbctrl", but that's just nitpicking.

Quoted 11 lines
tools/libxl/libxl.h +7 -0
+
+void libxl_device_usb_list_free(libxl_device_usb *list, int nr);
+
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid,
+                             libxl_device_usb *usb,
+                             libxl_usbinfo *usbinfo);
+
 /* Network Interfaces */
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid,

libxl_device_nic *nic,
const libxl_asyncop_how *ao_how)

[...]

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 598

Quoted 10 lines
tools/libxl/libxl_types.idl +2 -0
index ef346e7..ef10484 100644
@@ -594,6 +594,37 @@ libxl_device_rdm = Struct("device_rdm", [
     ("policy", libxl_rdm_reserve_policy),
     ])
 
+libxl_usbctrl_type = Enumeration("usbctrl_type", [
+    (0, "AUTO"),

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 600

Quoted 2 lines
tools/libxl/libxl_types.idl +2 -0
+    (1, "PV"),
+    (2, "QEMU"),

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

Quoted 14 lines
tools/libxl/libxl_types.idl +14 -0
+    ])
+
+libxl_usbdev_type = Enumeration("usbdev_type", [
+    (0, "invalid"),
+    (1, "hostdev"),
+    ])
+
+libxl_device_usbctrl = Struct("device_usbctrl", [
+    ("type", libxl_usbctrl_type),
+    ("devid", libxl_devid),
+    ("version", integer),
+    ("ports", integer),
+    ("backend_domid", libxl_domid),
+    ("backend_domname", string),

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 624

Quoted 10 lines
tools/libxl/libxl_types.idl +10 -0
+   ])
+
+libxl_device_usb = Struct("device_usb", [
+    ("ctrl", libxl_devid),
+    ("port", integer),
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype",
+           [("hostdev", Struct(None, [
+                 ("hostbus",   integer),
+                 ("hostaddr",  integer)])),
+            ("invalid", None),

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

Do these fields have any particular size requirements arising from e.g. the USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe we could use the appropriate fixed size types?

Quoted 31 lines
tools/libxl/libxl_types.idl +17 -0
+           ])),
+    ])
+
 libxl_device_dtdev = Struct("device_dtdev", [
     ("path", string),
     ])
@@ -626,6 +657,8 @@ libxl_domain_config = Struct("domain_config", [
     ("pcidevs", Array(libxl_device_pci, "num_pcidevs")),
     ("rdms", Array(libxl_device_rdm, "num_rdms")),
     ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")),
+    ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")),
+    ("usbs", Array(libxl_device_usb, "num_usbs")),
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")),
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")),
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
@@ -674,6 +707,32 @@ libxl_vtpminfo = Struct("vtpminfo", [
     ("uuid", libxl_uuid),
     ], dir=DIR_OUT)
 
+libxl_usbctrlinfo = Struct("usbctrlinfo", [
+    ("type", libxl_usbctrl_type),
+    ("devid", libxl_devid),
+    ("version", integer),
+    ("ports", integer),
+    ("backend", string),
+    ("backend_id", uint32),
+    ("frontend", string),
+    ("frontend_id", uint32),
+    ("state", integer),
+    ("evtch", integer),
+    ("ref_urb", integer),

tools/libxl/libxl_types.idl libxl_vtpminfo = Struct("vtpminfo", [ · line 731

Quoted 10 lines
tools/libxl/libxl_types.idl +10 -0
+    ("ref_conn", integer),
+    ], dir=DIR_OUT)
+
+libxl_usbinfo = Struct("usbinfo", [
+    ("ctrl", libxl_devid),
+    ("port", integer),
+    ("busnum", integer),
+    ("devnum", integer),
+    ("idVendor", integer),
+    ("idProduct", integer),

I think id* are 16 bits? uint16 might be better then.

Quoted 7 lines
tools/libxl/libxl_types.idl +4 -0
+    ("prod", string),
+    ("manuf", string),
+    ], dir=DIR_OUT)
+
 libxl_vcpuinfo = Struct("vcpuinfo", [
     ("vcpuid", uint32),
     ("cpu", uint32),
#15 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 15 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

Quoted 7 lines
tools/libxl/libxl.h +0 -0
index 5f9047c..05b6331 100644
@@ -123,6 +123,23 @@
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1
 
Quoted 4 lines

tools/libxl/libxl.h line 126

Quoted 2 lines
tools/libxl/libxl.h +1 -0
 /*
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of

And cold-plug, no?

So you should probably say something like "indicates functions for plugging in USB devices through pvusb -- both hotplug and at domain creation time."

Quoted 4 lines

tools/libxl/libxl.h line 128

Quoted 2 lines
tools/libxl/libxl.h +2 -0
+libxl_usbctrl_type = Enumeration("usbctrl_type", [
+    (0, "AUTO"),

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

Generally "DTRT". Meaning:
1. If your domain has no devicemodel, use PV.
2. If your device has a devicemodel, and no PV drivers have peen detected, use the devicemodel.
3. If your device has a devicemodel, but PV drivers have been detected, use PV.

At the moment we don't have a way to check for PV drivers, so this just collapses down to "PV for domains without a DM and DM for domains with a DM."

Quoted 5 lines

tools/libxl/libxl.h line 130

Quoted 3 lines
tools/libxl/libxl.h +2 -0
+    (1, "PV"),
+    (2, "QEMU"),

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I had this as "DEVICEMODEL", since what we mean is that we want the device model to provide access (and in theory in the future we may use a different device model). But "EMU" works for me too.

Quoted 17 lines

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Quoted 4 lines

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

I think the idea was to simply offer 1, 2, and 3 as options, and for the devicemodel version, choose a suitable controller (or set of controllers) for each option; similar to what usbversion= does now.

Quoted 29 lines
Quoted 15 lines
tools/libxl/libxl.h +14 -0
+    ])
+
+libxl_usbdev_type = Enumeration("usbdev_type", [
+    (0, "invalid"),
+    (1, "hostdev"),
+    ])
+
+libxl_device_usbctrl = Struct("device_usbctrl", [
+    ("type", libxl_usbctrl_type),
+    ("devid", libxl_devid),
+    ("version", integer),
+    ("ports", integer),
+    ("backend_domid", libxl_domid),
+    ("backend_domname", string),

tools/libxl/libxl.h

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+   ])
+
+libxl_device_usb = Struct("device_usb", [
+    ("ctrl", libxl_devid),
+    ("port", integer),
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype",
+           [("hostdev", Struct(None, [
+                 ("hostbus",   integer),
+                 ("hostaddr",  integer)])),
+            ("invalid", None),

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Quoted 3 lines

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

I can confirm this.

-George

#16 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/9/2015 at 12:52 AM, in message <[email protected]>, George Dunlap

Quoted 16 lines · <[email protected]> wrote:
Quoted 15 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

Quoted 7 lines
tools/libxl/libxl.h +0 -0
index 5f9047c..05b6331 100644 
@@ -123,6 +123,23 @@ 
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1 
 
Quoted 8 lines
Quoted 4 lines

tools/libxl/libxl.h line 126

Quoted 2 lines
tools/libxl/libxl.h +1 -0
 /* 
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of 

And cold-plug, no?

So you should probably say something like "indicates functions for plugging in USB devices through pvusb -- both hotplug and at domain creation time."

Thanks. Will clarify.

Quoted 13 lines
Quoted 5 lines

tools/libxl/libxl.h line 128

Quoted 3 lines
tools/libxl/libxl.h +2 -0
+libxl_usbctrl_type = Enumeration("usbctrl_type", [ 
+    (0, "AUTO"), 

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

Generally "DTRT". Meaning:
1. If your domain has no devicemodel, use PV.
2. If your device has a devicemodel, and no PV drivers have peen detected, use the devicemodel.
3. If your device has a devicemodel, but PV drivers have been detected, use PV.

Quoted 3 lines

At the moment we don't have a way to check for PV drivers, so this just collapses down to "PV for domains without a DM and DM for domains with a DM."

Better to be: by default, PV for PV guest and DM for HVM guest.

Thanks,
Chunyan

Quoted 76 lines
Quoted 6 lines

tools/libxl/libxl.h line 130

Quoted 4 lines
tools/libxl/libxl.h +2 -0
+    (1, "PV"), 
+    (2, "QEMU"), 

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I had this as "DEVICEMODEL", since what we mean is that we want the device model to provide access (and in theory in the future we may use a different device model). But "EMU" works for me too.

Quoted 17 lines

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Quoted 4 lines

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

I think the idea was to simply offer 1, 2, and 3 as options, and for the devicemodel version, choose a suitable controller (or set of controllers) for each option; similar to what usbversion= does now.

Quoted 29 lines
Quoted 15 lines
tools/libxl/libxl.h +14 -0
+    ]) 
+ 
+libxl_usbdev_type = Enumeration("usbdev_type", [ 
+    (0, "invalid"), 
+    (1, "hostdev"), 
+    ]) 
+ 
+libxl_device_usbctrl = Struct("device_usbctrl", [ 
+    ("type", libxl_usbctrl_type), 
+    ("devid", libxl_devid), 
+    ("version", integer), 
+    ("ports", integer), 
+    ("backend_domid", libxl_domid), 
+    ("backend_domname", string), 

tools/libxl/libxl.h

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+   ]) 
+ 
+libxl_device_usb = Struct("device_usb", [ 
+    ("ctrl", libxl_devid), 
+    ("port", integer), 
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", 
+           [("hostdev", Struct(None, [ 
+                 ("hostbus",   integer), 
+                 ("hostaddr",  integer)])), 
+            ("invalid", None), 

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Quoted 3 lines

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

I can confirm this.

-George

#17 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to George Dunlap
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/9/2015 at 12:52 AM, in message <[email protected]>, George Dunlap

Quoted 68 lines · <[email protected]> wrote:
Quoted 15 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

Quoted 7 lines
tools/libxl/libxl.h +0 -0
index 5f9047c..05b6331 100644 
@@ -123,6 +123,23 @@ 
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1 
 
Quoted 4 lines

tools/libxl/libxl.h line 126

Quoted 2 lines
tools/libxl/libxl.h +1 -0
 /* 
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of 

And cold-plug, no?

So you should probably say something like "indicates functions for plugging in USB devices through pvusb -- both hotplug and at domain creation time."

Quoted 4 lines

tools/libxl/libxl.h line 128

Quoted 2 lines
tools/libxl/libxl.h +2 -0
+libxl_usbctrl_type = Enumeration("usbctrl_type", [ 
+    (0, "AUTO"), 

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

Generally "DTRT". Meaning:
1. If your domain has no devicemodel, use PV.
2. If your device has a devicemodel, and no PV drivers have peen detected, use the devicemodel.
3. If your device has a devicemodel, but PV drivers have been detected, use PV.

At the moment we don't have a way to check for PV drivers, so this just collapses down to "PV for domains without a DM and DM for domains with a DM."

Quoted 5 lines

tools/libxl/libxl.h line 130

Quoted 3 lines
tools/libxl/libxl.h +2 -0
+    (1, "PV"), 
+    (2, "QEMU"), 

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I had this as "DEVICEMODEL", since what we mean is that we want the device model to provide access (and in theory in the future we may use a different device model). But "EMU" works for me too.

Quoted 17 lines

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Quoted 8 lines
Quoted 4 lines

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

I think the idea was to simply offer 1, 2, and 3 as options, and for the devicemodel version, choose a suitable controller (or set of controllers) for each option; similar to what usbversion= does now.

Hi, George,

I'm still confused about the expected look concerning PV/EMU type handling in this patch series.

In earlier version, we tried to extract common things in libxl_usb.c and put pvusb specific thing in libxl_pvusb.c, prefixed with pvusb_xxx. As you suggested, we can leave that when EMU USB patch series added.

Now, about how to handle PV/EMU type in this patch series, I can think of 3 ways:

1. We define the enumeration (contains PV/AUTO only, user interface only allows 'pv' or 'not specified', so we handle everything in 'pv' way without further check. Leave check and other adjusting things when EMU USB patch series added.

2. We check domain type and set proper type if not specified (i.e. 'pv' for PV guest, 'emu' for HVM guest). In add/remove function, check if type='emu', report 'not supported' directly; otherwise, continue do following things. When EMU USB patch serires added, need to extract common things and adjust the check place.

3. Same as 2, but extract common things, only in PV/EMU USB specific part, check type, if type='emu', report 'not supported'; otherwise, do pvusb work. When adding EMU USB patch series, only need to add EMU USB specific things in the type='emu' branch.

Which one is expected? Or none?

- Chunyan

Quoted 45 lines
Quoted 30 lines
Quoted 16 lines
tools/libxl/libxl.h +14 -0
+    ]) 
+ 
+libxl_usbdev_type = Enumeration("usbdev_type", [ 
+    (0, "invalid"), 
+    (1, "hostdev"), 
+    ]) 
+ 
+libxl_device_usbctrl = Struct("device_usbctrl", [ 
+    ("type", libxl_usbctrl_type), 
+    ("devid", libxl_devid), 
+    ("version", integer), 
+    ("ports", integer), 
+    ("backend_domid", libxl_domid), 
+    ("backend_domname", string), 

tools/libxl/libxl.h

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+   ]) 
+ 
+libxl_device_usb = Struct("device_usb", [ 
+    ("ctrl", libxl_devid), 
+    ("port", integer), 
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", 
+           [("hostdev", Struct(None, [ 
+                 ("hostbus",   integer), 
+                 ("hostaddr",  integer)])), 
+            ("invalid", None), 

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Quoted 3 lines

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

I can confirm this.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 103 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/9/2015 at 12:52 AM, in message <[email protected]>, George Dunlap

Quoted 68 lines · <[email protected]> wrote:
Quoted 15 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

Quoted 7 lines
tools/libxl/libxl.h +0 -0
index 5f9047c..05b6331 100644 
@@ -123,6 +123,23 @@ 
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1 
 
Quoted 4 lines

tools/libxl/libxl.h line 126

Quoted 2 lines
tools/libxl/libxl.h +1 -0
 /* 
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of 

And cold-plug, no?

So you should probably say something like "indicates functions for plugging in USB devices through pvusb -- both hotplug and at domain creation time."

Quoted 4 lines

tools/libxl/libxl.h line 128

Quoted 2 lines
tools/libxl/libxl.h +2 -0
+libxl_usbctrl_type = Enumeration("usbctrl_type", [ 
+    (0, "AUTO"), 

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

Generally "DTRT". Meaning:
1. If your domain has no devicemodel, use PV.
2. If your device has a devicemodel, and no PV drivers have peen detected, use the devicemodel.
3. If your device has a devicemodel, but PV drivers have been detected, use PV.

At the moment we don't have a way to check for PV drivers, so this just collapses down to "PV for domains without a DM and DM for domains with a DM."

Quoted 5 lines

tools/libxl/libxl.h line 130

Quoted 3 lines
tools/libxl/libxl.h +2 -0
+    (1, "PV"), 
+    (2, "QEMU"), 

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I had this as "DEVICEMODEL", since what we mean is that we want the device model to provide access (and in theory in the future we may use a different device model). But "EMU" works for me too.

Quoted 17 lines

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Quoted 8 lines
Quoted 4 lines

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

I think the idea was to simply offer 1, 2, and 3 as options, and for the devicemodel version, choose a suitable controller (or set of controllers) for each option; similar to what usbversion= does now.

Hi, George,

I'm still confused about the expected look concerning PV/EMU type handling in this patch series.

In earlier version, we tried to extract common things in libxl_usb.c and put pvusb specific thing in libxl_pvusb.c, prefixed with pvusb_xxx. As you suggested, we can leave that when EMU USB patch series added.

Now, about how to handle PV/EMU type in this patch series, I can think of 3 ways:

1. We define the enumeration (contains PV/AUTO only, user interface only allows 'pv' or 'not specified', so we handle everything in 'pv' way without further check. Leave check and other adjusting things when EMU USB patch series added.

2. We check domain type and set proper type if not specified (i.e. 'pv' for PV guest, 'emu' for HVM guest). In add/remove function, check if type='emu', report 'not supported' directly; otherwise, continue do following things. When EMU USB patch serires added, need to extract common things and adjust the check place.

Quoted 6 lines

3. Same as 2, but extract common things, only in PV/EMU USB specific part, check type, if type='emu', report 'not supported'; otherwise, do pvusb work. When adding EMU USB patch series, only need to add EMU USB specific things in the type='emu' branch.

Which one is expected? Or none?

So there are two questions here, first WRT the code, the second WRT the interface.

WRT the code, *normally* the first person to submit the code gets to have it easy, and the second person has to do all the work of refactoring. So you would be completely within your rights to simply submit "libxl_usb.c", and make me refactor that into libxl_pvusb.c and whatever else (probably the qemu stuff would go in libxl_qmp.c).

Earlier I asked you as a favor to put things in libxl_pvusb.c, and you were kind enough to do so -- so thank you. Just having things roughly where they might end up eventually has already been a big help. I'll have to move some of the code around pretty much no matter what you do.
So I don't think it's worth making any more effort wrt the code itself.

WRT the interface -- if we do a release with PV defined, but not EMU/DEVICEMODEL, then when we add that option, we'll have to add Yet Another LIBL_HAS_BLAH. I would personally like too avoid that.

As it happens, if you were to check this in now at the beginning of the cycle, it's very likely I could get the EMU side in before the release.
So it's *probably* OK to just write AUTO and PV.

I would personally prefer to play it safe and give all three interface elements (AUTO, PV, and EMU/DEVICEMODEL), and return ENOTSUPP (or whatever) for DEVICEMODEL until it's implemented. But that's really a policy decision for the maintianers at this point.

-George

#19 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

On Thu, Sep 17, 2015 at 10:54:23AM +0100, George Dunlap wrote:
[...]

Quoted 43 lines
Quoted 21 lines

Hi, George,

I'm still confused about the expected look concerning PV/EMU type handling in this patch series.

In earlier version, we tried to extract common things in libxl_usb.c and put pvusb specific thing in libxl_pvusb.c, prefixed with pvusb_xxx. As you suggested, we can leave that when EMU USB patch series added.

Now, about how to handle PV/EMU type in this patch series, I can think of 3 ways:

1. We define the enumeration (contains PV/AUTO only, user interface only allows 'pv' or 'not specified', so we handle everything in 'pv' way without further check. Leave check and other adjusting things when EMU USB patch series added.

2. We check domain type and set proper type if not specified (i.e. 'pv' for PV guest, 'emu' for HVM guest). In add/remove function, check if type='emu', report 'not supported' directly; otherwise, continue do following things. When EMU USB patch serires added, need to extract common things and adjust the check place.

Quoted 6 lines

3. Same as 2, but extract common things, only in PV/EMU USB specific part, check type, if type='emu', report 'not supported'; otherwise, do pvusb work. When adding EMU USB patch series, only need to add EMU USB specific things in the type='emu' branch.

Which one is expected? Or none?

So there are two questions here, first WRT the code, the second WRT the interface.

WRT the code, *normally* the first person to submit the code gets to have it easy, and the second person has to do all the work of refactoring. So you would be completely within your rights to simply submit "libxl_usb.c", and make me refactor that into libxl_pvusb.c and whatever else (probably the qemu stuff would go in libxl_qmp.c).

Earlier I asked you as a favor to put things in libxl_pvusb.c, and you were kind enough to do so -- so thank you. Just having things roughly where they might end up eventually has already been a big help. I'll have to move some of the code around pretty much no matter what you do.
So I don't think it's worth making any more effort wrt the code itself.

Quoted 4 lines

WRT the interface -- if we do a release with PV defined, but not EMU/DEVICEMODEL, then when we add that option, we'll have to add Yet Another LIBL_HAS_BLAH. I would personally like too avoid that.

(Note that I didn't go through all emails)

I think adding yet another LIBXL_HAS_BLAH wouldn't be a problem. Chunyan will have to add one anyway.

Quoted 4 lines

As it happens, if you were to check this in now at the beginning of the cycle, it's very likely I could get the EMU side in before the release.
So it's *probably* OK to just write AUTO and PV.

Again, extending the interface shouldn't be a problem -- we do that all the time. So IMHO having AUTO and PV only is OK.

Quoted 5 lines

I would personally prefer to play it safe and give all three interface elements (AUTO, PV, and EMU/DEVICEMODEL), and return ENOTSUPP (or whatever) for DEVICEMODEL until it's implemented. But that's really a policy decision for the maintianers at this point.

This works for me too. I don't really see a problem in choosing one way or another TBH.

Wei.

Quoted 1 line

-George

#20 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to George Dunlap
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/9/2015 at 12:52 AM, in message <[email protected]>, George Dunlap

Quoted 68 lines · <[email protected]> wrote:
Quoted 15 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

Quoted 7 lines
tools/libxl/libxl.h +0 -0
index 5f9047c..05b6331 100644 
@@ -123,6 +123,23 @@ 
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1 
 
Quoted 4 lines

tools/libxl/libxl.h line 126

Quoted 2 lines
tools/libxl/libxl.h +1 -0
 /* 
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of 

And cold-plug, no?

So you should probably say something like "indicates functions for plugging in USB devices through pvusb -- both hotplug and at domain creation time."

Quoted 4 lines

tools/libxl/libxl.h line 128

Quoted 2 lines
tools/libxl/libxl.h +2 -0
+libxl_usbctrl_type = Enumeration("usbctrl_type", [ 
+    (0, "AUTO"), 

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

Generally "DTRT". Meaning:
1. If your domain has no devicemodel, use PV.
2. If your device has a devicemodel, and no PV drivers have peen detected, use the devicemodel.
3. If your device has a devicemodel, but PV drivers have been detected, use PV.

At the moment we don't have a way to check for PV drivers, so this just collapses down to "PV for domains without a DM and DM for domains with a DM."

Quoted 5 lines

tools/libxl/libxl.h line 130

Quoted 3 lines
tools/libxl/libxl.h +2 -0
+    (1, "PV"), 
+    (2, "QEMU"), 

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I had this as "DEVICEMODEL", since what we mean is that we want the device model to provide access (and in theory in the future we may use a different device model). But "EMU" works for me too.

Quoted 17 lines

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Quoted 8 lines
Quoted 4 lines

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

I think the idea was to simply offer 1, 2, and 3 as options, and for the devicemodel version, choose a suitable controller (or set of controllers) for each option; similar to what usbversion= does now.

Hi, George,

I'm still confused about the expected look concerning PV/EMU type handling in this patch series.

In earlier version, we tried to extract common things in libxl_usb.c and put pvusb specific thing in libxl_pvusb.c, prefixed with pvusb_xxx. As you suggested, we can leave that when EMU USB patch series added.

Now, about how to handle PV/EMU type in this patch series, I can think of 3 ways:

1. We define the enumeration (contains PV/AUTO only, user interface only allows 'pv' or 'not specified', so we handle everything in 'pv' way without further check. Leave check and other adjusting things when EMU USB patch series added.

2. We check domain type and set proper type if not specified (i.e. 'pv' for PV guest, 'emu' for HVM guest). In add/remove function, check if type='emu', report 'not supported' directly; otherwise, continue do following things. When EMU USB patch serires added, need to extract common things and adjust the check place.

3. Same as 2, but extract common things, only in PV/EMU USB specific part, check type, if type='emu', report 'not supported'; otherwise, do pvusb work. When adding EMU USB patch series, only need to add EMU USB specific things in the type='emu' branch.

Which one is expected? Or none?

- Chunyan

Quoted 45 lines
Quoted 30 lines
Quoted 16 lines
tools/libxl/libxl.h +14 -0
+    ]) 
+ 
+libxl_usbdev_type = Enumeration("usbdev_type", [ 
+    (0, "invalid"), 
+    (1, "hostdev"), 
+    ]) 
+ 
+libxl_device_usbctrl = Struct("device_usbctrl", [ 
+    ("type", libxl_usbctrl_type), 
+    ("devid", libxl_devid), 
+    ("version", integer), 
+    ("ports", integer), 
+    ("backend_domid", libxl_domid), 
+    ("backend_domname", string), 

tools/libxl/libxl.h

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+   ]) 
+ 
+libxl_device_usb = Struct("device_usb", [ 
+    ("ctrl", libxl_devid), 
+    ("port", integer), 
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", 
+           [("hostdev", Struct(None, [ 
+                 ("hostbus",   integer), 
+                 ("hostaddr",  integer)])), 
+            ("invalid", None), 

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Quoted 3 lines

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

I can confirm this.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Ian Campbell
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/8/2015 at 10:17 PM, in message <[email protected]>,

Quoted 160 lines · Ian Campbell

On Mon, 2015-08-10 at 18:35 +0800, Chunyan Liu wrote:

Sorry for the delay, between 4.6 freeze crunch, conference and vacation I've been a bit swamped.

I'm just going to comment on the APIs (mainly public libxl.h and .idl) in this pass.

tools/libxl/libxl.h line 126

Quoted 9 lines
tools/libxl/libxl.h +1 -0
index 5f9047c..05b6331 100644 
@@ -123,6 +123,23 @@ 
 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1 
 
 /* 
+ * LIBXL_HAVE_PVUSB indicates the functions for doing hot-plug of 

And cold-plug, no?

tools/libxl/libxl.h line 137

Quoted 11 lines
tools/libxl/libxl.h +11 -0
+ * USB devices through pvusb. 
+ * 
+ * With this functionality, one can add/remove USB controllers to/from 
+ * guest, and attach/detach USB devices to/from USB controllers. To add 
+ * USB controllers and USB devices, one can either adding USB controllers 
+ * first and then attaching USB devices to some USB controller, or adding 
+ * USB devices to guest directly, it will automatically create a USB 
+ * controller for USB devices to attach. To remove USB controllers or USB 
+ * devices, one can either remove USB devices under USB controller one by 
+ * one and then remove USB controller, or remove USB controller directly, 
+ * it will remove all USB devices under it automatically. 

I think this API documentation belongs alongside the API declarations (i.e the prototypes) rather than hidden away next to the feature flag.

Quoted 9 lines
tools/libxl/libxl.h +5 -0
+ * 
+ */ 
+#define LIBXL_HAVE_PVUSB 1 
+ 
+/* 
  * LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE indicates that the 
  * libxl_vendor_device field is present in the hvm sections of 
  * libxl_domain_build_info. This field tells libxl which 

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t · line 1411

Quoted 6 lines
tools/libxl/libxl.h +1 -0
@@ -1389,6 +1406,54 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t 
 domid, libxl_device_disk *disk, 
                        const libxl_asyncop_how *ao_how) 
                        LIBXL_EXTERNAL_CALLERS_ONLY; 
 
+/* USB Controllers*/ 
 

[....]

Seem fine.

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,

Quoted 3 lines
tools/libxl/libxl.h +3 -0
+ 
+/* USB Devices */ 
+int libxl_device_usb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usb  

*usb,

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,

Quoted 4 lines
tools/libxl/libxl.h +4 -0
+                         const libxl_asyncop_how *ao_how) 
+                         LIBXL_EXTERNAL_CALLERS_ONLY; 
+ 
+int libxl_device_usb_remove(libxl_ctx *ctx, uint32_t domid,  

libxl_device_usb *usb,

tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, · line 1449

Quoted 9 lines
tools/libxl/libxl.h +9 -0
+                            const libxl_asyncop_how *ao_how) 
+                            LIBXL_EXTERNAL_CALLERS_ONLY; 
+ 
+libxl_device_usb * 
+libxl_device_usb_list(libxl_ctx *ctx, uint32_t domid, int *num); 
+ 
+libxl_device_usb * 
+libxl_device_usb_list_per_usbctrl(libxl_ctx *ctx, uint32_t domid, 
+                                  libxl_devid usbctrl, int *num); 

I'd probably say "..._for_usbctrl" or "..._by_usbctrl", but that's just nitpicking.

Quoted 11 lines
tools/libxl/libxl.h +7 -0
+ 
+void libxl_device_usb_list_free(libxl_device_usb *list, int nr); 
+ 
+int libxl_device_usb_getinfo(libxl_ctx *ctx, uint32_t domid, 
+                             libxl_device_usb *usb, 
+                             libxl_usbinfo *usbinfo); 
+ 
 /* Network Interfaces */ 
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, 

libxl_device_nic *nic,
const libxl_asyncop_how *ao_how)

[...]

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 598

Quoted 10 lines
tools/libxl/libxl_types.idl +2 -0
index ef346e7..ef10484 100644 
@@ -594,6 +594,37 @@ libxl_device_rdm = Struct("device_rdm", [ 
     ("policy", libxl_rdm_reserve_policy), 
     ]) 
 
+libxl_usbctrl_type = Enumeration("usbctrl_type", [ 
+    (0, "AUTO"), 

What are the proposed semantics of using LIBXL_USBCTRL_TYPE_AUTO?

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 600

Quoted 2 lines
tools/libxl/libxl_types.idl +2 -0
+    (1, "PV"), 
+    (2, "QEMU"), 

Is "QEMU" what we want here, as opposed to, say, "EMU" (similar to NICs)?

I think we probably don't want to go as fine grained as "XHCI" and "EHCI" etc, do we? I see we have a version field below, is it intended that there be some way to select between e.g. UHCI and OHCI (which IIRC are different USB 1.0 controllers).

Maybe these questions should all be left aside for when QMEU support is actually added (AFAICT this field is just a placeholder)? In fact I glanced at the code and was surprised to find nothing checking for LIBXL_USBCTRL_TYPE at all, did I miss something?

I think the two choices are:

We can decide quickly and easily what the option(s) other than PV should be here and you include it in the IDL, but you would then need to check usbctrl->type == PV at various points, not silently treat all options as PV.

Or this becomes a long conversation in which case I think your best bet would be to leave the enum with just the PV (and maybe AUTO) entries and leave the decision on the name for the emulated option to the series which implements that.

Quoted 14 lines
tools/libxl/libxl_types.idl +14 -0
+    ]) 
+ 
+libxl_usbdev_type = Enumeration("usbdev_type", [ 
+    (0, "invalid"), 
+    (1, "hostdev"), 
+    ]) 
+ 
+libxl_device_usbctrl = Struct("device_usbctrl", [ 
+    ("type", libxl_usbctrl_type), 
+    ("devid", libxl_devid), 
+    ("version", integer), 
+    ("ports", integer), 
+    ("backend_domid", libxl_domid), 
+    ("backend_domname", string), 

tools/libxl/libxl_types.idl libxl_device_rdm = Struct("device_rdm", [ · line 624

Quoted 10 lines
tools/libxl/libxl_types.idl +10 -0
+   ]) 
+ 
+libxl_device_usb = Struct("device_usb", [ 
+    ("ctrl", libxl_devid), 
+    ("port", integer), 
+    ("u", KeyedUnion(None, libxl_usbdev_type, "devtype", 
+           [("hostdev", Struct(None, [ 
+                 ("hostbus",   integer), 
+                 ("hostaddr",  integer)])), 
+            ("invalid", None), 

AIUI this is what was agreed to, i.e. an enum with only one real option, in order to leave a space for new devtypes without major API overhaul.

Please can you confirm that hostbus and hostaddr are both flat integer namespaces (i.e. there is no structure to the bits within either, they are just a number).

Quoted 5 lines

Do these fields have any particular size requirements arising from e.g. the USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe we could use the appropriate fixed size types?

Didn't see the size limitation. In Linux kernel code, busnum and devnum (here 'hostbus, hostaddr') are both 'int' type. And idProduct and idVendor are 'u16'.

- Chunyan

Quoted 55 lines
Quoted 32 lines
tools/libxl/libxl_types.idl +17 -0
+           ])), 
+    ]) 
+ 
 libxl_device_dtdev = Struct("device_dtdev", [ 
     ("path", string), 
     ]) 
@@ -626,6 +657,8 @@ libxl_domain_config = Struct("domain_config", [ 
     ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), 
     ("rdms", Array(libxl_device_rdm, "num_rdms")), 
     ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), 
+    ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")), 
+    ("usbs", Array(libxl_device_usb, "num_usbs")), 
     ("vfbs", Array(libxl_device_vfb, "num_vfbs")), 
     ("vkbs", Array(libxl_device_vkb, "num_vkbs")), 
     ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), 
@@ -674,6 +707,32 @@ libxl_vtpminfo = Struct("vtpminfo", [ 
     ("uuid", libxl_uuid), 
     ], dir=DIR_OUT) 
 
+libxl_usbctrlinfo = Struct("usbctrlinfo", [ 
+    ("type", libxl_usbctrl_type), 
+    ("devid", libxl_devid), 
+    ("version", integer), 
+    ("ports", integer), 
+    ("backend", string), 
+    ("backend_id", uint32), 
+    ("frontend", string), 
+    ("frontend_id", uint32), 
+    ("state", integer), 
+    ("evtch", integer), 
+    ("ref_urb", integer), 

tools/libxl/libxl_types.idl libxl_vtpminfo = Struct("vtpminfo", [ · line 731

Quoted 10 lines
tools/libxl/libxl_types.idl +10 -0
+    ("ref_conn", integer), 
+    ], dir=DIR_OUT) 
+ 
+libxl_usbinfo = Struct("usbinfo", [ 
+    ("ctrl", libxl_devid), 
+    ("port", integer), 
+    ("busnum", integer), 
+    ("devnum", integer), 
+    ("idVendor", integer), 
+    ("idProduct", integer), 

I think id* are 16 bits? uint16 might be better then.

Quoted 7 lines
tools/libxl/libxl_types.idl +4 -0
+    ("prod", string), 
+    ("manuf", string), 
+    ], dir=DIR_OUT) 
+ 
 libxl_vcpuinfo = Struct("vcpuinfo", [ 
     ("vcpuid", uint32), 
     ("cpu", uint32), 
#22 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 10 lines · Chun Yan Liu
Quoted 7 lines

Do these fields have any particular size requirements arising from e.g. the USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe we could
use the appropriate fixed size types?

Di> dn't see the size limitation. In Linux kernel code, busnum and devnum (here 'hostbus, hostaddr') are both 'int' type.

Is that a Linux-specific implementation detail or a fundamental property of USB? We should be designing the interface around Linux implementation details. It seems like something in the USB spec ought to define precisely the number of bits in both a bus number and a device address within that bus.

Note also that integer in the libxl IDL is signed 24 bits.

Quoted 1 line

And idProduct and idVendor are 'u16'.

That's a USB spec thing, I think, so int16 in the IDL seems appropriate.

Ian.

#23 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 9 lines · Ian Campbell
Quoted 8 lines · Chun Yan Liu
Quoted 7 lines

Do these fields have any particular size requirements arising from e.g. the USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe we could
use the appropriate fixed size types?

Quoted 8 lines
Quoted 2 lines

Di> dn't see the size limitation. In Linux kernel code, busnum and devnum (here 'hostbus, hostaddr') are both 'int' type.

Is that a Linux-specific implementation detail or a fundamental property of USB? We should be designing the interface around Linux implementation details. It seems like something in the USB spec ought to define precisely the number of bits in both a bus number and a device address within that bus.

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 6 lines

Note also that integer in the libxl IDL is signed 24 bits.

Quoted 1 line

And idProduct and idVendor are 'u16'.

That's a USB spec thing, I think, so int16 in the IDL seems appropriate.

Correct.

Juergen

#24 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 25 lines · Juergen Gross
Quoted 15 lines · Ian Campbell
Quoted 5 lines · Chun Yan Liu
Quoted 5 lines

Do these fields have any particular size requirements arising from e.g. the
USB spec or from possible dom0 implementations?

Quoted 8 lines
Quoted 4 lines

If they have a well defined fixed size from a USB spec then maybe we
could
use the appropriate fixed size types?

Di> dn't see the size limitation. In Linux kernel code, busnum and devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 8 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

Quoted 8 lines

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but the last link in that path.

What is the size of each element in the chain, that would seem to be the correct size of "hostaddr".

Ian.

#25 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 35 lines · Ian Campbell
Quoted 25 lines · Juergen Gross
Quoted 15 lines · Ian Campbell
Quoted 5 lines · Chun Yan Liu
Quoted 5 lines

Do these fields have any particular size requirements arising from e.g. the
USB spec or from possible dom0 implementations?

Quoted 8 lines
Quoted 4 lines

If they have a well defined fixed size from a USB spec then maybe we
could
use the appropriate fixed size types?

Di> dn't see the size limitation. In Linux kernel code, busnum and devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 8 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

Quoted 8 lines

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 3 lines

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but the last link in that path.

I'm not sure in which direction you are looking. "address" is a path. A path is normally a list of ports starting at the host and walking through all hubs until you reach the device. The "bus" is the root of that path. So the number of buses the host knows of is the number of USB host adapters without any hub.

Quoted 2 lines

What is the size of each element in the chain, that would seem to be the correct size of "hostaddr".

One bus can have up to 31 ports. In theory I think up to 7 cascaded hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

Juergen

#26 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 46 lines · Juergen Gross
Quoted 40 lines · Ian Campbell
Quoted 32 lines · Juergen Gross
Quoted 18 lines · Ian Campbell
Quoted 12 lines · Chun Yan Liu
Quoted 11 lines

Do these fields have any particular size requirements arising from
e.g. the
USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe
we
could
use the appropriate fixed size types?

Quoted 4 lines

Di> dn't see the size limitation. In Linux kernel code, busnum and
devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 9 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation
details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Quoted 6 lines

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent
is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 4 lines

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but
the last link in that path.

Quoted 5 lines

I'm not sure in which direction you are looking. "address" is a path. A path is normally a list of ports starting at the host and walking through all hubs until you reach the device. The "bus" is the root of that path. So the number of buses the host knows of is the number of USB host adapters without any hub.

OK, I thought I understood but the above suggests not.

In USB speak, the address is a list of port numbers, which you follow from the host bus which is the root.

In Linux speak a "bus" is actually each hub along that path.

Let me try a worked example and see if I've got it right. Lets take this topology:

ROOT0
|-PORT0 ----+--HUB1

 |-PORT1-,   |-PORT0 -- DEVICE A
         |   `-PORT1 -- DEVICE B
         |
         `--HUB2
             |-PORT0 -- DEVICE C
             `-PORT1 -- HUB3
                         |-PORT0 -- DEVICE D
                         `-PORT1 -x

ROOT1 -- ... other stuff

In the USB protocol there are two buses corresponding to ROOT0 and ROOT1.

So in the protocol the address of DEVICE D on the bus associated with ROOT0 is [1,1,0], that is PORT1 on ROOT0 => PORT1 on HUB2 => PORT0 on HUB3.

DEVICE A is [0,0] on the bus associated with ROOT0, similarly.

In the Linux numbering scheme each ROOTn or HUBn is given a bus number, somewhat arbitrarily (although I'm sure there is a scheme by which they allocated). So perhaps:

ROOT0==BUS1
HUB1==BUS2
HUB2==BUS2
HUB3==BUS4
ROOT1==BUS42

And in this scheme the address is hostbus+hostaddr, so DEVICE D is [3,0], that is hostbus==3==HUB3, and port 0. And DEVICE A is [2,0]

Is that right?

Quoted 1 line

One bus can have up to 31 ports.

So the answer is that hostaddr can be 5 bits?

Quoted 3 lines

In theory I think up to 7 cascaded
hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

And this suggests that in principal a Linux hostbus could be 5*7 bits == 35 bits, maybe. Or at least that any USB address can be encoded in that many bits.

Ian.

#27 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Most of what you say is right, I think, but:

Ian Campbell writes ("Re: [Xen-devel] [PATCH V6 3/7] libxl: add pvusb API"):

Quoted 8 lines · Juergen Gross
Quoted 3 lines

In theory I think up to 7 cascaded
hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

And this suggests that in principal a Linux hostbus could be 5*7 bits == 35 bits, maybe. Or at least that any USB address can be encoded in that many bits.

No. The total possible number of `buses' in that sense per root is:

    1                   root
  + 31                  in theory a hub plugged into each of 31 ports
  + 31^2                in theory a hub plugged into each port

...
+ 31^6
You could plug hubs into the last layer but the maximum depth is 7 so you wouldn't be able to plug any devices into that last hub.

And of course the number of root hubs is not really limited by anything meaningful.

Ian.

#28 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Ian Campbell
Quoted 53 lines · Ian Campbell
Quoted 46 lines · Juergen Gross
Quoted 40 lines · Ian Campbell
Quoted 32 lines · Juergen Gross
Quoted 18 lines · Ian Campbell
Quoted 12 lines · Chun Yan Liu
Quoted 11 lines

Do these fields have any particular size requirements arising from
e.g. the
USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe
we
could
use the appropriate fixed size types?

Quoted 4 lines

Di> dn't see the size limitation. In Linux kernel code, busnum and
devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 9 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation
details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Quoted 6 lines

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent
is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 4 lines

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but
the last link in that path.

Quoted 5 lines

I'm not sure in which direction you are looking. "address" is a path. A path is normally a list of ports starting at the host and walking through all hubs until you reach the device. The "bus" is the root of that path. So the number of buses the host knows of is the number of USB host adapters without any hub.

Quoted 6 lines

OK, I thought I understood but the above suggests not.

In USB speak, the address is a list of port numbers, which you follow from the host bus which is the root.

In Linux speak a "bus" is actually each hub along that path.

No. Each hub is just a port which happens to have more ports behind it.

Quoted 21 lines

Let me try a worked example and see if I've got it right. Lets take this topology:

ROOT0
|-PORT0 ----+--HUB1

  |-PORT1-,   |-PORT0 -- DEVICE A
          |   `-PORT1 -- DEVICE B
          |
          `--HUB2
              |-PORT0 -- DEVICE C
              `-PORT1 -- HUB3
                          |-PORT0 -- DEVICE D
                          `-PORT1 -x

ROOT1 -- ... other stuff

In the USB protocol there are two buses corresponding to ROOT0 and ROOT1.

So in the protocol the address of DEVICE D on the bus associated with ROOT0 is [1,1,0], that is PORT1 on ROOT0 => PORT1 on HUB2 => PORT0 on HUB3.

Quoted 7 lines

DEVICE A is [0,0] on the bus associated with ROOT0, similarly.

In the Linux numbering scheme each ROOTn or HUBn is given a bus number, somewhat arbitrarily (although I'm sure there is a scheme by which they allocated). So perhaps:

ROOT0==BUS1

Correct.

Quoted 1 line

HUB1==BUS2

No, Just Bus1-Port0 or Bus1:Devnum1

Quoted 1 line

HUB2==BUS2

Bus1-Port1 or Bus1:Devnum2

Quoted 1 line

HUB3==BUS4

Bus1-Port1.Port1 or Bus1:Devnum3

Quoted 1 line

ROOT1==BUS42

Bus2

Quoted 2 lines

And in this scheme the address is hostbus+hostaddr, so DEVICE D is [3,0], that is hostbus==3==HUB3, and port 0. And DEVICE A is [2,0]

Device D: Bus1-Port1.Port1.Port0 or e.g. Bus1:Devnum4 Device A: Bus1-Port0.Port0 or e.g. Bus1:Devnum5

Quoted 5 lines

Is that right?

Quoted 1 line

One bus can have up to 31 ports.

So the answer is that hostaddr can be 5 bits?

5*8 (7 hubs and a device at the last level) == 40, that's the 1 trillion I suggested before. Things are a little bit more complicated. A devnum in a bus is never assigned twice. So when you plug in a device, it might get devnum 6. Unplug it and replug it again will lead to devnum 7.

Quoted 7 lines
Quoted 3 lines

In theory I think up to 7 cascaded
hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

And this suggests that in principal a Linux hostbus could be 5*7 bits == 35 bits, maybe. Or at least that any USB address can be encoded in that many bits.

Busnum can grow to arbitrary values. A new USB bus detected will get a new bus number. Removing it and adding it again will again use a new number.

Juergen

#29 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 160 lines · Juergen Gross
Quoted 65 lines · Ian Campbell
Quoted 56 lines · Juergen Gross
Quoted 48 lines · Ian Campbell
Quoted 38 lines · Juergen Gross
Quoted 22 lines · Ian Campbell
Quoted 14 lines · Chun Yan Liu
Quoted 7 lines

Do these fields have any particular size requirements arising from
e.g. the
USB spec or from possible dom0 implementations?

Quoted 5 lines

If they have a well defined fixed size from a USB spec then maybe
we
could
use the appropriate fixed size types?

Quoted 4 lines

Di> dn't see the size limitation. In Linux kernel code, busnum and
devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 9 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation
details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Quoted 6 lines

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent
is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 4 lines

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but
the last link in that path.

Quoted 5 lines

I'm not sure in which direction you are looking. "address" is a path. A path is normally a list of ports starting at the host and walking through all hubs until you reach the device. The "bus" is the root of that path. So the number of buses the host knows of is the number of USB host adapters without any hub.

Quoted 6 lines

OK, I thought I understood but the above suggests not.

In USB speak, the address is a list of port numbers, which you follow from the host bus which is the root.

In Linux speak a "bus" is actually each hub along that path.

No. Each hub is just a port which happens to have more ports behind it.

Quoted 22 lines

Let me try a worked example and see if I've got it right. Lets take this topology:

ROOT0
|-PORT0 ----+--HUB1

  |-PORT1-,   |-PORT0 -- DEVICE A
          |   `-PORT1 -- DEVICE B
          |
          `--HUB2
              |-PORT0 -- DEVICE C
              `-PORT1 -- HUB3
                          |-PORT0 -- DEVICE D
                          `-PORT1 -x

ROOT1 -- ... other stuff

In the USB protocol there are two buses corresponding to ROOT0 and ROOT1.

So in the protocol the address of DEVICE D on the bus associated with ROOT0
is [1,1,0], that is PORT1 on ROOT0 => PORT1 on HUB2 => PORT0 on HUB3.

Quoted 7 lines

DEVICE A is [0,0] on the bus associated with ROOT0, similarly.

In the Linux numbering scheme each ROOTn or HUBn is given a bus number, somewhat arbitrarily (although I'm sure there is a scheme by which they allocated). So perhaps:

ROOT0==BUS1

Correct.

Quoted 1 line

HUB1==BUS2

No, Just Bus1-Port0 or Bus1:Devnum1

Quoted 1 line

HUB2==BUS2

Bus1-Port1 or Bus1:Devnum2

Quoted 1 line

HUB3==BUS4

Bus1-Port1.Port1 or Bus1:Devnum3

Quoted 1 line

ROOT1==BUS42

Bus2

Quoted 2 lines

And in this scheme the address is hostbus+hostaddr, so DEVICE D is [3,0], that is hostbus==3==HUB3, and port 0. And DEVICE A is [2,0]

Device D: Bus1-Port1.Port1.Port0 or e.g. Bus1:Devnum4 Device A: Bus1-Port0.Port0 or e.g. Bus1:Devnum5

Quoted 6 lines

Is that right?

Quoted 1 line

One bus can have up to 31 ports.

So the answer is that hostaddr can be 5 bits?

5*8 (7 hubs and a device at the last level) == 40, that's the 1 trillion I suggested before. Things are a little bit more complicated. A devnum in a bus is never assigned twice. So when you plug in a device, it might get devnum 6. Unplug it and replug it again will lead to devnum 7.

Quoted 9 lines
Quoted 3 lines

In theory I think up to 7 cascaded
hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

And this suggests that in principal a Linux hostbus could be 5*7 bits == 35
bits, maybe. Or at least that any USB address can be encoded in that many bits.

Quoted 3 lines

Busnum can grow to arbitrary values. A new USB bus detected will get a new bus number. Removing it and adding it again will again use a new number.

FWIW libusb seems to define these as uint8:

http://libusb.org/static/api-1.0/group__dev.html#gaf2718609d50c8ded2704e4051b3d2925

(I *think* that "bus number" and "device address" correspond to busnum and devnum...)

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

-George

#30 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 167 lines · George Dunlap
Quoted 160 lines · Juergen Gross
Quoted 65 lines · Ian Campbell
Quoted 56 lines · Juergen Gross
Quoted 48 lines · Ian Campbell
Quoted 38 lines · Juergen Gross
Quoted 22 lines · Ian Campbell
Quoted 14 lines · Chun Yan Liu
Quoted 7 lines

Do these fields have any particular size requirements arising from
e.g. the
USB spec or from possible dom0 implementations?

Quoted 5 lines

If they have a well defined fixed size from a USB spec then maybe
we
could
use the appropriate fixed size types?

Quoted 4 lines

Di> dn't see the size limitation. In Linux kernel code, busnum and
devnum (here
'hostbus, hostaddr') are both 'int' type.

Quoted 9 lines

Is that a Linux-specific implementation detail or a fundamental property of
USB? We should be designing the interface around Linux implementation
details. It seems like something in the USB spec ought to define precisely
the number of bits in both a bus number and a device address within that
bus.

The USB spec is only about _the_ bus. How many buses a host can operate and how they are numbered is outside the USB spec.

Quoted 6 lines

Devices are addressed via their ports in the USB protocol. devnum is a unique index for a device on the bus, the USB protocol equivalent
is a list of ports of:
- 1 member in case of direct attached devices
- multiple members in case of hubs between bus and device

Quoted 4 lines

Thanks for the info. So an "address" in the USB protocol is actually a "path" and "hostbus" is an implementation dependent shorthand for all but
the last link in that path.

Quoted 5 lines

I'm not sure in which direction you are looking. "address" is a path. A path is normally a list of ports starting at the host and walking through all hubs until you reach the device. The "bus" is the root of that path. So the number of buses the host knows of is the number of USB host adapters without any hub.

Quoted 6 lines

OK, I thought I understood but the above suggests not.

In USB speak, the address is a list of port numbers, which you follow from the host bus which is the root.

In Linux speak a "bus" is actually each hub along that path.

No. Each hub is just a port which happens to have more ports behind it.

Quoted 22 lines

Let me try a worked example and see if I've got it right. Lets take this topology:

ROOT0
|-PORT0 ----+--HUB1

   |-PORT1-,   |-PORT0 -- DEVICE A
           |   `-PORT1 -- DEVICE B
           |
           `--HUB2
               |-PORT0 -- DEVICE C
               `-PORT1 -- HUB3
                           |-PORT0 -- DEVICE D
                           `-PORT1 -x

ROOT1 -- ... other stuff

In the USB protocol there are two buses corresponding to ROOT0 and ROOT1.

So in the protocol the address of DEVICE D on the bus associated with ROOT0
is [1,1,0], that is PORT1 on ROOT0 => PORT1 on HUB2 => PORT0 on HUB3.

Quoted 7 lines

DEVICE A is [0,0] on the bus associated with ROOT0, similarly.

In the Linux numbering scheme each ROOTn or HUBn is given a bus number, somewhat arbitrarily (although I'm sure there is a scheme by which they allocated). So perhaps:

ROOT0==BUS1

Correct.

Quoted 1 line

HUB1==BUS2

No, Just Bus1-Port0 or Bus1:Devnum1

Quoted 1 line

HUB2==BUS2

Bus1-Port1 or Bus1:Devnum2

Quoted 1 line

HUB3==BUS4

Bus1-Port1.Port1 or Bus1:Devnum3

Quoted 1 line

ROOT1==BUS42

Bus2

Quoted 2 lines

And in this scheme the address is hostbus+hostaddr, so DEVICE D is [3,0], that is hostbus==3==HUB3, and port 0. And DEVICE A is [2,0]

Device D: Bus1-Port1.Port1.Port0 or e.g. Bus1:Devnum4 Device A: Bus1-Port0.Port0 or e.g. Bus1:Devnum5

Quoted 6 lines

Is that right?

Quoted 1 line

One bus can have up to 31 ports.

So the answer is that hostaddr can be 5 bits?

5*8 (7 hubs and a device at the last level) == 40, that's the 1 trillion I suggested before. Things are a little bit more complicated. A devnum in a bus is never assigned twice. So when you plug in a device, it might get devnum 6. Unplug it and replug it again will lead to devnum 7.

Quoted 9 lines
Quoted 3 lines

In theory I think up to 7 cascaded
hubs are possible, but I don't think the resulting theoretical maximum of about 1 trillion devices on a bus is to be considered. :-)

And this suggests that in principal a Linux hostbus could be 5*7 bits == 35
bits, maybe. Or at least that any USB address can be encoded in that many bits.

Quoted 3 lines

Busnum can grow to arbitrary values. A new USB bus detected will get a new bus number. Removing it and adding it again will again use a new number.

FWIW libusb seems to define these as uint8:

Quoted 7 lines

http://libusb.org/static/api-1.0/group__dev.html#gaf2718609d50c8ded2704e4051b3d2925

(I *think* that "bus number" and "device address" correspond to busnum and devnum...)

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

drivers/usb/core/hcd.c is using a bitmap to find the next bus number currently not in use. It's size is USB_MAXBUS which in turn has the value 64.

choose_devnum() in drivers/usb/core/hub.c is doing a similar job for device numbers. Here the highest number supported is 127.

Juergen

#31 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Juergen Gross writes ("Re: [Xen-devel] [PATCH V6 3/7] libxl: add pvusb API"):

Quoted 10 lines · George Dunlap
Quoted 2 lines

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

drivers/usb/core/hcd.c is using a bitmap to find the next bus number currently not in use. It's size is USB_MAXBUS which in turn has the value 64.

choose_devnum() in drivers/usb/core/hub.c is doing a similar job for device numbers. Here the highest number supported is 127.

We are defining an API, which shouldn't involve this kind of implementation-grobbling.

At an API level, it seems that this Linux busnum is not documented to have any particular number or behaviour or range or anything. We should use the biggest type we can use conveniently.

Do we need to worry that some bus might have 2^24 unplugs/plugs (perhaps in some kind of software emulation) and that we need to use a type which can hold a uint32_t or maybe even a uint64_t ?

Ian.

#32 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 12 lines · Ian Jackson

Juergen Gross writes ("Re: [Xen-devel] [PATCH V6 3/7] libxl: add pvusb API"):

Quoted 10 lines · George Dunlap
Quoted 2 lines

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

drivers/usb/core/hcd.c is using a bitmap to find the next bus number currently not in use. It's size is USB_MAXBUS which in turn has the value 64.

choose_devnum() in drivers/usb/core/hub.c is doing a similar job for device numbers. Here the highest number supported is 127.

Quoted 6 lines

We are defining an API, which shouldn't involve this kind of implementation-grobbling.

At an API level, it seems that this Linux busnum is not documented to have any particular number or behaviour or range or anything. We should use the biggest type we can use conveniently.

Agreed.

Quoted 3 lines

Do we need to worry that some bus might have 2^24 unplugs/plugs (perhaps in some kind of software emulation) and that we need to use a type which can hold a uint32_t or maybe even a uint64_t ?

uint128_t ? ;-)

I think 24 bits should be more than enough. Nobody will accept such huge numbers without any need: they are to be used by users.

Juergen

#33 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Ian Jackson
Quoted 15 lines · Ian Jackson

Juergen Gross writes ("Re: [Xen-devel] [PATCH V6 3/7] libxl: add pvusb API"):

Quoted 10 lines · George Dunlap
Quoted 2 lines

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

drivers/usb/core/hcd.c is using a bitmap to find the next bus number currently not in use. It's size is USB_MAXBUS which in turn has the value 64.

choose_devnum() in drivers/usb/core/hub.c is doing a similar job for device numbers. Here the highest number supported is 127.

We are defining an API, which shouldn't involve this kind of implementation-grobbling.

Quoted 7 lines

At an API level, it seems that this Linux busnum is not documented to have any particular number or behaviour or range or anything. We should use the biggest type we can use conveniently

Do we need to worry that some bus might have 2^24 unplugs/plugs (perhaps in some kind of software emulation) and that we need to use a type which can hold a uint32_t or maybe even a uint64_t ?

libusb is already a published API that supports uint8, or up to 255. Following their lead seems like a reasonable thing to do. If ever that number goes above 255, basically every Linux program that touches a USB device will need to be recompiled with a new version of libusb.

Is there any reason for Linux to go above 255? Things I can think of:

1. Users have more than 255 devices plugged into the same bus.

2. A security / confusion issue due to devnum reuse when users plug and unplug devices hundreds of times.

Both of these seem pretty unlikely.

I would personally go with uint8, but int16 or int32 certainly won't hurt.

-George

#34 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/14/2015 at 10:03 PM, in message

<CAFLBxZayaqTeJiB3RfG8qHxjCzQy8BBTe0Hxj+FT6ABSLf+Ntg@mail.gmail.com>, George

Quoted 33 lines · Dunlap
Quoted 1 line · Ian Jackson

Juergen Gross writes ("Re: [Xen-devel] [PATCH V6 3/7] libxl: add pvusb

API"):

Quoted 14 lines
Quoted 10 lines · George Dunlap
Quoted 2 lines

Anyone want to look into the Linux source code to find out how big it will allow busnum / devnum to grow?

drivers/usb/core/hcd.c is using a bitmap to find the next bus number currently not in use. It's size is USB_MAXBUS which in turn has the value 64.

choose_devnum() in drivers/usb/core/hub.c is doing a similar job for device numbers. Here the highest number supported is 127.

We are defining an API, which shouldn't involve this kind of implementation-grobbling.

Quoted 7 lines

At an API level, it seems that this Linux busnum is not documented to have any particular number or behaviour or range or anything. We should use the biggest type we can use conveniently

Do we need to worry that some bus might have 2^24 unplugs/plugs (perhaps in some kind of software emulation) and that we need to use a type which can hold a uint32_t or maybe even a uint64_t ?

libusb is already a published API that supports uint8, or up to 255. Following their lead seems like a reasonable thing to do. If ever that number goes above 255, basically every Linux program that touches a USB device will need to be recompiled with a new version of libusb.

Is there any reason for Linux to go above 255? Things I can think of:

Quoted 8 lines

1. Users have more than 255 devices plugged into the same bus.

2. A security / confusion issue due to devnum reuse when users plug and unplug devices hundreds of times.

Both of these seem pretty unlikely.

I would personally go with uint8, but int16 or int32 certainly won't hurt.

So can we agree to use uint8 for hostbus and hostaddr as libusb does?

Quoted 9 lines

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#35 lore raw

Re: [PATCH V6 3/7] libxl: add pvusb API

In reply to Ian Campbell
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 9/11/2015 at 09:26 PM, in message <[email protected]>, Ian

Quoted 11 lines · Campbell
Quoted 2 lines · Chun Yan Liu
Quoted 2 lines

Do these fields have any particular size requirements arising from e.g.

the

Quoted 7 lines
Quoted 5 lines

USB spec or from possible dom0 implementations?

If they have a well defined fixed size from a USB spec then maybe we could
use the appropriate fixed size types?

Di> dn't see the size limitation. In Linux kernel code, busnum and devnum

Quoted 8 lines

(here

Quoted 1 line

'hostbus, hostaddr') are both 'int' type.

Is that a Linux-specific implementation detail or a fundamental property of USB? We should be designing the interface around Linux implementation details. It seems like something in the USB spec ought to define precisely the number of bits in both a bus number and a device address within that bus.

Have a look at USB 2.0 Spec, it has some description on Device Address: a seven-bit value representing the address of the debvice on USB. (up to 127 devices). So
int8 is appropriate.
No description to Bus Num.

-Chunyan

Quoted 8 lines
Quoted 2 lines

And idProduct and idVendor are 'u16'.

That's a USB spec thing, I think, so int16 in the IDL seems appropriate.

Ian.

#36 lore raw

PATCH v6 4/7 libxl: add libxl_device_usb_assignable_list API

In reply to Chunyan Liu

Add API for listing assignable USB devices info. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.

---
This could be squashed with previous patch. Split because there is some dispute on this. If this is acceptable, could be squashed, otherwise could be removed.

 tools/libxl/libxl.h       |  3 +++
 tools/libxl/libxl_pvusb.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)
tools/libxl/libxl.h +3 -0
index 05b6331..d1360ce 100644
@@ -1433,6 +1433,9 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
                                  libxl_usbctrlinfo *usbctrlinfo);
 
 /* USB Devices */
+libxl_device_usb *
+libxl_device_usb_assignable_list(libxl_ctx *ctx, int *num);
+
 int libxl_device_usb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_usb *usb,
                          const libxl_asyncop_how *ao_how)
                          LIBXL_EXTERNAL_CALLERS_ONLY;
tools/libxl/libxl_pvusb.c +53 -0

59 lines not on this page · raw message

Signature · 1 line
2.1.4
#37 lore raw

PATCH v6 5/7 xl: add pvusb commands

In reply to Chunyan Liu

Add pvusb commands: usb-ctrl-attach, usb-ctrl-detach, usb-list, usb-attach and usb-detach.

To attach a usb device to guest through pvusb, one could follow following example:

#xl usb-ctrl-attach test_vm version=1 num_ports=8

#xl usb-list test_vm
will show the usb controllers and port usage under the domain.

#xl usb-attach test_vm 1.6
will find the first usable controller:port, and attach usb device whose bus address is 1.6 (busnum is 1, devnum is 6) to it. One could also specify which <controller> and which <port>.

#xl usb-detach test_vm 0 1
will detach USB device under controller 0 port 1.

#xl usb-ctrl-detach test_vm dev_id
will destroy the controller with specified dev_id. Dev_id can be traced in usb-list info.

---
 docs/man/xl.pod.1         |  40 ++++++++
 tools/libxl/xl.h          |   5 +
 tools/libxl/xl_cmdimpl.c  | 230 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |  25 +++++
 4 files changed, 300 insertions(+)
docs/man/xl.pod.1 +40 -0
index f22c3f3..4c92c78 100644
@@ -1345,6 +1345,46 @@ List pass-through pci devices for a domain.
 
 =back
 
+=head1 USB PASS-THROUGH
+
+=over 4
+
+=item B<usb-ctrl-attach> I<domain-id> I[<type=val>] [I<version=val>] [I<ports=number>]
+
+Create a new USB controller for the specified domain.
+B<type=val> is the usb controller type, currently only support 'pv'.
+B<version=val> is the usb controller version, could be 1 (USB1.1) or 2 (USB2.0).
+B<ports=number> is the total ports of the usb controller.
+By default, it will create a USB2.0 controller with 8 ports.
+
+=item B<usb-ctrl-detach> I<domain-id> I<devid>
+
+Destroy a USB controller from the specified domain.
+B<devid> is devid of the USB controller.
+
+If B<-f> is specified, B<xl> is going to forcefully remove the device even
+without guest's collaboration.
+
+=item B<usb-attach> I<domain-id> I<bus.addr> [I<controller=devid> [I<port=number>]]
+
+Hot-plug a new pass-through USB device to the specified domain.
+B<bus.addr> is the busnum.devnum of the physical USB device to pass-through.
+B<controller=devid> B<port=number> is the USB controller:port to hotplug the
+USB device to. By default, it will find the first available controller:port
+and use it; if there is no controller, it will create one.
+
+=item B<usb-detach> I<domain-id> I<controller=devid> I<port=number>
+
+Hot-unplug a previously assigned USB device from a domain.
+B<controller=devid> and B<port=number> is USB controller:port in guest where the
+USB device is attached to.
+
+=item B<usb-list> I<domain-id>
+
+List pass-through usb devices for a domain.
+
+=back
+
 =head1 TMEM
 
 =over 4
tools/libxl/xl.h +5 -0
index 13bccba..e136fdf 100644
@@ -85,6 +85,11 @@ int main_blockdetach(int argc, char **argv);
 int main_vtpmattach(int argc, char **argv);
 int main_vtpmlist(int argc, char **argv);
 int main_vtpmdetach(int argc, char **argv);
+int main_usbctrl_attach(int argc, char **argv);
+int main_usbctrl_detach(int argc, char **argv);
+int main_usbattach(int argc, char **argv);
+int main_usbdetach(int argc, char **argv);
+int main_usblist(int argc, char **argv);
 int main_uptime(int argc, char **argv);
 int main_claims(int argc, char **argv);
 int main_tmem_list(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +230 -0

236 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +25 -0
index 0071f12..46f276e 100644
@@ -551,6 +551,31 @@ struct cmd_spec cmd_table[] = {
     },
 
 #endif
+    { "usb-ctrl-attach",
+      &main_usbctrl_attach, 0, 1,
+      "Create a virtual USB controller for a domain",
+      "<Domain> [type=pv] [version=<version>] [ports=<number>]",
+    },
+    { "usb-ctrl-detach",
+      &main_usbctrl_detach, 0, 1,
+      "Remove the virtual USB controller specified by <DevId> for a domain",
+      "<Domain> <DevId>",
+    },
+    { "usb-attach",
+      &main_usbattach, 0, 1,
+      "Attach a USB device to a domain",
+      "<Domain> <bus.addr> [controller=<DevId> [port=<port>]]",
+    },
+    { "usb-detach",
+      &main_usbdetach, 0, 1,
+      "Detach a USB device from a domain",
+      "<Domain> <controller> <port>",
+    },
+    { "usb-list",
+      &main_usblist, 0, 0,
+      "List information about USB devices for a domain",
+      "<Domain>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 1 line
2.1.4
#38 lore raw

PATCH v6 6/7 xl: add usb-assignable-list command

In reply to Chunyan Liu

Add xl usb-assignable-list command to list assignable USB devices. Assignable USB device means the USB device type is assignable and it's not assigned to any guest yet.

---
Same as "libxl: add libxl_device_usb_assignable_list API" patch, this patch could be sqaushed to previous one. Split because of some dispute. Could be squashed if acceptable, otherwise could be removed.

 tools/libxl/xl.h          |  1 +
 tools/libxl/xl_cmdimpl.c  | 27 +++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |  4 ++++
 3 files changed, 32 insertions(+)
tools/libxl/xl.h +1 -0
index e136fdf..e579ecc 100644
@@ -85,6 +85,7 @@ int main_blockdetach(int argc, char **argv);
 int main_vtpmattach(int argc, char **argv);
 int main_vtpmlist(int argc, char **argv);
 int main_vtpmdetach(int argc, char **argv);
+int main_usbassignable_list(int argc, char **argv);
 int main_usbctrl_attach(int argc, char **argv);
 int main_usbctrl_detach(int argc, char **argv);
 int main_usbattach(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +27 -0
index 3e4d93a..e33871c 100644
@@ -3322,6 +3322,33 @@ int main_cd_insert(int argc, char **argv)
     return 0;
 }
 
+static void usb_assignable_list(void)
+{
+    libxl_device_usb *usbs;
+    int num, i;
+
+    usbs = libxl_device_usb_assignable_list(ctx, &num);
+
+    for (i = 0; i < num; i++) {
+        printf("%d.%d\n", usbs[i].u.hostdev.hostbus,
+               usbs[i].u.hostdev.hostaddr);
+    }
+
+    libxl_device_usb_list_free(usbs, num);
+}
+
+int main_usbassignable_list(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "usb-assignable-list", 0) {
+        /* No options */
+    }
+
+    usb_assignable_list();
+    return 0;
+}
+
 int main_usbctrl_attach(int argc, char **argv)
 {
     uint32_t domid;
tools/libxl/xl_cmdtable.c +4 -0
index 46f276e..ba51331 100644
@@ -576,6 +576,10 @@ struct cmd_spec cmd_table[] = {
       "List information about USB devices for a domain",
       "<Domain>",
     },
+    { "usb-assignable-list",
+      &main_usbassignable_list, 0, 0,
+      "List all assignable USB devices",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 1 line
2.1.4
#39 lore raw

PATCH v6 7/7 domcreate: support pvusb in configuration file

In reply to Chunyan Liu

Add code to support pvusb in domain config file. One could specify usbctrl and usb in domain's configuration file and create domain, then usb controllers will be created and usb device would be attached to guest automatically.

One could specify usb controllers and usb devices in config file like this:
usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['2.1,controller=0,port=1', ]

---
 docs/man/xl.cfg.pod.5        |  75 +++++++++++++++++++++++++++++
 tools/libxl/libxl_create.c   |  73 ++++++++++++++++++++++++++--
 tools/libxl/libxl_device.c   |   4 ++
 tools/libxl/libxl_internal.h |   8 ++++
 tools/libxl/xl_cmdimpl.c     | 112 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 268 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5 +75 -0
index 80e51bb..45f3ff3 100644
@@ -709,6 +709,81 @@ Note this may be overridden by rdm_policy option in PCI device configuration.
 
 =back
 
+=item B<usbctrl=[ "USBCTRL_SPEC_STRING", "USBCTRL_SPEC_STRING", ... ]>
+
+Specifies the USB controllers created for this guest. Each
+B<USB_SPEC_STRING> has the form C<KEY=VALUE,KEY=VALUE,...> where:
+
+=over 4
+
+=item B<KEY=VALUE>
+
+Possible B<KEY>s are:
+
+=over 4
+
+=item B<type=TYPE>
+
+Specifies the protocol to implement USB controller, could be "pv" (indicates
+PVUSB) or "qemu" (indicates QEMU emulated). Currently only "pv" is supported.
+
+=item B<version=VERSION>
+
+Specifies version of the USB controller, could be 1 (USB1.1) or 2 (USB2.0).
+Default is 2 (USB2.0).
+
+=item B<ports=PORTS>
+
+Specifies port number of the USB controller. Default is 8.
+
+Each USB controller will have an index starting from 0. On the same
+controller, each port will have an index starting from 1.
+
+E.g.
+usbctrl=["version=1,ports=4", "version=2,ports=8",]
+The first controller has:
+controller index = 0, and port 1,2,3,4.
+The second controller has:
+controller index = 1, and port 1,2,3,4,5,6,7,8.
+
+=back
+
+=back
+
+=item B<usbdev=[ "USB_SPEC_STRING", "USB_SPEC_STRING", ... ]>
+
+Specifies the host USB devices to passthrough to this guest. Each
+B<USB_SPEC_STRING> has the form C<bus.addr,KEY=VALUE,KEY=VALUE,...> where:
+
+=over 4
+
+=item B<bus.addr>
+
+Identifies the busnum.devnum of the USB device from the host perspective.
+This is the same scheme as used in the output of C<lsusb> for the device in
+question.
+
+=item B<KEY=VALUE>
+
+Possible B<KEY>s are:
+
+=over 4
+
+=item B<controller=CONTROLLER>
+
+Specifies USB controller index, to which controller the USB device is attached.
+
+=item B<port=PORT>
+
+Specifies USB port index, to which port the USB device is attached. B<port=PORT>
+is valid only when B<controller=CONTROLLER> is specified. Without
+B<controller=CONTROLLER>, it will find the first available USB controller:port
+and use it. If there is no controller at all, it will create one.
+
+=back
+
+=back
+
 =item B<pci=[ "PCI_SPEC_STRING", "PCI_SPEC_STRING", ... ]>
 
 Specifies the host PCI devices to passthrough to this guest. Each B<PCI_SPEC_STRING>
tools/libxl/libxl_create.c +70 -3

102 lines not on this page · raw message

tools/libxl/libxl_device.c +4 -0
index 935f25b..92d5d10 100644
@@ -544,6 +544,8 @@ void libxl__multidev_prepared(libxl__egc *egc,
  * libxl__add_disks
  * libxl__add_nics
  * libxl__add_vtpms
+ * libxl__add_usbctrls
+ * libxl__add_usbs
  */
 
 #define DEFINE_DEVICES_ADD(type)                                        \
@@ -563,6 +565,8 @@ void libxl__multidev_prepared(libxl__egc *egc,
 DEFINE_DEVICES_ADD(disk)
 DEFINE_DEVICES_ADD(nic)
 DEFINE_DEVICES_ADD(vtpm)
+DEFINE_DEVICES_ADD(usbctrl)
+DEFINE_DEVICES_ADD(usb)
 
 #undef DEFINE_DEVICES_ADD
 
tools/libxl/libxl_internal.h +8 -0
index 5be3b3a..c23741a 100644
@@ -3283,6 +3283,14 @@ _hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
                              libxl_domain_config *d_config,
                              libxl__multidev *multidev);
 
+_hidden void libxl__add_usbctrls(libxl__egc *egc, libxl__ao *ao,
+                                 uint32_t domid, libxl_domain_config *d_config,
+                                 libxl__multidev *multidev);
+
+_hidden void libxl__add_usbs(libxl__egc *egc, libxl__ao *ao,
+                             uint32_t domid, libxl_domain_config *d_config,
+                             libxl__multidev *multidev);
+
 /*----- device model creation -----*/
 
 /* First layer; wraps libxl__spawn_spawn. */
tools/libxl/xl_cmdimpl.c +111 -1

130 lines not on this page · raw message

Signature · 1 line
2.1.4
#40 lore raw

Re: [PATCH V6 7/7] domcreate: support pvusb in configuration file

Quoted 13 lines · Chunyan Liu

Add code to support pvusb in domain config file. One could specify usbctrl and usb in domain's configuration file and create domain, then usb controllers will be created and usb device would be attached to guest automatically.

One could specify usb controllers and usb devices in config file like this:
usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['2.1,controller=0,port=1', ]

---

[...]

Quoted 5 lines
     }
tools/libxl/xl_cmdimpl.c +3 -0
+    if (!xlu_cfg_get_list(config, "usbctrl", &usbctrls, 0, 0)) {
+        d_config->num_usbctrls = 0;
+        d_config->usbctrls = NULL;

tools/libxl/xl_cmdimpl.c skip_vfb: · line 2131

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+        while ((buf = xlu_cfg_get_listitem(usbctrls, d_config->num_usbctrls))
+               != NULL) {
+            libxl_device_usbctrl *usbctrl;
+
+            d_config->usbctrls =
+                (libxl_device_usbctrl *)realloc(d_config->usbctrls,
+                sizeof(libxl_device_usbctrl) * (d_config->num_usbctrls + 1));
+            usbctrl = d_config->usbctrls + d_config->num_usbctrls;
+            libxl_device_usbctrl_init(usbctrl);
+

Use ARRAY_EXTEND_INIT macro.

Quoted 7 lines
tools/libxl/xl_cmdimpl.c +7 -0
+            parse_usbctrl_config(usbctrl, buf);
+
+            d_config->num_usbctrls++;
+        }
+    }
+
+    if (!xlu_cfg_get_list(config, "usbdev", &usbs, 0, 0)) {

tools/libxl/xl_cmdimpl.c skip_vfb: · line 2148

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+        d_config->num_usbs = 0;
+        d_config->usbs = NULL;
+        while ((buf = xlu_cfg_get_listitem(usbs, d_config->num_usbs)) != NULL) {
+            libxl_device_usb *usb;
+
+            d_config->usbs = (libxl_device_usb *)realloc(d_config->usbs,
+                    sizeof(libxl_device_usb) * (d_config->num_usbs + 1));
+            usb = d_config->usbs + d_config->num_usbs;
+            libxl_device_usb_init(usb);
+

Ditto.

Wei.

Quoted 17 lines
tools/libxl/xl_cmdimpl.c +6 -0
+            parse_usb_config(usb, buf);
+
+            d_config->num_usbs++;
+        }
+    }
+
     switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
     case 0:
         {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel