Re: [PATCH V2 4/7] libxl: check available controller and port when hotplugging USB device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2016-06-15 at 14:00 +0800, Chunyan Liu wrote:
> When hotplug a USB device, check if there is available controller

typos:
When hotplugging a USB device, check if there is an available controller

> and port, if not, automatically create a USB controller of version
> 2.0 and 8 ports.
> 
> Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
> ---
>  src/libxl/libxl_driver.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index f614769..d9d7e3c 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -3068,6 +3068,8 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
>      libxl_device_usbdev usbdev;
>      virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
>      int ret = -1;
> +    size_t i;
> +    int ports = 0, usbdevs = 0;
>  
>      libxl_device_usbdev_init(&usbdev);
>  
> @@ -3075,6 +3077,36 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
>          hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
>          goto cleanup;
>  
> +    /* search for available controller:port */
> +    for (i = 0; i < vm->def->ncontrollers; i++)
> +        ports += vm->def->controllers[i]->opts.usbopts.ports;
> +
> +    for (i = 0; i < vm->def->nhostdevs; i++) {
> +        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> +            hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
> +            usbdevs++;
> +    }
> +
> +    if (ports <= usbdevs) {
> +        /* no free ports, we will create a new usb controller */
> +        virDomainControllerDefPtr controller;
> +
> +        if (!(controller = virDomainControllerDefNew(VIR_DOMAIN_CONTROLLER_TYPE_USB)))
> +            goto cleanup;
> +
> +        controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
> +        controller->idx = -1;
> +        controller->opts.usbopts.ports = 8;
> +
> +        if (libxlDomainAttachControllerDevice(driver, vm, controller) < 0) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("No available USB controller and port, and "
> +                             "failed to attach a new USB controller"));

Rewording: "and failed to attach a new one"

> +            virDomainControllerDefFree(controller);
> +            goto cleanup;
> +        }
> +    }
> +
>      if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
>          goto cleanup;
>  

ACK and pushed with the wording changes.

--
Cedric

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]