pvusb toolstack work
v2 cover pvusb toolstack work
This patch series is based on Simon's work. Since there is no progress after last August, I hope we can make this work proceed. Any comment will be very appreciated.
It adds pvusb toolstack implementation, with pvusb kernel side work, one could attach/detach a usb device to guest.
Changes to Simon's work:
- fix format issues
- fix bind/unbind if usb device has multiple interfaces
- add codes to update json config when hot add a usb device
- reorganize and update libxl code to make it more readable.
- split libxl code into several patches for easier review.
- remove many unused APIs in libxl_internal.h and libxl.h
- fix xl command implementation issues (many inconsistences between cmdtable and cmdimplementation) and update some command syntax
- remove usb-assigned-list
Known issues in testing:
- specify 'usb' in vm config file, then create vm, usb controller state keeps in not connected; same result when hot add a usb device in vm booting process. But hot adding a usb device after vm is booted, works very well.
- hot adding a usb device to 2.0 usb controller, usb device not working well in guest. But adding a usb device to 1.x usb controller, works well.
These issues are also found with old xend toolstack.
Simon's Patches:
http://lists.xen.org/archives/html/xen-devel/2014-08/msg01203.html
Chunyan Liu (5):
libxl: add pvusb definitions
libxl: export some functions for pvusb use
libxl: add pvusb API
xl: add pvusb commands
domcreate: support pvusb in configuration file
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 8 +- tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_create.c | 41 +- tools/libxl/libxl_internal.h | 11 + tools/libxl/libxl_types.idl | 58 +- tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++------ tools/libxl/libxlu_cfg_y.h | 38 +- tools/libxl/xl.h | 6 + tools/libxl/xl_cmdimpl.c | 296 +++++++- tools/libxl/xl_cmdtable.c | 30 + 13 files changed, 2058 insertions(+), 232 deletions(-) create mode 100644 tools/libxl/libxl_usb.c
Signature · 1 line
1.8.4.5
RFC PATCH v2 1/5 libxl: add pvusb definitions
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
--- tools/libxl/libxl_types.idl | 58 +++++++++++++++++++++++++++++++++++- tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)
tools/libxl/libxl_types.idl +57 -1
@@ -111,6 +111,16 @@ libxl_nic_type = Enumeration("nic_type", [ (2, "VIF"), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type",[ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usb_type = Enumeration("device_usb_type", [ + (1, "HOSTDEV"), + ]) + libxl_action_on_shutdown = Enumeration("action_on_shutdown", [ (1, "DESTROY"),
@@ -394,7 +404,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("ioports", Array(libxl_ioport_range, "num_ioports")), ("irqs", Array(uint32, "num_irqs")), ("iomem", Array(libxl_iomem_range, "num_iomem")), - ("claim_mode", libxl_defbool), + ("claim_mode", libxl_defbool), ("event_channels", uint32), ("kernel", string), ("cmdline", string),
@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8), + ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer), + ("port", integer), + ("intf", string), + ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ]) + libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),
@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("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")),
@@ -595,6 +627,30 @@ libxl_vtpminfo = Struct("vtpminfo", [ ("uuid", libxl_uuid), ], dir=DIR_OUT) +libxl_usbctrlinfo = Struct("usbctrlinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("evtch", integer), + ("version", integer), + ("type", string), + ("ref_urb", integer), + ("ref_conn", integer), + ("num_ports", integer), + ], dir=DIR_OUT) + +libxl_usbinfo = Struct("usbinfo", [ + ("bus", integer), + ("devnum", integer), + ("idVendor", integer), + ("idProduct", integer), + ("prod", string), + ("manuf", string), + ], dir=DIR_OUT) + libxl_vcpuinfo = Struct("vcpuinfo", [ ("vcpuid", uint32), ("cpu", uint32),
tools/libxl/libxl_types_internal.idl +1 -0
@@ -22,6 +22,7 @@ libxl__device_kind = Enumeration("device_kind", [ (6, "VKBD"), (7, "CONSOLE"), (8, "VTPM"), + (9, "VUSB"), ]) libxl__console_backend = Enumeration("console_backend", [
Signature · 1 line
1.8.4.5
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e. LIBXL_USBCTRL_TYPE_DEVICEMODEL) and libxl_usb_type are placeholders for emulated HVM support.
In fact I wonder if it should just be omitted, we will need a LIBXL_HAVE for HVM USB support anyway once it is implemented so we can add the enum then.
Or will we -- do we think returning an error for such an HVM guest with USB devices configured now is acceptable and for it to silently start working at some point in the future is OK?
Quoted 14 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/libxl_types.idl | 58 +++++++++++++++++++++++++++++++++++- tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)tools/libxl/libxl_types.idl +0
-0@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool),
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 541
Quoted 10 lines
tools/libxl/libxl_types.idl +8
-0]) +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8),
I think int would be fine for both of these last two (and is a bit kinder to language bindings).
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 545
Quoted 4 lines
tools/libxl/libxl_types.idl +4
-0+ ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer),
Is this an index into something? If so what?
There seems to be no usbctrl array added to the domain_config struct, so I'm unsure how this is used.
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 546
Quoted 1 line
tools/libxl/libxl_types.idl +1
-0+ ("port", integer),
Port on the hub?
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 547
Quoted 1 line
tools/libxl/libxl_types.idl +1
-0+ ("intf", string),
What is this one? (This may just be my lack of usb knowledge)
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 12 lines
tools/libxl/libxl_types.idl +8
-0+ ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ]) +@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),
So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
You pointed me to
http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html but having had a look through I can't see it.
For v3 please could you give an overview/summary of how it fits together in the 0/N patch.
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 12 lines · Ian Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.
Quoted 7 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.Or will we -- do we think returning an error for such an HVM guest with USB devices configured now is acceptable and for it to silently start working at some point in the future is OK?
I think that was my idea back when I was writing the HVM hotplug patches.
Quoted 36 lines
Quoted 15 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/libxl_types.idl | 58 +++++++++++++++++++++++++++++++++++- tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)tools/libxl/libxl_types.idl +0
-0@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool),tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 541
Quoted 10 lines
tools/libxl/libxl_types.idl +8
-0]) +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8),I think int would be fine for both of these last two (and is a bit kinder to language bindings).
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 545
Quoted 4 lines
tools/libxl/libxl_types.idl +4
-0+ ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer),Is this an index into something? If so what?
Quoted 2 lines
There seems to be no usbctrl array added to the
domain_configstruct, so I'm unsure how this is used.
It looks like this is meant to specify which USB controller you're plugging your device into; and if you set it to -1, then it will automatically try to plug it into the best one (and also automatically create one for you if one doesn't exist).
This should probably be a libxl_devid I'm guessing, then?
-George
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
In reply to Ian CampbellQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/3/2015 at 07:10 PM, in message <[email protected]>, Ian
Quoted 11 lines · Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.
Yes, I agree it's better placed in libxl_usb_type rather than ctrl_type.
Quoted 4 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.
It won't harm to omit it for current pvusb work. Acceptable to me to add enum later when adding HVM qemu emulated usb device implementation.
Quoted 22 lines
Or will we -- do we think returning an error for such an HVM guest with USB devices configured now is acceptable and for it to silently start working at some point in the future is OK?
Quoted 5 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>---
tools/libxl/libxl_types.idl | 58+++++++++++++++++++++++++++++++++++-
Quoted 11 lines
tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)tools/libxl/libxl_types.idl +0
-0@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ])
Quoted 11 lines
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 541
Quoted 8 lines
tools/libxl/libxl_types.idl +8
-0+libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8),I think int would be fine for both of these last two (and is a bit kinder to language bindings).
OK. Will update.
Quoted 7 lines
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 545
Quoted 5 lines
tools/libxl/libxl_types.idl +4
-0+ ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer),Is this an index into something? If so what?
To usb controller index.
A usb device should be connected to a usb port of a usb controller. e.g.: there is 2 usb controllers in system, each with 8 ports, then:
1st usb controller index will be 0, port will be 1~8.
2nd usb controller index will be 1, port will be 1~8.
To attach a usb device through pvusb way, it should be pointed to connect to which controller and which port.
Quoted 10 lines
There seems to be no usbctrl array added to the
domain_configstruct, so I'm unsure how this is used.tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 546
Quoted 1 line
tools/libxl/libxl_types.idl +1
-0+ ("port", integer),Port on the hub?
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 547
Quoted 1 line
tools/libxl/libxl_types.idl +1
-0+ ("intf", string),What is this one? (This may just be my lack of usb knowledge)
It means sysfs interface for the usb device under /sys/bus/usb/devices/,
like: 2-1.6.
Quoted 7 lines
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 553
Quoted 7 lines
tools/libxl/libxl_types.idl +6
-0+ ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ])
This part is for HVM qemu emulated usb device too. Currently not used.
Quoted 9 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 6 lines
tools/libxl/libxl_types.idl +2
-0+@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
In domain config, user only needs to specify usb=['2-1.6'], by default, it will create a default usb contoller, and probe the 1st available controller:port for the usb device to attach. So, it can work to specify usbs here only.
Reason didn't include controller in libxl_domain_config: for HVM qemu emulated usb device, all work is done in qemu (create usb controller and attach usb device), no controller exists in libxl in that case.
Quoted 7 lines
You pointed me to
http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html but having had a look through I can't see it.For v3 please could you give an overview/summary of ow it fits together in the 0/N patch.
Sure. Thanks!
-Chunyan
Quoted 3 lines
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 18 lines · Chun Yan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 3/3/2015 at 07:10 PM, in message <[email protected]>, Ian
Quoted 11 lines · Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.Yes, I agree it's better placed in
libxl_usb_typerather thanctrl_type.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.It won't harm to omit it for current pvusb work. Acceptable to me to add enum later when adding HVM qemu emulated usb device implementation.
I suppose users of libxl would like to be able to expose to their users whether or not HVM USB passthrough will work (i.e. to hide UI options). So I think we will want the #define eventually so they can know at compile time if HVM USB will work.
We could add a negative one now (LIBXC_NO_HVM_USB_PASSTHROUGH) and remove it later, but that's icky I think.
So I think omit the HVM stuff for now, it's less confusing overall that way.
George, is that OK with you?
Quoted 8 lines
Quoted 7 lines
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 545
Quoted 5 lines
tools/libxl/libxl_types.idl +4
-0+ ]) + +libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer),Is this an index into something? If so what?
Quoted 7 lines
To usb controller index.
A usb device should be connected to a usb port of a usb controller. e.g.: there is 2 usb controllers in system, each with 8 ports, then:
1st usb controller index will be 0, port will be 1~8.
2nd usb controller index will be 1, port will be 1~8.
To attach a usb device through pvusb way, it should be pointed to connect to which controller and which port.
I guess what I'm missing is how do I create this controller? I saw nothing in the guest cfg which would allow me to create one.
Is there some way to say "I don't care, find a controller and use it"?
Quoted 6 lines
Quoted 6 lines
There seems to be no usbctrl array added to the
domain_configstruct, so I'm unsure how this is used.Quoted 1 line
+ ("port", integer),
Quoted 7 lines
Quoted 4 lines
Port on the hub?
Quoted 1 line
+ ("intf", string),
What is this one? (This may just be my lack of usb knowledge)
It means sysfs interface for the usb device under
/sys/bus/usb/devices/,
like: 2-1.6.
Thanks. I think given Georges feedback we will be dropping this?
Quoted 12 lines
ntly not used.
Quoted 9 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 6 lines
+
tools/libxl/libxl_types.idl +1
-0@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
Quoted 7 lines
In domain config, user only needs to specify usb=['2-1.6'], by default, it will create a default usb contoller, and probe the 1st available controller:port for the usb device to attach. So, it can work to specify usbs here only.
Reason didn't include controller in
libxl_domain_config: for HVM qemu emulated usb device, all work is done in qemu (create usb controller and attach usb device), no controller exists in libxl in that case.
OK, so it's an HVM only thing. I think that makes sense, but then how does the libxl_device_usb.ctrl field make sense or how do I use it?
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 31 lines · Ian Campbell
Quoted 18 lines · Chun Yan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 3/3/2015 at 07:10 PM, in message <[email protected]>, Ian
Quoted 11 lines · Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.Yes, I agree it's better placed in
libxl_usb_typerather thanctrl_type.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.It won't harm to omit it for current pvusb work. Acceptable to me to add enum later when adding HVM qemu emulated usb device implementation.
I suppose users of libxl would like to be able to expose to their users whether or not HVM USB passthrough will work (i.e. to hide UI options). So I think we will want the #define eventually so they can know at compile time if HVM USB will work.
Quoted 7 lines
We could add a negative one now (
LIBXC_NO_HVM_USB_PASSTHROUGH) and remove it later, but that's icky I think.So I think omit the HVM stuff for now, it's less confusing overall that way.
George, is that OK with you?
Yes; particularly as I'm hoping that having the PVUSB stuff in will make it easier for me to add my HVM usb hot-plug stuff before the feature freeze. :-)
Quoted 8 lines
Quoted 7 lines
To usb controller index.
A usb device should be connected to a usb port of a usb controller. e.g.: there is 2 usb controllers in system, each with 8 ports, then:
1st usb controller index will be 0, port will be 1~8.
2nd usb controller index will be 1, port will be 1~8.
To attach a usb device through pvusb way, it should be pointed to connect to which controller and which port.
Quoted 4 lines
I guess what I'm missing is how do I create this controller? I saw nothing in the guest cfg which would allow me to create one.
Is there some way to say "I don't care, find a controller and use it"?
This isn't documented, but if you set "ctrl" to -1, the code as written will automatically:
* find an empty port on a controller, if there is one
* create a controller if there isn't one.
I meant to mention this in my mail yesterday though -- I think probably there should be a defined constant in the IDL (LIBXL_USBCTRL_AUTO or something) you should use for that, rather than just remembering a magic value.
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 6 lines
+
tools/libxl/libxl_types.idl +1
-0@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
In domain config, user only needs to specify usb=['2-1.6'], by default, it will create a default usb contoller, and probe the 1st available controller:port for the usb device to attach. So, it can work to specify usbs here only.
Quoted 6 lines
Quoted 3 lines
Reason didn't include controller in
libxl_domain_config: for HVM qemu emulated usb device, all work is done in qemu (create usb controller and attach usb device), no controller exists in libxl in that case.OK, so it's an HVM only thing. I think that makes sense, but then how does the libxl_device_usb.ctrl field make sense or how do I use it?
Well for one, you can use libxl_device_usbctrl_add() to make a new one on a running VM; then you can use libxl_device_usb_add() to attach it. (These are exposed in xl as usb-ctrl-attach and usb-attach.)
-George
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 35 lines · George Dunlap
Quoted 34 lines · Ian Campbell
Quoted 18 lines · Chun Yan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 3/3/2015 at 07:10 PM, in message <[email protected]>, Ian
Quoted 11 lines · Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.Yes, I agree it's better placed in
libxl_usb_typerather thanctrl_type.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.It won't harm to omit it for current pvusb work. Acceptable to me to add enum later when adding HVM qemu emulated usb device implementation.
I suppose users of libxl would like to be able to expose to their users whether or not HVM USB passthrough will work (i.e. to hide UI options). So I think we will want the #define eventually so they can know at compile time if HVM USB will work.
We could add a negative one now (
LIBXC_NO_HVM_USB_PASSTHROUGH) and remove it later, but that's icky I think.
Quoted 8 lines
Quoted 4 lines
So I think omit the HVM stuff for now, it's less confusing overall that way.
George, is that OK with you?
Yes; particularly as I'm hoping that having the PVUSB stuff in will make it easier for me to add my HVM usb hot-plug stuff before the feature freeze. :-)
Great.
Quoted 19 lines
Quoted 9 lines
Quoted 8 lines
To usb controller index.
A usb device should be connected to a usb port of a usb controller. e.g.: there is 2 usb controllers in system, each with 8 ports, then:
1st usb controller index will be 0, port will be 1~8.
2nd usb controller index will be 1, port will be 1~8.
To attach a usb device through pvusb way, it should be pointed to connect to which controller and which port.Quoted 4 lines
I guess what I'm missing is how do I create this controller? I saw nothing in the guest cfg which would allow me to create one.
Is there some way to say "I don't care, find a controller and use it"?
This isn't documented, but if you set "ctrl" to -1, the code as written will automatically:
* find an empty port on a controller, if there is one
* create a controller if there isn't one.
Quoted 4 lines
I meant to mention this in my mail yesterday though -- I think probably there should be a defined constant in the IDL (
LIBXL_USBCTRL_AUTOor something) you should use for that, rather than just remembering a magic value.
Yes, and it should be the init_val in the idl I think so that the default is to do something useful after _init is called.
Can we arrange for the default/auto value to be 0, or is that too confusing because it is expected that controllers will be zero based?
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 9 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 6 lines
+
tools/libxl/libxl_types.idl +1
-0@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
In domain config, user only needs to specify usb=['2-1.6'], by default, it will create a default usb contoller, and probe the 1st available controller:port for the usb device to attach. So, it can work to specify usbs here only.
Reason didn't include controller in
libxl_domain_config: for HVM qemu emulated usb device, all work is done in qemu (create usb controller and attach usb device), no controller exists in libxl in that case.
Quoted 6 lines
Quoted 2 lines
OK, so it's an HVM only thing. I think that makes sense, but then how does the libxl_device_usb.ctrl field make sense or how do I use it?
Well for one, you can use
libxl_device_usbctrl_add()to make a new one on a running VM; then you can uselibxl_device_usb_add()to attach it. (These are exposed in xl as usb-ctrl-attach and usb-attach.)
I was thinking in the context of the domain_config struct above, so runtime xl commands other than create aren't usable.
Ian.
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/4/2015 at 08:33 PM, in message <[email protected]>,
Quoted 67 lines · Ian Campbell
Quoted 4 lines · George Dunlap
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Chun Yan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 3/3/2015 at 07:10 PM, in message <[email protected]>,
Ian
Quoted 31 lines
Quoted 31 lines
Quoted 16 lines
Quoted 11 lines · Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
Sorry for the long delay in replying.
Quoted 2 lines
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Per <[email protected]> please could you mention here that the HVM guest related parts (i.e.
LIBXL_USBCTRL_TYPE_DEVICEMODEL) andlibxl_usb_typeare placeholders for emulated HVM support.Yes, I agree it's better placed in
libxl_usb_typerather thanctrl_type.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
In fact I wonder if it should just be omitted, we will need a
LIBXL_HAVEfor HVM USB support anyway once it is implemented so we can add the enum then.It won't harm to omit it for current pvusb work. Acceptable to me to add enum later when adding HVM qemu emulated usb device implementation.
I suppose users of libxl would like to be able to expose to their users whether or not HVM USB passthrough will work (i.e. to hide UI options). So I think we will want the #define eventually so they can know at compile time if HVM USB will work.
We could add a negative one now (
LIBXC_NO_HVM_USB_PASSTHROUGH) and remove it later, but that's icky I think.Quoted 8 lines
Quoted 4 lines
So I think omit the HVM stuff for now, it's less confusing overall that way.
George, is that OK with you?
Yes; particularly as I'm hoping that having the PVUSB stuff in will make it easier for me to add my HVM usb hot-plug stuff before the feature freeze. :-)
Great.
Quoted 19 lines
Quoted 9 lines
Quoted 8 lines
To usb controller index.
A usb device should be connected to a usb port of a usb controller. e.g.: there is 2 usb controllers in system, each with 8 ports, then:
1st usb controller index will be 0, port will be 1~8.
2nd usb controller index will be 1, port will be 1~8.
To attach a usb device through pvusb way, it should be pointed to connect to which controller and which port.Quoted 4 lines
I guess what I'm missing is how do I create this controller? I saw nothing in the guest cfg which would allow me to create one.
Is there some way to say "I don't care, find a controller and use it"?
This isn't documented, but if you set "ctrl" to -1, the code as written will automatically:
* find an empty port on a controller, if there is one
* create a controller if there isn't one.
Quoted 7 lines
Quoted 4 lines
I meant to mention this in my mail yesterday though -- I think probably there should be a defined constant in the IDL (
LIBXL_USBCTRL_AUTOor something) you should use for that, rather than just remembering a magic value.Yes, and it should be the
init_valin the idl I think so that the default is to do something useful after_initis called.
Got it. Will update.
Quoted 3 lines
Can we arrange for the default/auto value to be 0, or is that too confusing because it is expected that controllers will be zero based?
Yeah, controller index is zero based, so it might be confusing if setting default/auto to be 0.
- Chunyan
Quoted 37 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 7 lines
tools/libxl/libxl_types.idl +2
-0+@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),So, I'm unsure how this interacts with the controllers, which it doesn't seem to be possible to specify at domain build time.
Quoted 1 line
Quoted 1 line
Quoted 1 line
In domain config, user only needs to specify usb=['2-1.6'], by default, it
will
Quoted 1 line
Quoted 1 line
Quoted 1 line
create a default usb contoller, and probe the 1st available
controller:port for
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
the usb device to attach. So, it can work to specify usbs here only.
Reason didn't include controller in
libxl_domain_config: for HVM qemuemulated
Quoted 1 line
Quoted 1 line
Quoted 1 line
usb device, all work is done in qemu (create usb controller and attach usb
device),
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
no controller exists in libxl in that case.
OK, so it's an HVM only thing. I think that makes sense, but then how does the libxl_device_usb.ctrl field make sense or how do I use it?
Well for one, you can use
libxl_device_usbctrl_add()to make a new one on a running VM; then you can uselibxl_device_usb_add()to attach it. (These are exposed in xl as usb-ctrl-attach and usb-attach.)I was thinking in the context of the
domain_configstruct above, so runtime xl commands other than create aren't usable.Ian.
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
In reply to Chunyan LiuQuoted 5 lines · Chunyan Liu
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>
Chunyan, thanks for picking up this work!
A couple of things. First, I think that having the IDL stuff separate from the patches where they are used actually makes it *harder* to review, because you can't easily go to the code where it's used and see what's actually happening.
I think that the IDL stuff used in patch 3 should be in patch 3; and the domain creation IDL stuff should be included in patch 5.
Quoted 27 lines
--- tools/libxl/libxl_types.idl | 58 +++++++++++++++++++++++++++++++++++- tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)tools/libxl/libxl_types.idl +10
-0@@ -111,6 +111,16 @@ libxl_nic_type = Enumeration("nic_type", [ (2, "VIF"), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type",[ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usb_type = Enumeration("device_usb_type", [ + (1, "HOSTDEV"), + ]) + libxl_action_on_shutdown = Enumeration("action_on_shutdown", [ (1, "DESTROY"),
tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 407
Quoted 5 lines
tools/libxl/libxl_types.idl +1
-1@@ -394,7 +404,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("ioports", Array(libxl_ioport_range, "num_ioports")), ("irqs", Array(uint32, "num_irqs")), ("iomem", Array(libxl_iomem_range, "num_iomem")), - ("claim_mode", libxl_defbool), + ("claim_mode", libxl_defbool),
Spurious whitespace change -- please kill this.
Quoted 17 lines
tools/libxl/libxl_types.idl +10
-0("event_channels", uint32), ("kernel", string), ("cmdline", string),@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8), + ]) +
tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 553
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer), + ("port", integer), + ("intf", string), + ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ])
So "intf" here is wrong. To begin with, it's information specific to the "hostdev" type; so it would go under the "type" keyed union under "hostdev".
Secondly, this requires people to figure out that their media reader has an intf of "1-2.1.1:1.0". I don't think that's a good idea, for two
reasons: one, it just seems like a really hard interface to use. I couldn't find any straightforward tools to map USB devices onto intf; tools like "lsusb" instead give you a bus:addr combination. Secondly, it's inconsistent with qemu -- which means we'd either have to have two different ways of specifying the device, or we'd need to translate from "intf" back into bus:addr
I think the right thing to do here is to take "intf" out of this struct, and to translate "bus:addr" into intf internally.
It looks like the values qemu and lsusb use can be found in "busnum" and "devnum" in the sysfs files. You've already got code to scan those devices; you just need to add a bit of code to find which of those corresponds to a given "hostbus:hostaddr" combination.
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 9 lines
tools/libxl/libxl_types.idl +2
-0+ libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),
Any reason you don't make it possible to specify usb controllers as well?
Thanks again for picking this up. I'll give feedback on the other patches tomorrow.
-George
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/4/2015 at 01:15 AM, in message <[email protected]>, George
Quoted 9 lines · Dunlap
Quoted 5 lines · Chunyan Liu
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Chunyan, thanks for picking up this work!
Quoted 7 lines
A couple of things. First, I think that having the IDL stuff separate from the patches where they are used actually makes it *harder* to review, because you can't easily go to the code where it's used and see what's actually happening.
I think that the IDL stuff used in patch 3 should be in patch 3; and the domain creation IDL stuff should be included in patch 5.
Tha's OK. I'll update.
Quoted 69 lines
Quoted 3 lines
---
tools/libxl/libxl_types.idl | 58+++++++++++++++++++++++++++++++++++-
Quoted 25 lines
tools/libxl/libxl_types_internal.idl | 1 + 2 files changed, 58 insertions(+), 1 deletion(-)tools/libxl/libxl_types.idl +10
-0@@ -111,6 +111,16 @@ libxl_nic_type = Enumeration("nic_type", [ (2, "VIF"), ]) +libxl_usbctrl_type = Enumeration("usbctrl_type",[ + (0, "AUTO"), + (1, "PV"), + (2, "DEVICEMODEL"), + ]) + +libxl_usb_type = Enumeration("device_usb_type", [ + (1, "HOSTDEV"), + ]) + libxl_action_on_shutdown = Enumeration("action_on_shutdown", [ (1, "DESTROY"),tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 407
Quoted 5 lines
tools/libxl/libxl_types.idl +1
-1@@ -394,7 +404,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("ioports", Array(libxl_ioport_range, "num_ioports")), ("irqs", Array(uint32, "num_irqs")), ("iomem", Array(libxl_iomem_range, "num_iomem")), - ("claim_mode", libxl_defbool), + ("claim_mode", libxl_defbool),Spurious whitespace change -- please kill this.
Quoted 17 lines
tools/libxl/libxl_types.idl +10
-0("event_channels", uint32), ("kernel", string), ("cmdline", string),@@ -521,6 +531,27 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8), + ]) +tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 553
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer), + ("port", integer), + ("intf", string), + ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ])So "intf" here is wrong. To begin with, it's information specific to the "hostdev" type; so it would go under the "type" keyed union under "hostdev".
Quoted 4 lines
Secondly, this requires people to figure out that their media reader has an intf of "1-2.1.1:1.0". I don't think that's a good idea, for two
reasons: one, it just seems like a really hard interface to use. I couldn't find any straightforward tools to map USB devices onto intf;
Right. One can only use usb-assignable-list for a fast look. That follows the old xend toolstack way.
Quoted 4 lines
tools like "lsusb" instead give you a bus:addr combination. Secondly, it's inconsistent with qemu -- which means we'd either have to have two different ways of specifying the device, or we'd need to translate from "intf" back into bus:addr
You are right. Using bus:addr could unify qemu and pvusb. I also thought about that. Only concern is it's different from old xend toolstack usage. If that doesn't affect, we can update to use bus:addr, no problem.
Quoted 9 lines
I think the right thing to do here is to take "intf" out of this struct, and to translate "bus:addr" into intf internally.
It looks like the values qemu and lsusb use can be found in "busnum" and "devnum" in the sysfs files. You've already got code to scan those devices; you just need to add a bit of code to find which of those corresponds to a given "hostbus:hostaddr" combination.
Quoted 11 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 9 lines
tools/libxl/libxl_types.idl +2
-0+ libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),Any reason you don't make it possible to specify usb controllers as well?
For qemu emulated HVM usb device, usb controller is created by qemu, no way to specify it (?) Also I wonder if specifying usb controller is necessary, seems it won't affect without usb controller here. Correct me if I'm wrong. If it's necessary, we can add it.
Thanks,
Chunyan
Quoted 8 lines
Thanks again for picking this up. I'll give feedback on the other patches tomorrow.
-George
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 18 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/4/2015 at 01:15 AM, in message <[email protected]>, George
Quoted 14 lines · Dunlap
Quoted 5 lines · Chunyan Liu
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Chunyan, thanks for picking up this work!
A couple of things. First, I think that having the IDL stuff separate from the patches where they are used actually makes it *harder* to review, because you can't easily go to the code where it's used and see what's actually happening.
Quoted 4 lines
Quoted 2 lines
I think that the IDL stuff used in patch 3 should be in patch 3; and the domain creation IDL stuff should be included in patch 5.
Tha's OK. I'll update.
Great, thanks.
Quoted 33 lines
Quoted 25 lines
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8), + ]) +tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 553
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer), + ("port", integer), + ("intf", string), + ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ])So "intf" here is wrong. To begin with, it's information specific to the "hostdev" type; so it would go under the "type" keyed union under "hostdev".
Quoted 4 lines
Secondly, this requires people to figure out that their media reader has an intf of "1-2.1.1:1.0". I don't think that's a good idea, for two
reasons: one, it just seems like a really hard interface to use. I couldn't find any straightforward tools to map USB devices onto intf;Right. One can only use usb-assignable-list for a fast look. That follows the old xend toolstack way.
Quoted 8 lines
Quoted 4 lines
tools like "lsusb" instead give you a bus:addr combination. Secondly, it's inconsistent with qemu -- which means we'd either have to have two different ways of specifying the device, or we'd need to translate from "intf" back into bus:addr
You are right. Using bus:addr could unify qemu and pvusb. I also thought about that. Only concern is it's different from old xend toolstack usage. If that doesn't affect, we can update to use bus:addr, no problem.
Right, I see.
I think overall that the bus:addr is a better interface; it's also what's exposed by lsusb, qemu, and libvirt, AFAICT. So I definitely think that at the libxl level that's what we should be using.
We're already defining a new config file format, right? So domain configs that used pvusb with xend won't work with this patch series anyway, correct?
If we're not going to make something 100% compatible, I don't see any particular value in making it 25% compatible. :-)
Quoted 20 lines
Quoted 8 lines
I think the right thing to do here is to take "intf" out of this struct, and to translate "bus:addr" into intf internally.
It looks like the values qemu and lsusb use can be found in "busnum" and "devnum" in the sysfs files. You've already got code to scan those devices; you just need to add a bit of code to find which of those corresponds to a given "hostbus:hostaddr" combination.
Quoted 11 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 9 lines
+
libxl_device_vtpm= Struct("device_vtpm", [
("backend_domid",libxl_domid),
("backend_domname", string),tools/libxl/libxl_types.idl +1
-0@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),Any reason you don't make it possible to specify usb controllers as well?
Quoted 4 lines
For qemu emulated HVM usb device, usb controller is created by qemu, no way to specify it (?) Also I wonder if specifying usb controller is necessary, seems it won't affect without usb controller here. Correct me if I'm wrong. If it's necessary, we can add it.
On the contrary, there is a way to specify it. :-) See "usbversion=[n]". At the moment we specify the usb device on the qemu command-line; but I'm pretty sure that we can use qmp to hot-plug a USB controller just like we can use it to hot-plug a USB device.
qemu will automatically hot-plug a USB controller as necessary, similar to your "automatically create a pvusb controller" functionality for pvusb add. But there may be circumstances where we want to specify a controller (for instance, if you want to be able to control what kind of controller it is).
My long-term vision is to have the USB stuff unified. Instead of passing in USB devices on the qemu command-line, as we do now, we'd plug them in after starting qemu but before letting the VM run (similar to the way we do things with PCI pass-through).
In any case, I agree with your design decision that you shouldn't *have* to specify a controller. However, I think you should be able to specify a controller if you wish.
Adding that functionality to libxl should be pretty straightforward. Coming up with a sensible way to specify it in the xl config file would be a bit more work, and I would be open to the argument that it shouldn't be a requirement for this series to go in.
-George
Re: [PATCH RFC V2 1/5] libxl: add pvusb definitions
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/4/2015 at 10:41 PM, in message <[email protected]>, George
Quoted 68 lines · Dunlap
Quoted 18 lines · Chun Yan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/4/2015 at 01:15 AM, in message <[email protected]>, George
Quoted 14 lines · Dunlap
Quoted 5 lines · Chunyan Liu
To attach a usb device, a virtual usb controller should be created first. This patch defines usbctrl and usbdevice related structs.
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>Chunyan, thanks for picking up this work!
A couple of things. First, I think that having the IDL stuff separate from the patches where they are used actually makes it *harder* to review, because you can't easily go to the code where it's used and see what's actually happening.
Quoted 4 lines
Quoted 2 lines
I think that the IDL stuff used in patch 3 should be in patch 3; and the domain creation IDL stuff should be included in patch 5.
Tha's OK. I'll update.
Great, thanks.
Quoted 33 lines
Quoted 25 lines
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usbctrl = Struct("device_usbctrl", [ + ("name", string), + ("type", libxl_usbctrl_type), + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("usb_version", uint8), + ("num_ports", uint8), + ]) +tools/libxl/libxl_types.idl libxl_device_pci = Struct("device_pci", [ · line 553
Quoted 10 lines
tools/libxl/libxl_types.idl +10
-0+libxl_device_usb = Struct("device_usb", [ + ("ctrl", integer), + ("port", integer), + ("intf", string), + ("u", KeyedUnion(None, libxl_usb_type, "type", + [("hostdev", Struct(None, [ + ("hostbus", integer), + ("hostaddr", integer) ])) + ])) + ])So "intf" here is wrong. To begin with, it's information specific to the "hostdev" type; so it would go under the "type" keyed union under "hostdev".
Quoted 4 lines
Secondly, this requires people to figure out that their media reader has an intf of "1-2.1.1:1.0". I don't think that's a good idea, for two
reasons: one, it just seems like a really hard interface to use. I couldn't find any straightforward tools to map USB devices onto intf;Right. One can only use usb-assignable-list for a fast look. That follows the old xend toolstack way.
Quoted 8 lines
Quoted 4 lines
tools like "lsusb" instead give you a bus:addr combination. Secondly, it's inconsistent with qemu -- which means we'd either have to have two different ways of specifying the device, or we'd need to translate from "intf" back into bus:addr
You are right. Using bus:addr could unify qemu and pvusb. I also thought about that. Only concern is it's different from old xend toolstack usage. If that doesn't affect, we can update to use bus:addr, no problem.
Quoted 5 lines
Right, I see.
I think overall that the bus:addr is a better interface; it's also what's exposed by lsusb, qemu, and libvirt, AFAICT. So I definitely think that at the libxl level that's what we should be using.
Thanks. Got it. Will update.
Quoted 45 lines
We're already defining a new config file format, right? So domain configs that used pvusb with xend won't work with this patch series anyway, correct?
If we're not going to make something 100% compatible, I don't see any particular value in making it 25% compatible. :-)
Quoted 20 lines
Quoted 8 lines
I think the right thing to do here is to take "intf" out of this struct, and to translate "bus:addr" into intf internally.
It looks like the values qemu and lsusb use can be found in "busnum" and "devnum" in the sysfs files. You've already got code to scan those devices; you just need to add a bit of code to find which of those corresponds to a given "hostbus:hostaddr" combination.
Quoted 11 lines
tools/libxl/libxl_types.idl libxl_domain_config = Struct("domain_config", [ · line 581
Quoted 9 lines
tools/libxl/libxl_types.idl +2
-0+ libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),@@ -547,6 +578,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("usbs", Array(libxl_device_usb, "num_usbs")),Any reason you don't make it possible to specify usb controllers as well?
Quoted 2 lines
For qemu emulated HVM usb device, usb controller is created by qemu, no way to specify it (?) Also I wonder if specifying usb controller is
necessary,
Quoted 2 lines
seems it won't affect without usb controller here. Correct me if I'm wrong. If it's necessary, we can add it.
On the contrary, there is a way to specify it. :-) See "usbversion=[n]". At the moment we specify the usb device on the qemu command-line; but I'm pretty sure that we can use qmp to hot-plug a USB controller just like we can use it to hot-plug a USB device.
qemu will automatically hot-plug a USB controller as necessary, similar to your "automatically create a pvusb controller" functionality for pvusb add. But there may be circumstances where we want to specify a controller (for instance, if you want to be able to control what kind of controller it is).
Quoted 4 lines
My long-term vision is to have the USB stuff unified. Instead of passing in USB devices on the qemu command-line, as we do now, we'd plug them in after starting qemu but before letting the VM run (similar to the way we do things with PCI pass-through).
Thanks for explanation. So I'll add usb controllers to domain_config, and for that libxl_device_usbctrl should be finally able to represent pvusb controller and qemu emulated controller. Currently, it's defined to represent a pvusb controller, in future, when HVM qemu emulated USB is implemented, it could be extended.
- Chunyan
Quoted 14 lines
In any case, I agree with your design decision that you shouldn't *have* to specify a controller. However, I think you should be able to specify a controller if you wish.
Adding that functionality to libxl should be pretty straightforward. Coming up with a sensible way to specify it in the xl config file would be a bit more work, and I would be open to the argument that it shouldn't be a requirement for this series to go in.
-George
RFC PATCH v2 2/5 libxl: export some functions for pvusb use
In reply to Chunyan Liu--- tools/libxl/libxl.c | 6 +++--- tools/libxl/libxl_internal.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +3 -3
@@ -1906,7 +1906,7 @@ out:/******************************************************************************/ /* generic callback for devices that only need to set ao_complete */ -static void device_addrm_aocomplete (libxl__egc *egc,libxl__ao_device *aodev) +void device_addrm_aocomplete (libxl__egc *egc,libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao);
@@ -1929,7 +1929,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;
@@ -1948,7 +1948,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 +5 -0
@@ -1057,6 +1057,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:
@@ -2181,6 +2184,8 @@ struct libxl__ao_device {/* Starts preparing to add/remove a bunch of devices. */ _hidden void libxl__multidev_begin(libxl__ao *ao, libxl__multidev*); +/* generic callback for devices that only need to set ao_complete */ +_hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev);/* Prepares to add/remove one of many devices. * Calls libxl__prepare_ao_device on libxl__ao_device argument provided and
Signature · 1 line
1.8.4.5
Re: [PATCH RFC V2 2/5] libxl: export some functions for pvusb use
Quoted 2 lines · Chunyan Liu
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>
RFC PATCH v2 3/5 libxl: add pvusb API
In reply to Chunyan LiuAdd pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functions
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +- 7 files changed, 1623 insertions(+), 224 deletions(-) create mode 100644 tools/libxl/libxl_usb.c
tools/libxl/Makefile +1 -1
@@ -95,7 +95,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_internal.o libxl_utils.o libxl_uuid.o \ libxl_json.o libxl_aoutils.o libxl_numa.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ - libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) + libxl_qmp.o libxl_event.o libxl_fork.o libxl_usb.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 +2 -0
@@ -1594,6 +1594,8 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)if (libxl__device_pci_destroy_all (gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"pci shutdown failed for domid %d" , domid); +if (libxl__device_usb_destroy_all (gc, domid) <0 ) +LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"usb shutdown failed for domid %d" , domid); rc =xc_domain_pause (ctx->xch, domid);if (rc <0 ) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"xc_domain_pause failed for %d" , domid);
tools/libxl/libxl.h +58 -0
76 lines not on this page · raw message
tools/libxl/libxl_internal.h +6 -0
@@ -2395,6 +2395,11 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, libxl_device_vtpm *vtpm, libxl__ao_device *aodev); +/* from libxl_usb */ +_hidden int libxl__device_usb_add(libxl__gc *gc, uint32_t domid, +libxl_device_usb *usb); +_hidden int libxl__device_usb_destroy_all(libxl__gc *gc, uint32_t domid); +/* Internal function to connect a vkb device */ _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,libxl_device_vkb *vkb);
@@ -3574,6 +3579,7 @@ 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) (!strcmp((a)->intf, (b)->intf))/* DEVICE_ADD *
tools/libxl/libxl_usb.c new file +1277 -0
1,277 lines not on this page · raw message
tools/libxl/libxlu_cfg_y.c +251 -213
776 lines not on this page · raw message
tools/libxl/libxlu_cfg_y.h +28 -10
@@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. +Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
@@ -30,6 +30,15 @@This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +#ifndef YY_XLU_CFG_YY_LIBXLU_CFG_Y_H_INCLUDED +# define YY_XLU_CFG_YY_LIBXLU_CFG_Y_H_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int xlu__cfg_yydebug; +#endif /* Tokens. */ #ifndef YYTOKENTYPE
@@ -45,29 +54,24 @@#endif -#if ! definedYYSTYPE && ! definedYYSTYPE_IS_DECLARED typedef union YYSTYPE { - -/* Line 2068 of yacc.c */ +/* Line 2058 of yacc.c */ #line 25 "libxlu_cfg_y.y"char *string;XLU_ConfigSetting *setting; - -/* Line 2068 of yacc.c */ -#line 63 "libxlu_cfg_y.h" +/* Line 2058 of yacc.c */ +#line 69 "libxlu_cfg_y.h" }YYSTYPE ;# define YYSTYPE_IS_TRIVIAL 1# define yystype YYSTYPE/* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1#endif - - #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED typedef struct YYLTYPE {
@@ -82,4 +86,18 @@ typedef struct YYLTYPE#endif +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int xlu__cfg_yyparse (void *YYPARSE_PARAM ); +#else +int xlu__cfg_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int xlu__cfg_yyparse (CfgParseContext *ctx); +#else +int xlu__cfg_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ +#endif /* !YY_XLU_CFG_YY_LIBXLU_CFG_Y_H_INCLUDED */
Signature · 1 line
1.8.4.5
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 2 lines · Chunyan Liu
tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +-
I think these are spurious changes caused by you having different versions of flex/bison installed, could you arrange to omit these please.
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 1/28/2015 at 11:54 PM, in message <[email protected]>, Ian
Quoted 7 lines · Campbell
Quoted 2 lines · Chunyan Liu
tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +-I think these are spurious changes caused by you having different versions of flex/bison installed, could you arrange to omit these please.
Sorry, will delete.
Quoted 4 lines
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to Chunyan LiuQuoted 183 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +- 7 files changed, 1623 insertions(+), 224 deletions(-)create mode 100644
tools/libxl/libxl_usb.ctools/libxl/Makefile +1
-1@@ -95,7 +95,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_internal.o libxl_utils.o libxl_uuid.o \ libxl_json.o libxl_aoutils.o libxl_numa.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ - libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) + libxl_qmp.o libxl_event.o libxl_fork.o libxl_usb.o $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.otools/libxl/libxl.c +2
-0@@ -1594,6 +1594,8 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)if (libxl__device_pci_destroy_all (gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"pci shutdown failed for domid %d" , domid); +if (libxl__device_usb_destroy_all (gc, domid) <0 ) +LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"usb shutdown failed for domid %d" , domid); rc =xc_domain_pause (ctx->xch, domid);if (rc <0 ) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"xc_domain_pause failed for %d" , domid);tools/libxl/libxl.h +58
-0@@ -98,6 +98,12 @@#define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1/* +* LIBXL_HAVE_DEVICE_USB indicates the functions for doing hot-plug of +* USB devices. +*/ +#define LIBXL_HAVE_DEVICE_USB 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 @@ -1168,6 +1174,56 @@ 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*/ +int libxl_device_usbctrl_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_usbctrl *usbctrl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +int libxl_device_usbctrl_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_usbctrl *usbctrl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +int libxl_device_usbctrl_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_usbctrl *usbctrl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +libxl_device_usbctrl *libxl_device_usbctrl_list (libxl_ctx *ctx, +uint32_t domid,int *num); + +int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_usbctrl *usbctrl) + LIBXL_EXTERNAL_CALLERS_ONLY; + +int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_usbctrl *usbctrl, + libxl_usbctrlinfo *usbctrlinfo) + LIBXL_EXTERNAL_CALLERS_ONLY; + +/* 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; + +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; + +int libxl_device_usb_destroy(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 usbctrl,int *num); + +int libxl_intf_to_device_usb(libxl_ctx *ctx, uint32_t domid, + char *intf, libxl_device_usb *usb) + LIBXL_EXTERNAL_CALLERS_ONLY; + +int libxl_device_usb_getinfo(libxl_ctx *ctx, char *intf, libxl_usbinfo *usbinfo) + LIBXL_EXTERNAL_CALLERS_ONLY;/* Network Interfaces */ int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic,const libxl_asyncop_how *ao_how)@@ -1294,6 +1350,8 @@ int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pcidev, inint libxl_device_pci_assignable_remove (libxl_ctx *ctx,libxl_device_pci *pcidev,int rebind);libxl_device_pci *libxl_device_pci_assignable_list (libxl_ctx *ctx,int *num); +libxl_device_usb *libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num); +/* CPUID handling */ int libxl_cpuid_parse_config (libxl_cpuid_policy_list *cpuid,const char * str); int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,tools/libxl/libxl_internal.h +6
-0@@ -2395,6 +2395,11 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, libxl_device_vtpm *vtpm, libxl__ao_device *aodev); +/* from libxl_usb */ +_hidden int libxl__device_usb_add(libxl__gc *gc, uint32_t domid, +libxl_device_usb *usb); +_hidden int libxl__device_usb_destroy_all(libxl__gc *gc, uint32_t domid); +/* Internal function to connect a vkb device */ _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,libxl_device_vkb *vkb);@@ -3574,6 +3579,7 @@ 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) (!strcmp((a)->intf, (b)->intf))/* DEVICE_ADD * tools/libxl/libxl_usb.c new file +25
-0@@ -0,0 +1,1277 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#include "libxl_osdeps.h" /* must come before any other headers */ + +#include "libxl_internal.h" + +#define SYSFS_USB_DEVS_PATH "/sys/bus/usb/devices" +#define SYSFS_USBBACK_DRIVER "/sys/bus/usb/drivers/usbback" +#define USBBACK_INFO_PATH "/libxl/usbback" + +#define USBHUB_CLASS_CODE "09" + +static int libxl__device_usbctrl_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{
tools/libxl/libxl_usb.c line 35
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+int rc; + +if (!usbctrl->usb_version) + usbctrl->usb_version =2 ; + +if (!usbctrl->num_ports) + usbctrl->num_ports =8 ; + +if (!usbctrl->backend_domid) + usbctrl->backend_domid =0 ;
Just use a comment?
tools/libxl/libxl_usb.c line 48
Quoted 13 lines
tools/libxl/libxl_usb.c new file +13
-0+ +if (!usbctrl->type) + usbctrl->type =LIBXL_USBCTRL_TYPE_PV ; + + rc =libxl__resolve_domid (gc, usbctrl->backend_domname, + &usbctrl->backend_domid); + +return rc; +} + +static int libxl__device_from_usbctrl (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl__device *device)
Make function type void?
Quoted 78 lines
tools/libxl/libxl_usb.c new file +78
-0+{ + device->backend_devid = usbctrl->devid; + device->backend_domid = usbctrl->backend_domid; + device->backend_kind =LIBXL__DEVICE_KIND_VUSB ; + device->devid = usbctrl->devid; + device->domid = domid; + device->kind =LIBXL__DEVICE_KIND_VUSB ; + +return 0 ; +} + +static int libxl__usbport_add_xenstore (libxl__gc *gc, +xs_transaction_t tran, +uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +char *path; +int i; + + path =GCSPRINTF ("%s/backend/vusb/%d/%d/port" , +libxl__xs_get_dompath (gc,0 ), domid, usbctrl->devid); + +libxl__xs_mkdir (gc, tran, path,NULL ,0 ); + +for (i =1 ; i <= usbctrl->num_ports; i++) { +if (libxl__xs_write_checked (gc, tran,GCSPRINTF ("%s/%d" , path, i),"" )) +return ERROR_FAIL ; + } + +return 0 ; +} + +static int libxl__usbctrl_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +flexarray_t *front; +flexarray_t *back; +libxl__device *device; +xs_transaction_t tran; +int rc =0 ; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out; + + front =flexarray_make (gc,4 ,1 ); + back =flexarray_make (gc,12 ,1 ); + +flexarray_append (back,"frontend-id" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid)); +flexarray_append (back,"online" ); +flexarray_append (back,"1" ); +flexarray_append (back,"state" ); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 )); +flexarray_append (back,"usb-ver" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->usb_version)); +flexarray_append (back,"num-ports" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->num_ports)); +flexarray_append (back,"type" ); +switch (usbctrl->type) { +case LIBXL_USBCTRL_TYPE_PV :{ +flexarray_append (back,"PVUSB" ); +break ; + } +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : { +flexarray_append (back,"IOEMU" ); +break ; + } +default : +/* not supported */ + rc =ERROR_FAIL ; + goto out; + } + +flexarray_append (front,"backend-id" ); +flexarray_append (front,libxl__sprintf (gc,"%d" , usbctrl->backend_domid)); +flexarray_append (front,"state" );
tools/libxl/libxl_usb.c line 136
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+flexarray_append (front,libxl__sprintf (gc,"%d" ,1 )); + +retry_transaction: + tran =xs_transaction_start (ctx->xsh); + +libxl__device_generic_add (gc, tran, device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count), +NULL ); +libxl__usbport_add_xenstore (gc, tran, domid, usbctrl);
No check of rc?
Quoted 11 lines
tools/libxl/libxl_usb.c new file +11
-0+ +if (!xs_transaction_end (ctx->xsh, tran,0 )) { +if (errno ==EAGAIN ) + goto retry_transaction; +else { + rc =ERROR_FAIL ; + goto out; + } + } + +out:
tools/libxl/libxl_usb.c line 157
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+return rc; +} + +static int libxl__device_usbctrl_add (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +int rc =0 ; + + rc =libxl__device_usbctrl_setdefault (gc, domid, usbctrl); +if (rc) goto out;
Coding style.
tools/libxl/libxl_usb.c line 160
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+ +if (usbctrl->devid ==-1 ) { +if ((usbctrl->devid =libxl__device_nextid (gc, domid,"vusb" )) <0 ) {
Combine above 2 ifs in one?
Quoted 37 lines
tools/libxl/libxl_usb.c new file +37
-0+ rc =ERROR_FAIL ; + goto out; + } + } + +if (libxl__usbctrl_add_xenstore (gc, domid, usbctrl) <0 ){ + rc =ERROR_FAIL ; + goto out; + } + +out: +return rc; +} + +int libxl_device_usbctrl_add (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how) +{ +AO_CREATE (ctx, domid, ao_how); +int rc; + + rc =libxl__device_usbctrl_add (gc, domid, usbctrl); +libxl__ao_complete (egc, ao, rc); +return AO_INPROGRESS ; +} + +libxl_device_usbctrl * +libxl_device_usbctrl_list (libxl_ctx *ctx,uint32_t domid,int *num) +{ +GC_INIT (ctx); + +libxl_device_usbctrl *usbctrls =NULL ; +char *fe_path =NULL ; +char **dir =NULL ; +unsigned int ndirs =0 ; + + *num =0 ;
tools/libxl/libxl_usb.c line 207
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ + fe_path =libxl__sprintf (gc,"%s/device/vusb" , +libxl__xs_get_dompath (gc, domid)); + dir =libxl__xs_directory (gc,XBT_NULL , fe_path, &ndirs); + +if (dir && ndirs) { + usbctrls =malloc (sizeof (*usbctrls) * ndirs); +libxl_device_usbctrl * usbctrl; +libxl_device_usbctrl * end = usbctrls + ndirs; +for (usbctrl = usbctrls; usbctrl < end; usbctrl++, dir++, (*num)++) {
Coding style.
Why (*num)++? *num is set at end of loop.
Quoted 50 lines
tools/libxl/libxl_usb.c new file +50
-0+char *tmp; +const char *be_path =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s/backend" , fe_path, *dir)); + +libxl_device_usbctrl_init (usbctrl); + + usbctrl->devid =atoi (*dir); + + tmp =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s/backend-id" , fe_path, *dir)); +if (!tmp) goto outerr; + usbctrl->backend_domid =atoi (tmp); + + tmp =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/usb-ver" , be_path)); +if (!tmp) goto outerr; + usbctrl->usb_version =atoi (tmp); + + tmp =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/num-ports" , be_path)); +if (!tmp) goto outerr; + usbctrl->num_ports =atoi (tmp); + } + } + *num = ndirs; + +return usbctrls; + +outerr: +LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Unable to list USB Controllers" ); +for (int i =0 ; i < *num; i++) { +libxl_device_usbctrl_dispose (usbctrls + i); + } +free (usbctrls); + *num =0 ; +return NULL ; +} + +static int libxl__device_usb_list (libxl__gc *gc,uint32_t domid,int usbctrl, +libxl_device_usb **usbs,int *num); + +static int libxl__device_usb_remove_common (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb,int force); + +static int +libxl__device_usbctrl_remove_common (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how, +int force) +{
tools/libxl/libxl_usb.c line 267
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+AO_CREATE (ctx, domid, ao_how); +libxl__device *device; +libxl__ao_device *aodev; +libxl_device_usb *usbs =NULL ; +int numusb =0 ; +int i, rc; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out;
Coding style, but rc check can be probably removed.
tools/libxl/libxl_usb.c line 270
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+ +/* Remove usb devives first */ + rc =libxl__device_usb_list (gc, domid, usbctrl->devid, &usbs, &numusb);
Coding style.
Quoted 8 lines
tools/libxl/libxl_usb.c new file +8
-0+if (rc) goto out; +for (i =0 ; i < numusb; i++) { +if (libxl__device_usb_remove_common (gc, domid, &usbs[i],0 )) { +fprintf (stderr,"libxl_device_usb_remove failed.\n" ); +return -1 ; + } + } +/* remove usbctrl */
tools/libxl/libxl_usb.c line 288
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+GCNEW (aodev); +libxl__prepare_ao_device (ao, aodev); + aodev->action =LIBXL__DEVICE_ACTION_REMOVE ; + aodev->dev = device; + aodev->callback = device_addrm_aocomplete; + aodev->force = force; +libxl__initiate_device_remove (egc, aodev); + +out: +if (rc)return AO_ABORT (rc);
Coding style.
Quoted 170 lines
tools/libxl/libxl_usb.c new file +170
-0+return AO_INPROGRESS ; +} + +int libxl_device_usbctrl_remove (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how) +{ +return libxl__device_usbctrl_remove_common (ctx, domid, usbctrl, ao_how,0 ); +} + +int libxl_device_usbctrl_destroy (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how) +{ +return libxl__device_usbctrl_remove_common (ctx, domid, usbctrl, ao_how,1 ); +} + +int libxl_device_usbctrl_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +libxl_usbctrlinfo *usbctrlinfo) +{ +GC_INIT (ctx); +char *dompath, *usbctrlpath; +char *val; +int rc =0 ; + + dompath =libxl__xs_get_dompath (gc, domid); + usbctrlinfo->devid = usbctrl->devid; + usbctrlinfo->num_ports = usbctrl->num_ports; + usbctrlinfo->version = usbctrl->usb_version; + + usbctrlpath =libxl__sprintf (gc,"%s/device/vusb/%d" , dompath, usbctrlinfo->devid); + usbctrlinfo->backend =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/backend" , usbctrlpath)); +if (!usbctrlinfo->backend) { + rc =ERROR_FAIL ; + goto out; + } + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/backend-id" , usbctrlpath)); + usbctrlinfo->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/state" , usbctrlpath)); + usbctrlinfo->state = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/event-channel" , usbctrlpath)); + usbctrlinfo->evtch = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/urb-ring-ref" , usbctrlpath)); + usbctrlinfo->ref_urb = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/conn-ring-ref" , usbctrlpath)); + usbctrlinfo->ref_conn= val ?strtoul (val,NULL ,10 ) :-1 ; + + usbctrlinfo->type =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/type" , usbctrlinfo->backend)); + + usbctrlinfo->frontend =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/frontend" , usbctrlinfo->backend)); + + val =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/frontend-id" , usbctrlinfo->backend)); + usbctrlinfo->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + +out: +GC_FREE ; +return rc; +} + +int libxl_devid_to_device_usbctrl (libxl_ctx *ctx,uint32_t domid, +int devid,libxl_device_usbctrl *usbctrl) +{ +GC_INIT (ctx); +char * fe_path =NULL , *be_path =NULL , *tmp; +int rc =0 ; + +libxl_device_usbctrl_init (usbctrl); + usbctrl->devid = devid; + + fe_path =libxl__sprintf (gc,"%s/device/vusb" , +libxl__xs_get_dompath (gc, domid)); + be_path =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%d/backend" , fe_path, devid)); + + tmp =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%d/backend-id" , fe_path, devid)); +if (!tmp) { + rc =ERROR_FAIL ; + goto out; + } + usbctrl->backend_domid =atoi (tmp); + + tmp =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/usb-ver" , be_path)); + usbctrl->usb_version =atoi (tmp); + + tmp =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/num-ports" , be_path)); + usbctrl->num_ports =atoi (tmp); + +out: +GC_FREE ; +return rc; +} + +/* usb device functions */ + +/* Following functions are to get assignable usb devices */ +static int +libxl__device_usb_assigned_list (libxl__gc *gc, +libxl_device_usb **list,int *num) +{ +char **domlist; +unsigned int nd =0 , i, j; +char *be_path; +libxl_device_usb *usb; + + *list =NULL ; + *num =0 ; + + domlist =libxl__xs_directory (gc,XBT_NULL ,"/local/domain" , &nd); + be_path =libxl__sprintf (gc,"/local/domain/0/backend/vusb" ); +for (i =0 ; i < nd; i++) { +char *path, *num_ports, **ctrl_list; +unsigned int nc =0 ; + path =libxl__sprintf (gc,"%s/%s" , be_path, domlist[i]); + ctrl_list =libxl__xs_directory (gc,XBT_NULL , path , &nc); + +for (j =0 ; j < nc; j++) { + path =libxl__sprintf (gc,"%s/%s/%s/num-ports" , be_path, + domlist[i], ctrl_list[j]); + num_ports =libxl__xs_read (gc,XBT_NULL , path); +if ( num_ports ) { +int nport =atoi (num_ports), k; +char *devpath, *intf; + +for (k =1 ; k <= nport; k++) { + devpath =libxl__sprintf (gc,"%s/%s/%s/port/%u" , be_path, + domlist[i], ctrl_list[j], k); + intf =libxl__xs_read (gc,XBT_NULL , devpath); +/* If there are USB device attached, add it to list */ +if (intf &&strcmp (intf,"" ) ) { + *list =realloc (*list, +sizeof (libxl_device_usb) * ((*num) +1 )); +if (*list ==NULL ) +return ERROR_NOMEM ; + usb = *list + *num; + usb->ctrl =atoi (ctrl_list[j]); + usb->port = k; + usb->intf =strdup (intf); + (*num)++; + } + } + } + } + } +libxl__ptr_add (gc, *list); + +return 0 ; +} + +static bool is_usb_in_array (libxl_device_usb *usbs,int num,char *intf) +{ +int i; + +for (i =0 ; i < num; i++) { +if (!strcmp (usbs[i].intf, intf) )
tools/libxl/libxl_usb.c line 468
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+return true; + } + +return false; +} + +static int get_usb_bDeviceClass (libxl__gc *gc,char *intf,char *buf) +{ +char *path; +FILE *fd;
Naming a FILE pointer fd isn't very common. I always think "int" when I see a file related variable named "fd". Perhaps "fp"?
+3333333333333 (might look strange, but my cat wanted this comment to go in).
tools/libxl/libxl_usb.c line 477
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+int rc; + + path =libxl__sprintf (gc,SYSFS_USB_DEVS_PATH "/%s/bDeviceClass" , intf); + +/* Check if this path exist, if not return -1 */ +if (access (path,R_OK ) ) +return -1 ; + + fd =popen (GCSPRINTF ("cat %s" , path),"r" );
Why can't you just read from sysfs? Using a pipe here seems overkill.
tools/libxl/libxl_usb.c line 478
Quoted 1 line
tools/libxl/libxl_usb.c new file +1
-0+ rc =fscanf (fd,"%s" , buf);
Is buf always large enough?
Quoted 29 lines
tools/libxl/libxl_usb.c new file +29
-0+pclose (fd); + +return (rc >0 ) ?0 :-1 ; +} + +static bool is_usb_assignable (libxl__gc *gc,char *intf) +{ +char buf[5 ]; + +if (get_usb_bDeviceClass (gc, intf, buf) <0 ) +return false; + +if (strcmp (buf,USBHUB_CLASS_CODE )) +return false; + +return true; +} + +libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num) +{ +GC_INIT (ctx); +libxl_device_usb *usbs =NULL ; +libxl_device_usb *assigned; +int num_assigned; +struct dirent *de; +DIR *dir; + + *num =0 ;
tools/libxl/libxl_usb.c line 517
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +if (libxl__device_usb_assigned_list (gc, &assigned, &num_assigned) <0 ) + goto out; + +if (!(dir =opendir (SYSFS_USB_DEVS_PATH ))) + goto out; + +while ((de =readdir (dir))) { +if (!de->d_name) +continue ;
Check for entry type?
Exclude ".", ".."?
tools/libxl/libxl_usb.c line 519
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+ +if (is_usb_assignable (gc, de->d_name))
!is_usb_assignable?
Coding style. There are lots of other style errors more, especially regarding if statements.
Quoted 584 lines
tools/libxl/libxl_usb.c new file +584
-0+continue ; + +if (is_usb_in_array (assigned, num_assigned, de->d_name)) +continue ; + + usbs =realloc (usbs,sizeof (*usbs)*((*num) +1 )); + usbs[*num].intf =strdup (de->d_name); + (*num)++; + } + +closedir (dir); + +out: +GC_FREE ; +return usbs; +} + +/* get usb devices under certain usb controller */ +static int libxl__device_usb_list (libxl__gc *gc,uint32_t domid,int usbctrl, +libxl_device_usb **usbs,int *num) +{ +char *be_path, *num_devs; +int n, i; +libxl_device_usb *usb =NULL ; + + usbs =NULL ; + *num =0 ; + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d" , +libxl__xs_get_dompath (gc,0 ), domid, usbctrl); + num_devs =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/num-ports" , be_path)); +if (!num_devs) +return 0 ; + + n =atoi (num_devs); + usb =calloc (n,sizeof (libxl_device_usb)); + usbs = &usb; + +for (i =0 ; i < n; i++) { +char *intf; + intf =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/port/%d" , be_path, i +1 )); +if (intf &&strcmp (intf,"" ) ) { + usbs[i]->ctrl = usbctrl; + usbs[i]->port = i +1 ; + usbs[i]->intf =strdup (intf); + (*num)++; + } + } + +return 0 ; +} + +libxl_device_usb *libxl_device_usb_list (libxl_ctx *ctx,uint32_t domid, +int usbctrl,int *num) +{ +GC_INIT (ctx); +libxl_device_usb *usbs =NULL ; + +libxl__device_usb_list (gc, domid, usbctrl, &usbs, num); + +GC_FREE ; +return usbs; +} + +/* get all usb devices of the domain */ +static libxl_device_usb * +libxl_device_usb_list_all (libxl__gc *gc,uint32_t domid,int *num) +{ +char **usbctrls; +unsigned int nd, i, j; +char *be_path; +int rc; +libxl_device_usb *usbs =NULL ; + + *num =0 ; + + be_path =GCSPRINTF ("/local/domain/0/backend/vusb/%d" , domid); + usbctrls =libxl__xs_directory (gc,XBT_NULL , be_path, &nd); + +for (i =0 ; i < nd; i++) { +int nc =0 ; +libxl_device_usb *tmp =NULL ; + rc =libxl__device_usb_list (gc, domid,atoi (usbctrls[i]), &tmp, &nc); +if (!nc)continue ; + + usbs =realloc (usbs,sizeof (libxl_device_usb)*((*num) + nc)); +for (j =0 ; j < nc; j++) { + usbs[*num].ctrl = tmp[j].ctrl; + usbs[*num].port = tmp[j].port; + usbs[*num].intf =strdup (tmp[j].intf); + (*num)++; + } +free (tmp); + } +return usbs; +} + +/* set default value */ + +/* find first unused controller:port and give that to usb device */ +static int +libxl__device_usb_set_default_usbctrl (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +libxl_device_usbctrl *usbctrls; +libxl_device_usb *usbs =NULL ; +int numctrl, numusb, i, j, rc =-1 ; +char *be_path, *tmp; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &numctrl); +if ( !numctrl) + goto out; + +for (i =0 ; i < numctrl; i++) { + rc =libxl__device_usb_list (gc, domid, usbctrls[i].devid, + &usbs, &numusb); +if (rc)continue ; + +if (!usbctrls[i].num_ports || numusb == usbctrls[i].num_ports) +continue ; + +for (j =1 ; i <= numusb; j++) { + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d/port/%d" , +libxl__xs_get_dompath (gc,0 ), domid, + usbctrls[i].devid, j); + tmp =libxl__xs_read (gc,XBT_NULL , be_path); +if (tmp && !strcmp ( tmp,"" )) { + usb->ctrl = usbctrls[i].devid; + usb->port = j; +break ; + } + } + } + + rc =0 ; + +out: +if (usbctrls) +free (usbctrls); +if (usbs) +free (usbs); +return rc; +} + +static int libxl__device_usb_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +char *be_path, *tmp; + +if (usb->ctrl ==-1 ) { +int ret =libxl__device_usb_set_default_usbctrl (gc, domid, usb); +/* If no existing ctrl to host this usb device, setup a new one */ +if (ret) { +libxl_device_usbctrl usbctrl; +libxl_device_usbctrl_init (&usbctrl); +libxl__device_usbctrl_add (gc, domid, &usbctrl); + usb->ctrl = usbctrl.devid; + usb->port =1 ; +libxl_device_usbctrl_dispose (&usbctrl); + } + } + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/path/%d" , +libxl__xs_get_dompath (gc,0 ), usb->ctrl, usb->port); + tmp =libxl__xs_read (gc,XBT_NULL , be_path); +if (!tmp ||strcmp (tmp,"" ) ){ +LOG (ERROR ,"The controller port isn't available." ); +return ERROR_INVAL ; + } + +return 0 ; +} + +/* xenstore usb data */ +static int libxl__device_usb_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +char *be_path; +int rc; +libxl_domain_config d_config; +libxl_device_usb usb_saved; +libxl__domain_userdata_lock *lock =NULL ; + +libxl_domain_config_init (&d_config); +libxl_device_usb_init (&usb_saved); +libxl_device_usb_copy (CTX , &usb_saved, usb); + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d" , +libxl__xs_get_dompath (gc,0 ), domid, usb->ctrl); +if (libxl__wait_for_backend (gc, be_path,"4" ) <0 ) { + rc =ERROR_FAIL ; + goto out; + } + + lock =libxl__lock_domain_userdata (gc, domid); +if (!lock) { + rc =ERROR_LOCK_FAIL ; + goto out; + } + + rc =libxl__get_domain_configuration (gc, domid, &d_config); +if (rc) goto out; + +DEVICE_ADD (usb, usbs, domid, &usb_saved,COMPARE_USB , &d_config); + + rc =libxl__set_domain_configuration (gc, domid, &d_config); +if (rc) goto out; + + be_path =libxl__sprintf (gc,"%s/port/%d" , be_path, usb->port); +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Adding new usb device to xenstore" ); +if (libxl__xs_write_checked (gc,XBT_NULL , be_path, usb->intf)) { + rc =ERROR_FAIL ; + goto out; + } + + rc =0 ; + +out: +if (lock)libxl__unlock_domain_userdata (lock); +libxl_device_usb_dispose (&usb_saved); +libxl_domain_config_dispose (&d_config); +return rc; + +} + +static int libxl__device_usb_remove_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +char *be_path; + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d" , +libxl__xs_get_dompath (gc,0 ), domid, usb->ctrl); +if (libxl__wait_for_backend (gc, be_path,"4" ) <0 ) +return ERROR_FAIL ; + + be_path =libxl__sprintf (gc,"%s/port/%d" , be_path, usb->port); +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Removing USB device from xenstore" ); +if (libxl__xs_write_checked (gc,XBT_NULL , be_path,"" )) +return ERROR_FAIL ; + +return 0 ; +} + +/* bind/unbind usb device interface */ +static int unbind_usb_intf (libxl__gc *gc,char *intf,char *drvpath) +{ +char *path; +int fd, rc =0 ; + + drvpath =GCSPRINTF (SYSFS_USB_DEVS_PATH "/%s/driver" , intf); + +/* if not bound to a driver, return directly */ +if (!drvpath) +return 0 ; + +/* else, unbind from driver */ + path =GCSPRINTF ("%s/unbind" , drvpath); + fd =open (path,O_WRONLY ); +if (fd <0 ) { + rc =ERROR_FAIL ; + goto out; + } +if (write (fd, intf,strlen (intf)) <0 ) { + rc =ERROR_FAIL ; + goto out; + } +close (fd); + +out: +return rc; +} + +static int bind_usb_intf (libxl__gc *gc,char *intf,char *drvpath) +{ +char *path; +int fd, rc =0 ; + + path =GCSPRINTF ("%s/bind" , drvpath); + fd =open (path,O_WRONLY ); +if (fd <0 ) { + rc =ERROR_FAIL ; + goto out; + } +if (write (fd, intf,strlen (intf)) <0 ) { + rc =ERROR_FAIL ; + goto out; + } +close (fd); + +out: +return rc; +} + +static int usb_get_all_interfaces (libxl__gc *gc,libxl_device_usb *usb, +char **intfs,int *num) +{ +DIR *dir; +struct dirent *entry; +char *buf; +int rc =0 ; + + intfs =NULL ; + *num =0 ; + + buf =GCSPRINTF ("%s:" , usb->intf); + +if (!(dir =opendir (SYSFS_USB_DEVS_PATH ))) { + rc =ERROR_FAIL ; + goto out; + } + +while ((entry =readdir (dir)) !=NULL ) { +if (!strncmp (entry->d_name, buf,strlen (buf))){ + intfs =realloc (intfs,sizeof (char *) * (*num +1 )); +if (!intfs) { + rc =ERROR_FAIL ; + goto out; + } + intfs[*num] =strdup (entry->d_name); + (*num)++; + } + } + +closedir (dir); + +out: +return rc; +} + +/* unbind usb device from usbback driver, if there are many interfaces +* under the usb device, then check each interface, unbind from usbback +* driver and rebind to original driver +*/ +static int unbind_usb_device_from_usbback (libxl__gc *gc,libxl_device_usb *usb) +{ +char **intfs =NULL ; +char *path; +int num =0 , i; +int rc =0 ; + +if (usb_get_all_interfaces (gc, usb, intfs, &num) <0 ) +return ERROR_FAIL ; + +for (i =0 ; i < num; i++){ +char *intf = intfs[i]; +char *drvpath =NULL ; +char *tmp =NULL ; + + drvpath =GCSPRINTF (SYSFS_USB_DEVS_PATH "/%s/driver" , intf); +if (!drvpath ||strcmp (drvpath,SYSFS_USBBACK_DRIVER )) +continue ; + +/* unbind interface from usbback driver */ +if (unbind_usb_intf (gc, intf,NULL ) <0 ) { + rc =ERROR_FAIL ; + goto out; + } + +/* bind interface to its originial driver */ + tmp =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF (USBBACK_INFO_PATH "/%s/%s/driver_path" , + usb->intf, intf)); +if (tmp) { +if (bind_usb_intf (gc, intf,GCSPRINTF ("%s/bind" , tmp)) <0 ) { +free (tmp); + rc =ERROR_FAIL ; + goto out; + } +free (tmp); + } + } + +/* finally, remove xs driver path */ + path =GCSPRINTF (USBBACK_INFO_PATH "/%s" , usb->intf); +if (libxl__xs_rm_checked (gc,XBT_NULL , path) <0 ) + rc =ERROR_FAIL ; + +out: +if (intfs) { +for (i =0 ; i < num; i++) +free (intfs[i]); +free (intfs); + } +return rc; +} + +/* bind usb device to "usbback" driver, if there are many interfaces +* under the usb device, check each interface, unbind from original +* driver and bind to usbback driver. +*/ +static int bind_usb_device_to_usbback (libxl__gc *gc,libxl_device_usb *usb) +{ +char **intfs =NULL ; +int num =0 , i; +int rc =0 ; + +if (usb_get_all_interfaces (gc, usb, intfs, &num) <0 ) +return ERROR_FAIL ; + +for (i =0 ; i < num; i++){ +char *intf = intfs[i]; +char *path =NULL ; +char *drvpath =NULL ; + +/* unbind interface from original driver */ +if (unbind_usb_intf (gc, intf, drvpath) <0 ) { + rc =ERROR_FAIL ; + goto out_rebind; + } + +if (drvpath) { +/* write driver path to xenstore for later rebinding */ + path =GCSPRINTF (USBBACK_INFO_PATH "/%s/%s/driver_path" , + usb->intf, intf); +if (libxl__xs_write_checked (gc,XBT_NULL , path, drvpath) <0 ) { + rc =ERROR_FAIL ; + goto out_rebind; + } + } + +/* bind interface to usbback */ +if (bind_usb_intf (gc, intf,SYSFS_USBBACK_DRIVER ) <0 ){ + rc =ERROR_FAIL ; + goto out_rebind; + } + } + + goto out; + +out_rebind: +/* some interfaces might be bound to usbback, unbind it then and +* rebind to its original driver +*/ +unbind_usb_device_from_usbback (gc, usb); +out: +if (intfs) { +for (i =0 ; i < num; i++) +free (intfs[i]); +free (intfs); + } + +return rc; +} + +static int do_usb_add (libxl__gc *gc,uint32_t domid,libxl_device_usb *usb) +{ +int rc =0 ; + + rc =libxl__device_usb_add_xenstore (gc, domid, usb); +if (rc) goto out; + + rc =bind_usb_device_to_usbback (gc, usb); +if (rc) +libxl__device_usb_remove_xenstore (gc, domid, usb); + +out: +return rc; +} + +int libxl__device_usb_add (libxl__gc *gc,uint32_t domid,libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +libxl_device_usb *usbs; +int rc, num; + + rc =libxl__device_usb_setdefault (gc, domid, usb); +if (rc) goto out; + + rc =libxl__device_usb_assigned_list (gc, &usbs, &num); +if (rc) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Fail to get assigned usb list" ); + goto out; + } + +if (is_usb_in_array (usbs, num, usb->intf)) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"USB device is already attached to a domain" ); + rc =ERROR_FAIL ; + goto out; + } + + rc =do_usb_add (gc, domid, usb); + +out: +return rc; +} + +int libxl_device_usb_add (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +const libxl_asyncop_how *ao_how) +{ +AO_CREATE (ctx, domid, ao_how); +int rc; + + rc =libxl__device_usb_add (gc, domid, usb); +libxl__ao_complete (egc, ao, rc); +return AO_INPROGRESS ; +} + +static int do_usb_remove (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb,int force) +{ + +libxl_ctx *ctx =CTX ; +libxl_device_usb *usbs =NULL ; +int rc =-1 , num; + + usbs =libxl_device_usb_list_all (gc, domid, &num); +if (!usbs) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"No USB device attached to this domain" ); + goto out; + } + +if (!is_usb_in_array (usbs, num, usb->intf)) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"USB device is not attached to this domain" ); + goto out; + } + +if (libxl__device_usb_remove_xenstore (gc, domid, usb)) + goto out; + +if (unbind_usb_device_from_usbback (gc, usb)) + goto out; + + rc =0 ; + +out: +return rc; +} + +static int libxl__device_usb_remove_common (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb,int force) +{ +return do_usb_remove (gc, domid, usb, force); +} + +int libxl_device_usb_remove (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +const libxl_asyncop_how *ao_how) + +{ +AO_CREATE (ctx, domid, ao_how); +int rc; + + rc =libxl__device_usb_remove_common (gc, domid, usb,0 ); + +libxl__ao_complete (egc, ao, rc); +return AO_INPROGRESS ; +} + +int libxl_device_usb_destroy (libxl_ctx *ctx,uint32_t domid, +libxl_device_usb *usb, +const libxl_asyncop_how *ao_how) +{ +AO_CREATE (ctx, domid, ao_how); +int rc; + + rc =libxl__device_usb_remove_common (gc, domid, usb,1 ); + +libxl__ao_complete (egc, ao, rc); +return AO_INPROGRESS ; +} + +int libxl__device_usb_destroy_all (libxl__gc *gc,uint32_t domid) +{ +libxl_ctx *ctx =CTX ; +libxl_device_usbctrl *usbctrls; +int num, i, rc =0 ; + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &num); +if (!usbctrls) +return 0 ; + +for (i =0 ; i < num; i++) { +/* Force remove on shutdown since, on HVM, qemu will not always +* respond to SCI interrupt because the guest kernel has shut +* down the devices by the time we even get here!
tools/libxl/libxl_usb.c line 1113
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+*/ +if (libxl__device_usbctrl_remove_common (ctx, domid, + usbctrls + i,0 ,1 ) <0 ) { + rc =ERROR_FAIL ; + goto out; + } + } + +out: +if (usbctrls)
Pointless test.
tools/libxl/libxl_usb.c line 1123
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+free (usbctrls); +return rc; +} + +/*Get usb device information */ +static int get_usb_devnum (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
Variable naming again.
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/devnum" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
tools/libxl/libxl_usb.c line 1138
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+pclose (fd); + +return rc; +} + +static int get_usb_busnum (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
And again.
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/busnum" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
tools/libxl/libxl_usb.c line 1153
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+pclose (fd); + +return rc; +} + +static int get_usb_idVendor (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
Again.
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/idVendor" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
tools/libxl/libxl_usb.c line 1168
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+pclose (fd); + +return rc; +} + +static int get_usb_idProduct (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
Again.
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/idProduct" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
tools/libxl/libxl_usb.c line 1183
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+pclose (fd); + +return rc; +} + +static int get_usb_manufacturer (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
Again.
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/manufacturer" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
tools/libxl/libxl_usb.c line 1198
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+pclose (fd); + +return rc; +} + +static int get_usb_product (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd;
Again.
tools/libxl/libxl_usb.c line 1207
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+ + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/product" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); + +return rc; +}
Wouldn't it make sense to have just one generic function taking the leaf name as additional argument?
Like:
static int get_usb_leaf(libxl__gc *gc, const char *intf, char *buf,
char *leaf)
{
char *path;
int rc = 0;
FILE *fp;
path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/%s", intf,
leaf);
fp = popen(path, "r"); /* a pipe shouldn't be needed here */
if (fgets(buf, 512, fp) == NULL || ferror(fp))
rc = -1;
pclose(fp);
return rc;
}static int get_usb_product(libxl__gc *gc, const char *intf, char *buf)
{
return get_usb_leaf(gc, intf, buf, "product");
}Quoted 60 lines
tools/libxl/libxl_usb.c new file +60
-0+ +int libxl_device_usb_getinfo (libxl_ctx *ctx,char *intf,libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx); +char buf[512 ]; + +if (!get_usb_devnum (gc, intf, buf) ) + usbinfo->devnum =atoi (buf); + +if ( !get_usb_busnum (gc, intf, buf)) + usbinfo->bus =atoi (buf); + +if (!get_usb_idVendor (gc, intf, buf) ) + usbinfo->idVendor =atoi (buf); + +if (!get_usb_idProduct (gc, intf, buf) ) + usbinfo->idProduct =atoi (buf); + +if (!get_usb_manufacturer (gc, intf, buf) ) + usbinfo->manuf =strdup (buf); + +if (!get_usb_product (gc, intf, buf) ) + usbinfo->prod =strdup (buf); + +GC_FREE ; +return 0 ; +} + +int libxl_intf_to_device_usb (libxl_ctx *ctx,uint32_t domid, +char *intf,libxl_device_usb *usb) +{ +GC_INIT (ctx); +libxl_device_usb *usbs =NULL ; +int num, i, rc; +bool find = false; + + usbs =libxl_device_usb_list_all (gc, domid, &num); + +for (i =0 ; i < num; i++) { +if (!strcmp (intf, usbs[i].intf) ) { + usb->ctrl = usbs[i].ctrl; + usb->port = usbs[i].port; + usb->intf =strdup (usbs[i].intf); + find =1 ; +break ; + } + } + +/* doesn't find the usb device in domain's usb device list*/ +if (!find) { + rc =ERROR_FAIL ; + goto out; + } + + rc =0 ; + +out: +GC_FREE ; +if (usbs) +free (usbs);
tools/libxl/libxl_usb.c line 1277
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+return rc; +} + +/* +* Local variables: +* mode: C +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Juergen
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to Chunyan LiuJust found other issues:
Quoted 19 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +- 7 files changed, 1623 insertions(+), 224 deletions(-)create mode 100644
tools/libxl/libxl_usb.c
...
Quoted 58 lines
tools/libxl/libxl_usb.c new file +58
-0+/*Get usb device information */ +static int get_usb_devnum (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/devnum" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); + +return rc; +} + +static int get_usb_busnum (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/busnum" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); + +return rc; +} + +static int get_usb_idVendor (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/idVendor" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); + +return rc; +} + +static int get_usb_idProduct (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/idProduct" , intf); + fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); +
tools/libxl/libxl_usb.c line 1185
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+return rc; +} + +static int get_usb_manufacturer (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/manufacturer" , intf);
File does not exist in newer kernels (checked 3.16 and 3.19).
tools/libxl/libxl_usb.c line 1128
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+ fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ;
Another reason not to use popen(): file doesn't exist, but rc = 0. And buf contains garbage.
tools/libxl/libxl_usb.c line 1200
Quoted 12 lines
tools/libxl/libxl_usb.c new file +12
-0+pclose (fd); + +return rc; +} + +static int get_usb_product (libxl__gc *gc,const char *intf,char *buf) +{ +char *path; +int rc =0 ; +FILE *fd; + + path =libxl__sprintf (gc,"cat " SYSFS_USB_DEVS_PATH "/%s/product" , intf);
File does not exist in newer kernels (checked 3.16 and 3.19).
Quoted 11 lines
tools/libxl/libxl_usb.c new file +11
-0+ fd =popen (path,"r" ); +if (fgets (buf,512 , fd) ==NULL ||ferror (fd)) + rc =-1 ; +pclose (fd); + +return rc; +} + +int libxl_device_usb_getinfo (libxl_ctx *ctx,char *intf,libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx);
tools/libxl/libxl_usb.c line 1221
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+char buf[512 ]; + +if (!get_usb_devnum (gc, intf, buf) ) + usbinfo->devnum =atoi (buf); + +if ( !get_usb_busnum (gc, intf, buf)) + usbinfo->bus =atoi (buf); + +if (!get_usb_idVendor (gc, intf, buf) ) + usbinfo->idVendor =atoi (buf);
atoi is wrong. idVendor in sysfs is a hex-string.
tools/libxl/libxl_usb.c line 1224
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+ +if (!get_usb_idProduct (gc, intf, buf) ) + usbinfo->idProduct =atoi (buf);
again hex-string.
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +if (!get_usb_manufacturer (gc, intf, buf) ) + usbinfo->manuf =strdup (buf); + +if (!get_usb_product (gc, intf, buf) ) + usbinfo->prod =strdup (buf); + +GC_FREE ; +return 0 ; +}
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to Chunyan LiuQuoted 24 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +- 7 files changed, 1623 insertions(+), 224 deletions(-) create mode 100644 tools/libxl/libxl_usb.ctools/libxl/Makefile +0
-0
tools/libxl/Makefile LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ · line 98
Quoted 5 lines
tools/libxl/Makefile +1
-1@@ -95,7 +95,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_internal.o libxl_utils.o libxl_uuid.o \ libxl_json.o libxl_aoutils.o libxl_numa.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ - libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) + libxl_qmp.o libxl_event.o libxl_fork.o libxl_usb.o $(LIBXL_OBJS-y)
The contents of that file looks Linux specific, so I think you might have to arrange for it to only be built there and also to provide a libxl_nousb.c with stubs returning appropriate errors to be used on other platforms.
Or it may be possible (even better) to refactor the linux specific bits of libxl_usb.c into libxl_linux.c and leave the common stuff behind.
I thought libxl_pci.c would be a good example of this, but it doesn't seem to have any conditional stuff, yet I expected it to be Linux specific. I've no idea how that works :-(. Maybe usb can get away with it too.
tools/libxl/Makefile LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ · line 101
Quoted 3 lines
tools/libxl/Makefile +3
-0+int libxl_intf_to_device_usb(libxl_ctx *ctx, uint32_t domid, + char *intf, libxl_device_usb *usb) + LIBXL_EXTERNAL_CALLERS_ONLY;
I wasn't sure what an "intf" was on patch #1. hopefully your answer there will help me understand what this is for!
tools/libxl/libxl_usb.c
Quoted 5 lines
tools/libxl/libxl_usb.c new file +0
-0
Apart from my not yet understanding the interface semantics and the potential for Linux-specificness mentioned above the actual code here looks reasonably OK to me. I have smaller and larger comments below though.
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+static int libxl__device_usbctrl_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{
[...]
Quoted 1 line
+
if(!usbctrl->backend_domid)
Missing space before (.
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+static int libxl__usbctrl_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +flexarray_t *front; +flexarray_t *back; +libxl__device *device; +xs_transaction_t tran; +int rc =0 ;
tools/libxl/libxl_usb.c line 99
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out; + + front =flexarray_make (gc,4 ,1 ); + back =flexarray_make (gc,12 ,1 ); + +flexarray_append (back,"frontend-id" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid));
GCSPRINTF would be good for all of these (and in lots of other places too).
flexarray_append_pair is also nice for adding key+value at the same time since it makes it easier to see what goes together.
tools/libxl/libxl_usb.c line 130
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+retry_transaction: + tran =xs_transaction_start (ctx->xsh);
Please follow the design pattern in e.g. libxl__device_vtpm_add or device_disk_add and use libxl__xs_transaction_start/commit/abort here inside a for (;;).
tools/libxl/libxl_usb.c line 166
Quoted 5 lines
tools/libxl/libxl_usb.c new file +4
-0+static int libxl__device_usbctrl_add (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +if (libxl__usbctrl_add_xenstore (gc, domid, usbctrl) <0 ){
Space before { please.
tools/libxl/libxl_usb.c line 274
Quoted 10 lines
tools/libxl/libxl_usb.c new file +9
-0+static int +libxl__device_usbctrl_remove_common (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how, +int force) +{ +for (i =0 ; i < numusb; i++) { +if (libxl__device_usb_remove_common (gc, domid, &usbs[i],0 )) { +fprintf (stderr,"libxl_device_usb_remove failed.\n" );
Use LOG*( please, not fprintf (this is true everywhere in libxl in case I missed any other).
Quoted 7 lines
tools/libxl/libxl_usb.c new file +7
-0+/* usb device functions */ + +/* Following functions are to get assignable usb devices */ +static int +libxl__device_usb_assigned_list (libxl__gc *gc, +libxl_device_usb **list,int *num) +{
tools/libxl/libxl_usb.c line 413
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+char **domlist; +unsigned int nd =0 , i, j; +char *be_path; +libxl_device_usb *usb; + + *list =NULL ; + *num =0 ; + + domlist =libxl__xs_directory (gc,XBT_NULL ,"/local/domain" , &nd); + be_path =libxl__sprintf (gc,"/local/domain/0/backend/vusb" );
GCSPRINTF.
Also I notice a hardcoded 0, shouldn't that be backend_domid somehow? I've seen a few /0/ hardcoded here and there in this patch, which if not backend_domid perhaps ought to at least be LIBXL_TOOLSTACK_DOMID.
If not then is it necessary to dup the string, can't it just be a const string literal?
tools/libxl/libxl_usb.c line 492
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+static bool is_usb_assignable (libxl__gc *gc,char *intf) +{ +char buf[5 ]; + +if (get_usb_bDeviceClass (gc, intf, buf) <0 ) +return false; + +if (strcmp (buf,USBHUB_CLASS_CODE )) +return false;
OOI are hubs inherently unassignable, or is that a short coming of the current driver code?
tools/libxl/libxl_usb.c line 588
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+/* get all usb devices of the domain */ +static libxl_device_usb * +libxl_device_usb_list_all (libxl__gc *gc,uint32_t domid,int *num)
Should be in libxl__ namespace, or since it is static you could omit the namespacing completely if you prefer.
tools/libxl/libxl_usb.c line 700
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+/* xenstore usb data */ +static int libxl__device_usb_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ;
FYI although it's not required, you can just use CTX in the code if you prefer.
tools/libxl/libxl_usb.c line 733
Quoted 3 lines
[...]
tools/libxl/libxl_usb.c new file +2
-0+ be_path =libxl__sprintf (gc,"%s/port/%d" , be_path, usb->port); +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Adding new usb device to xenstore" );
The LOG*( macros will help shorten this line.
Quoted 1 line
+ path =
libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/manufacturer", intf);
Whoah, what now?
What you want here is to open the fd and use read on it. We may even have existing helpers for doing so. Certainly using popen on a string starting with cat isn't what is wanted (at least not without a big and convincing comment explaining why this should be needed).
I see a bunch of this in this area.
tools/libxl/libxl_usb.c line 1214
Quoted 6 lines
tools/libxl/libxl_usb.c new file +6
-0+int libxl_device_usb_getinfo (libxl_ctx *ctx,char *intf,libxl_usbinfo *usbinfo) +{ +GC_INIT (ctx); +char buf[512 ]; + +if (!get_usb_devnum (gc, intf, buf) )
In consistent spacing.
tools/libxl/libxl_usb.c line 1227
Quoted 13 lines
tools/libxl/libxl_usb.c new file +13
-0+ usbinfo->devnum =atoi (buf); + +if ( !get_usb_busnum (gc, intf, buf)) + usbinfo->bus =atoi (buf); + +if (!get_usb_idVendor (gc, intf, buf) ) + usbinfo->idVendor =atoi (buf); + +if (!get_usb_idProduct (gc, intf, buf) ) + usbinfo->idProduct =atoi (buf); + +if (!get_usb_manufacturer (gc, intf, buf) ) + usbinfo->manuf =strdup (buf);
libxl_strdup with NOGC to get correct error handling please.
Quoted 8 lines
tools/libxl/libxl_usb.c new file +8
-0+ +if (!get_usb_product (gc, intf, buf) ) + usbinfo->prod =strdup (buf); + +GC_FREE ; +return 0 ; +} +
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/3/2015 at 07:38 PM, in message <[email protected]>,
Quoted 46 lines · Ian Campbell
Quoted 6 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functionsQuoted 8 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>---
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_internal.h | 6 + tools/libxl/libxl_usb.c | 1277++++++++++++++++++++++++++++++++++++++++++
tools/libxl/Makefile LIBXL_OBJS = flexarray.o libxl.o libxl_create.o
Quoted 10 lines
tools/libxl/libxlu_cfg_y.c | 464 ++++++++------- tools/libxl/libxlu_cfg_y.h | 38 +- 7 files changed, 1623 insertions(+), 224 deletions(-) create mode 100644 tools/libxl/libxl_usb.ctools/libxl/Makefile +0
-0@@ -95,7 +95,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.olibxl_dm.o libxl_pci.o \
tools/libxl/Makefile LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ · line 98
Quoted 5 lines
tools/libxl/Makefile +1
-1libxl_internal.o libxl_utils.o libxl_uuid.o \ libxl_json.o libxl_aoutils.o libxl_numa.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ - libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) + libxl_qmp.o libxl_event.o libxl_fork.o libxl_usb.o $(LIBXL_OBJS-y)The contents of that file looks Linux specific, so I think you might have to arrange for it to only be built there and also to provide a
libxl_nousb.cwith stubs returning appropriate errors to be used on other platforms.Or it may be possible (even better) to refactor the linux specific bits of
libxl_usb.cintolibxl_linux.cand leave the common stuff behind.I thought
libxl_pci.cwould be a good example of this, but it doesn't seem to have any conditional stuff, yet I expected it to be Linux specific. I've no idea how that works :-(. Maybe usb can get away with it too.
Quoted 6 lines
tools/libxl/Makefile LIBXL_OBJS = flexarray.o libxl.o libxl_create.o · line 101
Quoted 3 lines
tools/libxl/Makefile +3
-0+int libxl_intf_to_device_usb(libxl_ctx *ctx, uint32_t domid, + char *intf, libxl_device_usb *usb) + LIBXL_EXTERNAL_CALLERS_ONLY;I wasn't sure what an "intf" was on patch #1. hopefully your answer there will help me understand what this is for!
As in patch#1, it means syfs interface for the usb device, like: 2-1.6. This function will be used when detaching a usb device, use indicates 2-1.6, it will return the corresponding libxl_device_usb structure.
Quoted 44 lines
tools/libxl/libxl_usb.c
Quoted 6 lines
tools/libxl/libxl_usb.c new file +0
-0Apart from my not yet understanding the interface semantics and the potential for Linux-specificness mentioned above the actual code here looks reasonably OK to me. I have smaller and larger comments below though.
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+static int libxl__device_usbctrl_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{[...]
Quoted 1 line
+
if(!usbctrl->backend_domid)Missing space before (.
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+static int libxl__usbctrl_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +flexarray_t *front; +flexarray_t *back; +libxl__device *device; +xs_transaction_t tran; +int rc =0 ;tools/libxl/libxl_usb.c line 99
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out; + + front =flexarray_make (gc,4 ,1 ); + back =flexarray_make (gc,12 ,1 ); + +flexarray_append (back,"frontend-id" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid));GCSPRINTF would be good for all of these (and in lots of other places too).
Quoted 2 lines
flexarray_append_pairis also nice for adding key+value at the same time since it makes it easier to see what goes together.
Got it. Will update all in next version.
Quoted 7 lines
tools/libxl/libxl_usb.c line 130
Quoted 3 lines
tools/libxl/libxl_usb.c new file +2
-0+retry_transaction: + tran =xs_transaction_start (ctx->xsh);Please follow the design pattern in e.g.
libxl__device_vtpm_addordevice_disk_addand use libxl__xs_transaction_start/commit/abort here inside a for (;;).
OK. Got it.
Quoted 43 lines
tools/libxl/libxl_usb.c line 166
Quoted 6 lines
tools/libxl/libxl_usb.c new file +4
-0+static int libxl__device_usbctrl_add (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +if (libxl__usbctrl_add_xenstore (gc, domid, usbctrl) <0 ){Space before { please.
tools/libxl/libxl_usb.c line 274
Quoted 10 lines
tools/libxl/libxl_usb.c new file +9
-0+static int +libxl__device_usbctrl_remove_common (libxl_ctx *ctx,uint32_t domid, +libxl_device_usbctrl *usbctrl, +const libxl_asyncop_how *ao_how, +int force) +{ +for (i =0 ; i < numusb; i++) { +if (libxl__device_usb_remove_common (gc, domid, &usbs[i],0 )) { +fprintf (stderr,"libxl_device_usb_remove failed.\n" );Use LOG*( please, not fprintf (this is true everywhere in libxl in case I missed any other).
Quoted 7 lines
tools/libxl/libxl_usb.c new file +7
-0+/* usb device functions */ + +/* Following functions are to get assignable usb devices */ +static int +libxl__device_usb_assigned_list (libxl__gc *gc, +libxl_device_usb **list,int *num) +{tools/libxl/libxl_usb.c line 413
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+char **domlist; +unsigned int nd =0 , i, j; +char *be_path; +libxl_device_usb *usb; + + *list =NULL ; + *num =0 ; + + domlist =libxl__xs_directory (gc,XBT_NULL ,"/local/domain" , &nd); + be_path =libxl__sprintf (gc,"/local/domain/0/backend/vusb" );GCSPRINTF.
Quoted 1 line
Also I notice a hardcoded 0, shouldn't that be
backend_domidsomehow?
Yes, it is. Will update. Thanks for pointing out.
Quoted 6 lines
I've seen a few /0/ hardcoded here and there in this patch, which if not
backend_domidperhaps ought to at least beLIBXL_TOOLSTACK_DOMID.If not then is it necessary to dup the string, can't it just be a const string literal?
Quoted 13 lines
tools/libxl/libxl_usb.c line 492
Quoted 9 lines
tools/libxl/libxl_usb.c new file +9
-0+static bool is_usb_assignable (libxl__gc *gc,char *intf) +{ +char buf[5 ]; + +if (get_usb_bDeviceClass (gc, intf, buf) <0 ) +return false; + +if (strcmp (buf,USBHUB_CLASS_CODE )) +return false;OOI are hubs inherently unassignable, or is that a short coming of the current driver code?
It's right. I'm very sorry here and other few places out of my mistake, some changes not included in this patch when sending. I noticed that when sending these patches to Juergen for his kernel patches testing. Will send the correct ones in next version.
Quoted 22 lines
tools/libxl/libxl_usb.c line 588
Quoted 4 lines
tools/libxl/libxl_usb.c new file +3
-0+/* get all usb devices of the domain */ +static libxl_device_usb * +libxl_device_usb_list_all (libxl__gc *gc,uint32_t domid,int *num)Should be in
libxl__namespace, or since it is static you could omit the namespacing completely if you prefer.tools/libxl/libxl_usb.c line 700
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+/* xenstore usb data */ +static int libxl__device_usb_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ;FYI although it's not required, you can just use CTX in the code if you prefer.
tools/libxl/libxl_usb.c
Quoted 3 lines
[...]
tools/libxl/libxl_usb.c new file +2
-0+ be_path =libxl__sprintf (gc,"%s/port/%d" , be_path, usb->port); + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new usb device toxenstore");
Quoted 8 lines
The LOG*( macros will help shorten this line.
Quoted 1 line
+ path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/manufacturer",
intf);
Whoah, what now?
What you want here is to open the fd and use read on it. We may even
Yes. I also think it's odd and so already updated this kinds of places locally for Juergen's testing. Will be posted in next version. Thanks.
Quoted 30 lines
have existing helpers for doing so. Certainly using popen on a string starting with cat isn't what is wanted (at least not without a big and convincing comment explaining why this should be needed).
I see a bunch of this in this area.
Quoted 1 line
+int libxl_device_usb_getinfo(libxl_ctx *ctx, char *intf,
libxl_usbinfo*usbinfo)
tools/libxl/libxl_usb.c line 1214
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+{ +GC_INIT (ctx); +char buf[512 ]; + +if (!get_usb_devnum (gc, intf, buf) )In consistent spacing.
tools/libxl/libxl_usb.c line 1227
Quoted 13 lines
tools/libxl/libxl_usb.c new file +13
-0+ usbinfo->devnum =atoi (buf); + +if ( !get_usb_busnum (gc, intf, buf)) + usbinfo->bus =atoi (buf); + +if (!get_usb_idVendor (gc, intf, buf) ) + usbinfo->idVendor =atoi (buf); + +if (!get_usb_idProduct (gc, intf, buf) ) + usbinfo->idProduct =atoi (buf); + +if (!get_usb_manufacturer (gc, intf, buf) ) + usbinfo->manuf =strdup (buf);
Quoted 1 line
libxl_strdupwith NOGC to get correct error handling please.
Got it. Will update.
- Chunyan
Quoted 12 lines
Quoted 9 lines
+
tools/libxl/libxl_usb.c new file +7
-0+if (!get_usb_product (gc, intf, buf) ) + usbinfo->prod =strdup (buf); + +GC_FREE ; +return 0 ; +} +
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to Chunyan Liutools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, · line 1223
Quoted 8 lines · Chunyan Liu
tools/libxl/libxl.h +3
-0+int libxl_intf_to_device_usb(libxl_ctx *ctx, uint32_t domid, + char *intf, libxl_device_usb *usb) + LIBXL_EXTERNAL_CALLERS_ONLY;
I guess this function will go away?
tools/libxl/libxl_usb.c line 63
Quoted 11 lines
tools/libxl/libxl_usb.c new file +4
-0@@ -0,0 +1,1277 @@ +static int libxl__usbport_add_xenstore (libxl__gc *gc, +xs_transaction_t tran, +uint32_t domid, +libxl_device_usbctrl *usbctrl)
Would it be too much to ask to have all the pvusb-specific stuff in a separate file -- say, "libxl_pvusb.c" or something? That would make it a lot easier when I add in the HVM USB stuff.
(Just to be clear, I'm asking as a favor -- it's policy that the first mover gets to have it easier, and people who want to come and add something later are the ones who have to do the refactoring.)
Quoted 34 lines
tools/libxl/libxl_usb.c new file +34
-0+{ +char *path; +int i; + + path =GCSPRINTF ("%s/backend/vusb/%d/%d/port" , +libxl__xs_get_dompath (gc,0 ), domid, usbctrl->devid); + +libxl__xs_mkdir (gc, tran, path,NULL ,0 ); + +for (i =1 ; i <= usbctrl->num_ports; i++) { +if (libxl__xs_write_checked (gc, tran,GCSPRINTF ("%s/%d" , path, i),"" )) +return ERROR_FAIL ; + } + +return 0 ; +} + +static int libxl__usbctrl_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +flexarray_t *front; +flexarray_t *back; +libxl__device *device; +xs_transaction_t tran; +int rc =0 ; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out; + + front =flexarray_make (gc,4 ,1 ); + back =flexarray_make (gc,12 ,1 ); +
tools/libxl/libxl_usb.c line 107
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+flexarray_append (back,"frontend-id" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid)); +flexarray_append (back,"online" ); +flexarray_append (back,"1" ); +flexarray_append (back,"state" ); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 )); +flexarray_append (back,"usb-ver" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->usb_version)); +flexarray_append (back,"num-ports" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->num_ports));
So how much of this is pvusb-specific, and how much would be shared between DEVICEMODEL? Because this bit looks specifically like the stuff used to set up the pvusb connection...
Quoted 5 lines
tools/libxl/libxl_usb.c new file +5
-0+flexarray_append (back,"type" ); +switch (usbctrl->type) { +case LIBXL_USBCTRL_TYPE_PV :{ +flexarray_append (back,"PVUSB" ); +break ;
tools/libxl/libxl_usb.c line 122
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ } +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : { +flexarray_append (back,"IOEMU" ); +break ; + } +default : +/* not supported */ + rc =ERROR_FAIL ; + goto out; + }
...but this looks like it's trying to be shared between PVUSB and DEVICEMODEL. I'm pretty sure this isn't going to work long-run, because if we were to write all this stuff for a devicemodel, wouldn't the pvusb back-end take this as setting up a new pvusb port?
Also, you don't seem to be storing or retreiving usbctrl->name here -- if we want that to be part of the interface we need to use it. (I think we wanted that so that it could default to something like pv-0, emul-1, &c).
In general, I don't think libxl should be storing stuff in the pvusb front/back xenstore directories not related to that protocol. We should store extraneous information in a libxl-specific directory. You can see an example of the kind of think I'm talking about in the HVM USB patch I submitted last year (see usb_add_xenstore()):
http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html
Alternately -- at the moment, the only extraneous information we've got is the name of the controller; if you wanted to propose that we get rid of the name field, then there wouldn't be any extra information to store.
Quoted 27 lines
tools/libxl/libxl_usb.c new file +27
-0+ +flexarray_append (front,"backend-id" ); +flexarray_append (front,libxl__sprintf (gc,"%d" , usbctrl->backend_domid)); +flexarray_append (front,"state" ); +flexarray_append (front,libxl__sprintf (gc,"%d" ,1 )); + +retry_transaction: + tran =xs_transaction_start (ctx->xsh); + +libxl__device_generic_add (gc, tran, device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count), +NULL ); +libxl__usbport_add_xenstore (gc, tran, domid, usbctrl); + +if (!xs_transaction_end (ctx->xsh, tran,0 )) { +if (errno ==EAGAIN ) + goto retry_transaction; +else { + rc =ERROR_FAIL ; + goto out; + } + } + +out: +return rc; +}
tools/libxl/libxl_usb.c line 159
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +static int libxl__device_usbctrl_add (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +int rc =0 ; + + rc =libxl__device_usbctrl_setdefault (gc, domid, usbctrl); +if (rc) goto out; + +if (usbctrl->devid ==-1 ) {
This also needs to have a symbolic name; something with "AUTO" in it.
Quoted 18 lines
tools/libxl/libxl_usb.c new file +16
-0+if ((usbctrl->devid =libxl__device_nextid (gc, domid,"vusb" )) <0 ) { + rc =ERROR_FAIL ; + goto out; + } + } + +if (libxl__usbctrl_add_xenstore (gc, domid, usbctrl) <0 ){ + rc =ERROR_FAIL ; + goto out; + } + +out: +return rc; +} + +/* Following functions are to get assignable usb devices */
<snip>
tools/libxl/libxl_usb.c line 498
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num)
I'm a bit ambivalent about this one. For people using xl, "lsusb" should be just fine. Is anyone building a toolstack on top of libxl directly going to need this functionality? Would libvirt use this functionality, for instance, or would it use libusb? Or just leave that to the caller?
tools/libxl/libxl_usb.c line 678
Quoted 12 lines
tools/libxl/libxl_usb.c new file +12
-0+static int libxl__device_usb_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +char *be_path, *tmp; + +if (usb->ctrl ==-1 ) { +int ret =libxl__device_usb_set_default_usbctrl (gc, domid, usb); +/* If no existing ctrl to host this usb device, setup a new one */ +if (ret) { +libxl_device_usbctrl usbctrl; +libxl_device_usbctrl_init (&usbctrl); +libxl__device_usbctrl_add (gc, domid, &usbctrl);
What happens if this fails?
-George
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 8 lines · George Dunlap
tools/libxl/libxl_usb.c line 498
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num)I'm a bit ambivalent about this one. For people using xl, "lsusb" should be just fine. Is anyone building a toolstack on top of libxl directly going to need this functionality? Would libvirt use this functionality, for instance, or would it use libusb? Or just leave that to the caller?
Do USB devices not need to be bound to some sort of placeholder driver (a la xen-pciback) or at least unbound from their actual driver before they can be assigned to a guest?
If so then I would expect a function such as this to list the subset of devices which have been correctly configured for USB passthrough, which would be a subset of the output of lsusb I think.
Ian.
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 10 lines · Ian Campbell
Quoted 8 lines · George Dunlap
tools/libxl/libxl_usb.c line 498
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num)I'm a bit ambivalent about this one. For people using xl, "lsusb" should be just fine. Is anyone building a toolstack on top of libxl directly going to need this functionality? Would libvirt use this functionality, for instance, or would it use libusb? Or just leave that to the caller?
Quoted 7 lines
Do USB devices not need to be bound to some sort of placeholder driver (a la xen-pciback) or at least unbound from their actual driver before they can be assigned to a guest?
If so then I would expect a function such as this to list the subset of devices which have been correctly configured for USB passthrough, which would be a subset of the output of lsusb I think.
Are you saying you think this is what the function *should* do, or are you saying that you think it should be renamed because that's what the name would lead you to expect it did?
This code, following xend's lead, seems to do the plugging stuff automatically; similar to the "seize=1" flag I added for PCI devices. I think this is probably the best interface here; the reason it's not enabled by default in the PCI case is that it's so dangerous (you might yank out your own hard disk by accident).
Given this "auto-seize" is what xend did, and what qemu does (and what VirtualBox does, and what presumably every other virtualization-related software does), I think adding the "make assignable" step would be unnecessary and confusing.
-George
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Quoted 15 lines · George Dunlap
Quoted 14 lines · Ian Campbell
Quoted 8 lines · George Dunlap
tools/libxl/libxl_usb.c line 498
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num)I'm a bit ambivalent about this one. For people using xl, "lsusb" should be just fine. Is anyone building a toolstack on top of libxl directly going to need this functionality? Would libvirt use this functionality, for instance, or would it use libusb? Or just leave that to the caller?
Do USB devices not need to be bound to some sort of placeholder driver (a la xen-pciback) or at least unbound from their actual driver before they can be assigned to a guest?
Quoted 7 lines
Quoted 3 lines
If so then I would expect a function such as this to list the subset of devices which have been correctly configured for USB passthrough, which would be a subset of the output of lsusb I think.
Are you saying you think this is what the function *should* do, or are you saying that you think it should be renamed because that's what the name would lead you to expect it did?
I was saying that's what I would have expected, but also asking how USB passthru worked because I didn't know.
Quoted 10 lines
This code, following xend's lead, seems to do the plugging stuff automatically; similar to the "seize=1" flag I added for PCI devices. I think this is probably the best interface here; the reason it's not enabled by default in the PCI case is that it's so dangerous (you might yank out your own hard disk by accident).
Given this "auto-seize" is what xend did, and what qemu does (and what VirtualBox does, and what presumably every other virtualization-related software does), I think adding the "make assignable" step would be unnecessary and confusing.
I agree, given non-optional auto-seize I'm not sure having a function to enumerate the USB devices is all that useful, unless we happen to need it internally and it is convenient to expose it.
However, it might be the sort of thing we could put in libxlutil, since it is the sort of thing every toolstack would have to write for itself otherwise.
Ian.
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to George DunlapQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/7/2015 at 12:50 AM, in message
<CAFLBxZZfzL2F4qnuWGbPzA8v1fFGvvkBGn+gCO6CeEkvBf6hHA@mail.gmail.com>, George
Quoted 11 lines · Dunlap
tools/libxl/libxl.h int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, · line 1223
Quoted 8 lines · Chunyan Liu
tools/libxl/libxl.h +3
-0+int libxl_intf_to_device_usb(libxl_ctx *ctx, uint32_t domid, + char *intf, libxl_device_usb *usb) + LIBXL_EXTERNAL_CALLERS_ONLY;I guess this function will go away?
With using bus:addr instead of sysfs interface, this will be removed.
Quoted 8 lines
Quoted 7 lines
tools/libxl/libxl_usb.c new file +0
-0@@ -0,0 +1,1277 @@
Quoted 8 lines
tools/libxl/libxl_usb.c line 63
Quoted 4 lines
tools/libxl/libxl_usb.c new file +4
-0+static int libxl__usbport_add_xenstore (libxl__gc *gc, +xs_transaction_t tran, +uint32_t domid, +libxl_device_usbctrl *usbctrl)Would it be too much to ask to have all the pvusb-specific stuff in a separate file -- say, "
libxl_pvusb.c" or something? That would make it a lot easier when I add in the HVM USB stuff.
Sure.
Quoted 46 lines
(Just to be clear, I'm asking as a favor -- it's policy that the first mover gets to have it easier, and people who want to come and add something later are the ones who have to do the refactoring.)
tools/libxl/libxl_usb.c
Quoted 11 lines
tools/libxl/libxl_usb.c new file +11
-0+{ +char *path; +int i; + + path =GCSPRINTF ("%s/backend/vusb/%d/%d/port" , +libxl__xs_get_dompath (gc,0 ), domid, usbctrl->devid); + +libxl__xs_mkdir (gc, tran, path,NULL ,0 ); + +for (i =1 ; i <= usbctrl->num_ports; i++) { + if (libxl__xs_write_checked(gc, tran, GCSPRINTF("%s/%d", path, i),""))
Quoted 29 lines
tools/libxl/libxl_usb.c new file +29
-0+return ERROR_FAIL ; + } + +return 0 ; +} + +static int libxl__usbctrl_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +flexarray_t *front; +flexarray_t *back; +libxl__device *device; +xs_transaction_t tran; +int rc =0 ; + +GCNEW (device); + rc =libxl__device_from_usbctrl (gc, domid, usbctrl, device); +if (rc) goto out; + + front =flexarray_make (gc,4 ,1 ); + back =flexarray_make (gc,12 ,1 ); + +flexarray_append (back,"frontend-id" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid)); +flexarray_append (back,"online" ); +flexarray_append (back,"1" ); +flexarray_append (back,"state" ); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 ));
Quoted 8 lines
tools/libxl/libxl_usb.c line 107
Quoted 4 lines
tools/libxl/libxl_usb.c new file +4
-0+flexarray_append (back,"usb-ver" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->usb_version)); +flexarray_append (back,"num-ports" ); +flexarray_append (back,libxl__sprintf (gc,"%d" , usbctrl->num_ports));So how much of this is pvusb-specific, and how much would be shared between DEVICEMODEL? Because this bit looks specifically like the stuff used to set up the pvusb connection...
To share with qemu emulated usb controller? I think pvusb backend driver will probe things under backend/vusb/* and setup connection with pvusb frontend driver, qemu emulated usb controller should not be placed there at all maybe.
Quoted 17 lines
Quoted 6 lines
tools/libxl/libxl_usb.c new file +5
-0+flexarray_append (back,"type" ); +switch (usbctrl->type) { +case LIBXL_USBCTRL_TYPE_PV :{ +flexarray_append (back,"PVUSB" ); +break ;tools/libxl/libxl_usb.c line 122
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ } +case LIBXL_USBCTRL_TYPE_DEVICEMODEL : { +flexarray_append (back,"IOEMU" ); +break ; + } +default : +/* not supported */ + rc =ERROR_FAIL ; + goto out; + }
Quoted 4 lines
...but this looks like it's trying to be shared between PVUSB and DEVICEMODEL. I'm pretty sure this isn't going to work long-run, because if we were to write all this stuff for a devicemodel, wouldn't the pvusb back-end take this as setting up a new pvusb port?
Yes, I think you are right. This place should only allow pvusb type. Qemu emulated usb controller should not be stored here.
Quoted 5 lines
Also, you don't seem to be storing or retreiving
usbctrl->namehere -- if we want that to be part of the interface we need to use it. (I think we wanted that so that it could default to something like pv-0, emul-1, &c).
First I wonder usbctrl->name is really needed. If just for interface, we can use devid (index), it could be 0, 1, and with usb-list one knows info like:
0 is pv, 1 is emulated. But if it helps a lot with a 'name', surely we can add :)
Quoted 78 lines
In general, I don't think libxl should be storing stuff in the pvusb front/back xenstore directories not related to that protocol. We should store extraneous information in a libxl-specific directory. You can see an example of the kind of think I'm talking about in the HVM USB patch I submitted last year (see
usb_add_xenstore()):http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html
Alternately -- at the moment, the only extraneous information we've got is the name of the controller; if you wanted to propose that we get rid of the name field, then there wouldn't be any extra information to store.
tools/libxl/libxl_usb.c
Quoted 3 lines
tools/libxl/libxl_usb.c new file +3
-0+ +flexarray_append (front,"backend-id" ); + flexarray_append(front, libxl__sprintf(gc, "%d",
usbctrl->backend_domid));tools/libxl/libxl_usb.c
Quoted 8 lines
tools/libxl/libxl_usb.c new file +8
-0+flexarray_append (front,"state" ); +flexarray_append (front,libxl__sprintf (gc,"%d" ,1 )); + +retry_transaction: + tran =xs_transaction_start (ctx->xsh); + + libxl__device_generic_add(gc, tran, device, + libxl__xs_kvs_of_flexarray(gc, back,
back->count),tools/libxl/libxl_usb.c line 75
Quoted 1 line
tools/libxl/libxl_usb.c new file +1
-0+ libxl__xs_kvs_of_flexarray(gc, front,
front->count),Quoted 15 lines
tools/libxl/libxl_usb.c new file +15
-0+ NULL); +libxl__usbport_add_xenstore (gc, tran, domid, usbctrl); + +if (!xs_transaction_end (ctx->xsh, tran,0 )) { +if (errno ==EAGAIN ) + goto retry_transaction; +else { + rc =ERROR_FAIL ; + goto out; + } + } + +out: +return rc; +}tools/libxl/libxl_usb.c line 159
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +static int libxl__device_usbctrl_add (libxl__gc *gc,uint32_t domid, +libxl_device_usbctrl *usbctrl) +{ +int rc =0 ; + + rc =libxl__device_usbctrl_setdefault (gc, domid, usbctrl); +if (rc) goto out; + +if (usbctrl->devid ==-1 ) {This also needs to have a symbolic name; something with "AUTO" in it.
Quoted 18 lines
tools/libxl/libxl_usb.c new file +16
-0+if ((usbctrl->devid =libxl__device_nextid (gc, domid,"vusb" )) <0 ) { + rc =ERROR_FAIL ; + goto out; + } + } + +if (libxl__usbctrl_add_xenstore (gc, domid, usbctrl) <0 ){ + rc =ERROR_FAIL ; + goto out; + } + +out: +return rc; +} + +/* Following functions are to get assignable usb devices */ <snip>
Quoted 8 lines
tools/libxl/libxl_usb.c line 498
Quoted 2 lines
tools/libxl/libxl_usb.c new file +2
-0+libxl_device_usb * +libxl_device_usb_assignable_list (libxl_ctx *ctx,int *num)I'm a bit ambivalent about this one. For people using xl, "lsusb" should be just fine. Is anyone building a toolstack on top of libxl directly going to need this functionality? Would libvirt use this functionality, for instance, or would it use libusb? Or just leave that to the caller?
This exists mainly because the proposed interface before using usb sysfs interface rather than bus:addr, user has no much idea about which sysfs interface is related to which usb device. Now if we decide to use bus:addr, I agree this API could be removed. Just use lsusb. (But user should have this knowledge in mind: a HUB could not be assigned to guest).
Quoted 16 lines
Quoted 4 lines
tools/libxl/libxl_usb.c new file +2
-0+static int libxl__device_usb_setdefault (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb)tools/libxl/libxl_usb.c line 678
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+{ +char *be_path, *tmp; + +if (usb->ctrl ==-1 ) { +int ret =libxl__device_usb_set_default_usbctrl (gc, domid, usb); +/* If no existing ctrl to host this usb device, setup a new one */ +if (ret) { +libxl_device_usbctrl usbctrl; +libxl_device_usbctrl_init (&usbctrl); +libxl__device_usbctrl_add (gc, domid, &usbctrl);What happens if this fails?
Currently it will check usb port existence later, so if this fails, errors will be reported in that step. But I think I'd better check the return value here to report error earlier. Thank you.
- Chunyan
Quoted 9 lines
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH RFC V2 3/5] libxl: add pvusb API
In reply to Chunyan LiuHi Chunyan,
I've found another problem while trying to write a qemu based pvUSB backend.
Quoted 9 lines · Chunyan Liu
Add pvusb APIs, including:
- attach/detach (create/destroy) virtual usb controller.
- attach/detach usb device
- list assignable usb devices in host
- some other helper functionsSigned-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>---
...
Quoted 5 lines
tools/libxl/libxl_usb.c new file +0
-0
...
Quoted 8 lines
tools/libxl/libxl_usb.c new file +8
-0+/* xenstore usb data */ +static int libxl__device_usb_add_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +char *be_path; +int rc; +libxl_domain_config d_config;
tools/libxl/libxl_usb.c line 713
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+libxl_device_usb usb_saved; +libxl__domain_userdata_lock *lock =NULL ; + +libxl_domain_config_init (&d_config); +libxl_device_usb_init (&usb_saved); +libxl_device_usb_copy (CTX , &usb_saved, usb); + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d" , +libxl__xs_get_dompath (gc,0 ), domid, usb->ctrl); +if (libxl__wait_for_backend (gc, be_path,"4" ) <0 ) {
Don't do this! That's the reason I had to change my backend driver in order to support assignment of a usb device via config file. Normally the backend will witch to state 4 only after the frontend is started.
You can just remove waiting for the backend here. The backend has to check all ports when it is changing is state to 4 ("connected").
Quoted 34 lines
tools/libxl/libxl_usb.c new file +34
-0+ rc =ERROR_FAIL ; + goto out; + } + + lock =libxl__lock_domain_userdata (gc, domid); +if (!lock) { + rc =ERROR_LOCK_FAIL ; + goto out; + } + + rc =libxl__get_domain_configuration (gc, domid, &d_config); +if (rc) goto out; + +DEVICE_ADD (usb, usbs, domid, &usb_saved,COMPARE_USB , &d_config); + + rc =libxl__set_domain_configuration (gc, domid, &d_config); +if (rc) goto out; + + be_path =libxl__sprintf (gc,"%s/port/%d" , be_path, usb->port); +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Adding new usb device to xenstore" ); +if (libxl__xs_write_checked (gc,XBT_NULL , be_path, usb->intf)) { + rc =ERROR_FAIL ; + goto out; + } + + rc =0 ; + +out: +if (lock)libxl__unlock_domain_userdata (lock); +libxl_device_usb_dispose (&usb_saved); +libxl_domain_config_dispose (&d_config); +return rc; + +}
tools/libxl/libxl_usb.c line 757
Quoted 10 lines
tools/libxl/libxl_usb.c new file +10
-0+ +static int libxl__device_usb_remove_xenstore (libxl__gc *gc,uint32_t domid, +libxl_device_usb *usb) +{ +libxl_ctx *ctx =CTX ; +char *be_path; + + be_path =libxl__sprintf (gc,"%s/backend/vusb/%d/%d" , +libxl__xs_get_dompath (gc,0 ), domid, usb->ctrl); +if (libxl__wait_for_backend (gc, be_path,"4" ) <0 )
Remove this one, too.
Juergen
RFC PATCH v2 4/5 xl: add pvusb commands
In reply to Chunyan LiuAdd pvusb commands.
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-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)
#xl usb-attach test_vm 2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>
#xl usb-detach test_vm 2-1.1
#xl usb-ctrl-detach test_vm dev_id
will destroy the controller with dev_id as specified. Dev_id can be traced in usb-list info
--- tools/libxl/xl.h | 6 ++ tools/libxl/xl_cmdimpl.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 30 ++++++ 3 files changed, 292 insertions(+)
tools/libxl/xl.h +6 -0
@@ -86,6 +86,12 @@ 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); +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 +256 -0
262 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +30 -0
@@ -541,6 +541,36 @@ struct cmd_spec cmd_table[] = {"\"cache_occupancy\": Show L3 cache occupancy\n" , }, #endif + { "usb-ctrl-attach", + &main_usbctrl_attach,1 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [version=<version>] [num_ports=<number>]" , + }, + { "usb-ctrl-detach", + &main_usbctrl_detach,0 ,1 , +"Destory the virtual USB controller specified by <DevId> for a domain" , +"<Domain> <DevId>" , + }, + { "usb-attach", + &main_usbattach,1 ,2 , +"Attach a USB device to a domain" , +"<Domain> <BusId> [controller=<DevId> port=<port>]" , + }, + { "usb-detach", + &main_usbdetach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <BusId>" , + }, + { "usb-list", + &main_usblist,0 ,0 , +"List information about USB devices for a domain" , +"<Domain>" , + }, + { "usb-assignable-list", + &main_usbassignable_list,0 ,0 , + "List all the assignable USB devices", + }, + };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Signature · 1 line
1.8.4.5
Re: [PATCH RFC V2 4/5] xl: add pvusb commands
Quoted 20 lines · Chunyan Liu
Add pvusb commands.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usb-ctrl-attach
test_vmversion=1 num_ports=8#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)#xl usb-attach
test_vm2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>
Quoted 5 lines
#xl usb-detach
test_vm2-1.1#xl usb-ctrl-detach
test_vmdev_id
will destroy the controller withdev_idas specified.Dev_idcan be traced in usb-list info
Sorry for late review.
Some comments inline.
Quoted 76 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/xl.h | 6 ++ tools/libxl/xl_cmdimpl.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 30 ++++++ 3 files changed, 292 insertions(+)tools/libxl/xl.h +6
-0@@ -86,6 +86,12 @@ 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); +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 +42
-0@@ -3000,6 +3000,262 @@ int main_cd_insert(int argc, char **argv)return 0 ; } +static void usbinfo_print (libxl_device_usb *usbs,int num) { +int i; +if ( usbs ==NULL ) +return ; +libxl_usbinfo usbinfo; +for (i =0 ; i < num; i++) { +/* TO BE Improved */ +if (usbs[i].port ) +printf ("Port %d:" , usbs[i].port); +printf ("Interface %8s " , usbs[i].intf); +if (!libxl_device_usb_getinfo (ctx, usbs[i].intf, &usbinfo)) { +printf ("Bus %03d Dev %03d: %04d:%04d %s %s\n" , + usbinfo.bus, usbinfo.devnum, usbinfo.idVendor, + usbinfo.idProduct, usbinfo.manuf, usbinfo.prod); + } +libxl_usbinfo_dispose (&usbinfo); + } +} + + +static void usb_assignable_list (void ) +{ +libxl_device_usb *usbs; +int num; + + usbs =libxl_device_usb_assignable_list (ctx, &num); + +usbinfo_print (usbs, num); + +free (usbs); +} + +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 ;
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3054
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+} + +int main_usbctrl_attach (int argc,char **argv) +{ +uint32_t domid; +int opt; +char *oparg; +libxl_device_usbctrl usbctrl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-controller-attach", 1) {
Should be "usb-ctrl-attach".
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3062
Quoted 8 lines
tools/libxl/xl_cmdimpl.c +8
-0+/* No options */ + } + + domid =find_domain (argv[optind++]); + +libxl_device_usbctrl_init (&usbctrl); + +while (argc >= optind) {
argc > optind?
Quoted 38 lines
tools/libxl/xl_cmdimpl.c +38
-0+if (MATCH_OPTION ("type" , argv[optind], oparg)) { +if (!strcmp ("pv" , oparg)) { + usbctrl.type =LIBXL_USBCTRL_TYPE_PV ; + }else if (!strcmp ("ioemu" , oparg)) { + usbctrl.type =LIBXL_USBCTRL_TYPE_DEVICEMODEL ; + }else { +fprintf (stderr,"Invalid parameter `type'.\n" ); +exit (-1 ); + } + }else if (MATCH_OPTION ("version" , argv[optind], oparg)) { + usbctrl.usb_version =atoi (oparg); + }else if (MATCH_OPTION ("num_ports" , argv[optind], oparg)) { + usbctrl.num_ports =atoi (oparg); + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); +exit (-1 ); + } + optind++; + } + +if (dryrun_only) { +char * json =libxl_device_usbctrl_to_json (ctx, &usbctrl); +printf ("usb controller: %s\n" , json); +free (json); +libxl_device_usbctrl_dispose (&usbctrl); +if (ferror (stdout) ||fflush (stdout)) { +perror ("stdout" ); +exit (-1 ); + } +return 0 ; + } + +if (libxl_device_usbctrl_add (ctx, domid, &usbctrl,0 )) { +fprintf (stderr,"libxl_device_usbctrl_add failed.\n" ); +exit (-1 ); + } +libxl_device_usbctrl_dispose (&usbctrl); +return 0 ;
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3110
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+} + +int main_usbctrl_detach (int argc,char **argv) +{ +uint32_t domid; +int devid; +int opt; +libxl_device_usbctrl usbctrl; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-controller-detach", 2) {
Should be "usb-ctrl-detach".
Quoted 27 lines
tools/libxl/xl_cmdimpl.c +27
-0+/* No options */ + } + + domid =find_domain (argv[optind]); + devid =atoi (argv[optind+1 ]); + +libxl_device_usbctrl_init (&usbctrl); + +if (libxl_devid_to_device_usbctrl (ctx, domid, devid, &usbctrl)) { +fprintf (stderr,"Unknown usb controller %d.\n" , devid); +exit (-1 ); + } + +if (libxl_device_usbctrl_remove (ctx, domid, &usbctrl,0 )) { +fprintf (stderr,"libxl_device_usbctrl_add failed.\n" ); +exit (-1 ); + } +libxl_device_usbctrl_dispose (&usbctrl); +return 0 ; + +} + +int main_usbattach (int argc,char **argv) +{ +uint32_t domid; +int opt; +char *oparg;
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3147
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10
-0+libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) { +/* No options */ + } + + domid =find_domain (argv[optind++]); +libxl_device_usb_init (&usb); +replace_string (&usb.intf, argv[optind++]); +while (argc >= optind) {
argc > optind?
Quoted 120 lines
tools/libxl/xl_cmdimpl.c +111
-0+if (MATCH_OPTION ("controller" , argv[optind], oparg)) { + usb.ctrl =atoi (oparg); + }else if (MATCH_OPTION ("port" , argv[optind], oparg)) { + usb.port =atoi (oparg); + }else { +fprintf (stderr,"unrecognized argument `%s'\n" , argv[optind]); +exit (-1 ); + } + optind++; + } + +if (dryrun_only) { +char *json =libxl_device_usb_to_json (ctx, &usb); +printf ("usb: %s\n" , json); +free (json); +libxl_device_usb_dispose (&usb); +if (ferror (stdout) ||fflush (stdout)) { +perror ("stdout" ); +exit (-1 ); + } +return 0 ; + } + +if (libxl_device_usb_add (ctx, domid, &usb,0 )) { +fprintf (stderr,"libxl_device_usb_add failed.\n" ); +exit (-1 ); + } + +libxl_device_usb_dispose (&usb); +return 0 ; +} + +int main_usbdetach (int argc,char **argv) +{ +uint32_t domid; +int opt; +libxl_device_usb usb; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 2) { +/* No options */ + } + + domid =find_domain (argv[optind++]); +libxl_device_usb_init (&usb); +replace_string (&usb.intf, argv[optind++]); + +if (argc > optind) { +fprintf (stderr,"Invalid arguments.\n" ); +exit (-1 ); + } + +if (libxl_intf_to_device_usb (ctx, domid, usb.intf, &usb) ) { +fprintf (stderr,"libxl_intf_to_device_usb failed.\n" ); +exit (-1 ); + } + +if (libxl_device_usb_remove (ctx, domid, &usb,0 ) ) { +fprintf (stderr,"libxl_device_usb_remove failed.\n" ); +exit (-1 ); + } +libxl_device_usb_dispose (&usb); +return 0 ; +} + +int main_usblist (int argc,char **argv) +{ +uint32_t domid; +libxl_device_usbctrl *usbctrls; +libxl_device_usb *usbs; +libxl_usbctrlinfo usbctrlinfo; +int numctrl, numusb, i, opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-list", 1) { +/* No options */ + } + + domid =find_domain (argv[optind++]); + +if (argc > optind) { +fprintf (stderr,"Invalid arguments.\n" ); +exit (-1 ); + } + + usbctrls =libxl_device_usbctrl_list (ctx, domid, &numctrl); +if (!usbctrls) { +return 0 ; + } + +for (i =0 ; i < numctrl; ++i) { +printf ("%-3s %-5s %-3s %-5s %-7s %-30s\n" , +"Idx" ,"type" ,"BE" ,"state" ,"usb-ver" ,"BE-path" ); + +if (!libxl_device_usbctrl_getinfo (ctx, domid, + &usbctrls[i], &usbctrlinfo)) { +printf ("%-3d %-5s %-3d %-5d %-7d %-30s\n" , + i, usbctrlinfo.type, usbctrlinfo.backend_id, + usbctrlinfo.state, usbctrlinfo.version, + usbctrlinfo.backend ); + + usbs =libxl_device_usb_list (ctx, domid, usbctrlinfo.devid, &numusb); +usbinfo_print (usbs, numusb); + +libxl_usbctrlinfo_dispose (&usbctrlinfo); + } +libxl_device_usbctrl_dispose (&usbctrls[i]); + } + +free (usbctrls); +return 0 ; +} +int main_console (int argc,char **argv) {uint32_t domid;tools/libxl/xl_cmdtable.c +0
-0@@ -541,6 +541,36 @@ struct cmd_spec cmd_table[] = { "\"cache_occupancy\": Show L3 cache occupancy\n",
tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 551
Quoted 10 lines
tools/libxl/xl_cmdtable.c +8
-0},#endif + {"usb-ctrl-attach" , + &main_usbctrl_attach,1 ,1 , +"Create a virtual USB controller for a domain" , +"<Domain> [version=<version>] [num_ports=<number>]" , + }, + { "usb-ctrl-detach", + &main_usbctrl_detach,0 ,1 , + "Destory the virtual USB controller specified by <DevId> for a domain",
s/Destory/Destroy/
Quoted 16 lines
tools/libxl/xl_cmdtable.c +15
-0+"<Domain> <DevId>" , + }, + { "usb-attach", + &main_usbattach,1 ,2 , +"Attach a USB device to a domain" , +"<Domain> <BusId> [controller=<DevId> port=<port>]" , + }, + { "usb-detach", + &main_usbdetach,0 ,1 , +"Detach a USB device from a domain" , +"<Domain> <BusId>" , + }, + { "usb-list", + &main_usblist,0 ,0 , + "List information about USB devices for a domain",
tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 576
Quoted 10 lines
tools/libxl/xl_cmdtable.c +7
-0+ "<Domain>", + }, + {"usb-assignable-list" , + &main_usbassignable_list,0 ,0 , + "List all the assignable USB devices", + }, + };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Juergen
Re: [PATCH RFC V2 4/5] xl: add pvusb commands
In reply to Chunyan LiuQuoted 26 lines · Chunyan Liu
Add pvusb commands.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usb-ctrl-attach
test_vmversion=1 num_ports=8#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)#xl usb-attach
test_vm2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>#xl usb-detach
test_vm2-1.1#xl usb-ctrl-detach
test_vmdev_id
will destroy the controller withdev_idas specified.Dev_idcan be traced in usb-list info
Quoted 6 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/xl.h | 6 ++ tools/libxl/xl_cmdimpl.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 30 ++++++
This patch should also touch docs/man/xl*.pod I think.
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3043
Quoted 9 lines
tools/libxl/xl_cmdimpl.c +9
-0+int main_usbassignable_list (int argc,char **argv) +{ +int opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-assignable-list", 0) { +/* No options */ + } + +usb_assignable_list ();
Unless there are other callers or a good reason to factor it out (e.g. complexity) you can just do the operation inline here if you like.
The rest of it seems pretty straightforward and looked ok to me.
Ian.
Re: [PATCH RFC V2 4/5] xl: add pvusb commands
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/3/2015 at 07:43 PM, in message <[email protected]>,
Quoted 32 lines · Ian Campbell
Quoted 26 lines · Chunyan Liu
Add pvusb commands.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usb-ctrl-attach
test_vmversion=1 num_ports=8#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)#xl usb-attach
test_vm2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>#xl usb-detach
test_vm2-1.1#xl usb-ctrl-detach
test_vmdev_id
will destroy the controller withdev_idas specified.Dev_idcan be traced in usb-list infoQuoted 5 lines
Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>---
tools/libxl/xl.h | 6 ++ tools/libxl/xl_cmdimpl.c | 256
Quoted 4 lines
++++++++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
tools/libxl/xl_cmdtable.c | 30 ++++++This patch should also touch docs/man/xl*.pod I think.
Right. Will update it.
Quoted 13 lines
tools/libxl/xl_cmdimpl.c int main_cd_insert(int argc, char **argv) · line 3043
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +9
-0+int main_usbassignable_list (int argc,char **argv) +{ +int opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-assignable-list", 0) { +/* No options */ + } + +usb_assignable_list ();Unless there are other callers or a good reason to factor it out (e.g. complexity) you can just do the operation inline here if you like.
Got it.
Quoted 7 lines
The rest of it seems pretty straightforward and looked ok to me.
Ian.
Re: [PATCH RFC V2 4/5] xl: add pvusb commands
In reply to Chunyan LiuQuoted 6 lines · Chunyan Liu
Add pvusb commands.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usb-ctrl-attach
test_vmversion=1 num_ports=8
This doesn't allow you to specify controller name or devid.
I was looking at the other device-attach code, and they all seem to have a "devicespec"-style specification. Would it make sense to do something similar?
For example:
xl usb-ctrl-attach test_vm name=pv-1,type=pv,version=1,ports=8
Then we could re-use this for the config file as well.
Quoted 8 lines
#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)
Quoted 6 lines
#xl usb-attach
test_vm2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>#xl usb-detach
test_vm2-1.1
Long-term we want to be able to attach and detach more kinds of devices than just host devices; for example for HVM guests we want to be able to attach mice, keyboards, tablets, &c.
What if we continued with the "devicespec" idea above, it might make more sense to say something like
xl usb-attach test_vm type=hostdev,hostbus=X,hostaddr=Y,ctrl=pv-1
(Assuming you had a controller named pv-1, for example.)
And then maybe in the future we could have something like
xl usb-attach test_vm type=tablet
Thoughts?
-George
Re: [PATCH RFC V2 4/5] xl: add pvusb commands
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 3/7/2015 at 01:25 AM, in message
<CAFLBxZb1N3_9PVvg-yC8dyVaiySZVRA3H2e8496vHNEfvrm6Zg@mail.gmail.com>, George
Quoted 44 lines · Dunlap
Quoted 6 lines · Chunyan Liu
Add pvusb commands.
To attach a usb device to guest through pvusb, one could follow following example:
#xl usb-ctrl-attach
test_vmversion=1 num_ports=8This doesn't allow you to specify controller name or devid.
I was looking at the other device-attach code, and they all seem to have a "devicespec"-style specification. Would it make sense to do something similar?
For example:
xl usb-ctrl-attach
test_vmname=pv-1,type=pv,version=1,ports=8Then we could re-use this for the config file as well.
Quoted 8 lines
#xl usb-list
test_vm
will show the usb controllers and port usage under the domain.#xl usb-assignable-list
will list all assignable usb devices now in host, with their sysfs interface. (This is very useful since later we will use sysfs interface to attach a usb devie to guest)Quoted 6 lines
#xl usb-attach
test_vm2-1.1
will find the first usable controller:port, and attach usb device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) to it. One could also specify which <controller> and which <port>#xl usb-detach
test_vm2-1.1Long-term we want to be able to attach and detach more kinds of devices than just host devices; for example for HVM guests we want to be able to attach mice, keyboards, tablets, &c.
What if we continued with the "devicespec" idea above, it might make more sense to say something like
xl usb-attach
test_vmtype=hostdev,hostbus=X,hostaddr=Y,ctrl=pv-1
Quoted 7 lines
(Assuming you had a controller named pv-1, for example.)
And then maybe in the future we could have something like
xl usb-attach
test_vmtype=tabletThoughts?
This could be. I can update.
Quoted 4 lines
-George
RFC PATCH v2 5/5 domcreate: support pvusb in configuration file
In reply to Chunyan LiuAdd code to support pvusb from domain create. One could specify usb in domain's configuration file and create domain, then usb device would be attached to guest automatically.
One could specify usb device in config file like this:
usb=['2-1.1']
--- tools/libxl/libxl_create.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdimpl.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-)
tools/libxl/libxl_create.c +38 -3
@@ -730,6 +730,8 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *aodevs,static void domcreate_attach_vtpms (libxl__egc *egc,libxl__multidev *multidev,int ret); +static void domcreate_attach_usbs (libxl__egc *egc,libxl__multidev *multidev, +int ret);static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *aodevs,int ret);
@@ -1367,13 +1369,13 @@ static void domcreate_attach_vtpms(libxl__egc *egc,if (d_config->num_vtpms >0 ) {/* Attach vtpms */ libxl__multidev_begin (ao, &dcs->multidev); - dcs->multidev.callback = domcreate_attach_pci; + dcs->multidev.callback = domcreate_attach_usbs;libxl__add_vtpms (egc, ao, domid, d_config, &dcs->multidev);libxl__multidev_prepared (egc, &dcs->multidev,0 );return ; } -domcreate_attach_pci (egc, multidev,0 ); +domcreate_attach_usbs (egc, multidev,0 );return ; error_out:
@@ -1381,6 +1383,39 @@ error_out:domcreate_complete (egc, dcs, ret); } +static void domcreate_attach_usbs (libxl__egc *egc,libxl__multidev *multidev, +int ret) +{ +libxl__domain_create_state *dcs =CONTAINER_OF (multidev, *dcs, multidev); +STATE_AO_GC (dcs->ao); +int i; +libxl_ctx *ctx =CTX ; +int domid = dcs->guest_domid; + +libxl_domain_config *const d_config = dcs->guest_config; + +if (ret) { +LOG (ERROR ,"unable to add vtpm devices" ); + goto error_out; + } + +for (i =0 ; i < d_config->num_usbs; i++) { + ret =libxl__device_usb_add (gc, domid, &d_config->usbs[i]); +if (ret <0 ) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"libxl__device_usb_add failed: %d" , ret); + goto error_out; + } + } + +domcreate_attach_pci (egc, multidev,0 ); +return ; + +error_out: +assert (ret); +domcreate_complete (egc, dcs, ret); +} +static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *multidev,int ret) {
@@ -1394,7 +1429,7 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev,libxl_domain_config *const d_config = dcs->guest_config;if (ret) { -LOG (ERROR ,"unable to add vtpm devices" ); +LOG (ERROR ,"unable to add usb devices" ); goto error_out; }
tools/libxl/xl_cmdimpl.c +39 -1
@@ -985,7 +985,7 @@ static void parse_config_data(const char *config_source,const char *buf;long l;XLU_Config *config; -XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; +XLU_ConfigList *cpus, *vbds, *nics, *pcis, *usbs, *cvfbs, *cpuids, *vtpms;XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian;int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian;int pci_power_mgmt =0 ;
@@ -1745,6 +1745,44 @@ skip_vfb:libxl_defbool_set (&b_info->u.pv.e820_host, true); } +if (!xlu_cfg_get_list (config,"usb" , &usbs,0 ,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; +char *buf2 =strdup (buf); +char *p, *p2; + + 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); + + p =strtok (buf2,"," ); +if (p) { + usb->port =-1 ; + usb->ctrl =-1 ; +do { +while (*p ==' ' ) + ++p; +if ((p2 =strchr (p,'=' )) ==NULL ) +break ; + *p2 ='\0' ; +if (!strcmp (p,"type" )) { +//Set type in libxl_device_usb + }else if (!strcmp (p,"interface" ) ){ + usb->intf =strdup (p2 +1 ); + }else { +fprintf (stderr,"Unknown string `%s' in usb spec\n" , p); +exit (1 ); + } + }while ((p =strtok (NULL ,"," )) !=NULL ); + } +free (buf2); + d_config->num_usbs++; + } + } +switch (xlu_cfg_get_list (config,"cpuid" , &cpuids,0 ,1 )) {case 0 : {
Signature · 1 line
1.8.4.5
Re: [PATCH RFC V2 5/5] domcreate: support pvusb in configuration file
Quoted 4 lines · Chunyan Liu
Add code to support pvusb from domain create. One could specify usb in domain's configuration file and create domain, then usb device would be attached to guest automatically.
Quoted 8 lines
One could specify usb device in config file like this:
usb=['2-1.1']Signed-off-by Chunyan Liu <[email protected]>Signed-off-by Simon Cao <[email protected]>--- tools/libxl/libxl_create.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdimpl.c | 40 +++++++++++++++++++++++++++++++++++++++-
This should be touching the docs too.
tools/libxl/libxl_create.c error_out: · line 1406
Quoted 9 lines
tools/libxl/libxl_create.c +8
-0+static void domcreate_attach_usbs (libxl__egc *egc,libxl__multidev *multidev, +int ret) +{ +for (i =0 ; i < d_config->num_usbs; i++) { + ret =libxl__device_usb_add (gc, domid, &d_config->usbs[i]); +if (ret <0 ) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"libxl__device_usb_add failed: %d" , ret);
Use the LOG*( macros please.
Otherwise the code looks fine, only the lack of docs stops me acking.
Ian.
Quoted 6 lines · Chunyan Liu
This patch series is based on Simon's work. Since there is no progress after last August, I hope we can make this work proceed. Any comment will be very appreciated.
It adds pvusb toolstack implementation, with pvusb kernel side work, one could attach/detach a usb device to guest.
By any chance do you (or anyone else) have a link handy to the design discussions for this stuff around the start of last year?
In particular I'm hoping for some reminder on what the libxl_usbctrl_type / libxl_usb_type options mean.
Although this is PV USB only I think the intention was to leave a suitable hole for HVM emulated USB support. Or am I mis-remembering?
[...]
Quoted 5 lines
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 8 +- tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_create.c | 41 +- tools/libxl/libxl_internal.h | 11 +
Quoted 8 lines
tools/libxl/libxl_types.idl | 58 +- tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_usb.c | 1277 ++++++++++++++++++++++++++++++++++ tools/libxl/libxlu_cfg_y.c | 464 ++++++------ tools/libxl/libxlu_cfg_y.h | 38 +- tools/libxl/xl.h | 6 + tools/libxl/xl_cmdimpl.c | 296 +++++++- tools/libxl/xl_cmdtable.c | 30 +
This will need some docs changes too, at least to the xl and xl.cfg manpages.
Quoted 3 lines
13 files changed, 2058 insertions(+), 232 deletions(-) create mode 100644 tools/libxl/libxl_usb.c
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Chunyan Liu
This patch series is based on Simon's work. Since there is no progress after last August, I hope we can make this work proceed. Any comment will be very appreciated.
Quoted 9 lines
Quoted 2 lines
It adds pvusb toolstack implementation, with pvusb kernel side work, one could attach/detach a usb device to guest.
By any chance do you (or anyone else) have a link handy to the design discussions for this stuff around the start of last year?
In particular I'm hoping for some reminder on what the
libxl_usbctrl_type/libxl_usb_typeoptions mean.
George probably knows/remembers the best..
Quoted 3 lines
Although this is PV USB only I think the intention was to leave a suitable hole for HVM emulated USB support. Or am I mis-remembering?
PVUSB should work with both PV and HVM guests, as long as the required PV drivers are in the domU kernel.
-- Pasi
Quoted 7 lines · Pasi Kärkkäinen
Quoted 3 lines · Ian Campbell
Although this is PV USB only I think the intention was to leave a suitable hole for HVM emulated USB support. Or am I mis-remembering?
PVUSB should work with both PV and HVM guests, as long as the required PV drivers are in the domU kernel.
I know this.
I was asking HVM *emulated* USB support...
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
On 1/28/2015 at 11:51 PM, in message <[email protected]>, Ian
Quoted 10 lines · Campbell
Quoted 6 lines · Chunyan Liu
This patch series is based on Simon's work. Since there is no progress after last August, I hope we can make this work proceed. Any comment will be very appreciated.
It adds pvusb toolstack implementation, with pvusb kernel side work, one could attach/detach a usb device to guest.
By any chance do you (or anyone else) have a link handy to the design discussions for this stuff around the start of last year?
Design Discussion Thread:
http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html
Quoted 3 lines
In particular I'm hoping for some reminder on what the
libxl_usbctrl_type/libxl_usb_typeoptions mean.
According to the design discussion, the intention of these two structures was to unify PVUSB way and HVM QEMU emulated way.
libxl_usbctrl_type is to differentiate it is PVUSB or QEMU emulated. George had a patch series to support add/remove usb in HVM by qemu emulated way. In that patch series, it uses libxl_usb_protocol to differeentiate PVUSB or QEMU emulated.
http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html
libxl_usb_type is used in QEMU emulated way, since qemu usb-add support many usb types, like: host, tablet, mouse, keyboard, net, serial, disk, etc.
For pvusb work only, this patch series sets libxl_usbctrl_type to 'PVUSB' always, and libxl_usb_type is not used.
Quoted 3 lines
Although this is PV USB only I think the intention was to leave a suitable hole for HVM emulated USB support. Or am I mis-remembering?
Yes. It intended to leave hole for HVM QEMU emulated USB support.
- Chunyan
Quoted 27 lines
[...]
Quoted 8 lines
tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 8 +- tools/libxl/libxl.h | 58 ++ tools/libxl/libxl_create.c | 41 +- tools/libxl/libxl_internal.h | 11 + tools/libxl/libxl_types.idl | 58 +- tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_usb.c | 1277++++++++++++++++++++++++++++++++++
Quoted 5 lines
tools/libxl/libxlu_cfg_y.c | 464 ++++++------ tools/libxl/libxlu_cfg_y.h | 38 +- tools/libxl/xl.h | 6 + tools/libxl/xl_cmdimpl.c | 296 +++++++- tools/libxl/xl_cmdtable.c | 30 +This will need some docs changes too, at least to the xl and xl.cfg manpages.
Quoted 3 lines
13 files changed, 2058 insertions(+), 232 deletions(-) create mode 100644 tools/libxl/libxl_usb.c