Disclosure of Invention
The application provides a method, a device and electronic equipment for dynamically migrating a virtual machine, which realize the dynamic migration of the virtual machine based on hardware.
In a first aspect, the present application provides a method for dynamically migrating a virtual machine, where the method includes:
determining the type of a virtual machine to be migrated on a source host;
Responding to the type consistent with the preset type, and storing a data structure corresponding to the interrupt controller which accords with the condition;
adding the data structure to migration transmission data of the virtual machine to be migrated;
And migrating the virtual machine to be migrated from a source host to a target host based on the migration transmission data.
By the method, after the types of the virtual machines on the source host are classified, migration transmission data containing the data structure is stored, so that the virtual machines can be migrated from the source host to the target host, and the registers of the target host can be restored.
In one possible design, responsive to the type being consistent with a preset type, the method includes:
matching the type of the virtual machine to be migrated with each preset type in a preset type set;
and when the preset type consistent with the type is matched, responding to the type consistent with the preset type.
By the method, the types of the virtual machines to be migrated are matched with the preset types of the virtual machines, and when the virtual machines to be migrated are matched with the virtual machines consistent with the preset types, the virtual machines to be migrated are determined to accord with the virtual machines of the preset types, so that the screening of the virtual machines based on the types of the virtual machines is realized.
In one possible design, storing a data structure corresponding to a eligible interrupt controller includes:
extracting the interrupt controller of the type, and extracting the register type of a register in the interrupt controller and data corresponding to the register;
And associating the register type with the data, generating a data structure, and storing the data structure.
By the method, the interrupt controller of the type is determined, the type and the data of the register in the interrupt controller are extracted, the type and the data are associated, a data structure is generated, and the data structure is stored, so that recovery of the virtual machine is ensured.
In one possible design, after the virtual machine to be migrated is migrated from the source host to the target host based on the migration transmission data, the method includes:
controlling a CPU on the target host to start and restore the virtual machine of the interrupt controller;
Extracting a preset register in the interrupt controller of the type and reading the preset register;
and inputting the register data into a preset register to realize the injection of the register data.
By the method, the server controls the target host to start and resume the virtual machine corresponding to the interrupt controller, and inputs the register data into the register in the interrupt controller, so that the injection of the terminal program is realized.
In a second aspect, the present application provides an apparatus for dynamic migration of a virtual machine, the apparatus comprising:
The determining module is used for determining the type of the virtual machine to be migrated on the source host;
The storage module is used for responding to the fact that the type is consistent with the preset type and storing the data structure corresponding to the interrupt controller which meets the condition;
The matching module is used for adding the data structure into migration transmission data of the virtual machine to be migrated;
and the migration module is used for migrating the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
In one possible design, the storage module is specifically configured to match a type of the to-be-migrated virtual machine with each preset type in a preset type set, and when a preset type consistent with the type is matched, respond to the type consistent with the preset type.
In one possible design, the storage module is further configured to extract the type of interrupt controller, extract a register type of a register in the interrupt controller and data corresponding to the register, associate the register type with the data, generate a data structure, and store the data structure.
In one possible design, the migration module is specifically configured to control a CPU on the target host to start and restore a virtual machine of the type of interrupt controller, extract a preset register in the type of interrupt controller, read the preset register, and input the register data into the preset register, so as to implement injection of the register data.
In a third aspect, the present application provides an electronic device, comprising:
a memory for storing a computer program;
and the processor is used for realizing the method steps of the dynamic migration of the virtual machine when executing the computer program stored on the memory.
In a fourth aspect, a computer readable storage medium has stored therein a computer program which, when executed by a processor, performs the method steps of a virtual machine live migration described above.
The technical effects of each of the first to fourth aspects and the technical effects that may be achieved by each aspect are referred to above for the technical effects that may be achieved by the first aspect or the various possible aspects of the first aspect, and are not repeated here.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings. The specific method of operation in the method embodiment may also be applied to the device embodiment or the system embodiment. In the description of the present application, "a plurality of" means "at least two". "and/or" describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate that there are three cases of a alone, a and B together, and B alone. A and B are connected, and it can be represented that A and B are directly connected and A and B are connected through C. In addition, in the description of the present application, the words "first," "second," and the like are used merely for distinguishing between the descriptions and not be construed as indicating or implying a relative importance or order.
Currently, in order to realize the dynamic migration of the virtual machine, a mode is adopted that the dynamic migration is realized based on software and apic simulation, on a 'lapic' transparent high-performance virtual machine, the virtual machine directly uses the physical lapic, and the state of the physical lapic is in a physical register, and the dynamic migration method of the hardware transparent virtual machine is lacking because the dynamic migration is realized based on software and lapic simulation.
In order to solve the above-described problems, an embodiment of the present application provides a method for dynamically migrating a virtual machine, which is used for dynamically migrating the virtual machine based on hardware transparent transmission. The method and the device according to the embodiments of the present application are based on the same technical concept, and because the principles of the problems solved by the method and the device are similar, the embodiments of the device and the method can be referred to each other, and the repetition is not repeated.
Embodiments of the present application will be described in detail below with reference to the accompanying drawings.
Referring to fig. 1, the application provides a method for dynamically migrating a virtual machine, which can realize dynamic migration based on hardware transparent virtual machines, and the implementation flow of the method is as follows:
And S1, determining the type of the virtual machine to be migrated on the source host.
In order to realize the dynamic migration of the virtual machine based on hardware transparent transmission, the embodiment of the application firstly needs to determine the type of the source host of the virtual machine to be migrated on the source host, the type of the host to be migrated can be a virtual machine capable of being added with 'lapic' transparent transmission, and in the embodiment of the application, the virtual machine to be migrated is a virtual machine capable of being transparent transmission, and the application needs to supplement that lapic in the file is an interrupt controller.
And step S2, storing a data structure corresponding to the interrupt controller which accords with the condition in response to the type being consistent with the preset type.
The type of the virtual machine to be migrated is determined, in order to ensure that the virtual machine to be migrated is a virtual machine of a specified type, the type of the virtual machine to be migrated needs to be matched with each preset type in a preset type set, if the type is matched with a consistent preset type, the type is represented as being in the preset type, and if the type is not matched with the consistent preset type, the type is represented as not being in the preset type.
When the type is consistent with the preset type, determining that each interrupt controller is corresponding to the type, wherein each interrupt controller is provided with a register, the register is used for reading and/or writing, the register type of the register and the data corresponding to the register are extracted from the interrupt controller, the register type can be TPR, APR, PPR, RRD, LDR, DFR, ICR, IRR, ISR, TMR, LVTT, and the like, and the register type can also be other types, and the description is omitted herein.
After the type of the register and the data corresponding to the register are obtained, the type and the data are associated to generate a data structure, and the data structure is stored, which should be noted that, when kvm_ vcpu _ioctl and kvm_get_lapic are called, the data structure may be added to the calling program, and the implementation of saving the physical LAPIC data structure is added to the kvm_ apic _get_state function, which is mainly implemented to save all readable physical LAPIC registers.
Step S3, adding the data structure to migration transmission data of the virtual machine to be migrated;
In the above description, during the migration process of the virtual machine, the KVM is combined with the QEMU to implement the migration of the virtual machine, the QEMU is a model of an open source simulator and a virtual machine supervisor, the QEMU can be used as a user mode simulator to execute codes different from the host architecture by using a dynamic code translation mechanism, the QEMU can also be used as a virtual machine supervisor to simulate a whole system, and other VMM (Xen, KVM, etc) is used to use virtualization support provided by hardware to create virtual machines close to the host performance, each virtual machine corresponds to one QEMU process in the host (host), and vcpu of the virtual machine corresponds to one thread of the QEMU process, and the vcpu is cpu of the virtual machine.
After the data structure is stored, the data structure is added to the migration transmission data of the virtual machine to be migrated, and the data structure of the stored physical LAPIC is added when the destination calls kvm_ vcpu _ioctl or kvm_set_lapic.
Based on the above description, the data structure is stored in the migration transmission data, and since the migration transmission data is stored in the KVM, the storage and recovery of the physical lapic state can be realized.
And step S4, migrating the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
The above description describes that the data structure is added to migration transmission data of the virtual machine to be migrated, and when the source host performs dynamic migration of the virtual machine to the target host, the server controls the source host to migrate the migration transmission data to the target host, thereby implementing dynamic migration based on the hardware transparent virtual machine.
After the target host receives the migration transmission data, the target host starts and resumes the virtual machine corresponding to the interrupt controller of the type described above, or starts a new virtual machine of transparent lapic according to qemu xml configuration, and resumes the physical lapic.
In order to realize the injection of register data in the register, the target host shuts down the corresponding cpu interrupt under host, restores the physical lapic normal register, reads the ir/isr register, re-injects the corresponding interrupt into the register according to the interrupt number, and finally, the server controls the target host to restore virtual machine operation.
Specifically, as shown in fig. 2, in the flow chart of the physical LAPIC dynamic migration source host, in fig. 2, there are QEMU and KVM in the source host, QEMU is a hardware virtualization program, a calling function kvm_get_ apic calls kvm_ vcpu _ioctl or kvm_get_lapic, because the source host exists on the virtual machine when migrating the dynamic virtual machine, host exists on the host, in the process of implementing migration of the virtual machine, it is required to ensure that host interrupt is closed, the cpu is designated to exit to host, all readable registers including physical LAPIC are acquired through a program kvm_ vcpu _ioctl_get_ LAPIC, only the non-Reserved registers are saved, the saved LAPIC states including the physical LAPIC states are saved through a program kvm_ apic _get_get_teand then the saved LAPIC states are migrated to the target host, thereby implementing migration from the source host to the virtual machine.
After the source host sends the virtual machine to the target host, the physical LAPIC dynamic migration target host flowchart is shown in fig. 3, after the QEMU of the target host receives LAPIC status data sent by the source host, the program kvm_put_ apic _state will read the saved LAPIC status information, including the physical LAPIC, and then based on the program kvm_ apic _put and the program kvm_ vcpu _ioctl or the kvm_set_lapic under the condition of closing the host interrupt, the state of LAPIC is read, including the physical LAPIC register into the KVM, the physical LAPIC status is SET by the program bm_ apic _set_state, and part of the readable and writable registers are directly written into the KVM, and because the interrupt request register and the interrupt processing register are read-only registers, the corresponding interrupt is required to be re-injected in the interrupt request register, and the interrupt is described above, when the program is injected in the registers, the program is reset, the qu is reset after the program injection in the registers, the program is reset, the purpose is restored from the virtual host is restored to the virtual machine is achieved, and finally the virtual machine is restored to the target host, and the virtual machine is migrated from the host.
Based on the method, the data structure is stored based on the type of the virtual machine to be migrated, the data structure is added into migration transmission data, and dynamic migration based on the hardware transparent virtual machine is realized in a mode that the migration transmission data is sent from a source host to a target host.
Based on the same inventive concept, the embodiment of the present application further provides a virtual machine dynamic migration apparatus, where the virtual machine dynamic migration apparatus is configured to implement a function of a virtual machine dynamic migration method, and referring to fig. 4, the apparatus includes:
a determining module 401, configured to determine a type of a virtual machine to be migrated on a source host;
A storage module 402, configured to store a data structure corresponding to the interrupt controller that meets the condition in response to the type being consistent with a preset type;
A matching module 403, configured to add the data structure to migration transmission data of the virtual machine to be migrated;
And the migration module 404 is configured to migrate the virtual machine to be migrated from the source host to the target host based on the migration transmission data.
In one possible design, the storage module 402 is specifically configured to match the type of the to-be-migrated virtual machine with each preset type in a preset type set, and when a preset type consistent with the type is matched, respond to the type consistent with the preset type.
In one possible design, the storage module 402 is further configured to extract the type of interrupt controller, extract a register type of a register in the interrupt controller and data corresponding to the register, associate the register type with the data, generate a data structure, and store the data structure.
In one possible design, the migration module 404 is specifically configured to control a CPU on the target host to start and restore a virtual machine of the type of interrupt controller, extract a preset register in the type of interrupt controller, read the preset register, and input the register data into the preset register to implement injection of the register data.
Based on the same inventive concept, the embodiment of the present application further provides an electronic device, where the electronic device may implement the function of the foregoing virtual machine dynamic migration apparatus, and referring to fig. 5, the electronic device includes:
The embodiment of the present application is not limited to a specific connection medium between the processor 501 and the memory 502, and the processor 501 and the memory 502 are exemplified in fig. 5 by a connection between the processor 501 and the memory 502 through the bus 500. The connection between the other components of bus 500 is shown in bold lines in fig. 5, and is merely illustrative and not limiting. Bus 500 may be divided into an address bus, a data bus, a control bus, etc., and is represented by only one thick line in fig. 5 for ease of illustration, but does not represent only one bus or one type of bus. Or processor 501 may also be referred to as a controller, without limitation on the name.
In an embodiment of the present application, the memory 502 stores instructions executable by the at least one processor 501, and the at least one processor 501 may perform a virtual machine live migration method as described above by executing the instructions stored in the memory 502. The processor 501 may implement the functions of the various modules in the apparatus shown in fig. 4.
The processor 501 is a control center of the device, and various interfaces and lines can be used to connect various parts of the entire control device, and by executing or executing instructions stored in the memory 502 and invoking data stored in the memory 502, various functions of the device and processing data can be performed to monitor the device as a whole.
In one possible design, processor 501 may include one or more processing units, and processor 501 may integrate an application processor and a modem processor, where the application processor primarily processes operating systems, user interfaces, application programs, and the like, and the modem processor primarily processes wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 501. In some embodiments, processor 501 and memory 502 may be implemented on the same chip, or they may be implemented separately on separate chips in some embodiments.
The processor 501 may be a general purpose processor such as a Central Processing Unit (CPU), digital signal processor, application specific integrated circuit, field programmable gate array or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, and may implement or perform the methods, steps and logic blocks disclosed in embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of a virtual machine dynamic migration method disclosed in connection with the embodiment of the application can be directly embodied as the execution completion of a hardware processor or the execution completion of the combination execution of hardware and software modules in the processor.
The memory 502, as a non-volatile computer readable storage medium, may be used to store non-volatile software programs, non-volatile computer executable programs, and modules. The Memory 502 may include at least one type of storage medium, and may include, for example, flash Memory, hard disk, multimedia card, card Memory, random access Memory (Random Access Memory, RAM), static random access Memory (Static Random Access Memory, SRAM), programmable Read-Only Memory (Programmable Read Only Memory, PROM), read-Only Memory (ROM), charged erasable programmable Read-Only Memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ-Only Memory, EEPROM), magnetic Memory, magnetic disk, optical disk, and the like. Memory 502 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 502 in embodiments of the present application may also be circuitry or any other device capable of performing storage functions for storing program instructions and/or data.
By programming the processor 501, code corresponding to a virtual machine live migration method described in the foregoing embodiment may be cured into the chip, so that the chip can execute a virtual machine live migration step of the embodiment shown in fig. 1 at runtime. How to design and program the processor 501 is a technique well known to those skilled in the art, and will not be described in detail herein.
Based on the same inventive concept, the embodiment of the present application further provides a storage medium storing computer instructions that, when executed on a computer, cause the computer to perform a method for dynamically migrating a virtual machine as described above.
In some possible embodiments, the aspects of a method for virtual machine live migration may also be implemented in the form of a program product comprising program code for causing a control apparatus to carry out the steps of a method for virtual machine live migration according to the various exemplary embodiments of the application as described herein above when the program product is run on a device.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.