CN-122001878-A - USB redirection system and method based on spice protocol
Abstract
The invention discloses a system and a method for USB redirection based on a spice protocol, wherein the method is applied to a system comprising a terminal machine and a target cloud desktop, libusbip library components independent of usbip application layers are configured to bind or unbind USB equipment, then the terminal machine modifies a spice client to support USB equipment plug management and interface display, finally the target cloud desktop modification SPICE SERVER establishes channel connection with the terminal machine usbip channel, a service program is introduced to call SPICE SERVER and libusbip component interfaces, and binding and unbinding of redirected USB equipment and vhci-hcd virtual drive are completed. The invention is independent of the environment configuration of the QEMU back end in the USB use of the cloud desktop.
Inventors
- ZHOU ZONGMIN
- XIE MING
- HE MINHONG
- YU JUN
Assignees
- 银河麒麟软件(长沙)有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260127
Claims (8)
- 1. A USB redirection system based on a spice protocol comprises a terminal machine and a target cloud desktop, and is characterized in that the terminal machine and the target cloud desktop are configured with libusbip library components independent of usbip application layers, the libusbip library components interact with kernel drivers of the corresponding terminal machine or the target cloud desktop to achieve binding or unbinding of USB equipment, the terminal machine modifies a spice client to support plug management and interface display of the USB equipment to achieve redirection selection of the USB equipment through the spice client, the target cloud desktop modifies SPICE SERVER to establish channel connection with usbip channel of the terminal machine, and a service program call SPICE SERVER and libusbip component interface are introduced to achieve binding and unbinding of the redirected USB equipment and kernel vhci-hcd driving modules of the target cloud desktop.
- 2. The USB redirection system based on spice protocol as defined in claim 1, wherein a self-starting script is introduced inside the terminal machine, and the self-starting script uses a module-load to start up a kernel usbip-host driver module of the self-starting terminal machine, and uses SYSTEMD SERVICE to serve a usbipd daemon on the side of the self-starting terminal machine.
- 3. The USB redirection system based on the spice protocol according to claim 1, wherein when the terminal machine modifies spic clients, the system specifically comprises: The method is realized by adding usbip channel channels in the spice-gtk, the request and the equipment information of the attach or detach are sent to SPICE SERVER of the target cloud desktop, and the result information replied by SPICE SERVER is acquired through a MSG HANDLER interface for corresponding processing; Adding usbip DEVICE MANAGER modules to the spice-gtk, completing insertion or removal monitoring of the USB equipment based on the libusb interface, and maintaining a current equipment list of the USB equipment, information of each equipment and a redirection state; And a usbip DEVICE WIDGET module is added in the spice-gtk, wherein the usbip DEVICE WIDGET module manages usbip equipment controls based on GtkBox and GTKWIDGET, achieves UI display and user behavior interaction of the USB equipment, and performs USBIP-based redirection starting and canceling according to user key selection.
- 4. The USB redirection system based on the spice protocol according to claim 3, wherein the usbip DEVICE MANAGER module provides an interface to the UI layer and usbip channel channel, interacts with the libusbip library component of the terminal machine, and completes the binding and unbinding of the USB device on the kernel usbip-host driver module of the terminal machine side and the command request and processing on the cloud desktop side according to the user behavior.
- 5. A USB redirection system based on the spice protocol as defined in claim 3, wherein when the target cloud desktop is modified SPICE SERVER, the processing of the subtype_ USBIP type CHAR DEVICE is further added, and the service program adds usbip SPICE INTERFACE interfaces and corresponding CHAR DEVICE INSTANCE instances, and registers with SPICE SERVER, so as to monitor data sent by usbip channel channels.
- 6. A USB redirection system based on the SPICE protocol as claimed in claim 3, characterized in that when the target cloud desktop modifies SPICE SERVER to establish a CHANNEL connection with the usbip CHANNEL of the end machine, in particular a SPICE CHANNEL USBIP CHANNEL is created and enabled, which SPICE CHANNEL USBIP CHANNEL establishes a CHANNEL connection with usbip CHANNEL.
- 7. The USB redirection system based on the spice protocol according to claim 1, wherein when the service program invokes SPICE SERVER and libusbip component interfaces to complete binding and unbinding of the redirection USB device and the kernel vhci-hcd driver of the target cloud desktop, the system specifically comprises: calling and starting SPICE SERVER a service by a service program, waiting for connection of a spice client of a terminal machine and establishing connection; When the terminal machine sends a request command, the service program receives data through a write interface, completes the attach or detach action of the USB equipment and the kernel vhci-hcd driving module of the target cloud desktop through a libusbip interface according to the command type, and returns an execution result to the terminal machine.
- 8. A USB redirection method based on a spice protocol, wherein the method is applied to the USB redirection system based on a spice protocol according to any one of claims 1 to 7, and the method comprises the following steps: Starting up a kernel usbip-host driving module of the self-starting terminal machine by using a self-starting script through a module-load, and starting up a usbipd daemon on the side of the self-starting terminal machine by using SYSTEMD SERVICE service; invoking and starting SPICE SERVER a service by using a service program, waiting for connection of a spice client of the terminal machine and establishing connection; If the user interacts with usbip DEVICE WIDGET module of the terminal machine to start redirection based on USBIP, after usbip DEVICE MANAGER module of the terminal machine monitors insertion or removal of the USB device, libusbip library is called to bind or unbind the USB device on usbip-host driving module of the terminal machine side core, current device list of the USB device and information and redirection state of each device are updated, and then corresponding information is displayed through usbip DEVICE WIDGET module of the terminal machine; The spice client sends an attach request and device information of the USB device bound at a terminal machine side kernel usbip-host driving module or a detach request and device information of the USB device unbound at a terminal machine side kernel usbip-host driving module to a target cloud desktop through a usbip channel channel of the terminal machine; The service program of the target cloud desktop receives request data of a SUBTYPE_ USBIP type CHAR DEVICE through a write interface, completes the attach or detach action of the USB device and the kernel vhci-hcd driving module of the target cloud desktop through a libusbip interface according to the command type, and returns an execution result to a usbip CHANNEL CHANNEL of the terminal machine through a SPICE_CHANNEL_ USBIP CHANNEL.
Description
USB redirection system and method based on spice protocol Technical Field The invention relates to the field of cloud computing, in particular to a USB redirection system and method based on a spice protocol. Background With the development of cloud computing, a cloud desktop platform is widely applied, so that the work of desktop delivery is simplified, and the burden of enterprises on PC management and operation and maintenance is reduced. The concepts of virtualization and cloud desktops are increasingly being understood and accepted by users. However, when using a conventional desktop, i.e. using USB technology to interact with a large number of peripherals, most of the work is related to USB peripherals. Therefore, support for USB technology is necessarily introduced when the cloud desktop is used, so that compatibility and interaction of the virtual desktop to the peripheral are achieved, and the virtual desktop can achieve user experience the same as that of a traditional desktop. The current use of locally connected USB devices in remote virtual desktops relies primarily on USB redirection techniques. In a cloud desktop architecture of qemu+kvm+spice remote protocol currently used mainly, a USB redirection technology is adopted based on USB device redirection, a USB2 EHCI or a USB3 XHCI virtual controller which is simulated by the QEMU back end is needed, and the number of USB devices which can be simultaneously redirected is determined according to the number of spicevmc channels added. Meanwhile, because the redirection of the USB device is realized at an application layer, data interaction is performed between two different peripheral drivers through protocol conversion, and therefore if a driver which does not conform to a peripheral protocol standard is provided by a peripheral manufacturer, the device cannot be well identified, and the compatibility is poor. The invention patent of publication number CN115269482A discloses a method for supporting connection of a plurality of USB devices, by acquiring the addresses and the device attributes of the USB devices recorded in a server, identifying, enumerating and driving the accessed USB devices by a USB system, acquiring the addresses and the device attributes of the USB devices recorded in the server, identifying, enumerating and driving the accessed USB devices by the USB system, sending a USB device detection instruction by a client to enable the server to receive the instruction and send the instruction to the server, receiving the instruction by the server to a daemon, processing complete data by the daemon and continuously executing a monitoring task through a subprocess, and realizing the network access function of USB without changing internal hardware of the USB devices, thus not only recycling the USB devices with old versions, but also improving the stability of network communication and the accuracy of data transmission in the network transmission in the fantasy traditional sense. However, this approach is a description of the USBIP original scheme. The patent of publication No. CN117478719A discloses a universal USB device remote mapping method and system based on DWC3, comprising the following steps of connecting USB devices to a mapping machine, performing P2P networking connection between the mapping machine and an intermediate machine, connecting the intermediate machine to a target machine, starting USBIP Server on the mapping machine, starting USBIP Client on the intermediate machine, acquiring a shared USB device list on the mapping machine USBIP server, connecting the shared USB devices, acquiring configuration information of the USB devices shared through USBIP by the intermediate machine through libusb, connecting a target machine USB Host, enumerating the USB devices, and transmitting or receiving data packets of actual USB devices by the target machine Host through the intermediate machine libusb. However, the method is based on USBIP technology, but the implementation architecture comprises a mapping machine, a middleware machine and a target machine. Disclosure of Invention Aiming at the problems in the prior art, the invention provides a USB redirection system and a method based on a spice protocol, which are used for enabling usbip technology to be accessed and used on a spice protocol cloud desktop, so that a cloud desktop user can autonomously select redirection equipment without relying on the original QEMU+ spice usbredir redirection flow, only two parts of a terminal machine and the terminal cloud desktop are needed, and then the spice protocol is used for communication, so that the whole function construction is completed. In order to solve the technical problems, the invention adopts the following technical scheme: A USB redirection system based on a spice protocol comprises a terminal machine and a target cloud desktop, wherein the terminal machine and the target cloud desktop are configured with libusbip libra