A method and related device for passing through USB devices in a virtualized environment

By identifying USB interface device information in a virtualized environment and adopting appropriate pass-through methods, the problem that virtual machines cannot pass through storage devices and network card devices based on non-USB protocol communication is solved, and efficient pass-through of different types of USB devices is achieved, improving the availability of the virtualized environment.

CN114995953BActive Publication Date: 2025-05-02JINAN INSPUR DATA TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210611052.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2025-05-02
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

The prior art has difficulty in passing the USB devices in a virtualized environment, especially storage devices and network card devices based on non-USB protocol communication, resulting in virtual machines being unable to use these devices.

Method used

By obtaining device pass-through instructions, identifying the device information connected to the device by the USB interface, and using the virtual machine to pass through the bare disk or network card according to the device type, the device is directly connected to the virtual machine.

Benefits of technology

Pass-through to different types of devices connected through the USB interface is realized, including storage devices and network card devices that cannot communicate through the USB protocol, improving the availability of the virtualized environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114995953B_ABST
    Figure CN114995953B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and related device for passing through USB devices in a virtualized environment, which are applied to the field of virtual machine technology, including: obtaining a device pass-through instruction; obtaining device information of a device connected to a host through a USB interface according to the device pass-through instruction; a virtual machine is established on the host; when the device information indicates that the device is a storage device based on non-USB protocol communication, the device is passed through to the virtual machine in the form of a virtual machine passing through a bare disk; when the device information indicates that the device is a network card device, the device is passed through to the virtual machine in the form of a virtual machine passing through a network card. The device information of the device connected to the USB interface is identified, and a storage device that cannot communicate through the USB protocol is directly mapped to the virtual machine in the form of a pass-through bare disk, and a network card device is directly mapped to the virtual machine in the form of a pass-through network card, so that different types of devices connected through the USB interface can be passed through to the virtual machine, thereby having high availability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of virtual machines, and in particular to a method for passing through a USB device in a virtualized environment, an apparatus for passing through a USB device in a virtualized environment, a device for passing through a USB device in a virtualized environment, and a computer-readable storage medium. Background Art

[0002] With the development and popularization of virtualization technology, facing complex and diverse application scenarios, virtualization technology needs to be continuously updated and iterated to solve the problems brought by these scenarios. USB (Universal Serial Bus) device passthrough is a common and widely used function in virtualization application scenarios. It can pass the USB device on the host to the virtual machine, so that the virtual machine can use the device like the host, and the USB device can run normally regardless of the operating system installed on the virtual machine.

[0003] In virtualization scenarios, common USB devices include USB keys (smart password keys), USB dongles, ordinary U disks, mobile hard disks, etc. When these devices on the host are directly connected to the virtual machine, the operating system inside the virtual machine will obtain the corresponding device information based on the device descriptor of the USB device, and select a suitable USB device driver to load, and finally realize data communication between the virtual machine and the host USB device; however, with the popularity of various USB interface devices on the market, the demand for USB pass-through is no longer limited to the above-mentioned conventional device types. With the emergence of special devices such as NVMe (Non Volatile Memory Host Controller Interface Specification) hard disk boxes and USB network cards with USB interfaces, virtualization technology needs to further cover these special scenarios.

[0004] If the conventional pass-through USB device steps are used to pass through these devices, problems will occur when the operating system inside the virtual machine loads the USB driver. For example, the NVMe hard disk box has an interface device protocol type of NVMe, so it cannot use the conventional USB protocol for communication, resulting in the virtual machine being unable to use the device. Therefore, how to provide a technical solution for pass-through USB devices in a virtualized environment with high availability is an urgent problem that technicians in this field need to solve. Summary of the invention

[0005] An object of the present invention is to provide a method for passing through a USB device in a virtualized environment, which has high availability; another object of the present invention is to provide an apparatus for passing through a USB device in a virtualized environment, a device for passing through a USB device in a virtualized environment, and a computer-readable storage medium, which have high availability.

[0006] In order to solve the above technical problems, the present invention provides a method for passing through a USB device in a virtualized environment, comprising:

