To support USB Controller in xen guest domains, just add
USB controller in domain config xml as following:
<controller type='usb' model='qusb2' ports='4'/>
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/libxl/libxl_conf.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/libxl/libxl_conf.h | 4 +++
2 files changed, 98 insertions(+)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f66264e..7bc9e7a 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1866,6 +1866,97 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
#ifdef LIBXL_HAVE_PVUSB
int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+ libxl_device_usbctrl *usbctrl)
+{
+ usbctrl->devid = controller->idx;
+
+ if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+ return -1;
+
+ if (controller->model == -1) {
+ usbctrl->version = 2;
+ usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+ } else {
+ switch (controller->model) {
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB1:
+ usbctrl->version = 1;
+ usbctrl->type = LIBXL_USBCTRL_TYPE_PV;
+ break;
+
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB2:
+ usbctrl->version = 2;
+ usbctrl->type = LIBXL_USBCTRL_TYPE_PV;
+ break;
+
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1:
+ usbctrl->version = 1;
+ usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+ break;
+
+ case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2:
+ usbctrl->version = 2;
+ usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+ break;
+
+ default:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("unsupported usb model"));
+ return -1;
+ }
+ }
+
+ if (controller->opts.usbopts.ports == -1)
+ usbctrl->ports = 8;
+ else
+ usbctrl->ports = controller->opts.usbopts.ports;
+
+ return 0;
+}
+
+static int
+libxlMakeUSBControllerList(virDomainDefPtr def, libxl_domain_config *d_config)
+{
+ virDomainControllerDefPtr *l_controllers = def->controllers;
+ size_t ncontrollers = def->ncontrollers;
+ size_t nusbctrls = 0;
+ libxl_device_usbctrl *x_usbctrls;
+ size_t i;
+
+ if (ncontrollers == 0)
+ return 0;
+
+ if (VIR_ALLOC_N(x_usbctrls, ncontrollers) < 0)
+ return -1;
+
+ for (i = 0; i < ncontrollers; i++) {
+ if (l_controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+ continue;
+
+ libxl_device_usbctrl_init(&x_usbctrls[nusbctrls]);
+
+ if (libxlMakeUSBController(l_controllers[i],
+ &x_usbctrls[nusbctrls]) < 0)
+ goto error;
+
+ nusbctrls++;
+ }
+
+ VIR_SHRINK_N(x_usbctrls, ncontrollers, ncontrollers - nusbctrls);
+ d_config->usbctrls = x_usbctrls;
+ d_config->num_usbctrls = nusbctrls;
+
+ return 0;
+
+ error:
+ for (i = 0; i < nusbctrls; i++)
+ libxl_device_usbctrl_dispose(&x_usbctrls[i]);
+
+ VIR_FREE(x_usbctrls);
+ return -1;
+}
+
+int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
{
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
@@ -2165,6 +2256,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
return -1;
#ifdef LIBXL_HAVE_PVUSB
+ if (libxlMakeUSBControllerList(def, d_config) < 0)
+ return -1;
+
if (libxlMakeUSBList(def, d_config) < 0)
return -1;
#endif
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index df318f4..de2a883 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -198,6 +198,10 @@ libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci
*pcidev);
#ifdef LIBXL_HAVE_PVUSB
int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+ libxl_device_usbctrl *usbctrl);
+
+int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
#endif
--
2.1.4