On Wed, 2016-06-15 at 14:00 +0800, Chunyan Liu wrote: > 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@xxxxxxxx> > --- > Changes: > drop pvusb1 and pvusb2 models > > src/libxl/libxl_conf.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ > src/libxl/libxl_conf.h | 4 +++ > 2 files changed, 88 insertions(+) > > diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c > index 5989819..a7d91d3 100644 > --- a/src/libxl/libxl_conf.c > +++ b/src/libxl/libxl_conf.c > @@ -1516,6 +1516,87 @@ 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_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; > @@ -1787,6 +1868,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 8cb2b14..ed5a3de 100644 > --- a/src/libxl/libxl_conf.h > +++ b/src/libxl/libxl_conf.h > @@ -186,6 +186,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 > ACK and pushed -- Cedric -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list