[0007] Get device direct access instructions;

[0008] According to the device direct instruction, the device information of the device connected to the host through the USB interface is obtained; the host has a virtual machine established;

[0009] When the device information indicates that the device is a storage device based on non-USB protocol communication, the device is directly connected to the virtual machine in a manner of directly connecting the virtual machine to a bare disk;

[0010] When the device information indicates that the device is a network card device, the device is directly connected to the virtual machine in the form of a virtual machine directly connected to the network card.

[0011] Optionally, the acquiring device information of a device connected to the host through a USB interface according to the device pass-through instruction further includes:

[0012] When the device information indicates that the device is a USB device, the bus number and the device number to which the device belongs are transmitted to the virtual machine, so as to directly connect the device to the virtual machine.

[0013] Optionally, the USB device includes a USB flash drive and a dongle.

[0014] Optionally, acquiring device information of a device connected to the host through a USB interface according to the device pass-through instruction includes:

[0015] Scan the device information corresponding to the connected device through the USB interface according to the device pass-through instruction;

[0016] Query the bus information of the storage device to determine the device information corresponding to the device whose interface type is the USB interface;

[0017] Query the bus information of the network card to determine the device information corresponding to the device whose interface type is the USB interface.

[0018] Optionally, the step of directly connecting the device to the virtual machine by directly connecting the virtual machine to a raw disk includes:

[0019] A disk storage block configuration file is created for the virtual machine, and a source parameter in the disk storage block configuration file is designated as identification information of the storage device, so as to directly pass the storage device to the virtual machine.

[0020] Optionally, the storage device includes a hard disk box of VMe.

[0021] Optionally, the step of directly connecting the device to the virtual machine in the form of a virtual machine direct network card includes:

[0022] An interface configuration file is created for the virtual machine, a MAC address of the network card device is specified for the interface configuration file, and information of the network card device is passed into a source parameter of the interface configuration file to directly connect the network card device to the virtual machine.

[0023] The present invention also provides a device for passing through a USB device in a virtualized environment, comprising:

[0024] The instruction acquisition module is used to obtain the device direct instruction;

[0025] A device information acquisition module is used to acquire device information of a device connected to the host through a USB interface according to the device direct instruction; the host has a virtual machine established;

[0026] A storage device direct access module, used for directly connecting the device to the virtual machine in a manner of direct access from the virtual machine to a bare disk when the device information indicates that the device is a storage device based on non-USB protocol communication;

[0027] The network card device direct pass module is used to connect the device to the virtual machine in the form of a virtual machine direct pass network card when the device information indicates that the device is a network card device.

[0028] Optionally, also include:

[0029] The USB device pass-through module is used to transfer the bus number and device number of the device to the virtual machine when the device information indicates that the device is a USB device, so as to pass the device directly to the virtual machine.

[0030] Optionally, the device information acquisition module includes:

[0031] A USB interface scanning unit, used to scan the device information corresponding to the connected device through the USB interface according to the device pass-through instruction;

[0032] The storage device bus query unit is used to query the bus information of the storage device and determine the device information corresponding to the device whose interface type is a USB interface;

[0033] The network card device bus query unit is used to query the bus information of the network card and determine the device information corresponding to the device whose interface type is the USB interface.

[0034] The present invention also provides a device for passing through a USB device in a virtualized environment, the device comprising:

[0035] Memory: used to store computer programs;

[0036] Processor: used to implement the steps of the method of passing through a USB device in a virtualized environment as described in any of the above items when executing the computer program.

[0037] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for passing through a USB device in a virtualized environment as described in any one of the above items are implemented.

[0038] The present invention provides a method for passing through a USB device in a virtualized environment, comprising: obtaining a device passing through instruction; obtaining device information of a device connected to a host through a USB interface according to the device passing through instruction; a virtual machine is established on the host; when the device information indicates that the device is a storage device based on non-USB protocol communication, the device is passed through to the virtual machine in a manner of passing through a bare disk by the virtual machine; when the device information indicates that the device is a network card device, the device is passed through to the virtual machine in a manner of passing through the network card by the virtual machine.

