[virt-tools-list] [PATCH 0/3] virt-viewer: add SIGINT handler

Francesco Giudici fgiudici at redhat.com
Fri Nov 29 17:58:10 UTC 2019



On 12/11/19 15:40, Daniel P. Berrangé wrote:
> On Tue, Nov 12, 2019 at 12:29:09PM +0100, Francesco Giudici wrote:
>> When remote-viewer or virt-viewer are terminated by a signal, they quit
>> without explicitly releasing resources. A bug[1] has been filed against
>> virt-viewer for not releasing redirected usb devices when it's terminated
>> by CTRL-C. Clearly this could be solved by adding a signal handler doing
>> proper shutdown of the application.
> 
> All resources used by a process are automatically released by the
> kernel when the process exits.
> 
> IOW, doing a "graceful exit" to manually release USB devices should
> not be required, not least because we want everything to behave
> well even in the face of an abnormal application crash where we have
> no way to manually releasing devices.
> 
> Can you explain what is preventing the USN device release from the
> kernel POV ?

To perform usb device redirection, virt-viewer leverages spice-gtk 
library, which in turn relies on usbredir library, which uses libusb.
In order to take control of the usb device the auto-loaded kernel driver 
must be detached. This is achieved (in the very end) with 
libusb_detach_kernel_driver(). Then the device interfaces can be claimed 
with libusb_claim_interface() and get in control to the application.
During normal application termination, the usb channel is teared down, 
performing a reset of the usb device and giving back the control of the 
device to the kernel (libusb_attach_kernel_driver()).
If the application quits without doing this, the device interfaces will 
end up with no driver attached, making them not usable in the host system.

Note that enabling libusb_set_auto_detach_kernel_driver() does not solve 
the issue, as this is just a convenient API from libusb: libusb will 
take care of detaching/attaching the driver to the interfaces of the usb 
device each time a call to libusb_release_interface() and 
libusb_claim_interface() is performed. An unexpected quit of the 
application will skip the libusb_release_interface() call too, leaving 
the interfaces without any driver attached.
Moreover, also assuming that the driver would be somehow attached, we 
would like to have a reset performed on the device, to not give back the 
device in some "dirty" state.

For these reasons we need a clean exit to get back the control from the 
redirected usb devices. Honestly, the SIGINT scenario is not that 
critical btw, but seems to me that adding the handler would not harm.
Opinions?

Thanks
Francesco

> 
> 
> Regards,
> Daniel
> 





More information about the virt-tools-list mailing list