A kind of USB device reorientation method of Virtual machine
Technical field
The present invention relates to the method for the USB device in a kind of virtual machine access Local or Remote physical machine created by simulator QEMU, be espespecially a kind ofly redirected by transmission control protocol socket (TCP Socket) and USB the method that the USB device in appointment physical machine to be redirected to designated virtual machine by agreement.
Background technology
The IBM large computer system that virtual (Virtualization) technology appears at the sixties in 20th century the earliest.Along with multiple nucleus system, cluster, the grid even widespread deployment of cloud computing in recent years, the advantage of Intel Virtualization Technology in business application embodies day by day, not only reduce IT cost, but also enhancing security of system and reliability, virtualized concept is also deep into the daily work of people gradually with life.But also there are problems in the use procedure of Intel Virtualization Technology.
USB is a kind of novel serial line interface, and compared with legacy interface, USB has numerous features such as speed is fast, independently-powered, plug and play, cost are low, has boundless range of application.But because the definition of its device category is various, Communications Protocol Specification is complicated, cause USB device Simulation Software Design intricate operation, development difficulty is larger.As everyone knows, printer, flash memory, the USB device such as portable hard drive, digital camera is very important concerning user.And in existing Intel Virtualization Technology, utilizing the virtual machine USB device of accessing in local physical machine also to there is a lot of problem, the Intel Virtualization Technology as much increased income still does not support the access to USB device, or only supports the access to limited several USB device; And although some business paying virtualization softwares improve than virtualization software of increasing income the support of USB device, but still having some limitations property.As virtual server (Hyper-V Server) and the virtual machine (Virtual PC) of himself of current Microsoft, still do not support the access of USB device, need by third-party charging software as network USB (USB Over Network) etc., by Web vector graphic USB device.The desktop virtual machine of VMWare company can use various USB device by configuration from desktop, when using this function, can access the USB device that most of native client end system connects from customer menu.But there is following limitation in the USB redirection function of VMWare company desktop virtual machine:
1, from customer menu, access USB device and in desktop, use this equipment time, this equipment (1 access can only be had) cannot be accessed on the local computer simultaneously;
If 2 from browsing entrance access desktop, then can only use this function on window client, and need the assembly be redirected with optional USB has been installed in advance in local Windows system;
3, will use USB printer in desktop, user must install required print driver in desktop.
And the free virtual machine of VMware company still lacks the support that USB is redirected now.
For utilizing virtual machine to access USB device on remote physical machine, the virtualization software that the virtualization software of no matter increasing income or business are paid, up to the present or a blank.
Want the development difficulty reducing virtual machine, reduce system consumption, improve versatility, make full use of existing driver, virtual machine is enable to access USB device in Local or Remote physical machine, study that to be redirected by transmission control protocol socket and USB the method that agreement combines be best mode, also there is important practice significance simultaneously.
Summary of the invention
For increase income and business paying virtualization software to the limitation of the local USB device of access, and the problem of USB device also on unrealized access remote physical machine, the present invention proposes a kind of USB device reorientation method of Virtual machine.
Simulator QEMU is a platform virtualization solution, allows to carry out virtual (comprising disk, graphics adapter and the network equipment) a complete PC environment.Any I/O request that client operating system generates all can be intercepted and captured halfway, and is again sent in the user model of QEMU process simulation.This method is exactly the redirection function adding USB device on the basis of simulator QEMU, and communicates with Local or Remote physical machine, thus the virtual machine realizing being created by simulator QEMU is to the access of the USB device in Local or Remote physical machine.
In order to realize above-mentioned functions, virtual machine USB reorientation method provided by the invention comprises the following steps:
1) revise simulator QEMU, add USB redirection function.Utilize this simulator QEMU to create QEMU virtual machine, the arbitrary physical machine in LAN (Local Area Network) accesses the QEMU virtual machine in this physical machine by RDP;
2) USB in the physical machine of USB device place is utilized to be redirected communication between protocol realization USB device and far-end QEMU virtual machine;
3) far-end QEMU virtual machine by command line instructions by step 2) in USB device be redirected in virtual machine.
Wherein step 1) comprise following concrete steps:
11) definition is for representing the structure of the USB device that needs are redirected;
12) function performance such as reading and writing, inquiry in order to operate this structure is realized;
13) module of carrying out with the distance host at USB device place communicating is realized;
14) utilize the simulator QEMU adding USB redirection function to create virtual machine, and carry out long-range connection.
Wherein step 12) detailed process be the particular type first judging data manipulation, then perform corresponding handling function according to data manipulation type.
Wherein step 2) in utilize order line command adapted thereto to obtain to need to carry out supplier ID and the product ID of the USB device be redirected, and in the physical machine at USB device place, start the server end process that a USB device is redirected agreement, then a port number assignment is given supplier ID and the product ID of this USB device, and this port is monitored.
Wherein step 3) in first obtain the supplier ID of USB device and the IP address of product ID and place physical machine thereof; Then by command line instructions, this USB device is redirected in far-end QEMU virtual machine in the monitor of far-end QEMU virtual machine.
Then utilize step 2), step 3) in the transmission control protocol socket that establishes carry out data transmission.
The present invention mainly comprises USB and is redirected agreement and USB device Redirectional system two parts based on simulator QEMU.Wherein USB is redirected agreement is that USB device in physical machine distributes a listening port, and starts to monitor this port; Set up transmission control protocol socket with far-end QEMU virtual machine to be connected simultaneously; Then the QEMU virtual machine receiving far-end, to the action type of USB device, operates USB device in physical machine accordingly according to different action types.And based on the USB device Redirectional system of simulator QEMU, the USB device on the main frame of given IP address is redirected in QEMU virtual machine, then receive by the operation of remote desktop to USB device in virtual machine, and by this operational feedback to the physical machine at USB device place; After USB device place physical machine processes assigned operation, result is sent back virtual machine, virtual machine simulates the data after the physical machine process of USB device place again, and reappears in virtual machine.
Technique effect of the present invention is, solves and increases income and the limitation of business paying virtualization software to the local USB device of access, and having filled up increases income cannot access the blank of the USB device on remote physical machine with business paying virtualization software.
Accompanying drawing explanation
Fig. 1 is the configuration diagram that USB device is redirected;
Fig. 2 is the processing flow chart that USB device is redirected agreement.
Embodiment
Clearer understanding is obtained for making feature of the present invention and advantage, below in conjunction with accompanying drawing, be described in detail below: as shown in Figure 1, describe framework of the present invention, by the virtual machine on the RDP access physical host B on physical host A, virtual machine now on physical host B needs to access the USB device (USB device on physical host C and USB are redirected agreement and also can be positioned on physical host A) on physical host C, and the concrete execution step in the present embodiment is:
1) utilize the simulator QEMU adding USB redirection function to create virtual machine, physical machine A is by the virtual machine on RDP access physical machine B;
2) USB device on physical machine C is utilized to be redirected communication between the USB device on protocol realization physical machine C and the virtual machine on physical machine B;
3) USB device on physical machine C to be redirected to by command line instructions in the virtual machine on physical machine B by the virtual machine on physical machine B.
4) by the USB device in the virtual machine on the remote desktop operation physical machine B on physical machine A.
Wherein step 1) in simulator QEMU, add USB redirection function, utilize a structure to represent the USB device that needs are redirected; Utilize the virtual machine that this QEMU creates, QEMU can determine current virtual machine configuration status and to the action type of USB device different types of data as control flow check data, filestream data, interrupt flow data etc., and these information beds is given the physical host C at USB device place.
Wherein step 2) need to utilize instruction acquisition needs to carry out supplier ID and the product ID of the USB device be redirected in order line, and on physical machine C, start the server end process that a USB device is redirected agreement, then a port number assignment is given supplier ID and the product ID of this USB device, and this port is monitored.Step 1) in simulator QEMU obtain the operation information that virtual machine carries out the USB device be redirected to wherein after, be redirected agreement by USB and send it to physical host C.After physical host C processes by result feedback to the simulator QEMU on physical host B; And the result be presented on after the namely process in virtual machine.
Wherein step 3) first obtain the supplier ID of USB device and the IP address of product ID and place physical machine; Then by command line instructions, the USB device of local host is redirected in far-end virtual machine in the monitor of far-end virtual machine.
Wherein step 4) on local physical machine A, utilize remote desktop to access virtual machine on remote physical machine B, and the USB device on the physical machine C be redirected in this virtual machine is read, write, the operations such as deletion, action type feeds back to the virtual machine on physical machine B by RDP, physical machine B is again by step 2) in the connection set up corresponding operating is sent to the physical machine C at USB device place, after physical machine C makes corresponding process, result is sent to the virtual machine on physical machine B, also corresponding result is presented by the remote desktop on physical machine A.
USB in the present invention is redirected agreement: this agreement is made up of following three parts:
1) USB device module usb-device: representative needs the USB device be redirected;
2) USB client module usb-guest: connect usb-device, and assigned operation is carried out to usb-device;
3) USB server end module usb-host: by network by usb-device in dedicating remote virtual machine to, and usb-device can be used to usb-guest.
This agreement is run a server end USB and is redirected usbredirserver process on physical machine C, and for needing the USB device be redirected to distribute a listening port, and start to monitor this port; Set up transmission control protocol socket with the virtual machine created by simulator QEMU on far-end physical machine B to be connected simultaneously; Then the various operation requests to USB device that send of sink virtual machine, to have carried out result feedback these requests after corresponding process to the virtual machine on far-end physical machine B until physical machine C.
USB device Redirectional system based on simulator QEMU: amendment simulator QEMU, add USB and be redirected connection usbredir-tcp module, be responsible for being redirected the usbredirserver process that agreement starts with USB to be connected, result is sent to corresponding part after processing the information obtained from virtual machine or usbredirserver process by part.By the USB device information of acquisition, the IP address of USB device place physical machine, in the virtual machine created by simulator QEMU utilizing command line instructions the USB device on physical machine C to be redirected on physical machine B, physical machine A utilizes the virtual machine on remote desktop access physical machine B, and the USB device be redirected on this virtual machine is operated; After these operations return to the virtual machine on physical machine B, the physical machine C that physical machine B utilizes USB device Redirectional system to send it to USB device place again processes accordingly.
Technique effect of the present invention is, solves and increases income and the limitation of business paying virtualization software to the local USB device of access, and having filled up increases income cannot access the blank of the USB device on remote physical machine with business paying virtualization software.