[0039] By identifying the device information of the device connected to the USB interface, the storage device that cannot communicate through the USB protocol can be directly mapped to the virtual machine by directly passing through the raw disk, and the network card device can be directly mapped to the virtual machine by directly passing through the network card. This can achieve direct connection of different types of devices connected through the USB interface to the virtual machine, thereby achieving high availability.

[0040] The present invention also provides a device for passing through a USB device in a virtualized environment, a device for passing through a USB device in a virtualized environment, and a computer-readable storage medium, which also have the above-mentioned beneficial effects and will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions of the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1A flowchart of a method for passing through a USB device in a virtualized environment provided by an embodiment of the present invention;

[0043] Figure 2 A flowchart of a method for passing through a USB device in a specific virtualized environment provided by an embodiment of the present invention;

[0044] Figure 3 A structural block diagram of a device for passing through a USB device in a virtualized environment provided by an embodiment of the present invention;

[0045] Figure 4 A device structure block diagram of a pass-through USB device in a virtualized environment provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The core of the present invention is to provide a method for passing through USB devices in a virtualized environment. In the prior art, with the popularity of various USB interface devices on the market, the demand for USB pass-through is no longer limited to conventional device types. With the emergence of special devices such as NVMe hard disk boxes and USB network cards with USB interfaces, virtualization technology needs to further cover these special scenarios. If the conventional steps of passing through USB devices are used to pass through these devices, problems will occur in the internal operating system of the virtual machine when loading the USB driver. Taking the NVMe hard disk box as an example, its interface device protocol type is NVMe, so it cannot use the conventional USB protocol for communication, resulting in the virtual machine being unable to use the device.

[0047] The present invention provides a method for passing through a USB device in a virtualized environment, comprising: obtaining a device pass-through instruction; obtaining device information of a device connected to a host through a USB interface according to the device pass-through instruction; a virtual machine is established on the host; when the device information indicates that the device is a storage device based on non-USB protocol communication, the device is passed through to the virtual machine in the form of a virtual machine passing through a bare disk; when the device information indicates that the device is a network card device, the device is passed through to the virtual machine in the form of a virtual machine passing through a network card.

[0048] By identifying the device information of the device connected to the USB interface, the storage device that cannot communicate through the USB protocol can be directly mapped to the virtual machine by directly passing through the raw disk, and the network card device can be directly mapped to the virtual machine by directly passing through the network card. This can achieve direct connection of different types of devices connected through the USB interface to the virtual machine, thereby achieving high availability.

[0049] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0050] Please refer to Figure 1 , Figure 1 The present invention provides a flowchart of a method for passing through a USB device in a virtualized environment.

[0051] See also Figure 1 In an embodiment of the present invention, a method for passing through a USB device in a virtualized environment includes:

[0052] S101: Obtain a device direct access instruction.

[0053] First of all, it should be noted that the method provided in the embodiment of the present invention is mainly applied to a host, which needs to have a virtual environment and a virtual machine. In the embodiment of the present invention, it is necessary to pass the device connected to the USB interface in the host to the virtual machine for use. Specifically, in this step, the host first needs to obtain a device pass-through instruction to trigger the subsequent steps. The specific content and triggering conditions of the device pass-through instruction can be set according to the actual situation, and are not specifically limited here.

[0054] S102: Obtain device information of a device connected to the host via a USB interface according to the device pass-through instruction.

[0055] In an embodiment of the present invention, a virtual machine is established on the host. In this step, it is necessary to obtain the device information of the device connected to the host through the USB interface according to the above-mentioned device pass-through instruction. The device information can specifically characterize the type of the corresponding device, such as whether it is a storage device, a network card device, an ordinary USB device, etc. The specific acquisition and determination process of the relevant device information will be described in detail in the following invention embodiments, and will not be repeated here. In this step, the device information can specifically characterize the type of the corresponding device, and the devices are all devices connected to the host through the USB interface.

[0056] S103: When the device information indicates that the device is a storage device based on non-USB protocol communication, the device is directly connected to the virtual machine in a manner of directly connecting the virtual machine to a raw disk.

