Qemu-kvm cloud desktop usb device redirection method based on rdp protocol
By adding the USB connection channel vmc in the QEMU virtual machine and adding the USB transit module in the host OS, the underlying system-level redirection of the USB device in the cloud desktop environment is realized, and the problem of insufficient redirection function of the USB device in the existing technology is solved, and compatibility and flexibility are improved, and user experience is improved.
Patent Information
- Application Number
- CN202510159042.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2025-05-13
AI Technical Summary
The existing Freerdp protocol cannot automatically map large-capacity USB devices to drives in a cloud desktop environment, and some complex USB devices such as dongles and professional audio devices may not work properly.
Add the USB connection channel vmc in the qemu virtual machine, and add the USB transit module in the host OS, through these modules, the underlying system-level redirection of the USB device is realized.
This method improves the compatibility and flexibility of USB device redirection, solves the problem of insufficient freerdp's original method, realizes normal redirection of USB devices in cloud desktop environment, and improves user experience and functionality.
Smart Images

Figure CN119987952A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of cloud computing, and in particular to a QEMU-KVM cloud desktop USB device redirection method based on an RDP protocol. Background Art
[0002] The RDP protocol is a remote desktop access protocol. Compared with other commonly used protocols, its high performance and low latency are particularly prominent, which can provide users with a good user experience. It is a common technology for cloud desktop access; FreePRDP is an open source implementation of the RDP protocol.
[0003] Qemu-kvm cloud desktop is a cloud computing application based on the Qemu-kvm open source virtualization technology. It has advantages that traditional PCs do not have, such as centralized control, mobile workstations, elastic computing, and remote access. It has become the preferred solution for enterprise IT construction and upgrades. Whether it can support USB and other peripheral device redirection is one of the factors that many companies consider when deploying cloud desktops.
[0004] QEMU-KVM also supports multiple desktop transmission protocols. In a QEMU-KVM-based cloud desktop system, two desktop transmission protocols, SPICE and RDP, are usually used in combination. SPICE is an open source desktop transmission protocol that aims to provide higher performance and lower bandwidth requirements than VNC. RDP is widely used in Windows systems due to its wide support and maturity.
[0005] For example, in an enterprise office environment, a virtual desktop environment can be built through QEMU-KVM technology, and remote access can be achieved through the RDP protocol, thereby improving resource utilization, reducing energy consumption, and enhancing data transmission efficiency. In addition, in this way, enterprises can centrally manage the desktop environment of all users, reduce equipment operation and maintenance costs, and improve office efficiency.
[0006] For example, the patented USB storage device redirection method with publication number CN111666122B includes a terminal and a cloud desktop, wherein the terminal includes a kernel layer iSCSI target driver and an application layer redirection client program, the cloud desktop includes an application layer redirection service program, an application layer iSCSI initiator service and a kernel layer iSCSI initiator driver, the kernel layer iSCSI target driver and the application layer redirection client program interact through the kernel interface at the application layer, the application layer redirection client program and the application layer redirection service program interact through a network socket, the redirection method is not only applicable to USB storage devices, the redirection device is initialized quickly in the virtual machine, the time from device discovery to the appearance of the drive letter and then to the disk is short, and the read and write speed of the redirection device in the virtual machine is also improved; For example, the patent with publication number CN113778917A, a USB device redirection method and apparatus, can solve the problem that using the same filtering rules for all clients does not meet the needs in all scenarios. The specific technical solution is: receiving target client identification information sent by the target client, the target client identification information includes the type and manufacturer information of the target client; determining the target client team where the target client is located according to the target client identification information, wherein the type and manufacturer information of each client in the target client team are consistent with the target client; sending the target filtering rules corresponding to the target client team to the target client, so that the target client redirects the inserted USB device according to the target filtering rules, and the target filtering rules include identification information of at least one USB device that can be redirected; Another example is the patent with publication number CN115022179B, which discloses a cloud desktop system, network redirection method, device and storage medium. It can establish a network redirection channel between the cloud desktop server and the terminal according to the cloud desktop transmission protocol, and redirect the network request initiated by the cloud desktop server to the terminal by establishing a network redirection channel between the cloud desktop server and the terminal. The terminal then performs network access to the destination address of the network request, thus achieving network redirection of the network request of the cloud desktop server. Compared with the traditional network redirection solution, this network redirection method does not require dedicated network configuration, helps improve the efficiency of network redirection, and can reduce the threshold for using cloud desktops and the cost of network redirection.
[0007] FreeRDP has the function of redirecting USB devices, but it has certain limitations. For example, it cannot automatically map large-capacity USB devices as drives; some complex USB dongles, professional USB audio and other devices may not work properly through FreeRDP as they do locally.
[0008] In view of the above problems, it is urgent to carry out innovative design based on the original qemu-kvm cloud desktop USB device redirection method. Summary of the invention
[0009] The purpose of the present invention is to provide a QEMU-KVM cloud desktop USB device redirection method based on the RDP protocol to solve the problem that large-capacity USB devices cannot be automatically mapped as drives in the above background technology; some complex USB dongles, professional USB audio and other devices may not be able to work normally through FreeRDP as directly locally.
[0010] To achieve the above object, the present invention provides the following technical solution: a QEMU-KVM cloud desktop USB device redirection method based on RDP protocol, comprising the following steps: S1. Add USB connection channel vmc in qemu virtual machine; The USB connection channel vmc connects the virtual USB device of the guest OS and the char device in the host OS; S2. Add a USB transfer module to the host OS; The USB transfer module can read and write char devices in the host OS, receive USB command data from the local system where the client is located, and send USB command data of the virtual USB device of the guest OS to the client; S3. When the client logs in, it obtains the rdp connection information of the cloud desktop and the usb transfer module connection information through the management platform; S4. When the client connects to the cloud desktop via RDP, the USB redirection function of RDP is not enabled, and the USB transfer module is connected at the same time; S5. When the user selects the USB device to be redirected, the client opens the corresponding USB device and sends the USB device command data to the USB transfer module; The USB transfer module writes the received local system USB device command data to the char device in the host OS; Finally, the local system USB device command data is sent to the virtual USB device of the guest OS through the USB connection channel, thereby realizing the USB device redirection function.
[0011] Preferably, the qemu virtual machine is started in the host os; One end of the USB connection channel vmc establishes a connection with the virtual machine USB device, and the other end of the USB connection channel vmc is connected to the char device in the host os, so that the host os can directly communicate with the virtual USB device of the guest os.
[0012] Preferably, the USB transfer module is started in the host OS; One end of the USB transfer module is connected to the CHAR device in the host OS, and the other end of the USB transfer module provides a communication interface to the outside.
[0013] Preferably, the client logs in to the server and obtains the rdp connection information of the qemu virtual machine in the host os and the communication interface of the usb transfer module from the server.
[0014] Preferably, the client is connected to the qemu virtual machine in the host os; The client uses the RDP protocol to connect to the QEMU virtual machine in the host OS, and does not enable the USB redirection function of RDP.
[0015] Preferably, the client is connected to a USB transfer module in the host OS; The client establishes a connection with the USB transfer module in the host OS.
[0016] Preferably, when the guest OS writes data to the virtual USB device, the data will be sent from the USB communication channel established above to the locally connected USB device.
[0017] Compared with the prior art, the present invention has the following beneficial effects: The qemu-kvm cloud desktop USB device redirection method based on the RDP protocol realizes the USB device redirection function from the underlying system level. Compared with the original application layer USB device redirection function of freerdp, it has better compatibility and flexibility, and solves the problem of insufficient USB device redirection function of freerdp. Furthermore, a USB connection channel vmc is added to the qemu virtual machine, and a USB transfer module is added to the host os. When the client logs in, the rdp connection information and the USB transfer module connection information of the cloud desktop are obtained through the management platform. When the client connects to the cloud desktop through rdp, the USB redirection function of rdp is not enabled, and the USB transfer module is connected at the same time; Furthermore, when the user selects a USB device to be redirected, the client opens the corresponding USB device and sends the USB device command data to the USB transfer module, and the USB transfer module writes the received local system USB device command data to the char device in the host OS; Finally, the local system USB device command data is sent to the virtual USB device of the guest OS through the USB connection channel, thereby realizing the USB device redirection function and realizing the redirection of USB devices in the qemu-kvm cloud desktop environment based on the RDP protocol, thereby improving the user experience and functionality of the cloud desktop; Instead of using the original USB device redirection function of the RDP protocol, the characteristics of qemu-kvm are used to implement the USB device redirection function of the cloud desktop, optimizing the shortcomings of the RDP protocol. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is an application flow chart of the present invention; Figure 2 It is the principle diagram of the present invention; DETAILED DESCRIPTION The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0019] Example 1: Please refer to Figure 1-Figure 2 , the present invention provides the following technical solutions: A qemu-kvm cloud desktop USB device redirection method based on rdp protocol includes the following steps: S1. Add USB connection channel vmc in qemu virtual machine; The USB connection channel vmc connects the virtual USB device of the guest OS and the char device in the host OS; S2. Add a USB transfer module to the host OS; The USB transfer module can read and write char devices in the host OS, receive USB command data from the local system where the client is located, and send USB command data of the virtual USB device of the guest OS to the client; S3. When the client logs in, it obtains the rdp connection information of the cloud desktop and the usb transfer module connection information through the management platform; S4. When the client connects to the cloud desktop via RDP, the USB redirection function of RDP is not enabled, and the USB transfer module is connected at the same time; S5. When the user selects the USB device to be redirected, the client opens the corresponding USB device and sends the USB device command data to the USB transfer module; The USB transfer module writes the received local system USB device command data to the char device in the host OS; Finally, the local system USB device command data is sent to the virtual USB device of the guest OS through the USB connection channel, thereby realizing the USB device redirection function.
[0020] Through the above steps, USB device redirection can be implemented in the qemu-kvm cloud desktop environment based on the RDP protocol, thereby improving the user experience and functionality of the cloud desktop.
[0021] The role of qemu-kvm is to virtualize hardware devices such as CPU, hard disk, memory, motherboard, etc., so that operating systems such as Windows and Linux can run without installing on personal computers; the role of the RDP protocol is the remote desktop protocol running in the operating system. The RDP protocol itself has the function of USB device redirection, but because it runs at the application layer, its compatibility and flexibility are poor. Qemu-kvm provides external and virtual hardware device communication methods, so USB device redirection can be realized directly from the hardware bottom layer, making the cloud desktop just like inserting a USB device locally; When using USB redirection, be careful not to select USB devices with keywords such as "mouse" and "keyboard", because these devices cannot operate the local system after being redirected, affecting the operating experience; RDP 8.0 is the protocol used by the Windows native client (mstsc.exe). Cloud desktop clients generally use the open source freerdp protocol. Freerdp can be used on both Windows and Linux systems. However, regardless of whether it is the Windows native RDP client or the open source freerdp protocol client, since the RDP service runs at the application layer of the operating system, the compatibility and flexibility of the USB device redirection function are poor. This application does not use the original USB device redirection function of the RDP protocol, but uses the characteristics of qemu-kvm to implement the cloud desktop USB device redirection function and optimize the shortcomings of the RDP protocol.
[0022] Embodiment 2: Start the qemu virtual machine in the host os; One end of the USB connection channel vmc is connected to the virtual machine's USB device, and the other end of the USB connection channel vmc is connected to the char device in hostos, which can enable host os to directly communicate with the guest os's virtual USB device; Start the USB transfer module in the host OS; One end of the USB transfer module is connected to the char device in the host OS, and the other end of the USB transfer module provides a communication interface to the outside; The client logs in to the server and obtains the rdp connection information of the qemu virtual machine in the host os and the communication interface of the usb transfer module from the server; The client connects to the qemu virtual machine in the host os; The client uses the RDP protocol to connect to the QEMU virtual machine in the host OS, and does not enable the USB redirection function of RDP; The client connects to the USB transfer module in the host OS; The client establishes a connection with the USB transfer module in the host OS; When the guest OS writes data to the virtual USB device, the data will be sent to the locally connected USB device through the USB communication channel established above.
[0023] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "connected" and "connection" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0024] Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments, or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A qemu-kvm cloud desktop USB device redirection method based on rdp protocol, characterized in that: The following steps are involved: S1. Add USB connection channel vmc in qemu virtual machine; The USB connection channel vmc connects the virtual USB device of the guest OS and the char device in the host OS; S2. Add a USB transfer module to the host OS; The USB transfer module can read and write char devices in the host OS, receive USB command data from the local system where the client is located, and send USB command data of the virtual USB device of the guest OS to the client; S3. When the client logs in, it obtains the rdp connection information of the cloud desktop and the usb transfer module connection information through the management platform; S4. When the client connects to the cloud desktop via RDP, the USB redirection function of RDP is not enabled, and the USB transfer module is connected at the same time; S5. When the user selects the USB device to be redirected, the client opens the corresponding USB device and sends the USB device command data to the USB transfer module; The USB transfer module writes the received local system USB device command data to the char device in the host OS; Finally, the local system USB device command data is sent to the virtual USB device of the guest OS through the USB connection channel, thereby realizing the USB device redirection function.
2. According to a qemu-kvm cloud desktop USB device redirection method based on RDP protocol according to claim 1, it is characterized in that: Start the qemu virtual machine in the host os; One end of the USB connection channel vmc establishes a connection with a virtual machine USB device, and the other end of the USB connection channel vmc is connected to a char device in hostos, so that host os can directly communicate with the virtual USB device of guest os.
3. According to a qemu-kvm cloud desktop USB device redirection method based on RDP protocol according to claim 2, it is characterized in that: The USB transfer module is started in the host OS; One end of the USB transfer module is connected to the CHAR device in the host OS, and the other end of the USB transfer module provides a communication interface to the outside.
4. According to a qemu-kvm cloud desktop USB device redirection method based on rdp protocol according to claim 1, it is characterized in that: The client logs in to the server and obtains the rdp connection information of the qemu virtual machine in the host os and the communication interface of the usb transfer module from the server.
5. According to a qemu-kvm cloud desktop USB device redirection method based on RDP protocol according to claim 4, it is characterized in that: The client connects to the qemu virtual machine in the host os; The client uses the RDP protocol to connect to the QEMU virtual machine in the host OS, and does not enable the USB redirection function of RDP.
6. According to a qemu-kvm cloud desktop USB device redirection method based on rdp protocol according to claim 4, it is characterized in that: The client is connected to the USB transfer module in the host OS; The client establishes a connection with the USB transfer module in the host OS.
7. According to a qemu-kvm cloud desktop USB device redirection method based on rdp protocol according to claim 1, it is characterized in that: When the guest OS writes data to the virtual USB device, the data will be sent to the locally connected USB device through the USB communication channel established above.
Citation Information
Patent Citations
A novel method for redirecting USB storage devices
CN111666122B
USB (Universal Serial Bus) equipment redirection method and device
CN113778917A
Cloud desktop system, network redirection method, device and storage medium
CN115022179B