[0057] In this step, when it is determined based on the above device information that the host is connected via a USB interface, and the host needs to directly pass through the device to the virtual machine, it is a storage device based on non-USB protocol communication, such as an NVMe hard disk box that communicates based on the NVMe protocol, etc. Although this type of storage device is connected to the host via a USB interface, its communication protocol is not the USB protocol, but other, such as the NVMe protocol, etc. for communication. For this type of storage device based on non-USB protocol communication, it is necessary to directly map the storage device to the virtual machine by directly passing through the bare disk, that is, adding a bare disk in the virtual machine, to achieve direct access to this type of storage device. The specific content of this step will be described in detail in the following invention embodiments, and will not be repeated here.

[0058] S104: When the device information indicates that the device is a network card device, the device is directly connected to the virtual machine in the form of the virtual machine directly connecting to the network card.

[0059] In addition to the above storage devices, the host cannot directly pass the USB network card to the virtual machine through the conventional USB device direct pass method. In this step, when it is determined according to the above device information that the device connected to the host through the USB interface and the host needs to directly pass to the virtual machine is a network card device, the network card device connected to the host through the USB interface will be directly passed to the virtual machine in the form of a virtual machine direct pass network card, rather than using the conventional USB protocol-based direct pass USB device method to directly pass the network card device. The specific content of this step will be described in detail in the following invention embodiments, and will not be repeated here.

[0060] A method for passing through USB devices in a virtualized environment provided by an embodiment of the present invention identifies device information of devices connected to a USB interface, directly maps storage devices that cannot communicate through a USB protocol to a virtual machine by passing through a bare disk, and directly maps a network card device to a virtual machine by passing through a network card. This method can achieve direct passing through of different types of devices connected through a USB interface to the virtual machine, thereby having high availability.

[0061] The specific contents of the method for passing through a USB device in a virtualized environment provided by the present invention will be described in detail in the following embodiments of the invention.

[0062] Please refer to Figure 2 , Figure 2 The present invention provides a flowchart of a method for passing through a USB device in a specific virtualized environment.

[0063] See also Figure 2 In an embodiment of the present invention, a method for passing through a USB device in a virtualized environment includes:

[0064] S201: Obtain device direct access instructions.

[0065] This step is basically the same as S101 in the above-mentioned embodiment of the invention. Please refer to the above-mentioned embodiment of the invention for details, and will not be described again here.

[0066] S202: Scanning device information corresponding to the connected device through the USB interface according to the device pass-through instruction.

[0067] In this step, the host first scans the device information corresponding to the connected device based on the USB interface in the host based on the above-mentioned device pass-through instruction. In this step, it is usually necessary to scan the device information of all devices connected to the USB interface in the host. It should be noted that since this step is specifically based on the USB interface and the device information obtained through the USB protocol, the device information scanned in this step can usually only represent the existence of each device connected through the USB interface, but cannot represent the specific type of each device. It cannot directly identify whether there is a storage device based on non-USB protocol communication, as well as a network card device, etc., which needs to be identified according to subsequent steps.

[0068] S203: Query bus information of the storage device to determine device information corresponding to the device whose interface type is a USB interface.

[0069] In this step, the host will query the bus information of its storage device. Specifically, the command can be used to query the bus information of the storage device. If the bus information indicates that the storage devices connected to the host are all PCI (Peripheral Component Interconnect) devices, this step can be ignored. If the above bus information indicates that the interface type corresponding to the storage device connected to the host has a USB interface, then the storage device can be determined to be a storage device based on non-USB protocol communication, that is, the device information corresponding to the device whose interface type is determined to be a USB interface in this step is the device information that can characterize the device as a storage device based on non-USB protocol communication.

[0070] S204: Query the bus information of the network card to determine the device information corresponding to the device whose interface type is the USB interface.

[0071] In this step, the host will query the bus information of its network card. Specifically, ethtool can be used to query the bus information of the network card. If the bus information indicates that the network card connected to the host is connected to the host based on a USB interface, that is, the interface type corresponding to the network card is a USB interface, then the network card device can be identified as a network card device connected to the host based on the USB interface, that is, the device information corresponding to the device with the interface type determined as a USB interface in this step is the device information that can characterize the device as a network card device.

[0072] After this step, the specific type of the device connected to the USB interface can be determined based on the above S203 and S204, and the device information obtained by scanning can be divided into ordinary USB devices that communicate based on the USB protocol, which usually include USB flash drives, dongles, or other similar devices; and storage devices based on non-USB protocol communication, such as NVMe hard disk boxes, etc.; and network card devices. It should be noted that each of the above devices is connected to the host through the USB interface of the host. There is no clear order between the above S203 and S204. It is possible to execute any one step first or execute both steps in parallel, and no specific limitation is made here.

[0073] S205: When the device information indicates that the device is a USB device, the bus number and the device number to which the device belongs are transmitted to the virtual machine, so as to directly connect the device to the virtual machine.

[0074] In this step, for common USB devices, including USB flash drives and dongles, i.e., the above devices that communicate based on the USB protocol, the bus number and device number to which they belong can be directly transferred to the virtual machine, i.e., the conventional method of directly connecting a device connected to the host via a USB interface to the virtual machine is used to connect the above USB devices to the virtual machine. The bus number and device number are equivalent to the identification information of the USB device, which will not be described in detail here.

[0075] S206: When the device information indicates that the device is a storage device based on non-USB protocol communication, a disk storage block configuration file is created for the virtual machine, and a source parameter in the disk storage block configuration file is specified as identification information of the storage device to directly pass the storage device to the virtual machine.

[0076] In this step, for storage devices including NVMe hard disk boxes, that is, storage devices based on non-USB protocol communication, you can first create a disk storage block configuration file in the virtual machine, that is, create a block disk configuration file for the virtual machine; the source parameter in the configuration file, that is, the source dev parameter needs to be specified as the identification information of the above-mentioned storage device, such as scsi id (small computer system interface identifier), and then pass the storage device directly to the virtual machine, that is, by adding a bare disk, the above-mentioned storage device connected to the USB interface can operate normally in the virtual machine.

[0077] S207: When the device information indicates that the device is a network card device, create an interface configuration file for the virtual machine, specify a MAC address of the network card device for the interface configuration file, and pass the information of the network card device into a source parameter of the interface configuration file to directly connect the network card device to the virtual machine.

[0078] In this step, for the network card device connected through the USB interface, you can first create an interface configuration file in the virtual machine, that is, the interface configuration file; the configuration file needs to specify the mac (Media Access Control Address) address of the network card device, and then pass the information of the network card device into the source parameter of the interface configuration file, that is, into the source parameter of the configuration file, to realize the direct connection of the network card device to the virtual machine.

[0079] A method for passing through USB devices in a virtualized environment provided by an embodiment of the present invention identifies device information of devices connected to a USB interface, directly maps storage devices that cannot communicate through a USB protocol to a virtual machine by passing through a bare disk, and directly maps a network card device to a virtual machine by passing through a network card. This method can achieve direct passing through of different types of devices connected through a USB interface to the virtual machine, thereby having high availability.

[0080] The following is an introduction to a device for passing through a USB device in a virtualized environment provided by an embodiment of the present invention. The device for passing through a USB device in a virtualized environment described below and the method for passing through a USB device in a virtualized environment described above can refer to each other.

[0081] Please refer to Figure 3 , Figure 3 The present invention provides a structural block diagram of an apparatus for passing through a USB device in a virtualized environment.

[0082] See also Figure 3 In an embodiment of the present invention, the apparatus for passing through a USB device in a virtualized environment may include:

[0083] The instruction acquisition module 100 is used to acquire device direct access instructions.

[0084] The device information acquisition module 200 is used to acquire device information of a device connected to the host through a USB interface according to the device direct instruction; the host has a virtual machine established.

[0085] The storage device direct access module 300 is used to connect the device to the virtual machine in a manner of direct access from the virtual machine to a raw disk when the device information indicates that the device is a storage device based on non-USB protocol communication.

[0086] The network card device direct access module 400 is used to connect the device to the virtual machine in the form of a virtual machine direct access network card when the device information indicates that the device is a network card device.

[0087] Preferably, in the embodiment of the present invention, it also includes:

[0088] The USB device pass-through module is used to transfer the bus number and device number of the device to the virtual machine when the device information indicates that the device is a USB device, so as to pass the device directly to the virtual machine.

[0089] Preferably, in the embodiment of the present invention, the USB device includes a USB flash drive and a dongle. Preferably, in the embodiment of the present invention, the device information acquisition module includes:

[0090] A USB interface scanning unit, used to scan the device information corresponding to the connected device through the USB interface according to the device pass-through instruction;

[0091] The storage device bus query unit is used to query the bus information of the storage device and determine the device information corresponding to the device whose interface type is a USB interface;

[0092] The network card device bus query unit is used to query the bus information of the network card and determine the device information corresponding to the device whose interface type is the USB interface.

[0093] Preferably, in the embodiment of the present invention, the storage device pass-through module 300 is specifically used for:

[0094] A disk storage block configuration file is created for the virtual machine, and a source parameter in the disk storage block configuration file is designated as identification information of the storage device, so as to directly pass the storage device to the virtual machine.

[0095] Preferably, in an embodiment of the present invention, the storage device includes a hard disk box of VMe.

[0096] Preferably, in the embodiment of the present invention, the network card device pass-through module 400 is specifically used for:

[0097] An interface configuration file is created for the virtual machine, a MAC address of the network card device is specified for the interface configuration file, and information of the network card device is passed into a source parameter of the interface configuration file to directly connect the network card device to the virtual machine.

[0098] The apparatus for passing through a USB device in a virtualized environment of this embodiment is used to implement the aforementioned method for passing through a USB device in a virtualized environment. Therefore, the specific implementation method of the apparatus for passing through a USB device in a virtualized environment can be seen in the embodiment part of the method for passing through a USB device in a virtualized environment in the previous text. For example, the instruction acquisition module 100, the device information acquisition module 200, the storage device pass-through module 300, and the network card device pass-through module 400 are respectively used to implement steps S101 to S104 in the method for passing through a USB device in the virtualized environment. Therefore, its specific implementation method can refer to the description of the corresponding embodiments of each part, which will not be repeated here.

[0099] The following is an introduction to a device for a pass-through USB device in a virtualized environment provided by an embodiment of the present invention. The device for a pass-through USB device in a virtualized environment described below and the method for a pass-through USB device in a virtualized environment and the apparatus for a pass-through USB device in a virtualized environment described above can be referenced to each other.

[0100] Please refer to Figure 4 , Figure 4 A device structure block diagram of a pass-through USB device in a virtualized environment provided by an embodiment of the present invention.

[0101] Reference Figure 4 The device for passing through the USB device in the virtualized environment may include a processor 11 and a memory 12 .

[0102] The memory 12 is used to store computer programs; the processor 11 is used to implement the method for passing through a USB device in a virtualized environment described in the above-mentioned embodiment of the invention when executing the computer program.

[0103] The processor 11 in the device for passing through a USB device in a virtualized environment of this embodiment is used to install the apparatus for passing through a USB device in a virtualized environment described in the above-mentioned invention embodiments, and the processor 11 combined with the memory 12 can implement the method for passing through a USB device in a virtualized environment described in any of the above-mentioned invention embodiments. Therefore, the specific implementation of the device for passing through a USB device in a virtualized environment can be seen in the embodiment of the method for passing through a USB device in a virtualized environment in the above text, and its specific implementation can refer to the description of the corresponding various partial embodiments, which will not be repeated here.

[0104] The present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, a method for passing through a USB device in a virtualized environment as described in any of the above-mentioned embodiments of the invention is implemented. The rest of the content can refer to the prior art and will not be described in detail here.

[0105] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0106] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0107] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0108] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0109] The above is a detailed introduction to a method for passing through a USB device in a virtualized environment, an apparatus for passing through a USB device in a virtualized environment, a device for passing through a USB device in a virtualized environment, and a computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention, and the description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A method for passing through a USB device in a virtualized environment, characterized in that: include: Get device direct access instructions; According to the device pass-through instruction, the device information of the device connected to the host through the USB interface is obtained; The host has a virtual machine established; When the device information indicates that the device is a storage device based on non-USB protocol communication, the device is directly connected to the virtual machine in a manner of directly connecting the virtual machine to a bare disk; When the device information indicates that the device is a network card device, the device is directly connected to the virtual machine in the form of a virtual machine direct network card; The acquiring device information of the device connected to the host through the USB interface according to the device direct instruction comprises: scanning the device information corresponding to the connected device through the USB interface according to the device direct instruction; querying the bus information of the storage device to determine the device information corresponding to the device whose interface type is the USB interface; querying the bus information of the network card to determine the device information corresponding to the device whose interface type is the USB interface; The querying of the bus information of the storage device to determine the device information corresponding to the device with the interface type of the USB interface includes: using a command to query the bus information of the storage device; if the bus information indicates that there is a non-PCI device in the storage device connected to the host, then judging whether the bus information indicates that there is a USB interface in the interface type corresponding to the storage device connected to the host; if the bus information indicates that there is a USB interface in the interface type corresponding to the storage device connected to the host, then determining that the storage device is a storage device based on non-USB protocol communication.

2. The method according to claim 1, characterized in that: The step of obtaining device information of a device connected to the host through a USB interface according to the device direct instruction further includes: When the device information indicates that the device is a USB device, the bus number and the device number to which the device belongs are transmitted to the virtual machine, so as to directly connect the device to the virtual machine.

3. The method according to claim 2, characterized in that The USB device includes a USB flash drive and a dongle.

4. The method according to claim 1, characterized in that: The method of directly connecting the device to the virtual machine by directly connecting the virtual machine to the raw disk includes: A disk storage block configuration file is created for the virtual machine, and a source parameter in the disk storage block configuration file is designated as identification information of the storage device, so as to directly pass the storage device to the virtual machine.

5. The method according to claim 4, characterized in that The storage device includes a hard disk box of VMe.

6. The method according to claim 1, characterized in that The step of directly connecting the device to the virtual machine in the form of a virtual machine direct network card includes: An interface configuration file is created for the virtual machine, a MAC address of the network card device is specified for the interface configuration file, and information of the network card device is passed into a source parameter of the interface configuration file to directly connect the network card device to the virtual machine.

7. A device for passing through a USB device in a virtualized environment, characterized in that: include: The instruction acquisition module is used to obtain the device direct instruction; A device information acquisition module is used to acquire device information of a device connected to the host through a USB interface according to the device direct instruction; the host has a virtual machine established; A storage device direct access module, used for directly connecting the device to the virtual machine in a manner of direct access from the virtual machine to a bare disk when the device information indicates that the device is a storage device based on non-USB protocol communication; A network card device direct access module, used for directly connecting the device to the virtual machine in the form of a virtual machine direct access network card when the device information indicates that the device is a network card device; The device information acquisition module is specifically used to scan the device information corresponding to the connected device through the USB interface according to the device direct instruction; query the bus information of the storage device to determine the device information corresponding to the device whose interface type is the USB interface; query the bus information of the network card to determine the device information corresponding to the device whose interface type is the USB interface; The device information acquisition module is also used to use a command to query the bus information of the storage device. If the bus information indicates that the storage device connected to the host is a non-PCI device, it is determined whether the bus information indicates that the interface type corresponding to the storage device connected to the host has a USB interface; if the bus information indicates that the interface type corresponding to the storage device connected to the host has a USB interface, the storage device is determined to be a storage device based on non-USB protocol communication.

8. A device for passing through a USB device in a virtualized environment, characterized in that: The device comprises: Memory: used to store computer programs; Processor: used to implement the steps of the method for passing through a USB device in a virtualized environment as claimed in any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for passing through a USB device in a virtualized environment according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Method for dynamically provisioning virtualized functions in USB equipment by means of virtual USB hub

    CN111581128A