CN117093332B - Method and device for realizing cloning of virtual machine - Google Patents

Method and device for realizing cloning of virtual machine Download PDF

Info

Publication number
CN117093332B
CN117093332B CN202311363296.9A CN202311363296A CN117093332B CN 117093332 B CN117093332 B CN 117093332B CN 202311363296 A CN202311363296 A CN 202311363296A CN 117093332 B CN117093332 B CN 117093332B
Authority
CN
China
Prior art keywords
disk
virtual machine
snapshot
temporary
creating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311363296.9A
Other languages
Chinese (zh)
Other versions
CN117093332A (en
Inventor
杨帅
杨其
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Youyun Technology Co ltd
Original Assignee
Hangzhou Youyun Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Youyun Technology Co ltd filed Critical Hangzhou Youyun Technology Co ltd
Priority to CN202311363296.9A priority Critical patent/CN117093332B/en
Publication of CN117093332A publication Critical patent/CN117093332A/en
Application granted granted Critical
Publication of CN117093332B publication Critical patent/CN117093332B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45562Creating, deleting, cloning virtual machine instances
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/4557Distribution of virtual machine instances; Migration and load balancing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45575Starting, stopping, suspending or resuming virtual machine instances
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45595Network integration; Enabling network access in virtual machine instances

Abstract

The invention discloses a virtual machine cloning realization method and a virtual machine cloning realization device, wherein the virtual machine cloning realization method comprises the steps of responding to a virtual machine cloning command, creating a temporary snapshot of a source virtual machine, creating a temporary disk as an active disk of the source virtual machine, freezing a first disk, wherein the temporary snapshot is of an external snapshot type, the source virtual machine at least comprises a snapshot chain at the moment of creating the temporary snapshot, the snapshot chain comprises a plurality of snapshot points, and the temporary snapshot and the snapshot points of the source virtual machine belong to the same snapshot chain; cloning data of a first disk to create a target virtual machine disk; creating a target virtual machine based on the target virtual machine disk, wherein the target virtual machine takes the target virtual machine disk as an operation disk; according to the method and the device for realizing cloning of the virtual machine, provided by the invention, the source virtual machine is ensured not to be suspended in the cloning process of the virtual machine by a snapshot technology, and the problems that the copy quantity of data is large in the cloning process of the virtual machine, multiple copies exist in a disk after cloning, and snapshot information of the source virtual machine is lost are solved.

Description

Method and device for realizing cloning of virtual machine
Technical Field
The invention relates to the technical field of virtual machine cloning, in particular to a method and a device for realizing virtual machine cloning.
Background
Virtual machine cloning refers to a process of creating a target virtual machine with the same resources as the source virtual machine according to a virtual machine instance; in many scene applications of the cloud computing platform, users need to create a large number of virtual machines in batches according to the existing virtual machine examples, and the method has strong appeal to virtual machine cloning technology.
In the virtual machine cloning technology, due to the fact that cloning of data samples is involved, multiple data copies are often generated, on one hand, the copying of the data copies can affect the cloning efficiency of the virtual machine, and in addition, multiple identical data copies are also wasted on storage resources to a great extent; when a cloned virtual machine has a snapshot chain, the snapshot point of the virtual machine may be lost during cloning.
In order to realize cloning of the KVM virtual machine, the methods commonly used in the industry are as follows:
1) Copying all disk data of the cloned virtual machine, creating a virtual machine instance according to the copied data, and further realizing cloning of the virtual machine as the target virtual machine inherits all disk data of the original virtual machine. The technology is simple to realize, but cloud examples need to be suspended in the implementation process, and a certain time is needed to copy the disk data, so that a large amount of time is wasted when the disk data volume is large;
2) And submitting all snapshots of the cloned virtual machine into a mirror image by means of snapshot submission, and creating a target virtual machine by using a mirror image file so as to complete cloning of the virtual machine. The method solves the defect that the virtual machine needs to be suspended and wait for cloning to be completed, but the disk image creation process is time-consuming, and when the snapshot exists in the source virtual machine instance, the clone virtual machine cannot inherit the original snapshot attribute.
Disclosure of Invention
In order to overcome the defects of the technology, the invention provides a method and a device for realizing cloning of a virtual machine, which are used for cloning the virtual machine more efficiently and rapidly, reducing the use of extra storage resources caused by cloning of the virtual machine as much as possible and solving the problem that the cloned virtual machine cannot inherit the snapshot point of the original virtual machine instance.
The technical scheme adopted for overcoming the technical problems is as follows: according to the implementation method of virtual machine cloning provided by the first aspect of the invention, a temporary snapshot of a source virtual machine is created in response to a virtual machine cloning command, a temporary disk is created as an active disk of the source virtual machine, a first disk is frozen, the first disk is the active disk of the source virtual machine at the moment of creating the temporary snapshot, wherein the temporary snapshot is of an external snapshot type, the source virtual machine at the moment of creating the temporary snapshot at least comprises a snapshot chain, the snapshot chain comprises a plurality of snapshot points, and the temporary snapshot and the snapshot points of the source virtual machine belong to the same snapshot chain; cloning data of a first disk to create a target virtual machine disk; and creating a target virtual machine based on the target virtual machine disk, wherein the target virtual machine takes the target virtual machine disk as an operation disk.
Further, the method further comprises deleting the temporary snapshot, and specifically comprises the following steps: submitting the disk data of the temporary disk to the first disk; deleting the temporary disk after the disk data of the temporary disk are submitted; and switching the first disk to an active disk of the source virtual machine, and modifying the disk attribute of the first disk to be a read-write disk.
And deleting the temporary snapshot and the temporary disk to ensure that the cloning process does not cause overhead to the state of the original virtual machine.
Further, the creating a temporary snapshot of the source virtual machine, and creating a temporary disk as an active disk of the source virtual machine, and freezing a first disk, where the first disk is an active disk of the source virtual machine at the moment of creating the temporary snapshot, specifically includes: creating a temporary snapshot time; creating a temporary disk; and modifying the disk attribute, wherein the temporary disk is set as an active disk, the first disk is set as a frozen disk as a parent node disk of the temporary disk, and the active disk of the source virtual machine is switched to the temporary disk.
By creating the temporary snapshot and the temporary disk and switching the active disk of the source virtual machine, the source virtual machine is ensured not to be affected in the cloning process. The cloud disk snapshot creation process of the source virtual machine is short, and the service of the virtual machine is not interrupted in the process.
Further, the cloning the data of the first disk to create the target virtual machine specifically includes: searching a target virtual machine disk based on the target virtual machine ID, the source virtual machine ID and the temporary snapshot time; if the target virtual machine disk does not exist, copying the first disk data based on the source virtual machine ID, and taking the disk created after the copying is completed as the target virtual machine disk; and creating a target virtual machine running environment, taking a target virtual machine disk as an active disk of the target virtual machine, and starting the target virtual machine.
Further, the method further comprises the step that the first disk and the target virtual machine disk have the same father node disk.
Further, after the disk data cloning is successful, the target virtual machine disk is taken as a leaf node, the corresponding parent node disk is traced back, the reference count of the parent node disk is accumulated, and the reference count of the disk referenced by the first disk is accumulated by 1.
Further, the method also comprises the step that the target virtual machine is restored based on a snapshot restoration point stored in a disk of the target virtual machine.
The disk chain of the target virtual machine reserves the existing snapshot information of the source virtual machine, and the cloned virtual machine can directly use snapshot points to execute restoration.
Further, the method also comprises the steps of responding to a virtual machine deleting command, and if the reference count of a corresponding disk on a snapshot chain included by the virtual machine is 1, deleting the disk data of the disk with the reference count of 1 while cleaning the virtual machine; if the reference count of the corresponding disk on the snapshot chain included in the virtual machine is greater than 1, deleting the disk data with the reference count not being 1 when deleting the virtual machine.
Further, when the virtual machine is created, a disk with the reference count larger than 1 is selected as a disk parent node of other virtual machines.
Based on the reference count, the disk is managed.
The second aspect of the present invention also provides an implementation device of virtual machine cloning, which is used for running the implementation method of virtual machine cloning, and is applied to a cloud computing platform, where the cloud computing platform at least includes a plurality of physical servers, a cloud platform management module and a distributed storage module for providing block storage services for the cloud computing platform, the physical servers at least include a host server and a summarizer server, the distributed storage module at least includes a plurality of distributed storage nodes, the summarizer server is used for managing the distributed storage nodes, disk data of a virtual machine is stored in the distributed storage module, each disk of the virtual machine corresponds to one of the distributed storage nodes, and the at least one host server is used for deploying the virtual machine, the virtual machine management module, the virtual machine snapshot management module and the virtual machine disk management module; the cloud platform management and control module responds to a clone virtual machine command and calls a virtual machine snapshot management module, a virtual machine disk management module and a virtual machine management module which are used for cloning the source virtual machine to obtain the target virtual machine; the virtual machine snapshot management module is used for creating a temporary snapshot and deleting the temporary snapshot; the virtual machine disk management module is used for creating a virtual machine disk, copying the virtual machine disk and modifying the attribute of the virtual machine disk; the virtual machine management module is used for responding to a clone virtual machine command of the cloud platform management and control module, calling the virtual machine snapshot management module to create a temporary snapshot, creating a temporary disk, creating a target virtual machine disk and modifying disk attributes, calling the virtual machine disk management module to copy first disk data to the target virtual machine disk, and starting the target virtual machine based on the target virtual machine disk.
The beneficial effects of the invention are as follows:
1. the disk is managed by the technical means of disk reference counting, the content submission is not required to be completed, the source disk data is not copied, and all original data only have one copy; the plurality of virtual machines share one disk chain, and snapshot points on the disk chain are shared by the two virtual machines; the method solves the problems that the copy quantity of data is large in the cloning process of the virtual machine, multiple copies exist in a cloned disk, snapshot information of a source virtual machine is lost and the like;
2. after the source virtual machine creates a temporary snapshot, the original disk data is frozen to be read-only, a new disk is created as an active node, the subsequent read-write content of the virtual machine is recorded, the source virtual machine is ensured not to be paused in the cloning process of the virtual machine by a snapshot technology, and only the extremely small part of disk data is required to be copied in the cloning process, so that the cloning process has no influence on the virtual machine;
3. after the cloning of the virtual machine is completed, the temporary disk data is submitted to the original active disk of the source virtual machine, so that the overhead on the state of the original virtual machine is avoided;
4. the snapshots generated by the source virtual machine may be inherited by the target virtual machine, which may use the snapshots to perform restore operations.
Drawings
FIG. 1 is a schematic flow chart of a method for implementing virtual machine cloning according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a cloud computing platform principle applied to a virtual machine cloning implementation method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an embodiment of creating a snapshot and creating a temporary snapshot in accordance with an embodiment of the present invention;
FIG. 4 is a schematic diagram of an embodiment of a clone disk according to an embodiment of the present invention;
FIG. 5 is a diagram of an embodiment of a delete snapshot in accordance with an embodiment of the present invention.
Detailed Description
For a further understanding of the present invention, reference is first made to the explanation of some of the terms mentioned herein:
KVM virtual machine: kernel-based Virtual Machine, an open-source system virtualization module, was integrated in each major release of Linux since Linux2.6.20. Virtualization of KVM requires hardware support, such as Intel VT technology or AMD V technology, and is based on complete virtualization of hardware;
libvirt: an open source API for managing a virtualized platform, a daemon and a management tool. It may be used to manage KVM, XEN, vmwareESX, QEMU and other virtualization technologies. Some general API interfaces provided by Libvirt are widely applied in cloud computing solutions, and snapshot creation, deletion and the like of a virtual machine can be completed through the interfaces. The management tool provides a plurality of convenient virtual machine management interfaces, and can conveniently operate the storage, network and other components of the virtual machine according to the interfaces;
snapshot: snapshot, which specifies an available copy of a data set, the copy comprising an image of the corresponding data at a point in time, may be a copy of the data it represents, or may be a replication object of the data. The snapshot has the function of enabling online data backup and recovery, namely, when the storage device has application faults or file damage, the host state can be quickly recovered to a certain available time point.
QEMU: a set of open source software simulating the operation of a processor is an open source full-virtualization solution running on a user layer, and has the characteristics of high speed, cross-platform and the like. QEMU works at the user level, and many hardware privileged instructions, kernel operations, etc. need to be completed with KVM as the underlying interface.
Qcoow 2: QEMU copy on write, a mirror image format of the QEMU, is a structured memory block. The storage block in the QCOW2 format has small storage space and supports the functions of snapshot, encryption and the like. Qcoo 2 is a disk image format supported by KVM, and the inside itself records some information during fast allocation.
Mirror image: image, a form of file storage, is a type of redundancy in that data on one disk exists as an identical copy on another disk.
Reference count: one management technique in computer programming languages refers to the process of saving the number of references to a resource and releasing it when the number of references becomes zero.
Disk chain: the snapshot is a moment point, a plurality of snapshots correspond to a disk chain, and when the snapshot point exists in the virtual machine, the corresponding disk forms a chain.
The invention will now be described in further detail with reference to the drawings and the specific examples, which are given by way of illustration only and are not intended to limit the scope of the invention, in order to facilitate a better understanding of the invention to those skilled in the art.
The flow diagram of the implementation method of virtual machine cloning is shown in fig. 1, and is applied to a cloud computing platform shown in fig. 2, wherein VM1 in fig. 2 represents a source virtual machine running in a host machine H1, and corresponding VM1-disk1 and VM1-disk1-s0 are disk files corresponding to a virtual machine VM 1. In order to clone the source virtual machine vm1 to obtain the target virtual machines vm2 and vm3, each step of a method flow for implementing virtual machine cloning is described in detail as follows:
s1, responding to a virtual machine cloning command, creating a temporary snapshot of a source virtual machine, creating a temporary disk as an active disk of the source virtual machine, freezing a first disk, wherein the first disk is the active disk of the source virtual machine at the moment of creating the temporary snapshot, the temporary snapshot is of an external snapshot type, the source virtual machine at the moment of creating the temporary snapshot at least comprises a snapshot chain, the snapshot chain comprises a plurality of snapshot points, and the temporary snapshot and the snapshot points of the source virtual machine belong to the same snapshot chain.
In one embodiment of the invention, all disk files are in qcow2 format, and disk parent node information is recorded in the data header of the file.
Snapshot chain correspondence for source virtual machine vm1 as shown in FIG. 3, vm1 has an original snapshot restore point S0, and the snapshot chain contains three data disks: the OS is the operating system of the virtual machine, the attribute is read-only, and vm1-disk1-S0 is the disk that vm1 generates when creating the external snapshot S0. After the external snapshot S0 is successfully generated, the vm1-disk1 disk data can be frozen to be read-only, and the source virtual machine running data can be written into the active disks vm1-disk1-S0.
It should be noted that, in one embodiment of the present invention, only a snapshot is taken as a point in time, in fact, multiple snapshots correspond to a disk chain, and when a virtual machine has a snapshot point, the corresponding disks form a chain. Creating a temporary snapshot of the source virtual machine, and creating a temporary disk as an active disk of the source virtual machine, wherein the specific flow of freezing the first disk is as follows.
S11, creating a temporary snapshot time.
The temporary snapshot creates a temporary snapshot time by striking an external snapshot point to the source virtual machine before performing cloning, and is used for freezing the data of the active disk of the source virtual machine at the cloning time.
S12, creating a temporary disk.
Generating a temporary disc vm1-disk1-s1 and a disc vm1-disk1-s0 as a first disc, wherein the frozen disc of the source virtual machine is the first disc at the moment, and ensuring that the cloning process has no influence on the source virtual machine.
S13, modifying the disc attribute.
Setting the temporary disk as an active disk, and setting the first disk as a father node disk of the temporary disk as a frozen disk. Note that an active disk corresponds to a disk readable/writable, and a frozen disk corresponds to a read-only disk.
S14, switching the read-write disk of the source virtual as a temporary disk.
In the embodiment of the invention, the snapshot refers to an external snapshot, disk data is divided into two parts during the snapshot, one part is frozen, the other part is continuously used as an active space for reading and writing, a new disk is re-created when the external snapshot creates a snapshot, the original disk data is frozen to be read-only, and the new disk is used as the active space for reading and writing. The cloud platform management and control module C creates an external snapshot S0 through a tool set provided by Libvirt, and the corresponding vm1-disk1-S0 is a disk generated when the vm1 creates the external snapshot S0. Wherein creating the external snapshot is a snapshot management interface provided through the Libvirt tool.
The virtual machine snapshot management module B creates a temporary snapshot S1 of the virtual machine vm1, and after the temporary snapshot S1 is successfully created, a temporary disk vm1-disk1-S1 and a disk vm1-disk1-S0 are generated to serve as a first disk. And modifying the attribute of the temporary disk, wherein the first disk is used as a father node disk of the temporary disk and is set as a frozen disk, the temporary disks vm1-disk1-s1 are set as active disks, and the active disk of the source virtual machine vm1 is switched to the temporary disks vm1-disk1-s1.
In one embodiment of the invention, the cloud platform management and control module C invokes the virtual machine snapshot management module to create a temporary snapshot, and the virtual machine snapshot management module invokes the Libvirt software API interface to create a temporary external snapshot.
S2, cloning the data of the first disk to create a target virtual machine disk.
The cloud platform management and control module C calls the virtual machine management module A, clones the disk and creates virtual machines vm2 and vm3, wherein the virtual machine management module is realized by using a Libvirt open source management tool. The specific execution flow is as follows.
S21, searching a target virtual machine disk based on the target virtual machine ID, the source virtual machine ID and the temporary snapshot time;
s22, if the target virtual machine disk does not exist, copying the first disk data based on the source virtual machine ID, and taking the disk created after the copying is completed as the target virtual machine disk;
s23, creating a target virtual machine running environment, taking a target virtual machine disk as an active disk of the target virtual machine, and starting the target virtual machine.
In one embodiment of the present invention, as shown in FIG. 4, the disk data at time S1 of the source virtual machine vm1 snapshot, i.e., the data of the copy disks vm1-disk1-S0, is cloned into the target and target virtual machine disks vm2-disk1, vm3-disk1. The virtual machine management module searches for a target virtual machine disk based on the target virtual machine ID and the temporary snapshot time transmitted by the source virtual machine ID, and if the target virtual machine disk vm2-disk1 or vm3-disk1 does not exist, the disk frozen based on the source virtual machine ID and the temporary snapshot time point, namely, the disk management module is called so as to copy the data of the first disk through a disk management interface provided by the QEMU and serve as a starting disk of the virtual machine. And calling a Libvirt starting virtual machine interface, distributing a CPU and a memory according to the resource configuration requirement of a user, constructing a virtualized operating environment, and starting the virtual machine normally after the initialization of the CPU, the internal disk and the disk resources is completed.
The target virtual machine disk vm2-disk1 and the target virtual machine disk vm3-disk1 inherit the disk blood edge relationship of vm1-disk1-s0, and have a common father node vm1-disk1. Since all disk data of the source virtual machine is referenced only by the source virtual machine before disk cloning, the disk reference count for vm1-disk1 is marked 1.
And after the disk data is cloned successfully, the target virtual machine disk is taken as a leaf node, the corresponding parent node disk is traced back, and the reference count of the parent node disk is accumulated.
In one embodiment of the invention, after disk data cloning is successful, the reference count sum of all parent node disks of the target virtual machine disk vm2-disk1 is modified, namely the reference count of the first disk vm1-disk1 is accumulated by 1, and the reference count of the first disk vm1-disk1 becomes 2 after the accumulated 1.
The reference count sum of all parent node disks of the target virtual machine disk vm3-disk1, i.e., the reference count sum of vm1-disk1, is incremented by 1, is also modified. Thus, after the target virtual machine disk clone is completed, the reference count for vm1-disk1 becomes 3.
And after the disk data cloning is successful, the reference count of the disk referenced by the first disk is accumulated by 1, namely the reference counts of the disks referenced by the first disk vm1-disk1 are correspondingly accumulated.
In the counting scheme of the application, the disk is managed through reference counting, content submission is not required to be completed, source disk data is not copied, all original data only have one copy, a plurality of virtual machines share one disk chain, and snapshot points on the disk chain are shared and used by two virtual machines. For example, when the source virtual machine is deleted, the reference count of disk nodes on all snapshot chains is greater than 1, and if the reference count is referenced by other virtual machines, the corresponding disk data is not cleaned when the source virtual machine is destroyed. If the nodes on the snapshot chain are not referenced by other virtual machines, the reference count is 1, and all disk data can be destroyed by destroying the virtual machines.
Or when the virtual machine is created, directly using the disk with the reference count larger than 1 as the disk parent node of other virtual machines.
Through reference count management, any cloud disk on the disk chain can be shared and referenced by other virtual machines, and extra data copying is not needed in the sharing process, such as: three disks are arranged on the disk snapshot chain of the virtual machine A: s1, S2 and S3, wherein S1 is a father node of S2, S2 is a father node of S3, when executing virtual machine cloning or creating a new virtual machine B, B can refer to S2 disk and S3 disk, for example, B virtual machine has disks S2 'and S3', S2 'refers to data of S2, S3' refers to data of S3, S2 is a father node of S2', S3' is a father node of S3, virtual machine B inherits data of disk S2 and disk S3 in the referencing process, and the reference count of disk S2 or disk S3 is accumulated by 1.
S3, creating a target virtual machine based on the target virtual machine disk, wherein the target virtual machine takes the target virtual machine disk as an operation disk.
And the cloud platform management and control module C calls the virtual machine management module and creates a target virtual machine by using the cloned disk.
In one embodiment of the invention, vm2-disk1 and vm3-disk1 are used as target virtual machine disks, and a target virtual machine vm2 and a target virtual machine vm3 are respectively created, wherein the target virtual machine disk vm2-disk1 is an active disk of the target virtual machine vm2, and the target virtual machine disk vm3-disk1 is an active disk of the target virtual machine vm 3. The newly created virtual machine uses the clone disk as an operation disk, and the target virtual machine reads and writes data into the cloned disk. Because the disk chain of the target virtual machine reserves the existing snapshot information of the source virtual machine, the cloned virtual machine can directly use the inherited snapshot points of the source virtual machine to execute the restoration.
So far, the target virtual machine clone is completed, and after the target virtual machines vm2 and vm3 clone is completed, the snapshot attribute can be directly inherited and the restore operation can be executed because the restore point S0 is arranged on the snapshot chain of the target virtual machine.
S4, deleting the temporary snapshot, and specifically comprising the following flow.
S41, submitting the disk data of the temporary disk to the first disk;
s42, deleting the temporary disk after the disk data of the temporary disk are submitted;
s43, switching the first disk to an active disk of the source virtual machine, and modifying the disk attribute of the first disk to be a read-write disk.
In one embodiment of the invention, the cloud platform management and control module C invokes the virtual machine snapshot management module to delete the created temporary snapshot. When deleting the temporary snapshot, the source virtual machine submits the data which is currently written into the disk to the parent node, and after the data is submitted successfully, the created temporary disk is deleted, and the read-write data of the source virtual machine is written into the submitted disk after deleting the snapshot.
As shown in FIG. 5, when the temporary snapshot S1 is deleted, all modified data on the temporary disks vm1-disk1-S1 will be committed to the first disk vm1-disk1-S0, and when vm1-disk1-S1 commit is successful, the temporary disks vm1-disk1-S1 are deleted and the virtual machine active disk is switched to vm1-disk1-S0.
It should be noted that, the disk commit of the virtual machine is to commit the data of one disk to another disk, and two disks are generated when creating the snapshot, one read-only disk and one active disk, and all the running data is written to the active disk from the cloning time. The disk commit functions to merge two disks into one disk, i.e., commit the write data of the active disk to the read-only disk, and modify the read-only disk to the active disk. In addition, the disk management layer of the first disk is not frozen, but only the service layer is frozen, so that the submission of the modified data of the temporary disk can be realized.
The embodiment of the application also provides a device for realizing cloning of the virtual machine, which is applied to the cloud computing platform shown in fig. 2 and is used for running the method for realizing cloning of the virtual machine, and the device comprises a plurality of physical servers, a cloud platform management and control module C and a distributed storage module for providing block storage service for the cloud computing platform, wherein the physical servers comprise host servers and summarizer servers, the distributed storage module at least comprises a plurality of distributed storage nodes, the summarizer servers are used for managing the distributed storage nodes, disk data of the virtual machine are stored in the distributed storage module, and each disk of the virtual machine corresponds to one distributed storage node in the distributed storage. The host server is used for deploying source and/or destination virtual machines, a virtual machine management module, a virtual machine snapshot management module and a virtual machine disk management module. And the cloud platform management and control module C responds to the clone virtual machine command and calls the virtual machine snapshot management module, the virtual machine disk management module and the virtual machine management module to clone the source virtual machine to obtain the target virtual machine.
It should be noted that, the cloud computing platform at least includes a virtual machine cloning device, and the virtual machine cloning is only a sub-functional block of the cloud computing platform, and in the present invention, because only virtual machine management is described, the cloud computing platform shown in fig. 2 may also be directly regarded as a functional block diagram of the virtual machine cloning device.
In one embodiment of the invention, the virtual machine snapshot management module is used to create a temporary snapshot and delete the temporary snapshot. The virtual machine disk management module is used for creating a virtual machine disk, copying the virtual machine disk, modifying the attribute of the virtual machine disk and modifying the reference count of the virtual machine; and the virtual machine management module is used for responding to the clone virtual machine command of the cloud platform management and control module C, calling the virtual machine snapshot management module to create a temporary snapshot, creating a temporary disk, creating a target virtual machine disk and modifying the disk attribute, calling the virtual machine disk management module to copy the first disk data to the target virtual machine disk, and starting the target virtual machine based on the target virtual machine disk.
Libvirt provides a set of API interfaces including creating virtual machines, starting virtual machines, closing virtual machines, destroying virtual machines, and the like. The virtual machine management module is adapted to the API interface of the cloud platform management and control module C for virtual machine management, and the virtual machine management is controlled and managed through the API interfaces, such as creation, deletion, startup, shutdown and the like. The virtual machine management module firstly searches whether corresponding disk files exist according to the transferred clone virtual machine ID, the source virtual machine ID, the temporary snapshot time point and other parameters, if no target virtual machine disk exists, the virtual machine management module calls the disk management module to copy the frozen disk according to the source virtual machine ID and the temporary snapshot time point, uses the disk files corresponding to the temporary snapshot time point as the starting disk of the virtual machine, and calls the starting virtual machine interface of Libvirt. The interface distributes CPU and memory according to the resource allocation requirement of the user, constructs the environment in which the virtualization needs to operate, and starts the normal starting of the virtual machine after the initialization of the CPU, the internal disk and the disk resources is completed.
The disk management module is adapted to an API interface of the cloud platform management and control module C for managing the virtual machine disk, carries out logic branch processing according to interface parameters, and further realizes the creation of the virtual machine disk, the copying of the virtual machine disk, the deletion of the virtual machine disk, the modification of the attributes such as the virtual machine reference count and the like through the disk management interface provided by the QEMU.
The virtual machine snapshot management module is used for virtual machine snapshot management, such as creating a snapshot, deleting a snapshot, and the like. The virtual machine snapshot management module is adapted to an API interface of the cloud platform management and control module C for virtual machine snapshot management, and operations such as creation, deletion, submission and the like of the virtual machine snapshot are mainly realized through a snapshot management interface provided by Libvirt. When creating a snapshot, the virtual machine snapshot management module transmits in an ID of the virtual machine to be created, a name of a target snapshot and a disk number of the virtual machine, and in the snapshot creation process, an active disk is created according to the corresponding disk ID and the snapshot name, and after the disk creation is finished, a snapshot creation interface of Libvirt is called to switch the active disk of the virtual machine.
In some embodiments, an electronic device further includes a memory, configured to store the computer program, and a processor, configured to perform the method for implementing virtual machine cloning.
In some embodiments, the method further comprises a computer readable storage medium, wherein the computer readable storage medium stores a computer program for implementing the method for cloning the virtual machine.
It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than described in this specification. Furthermore, individual steps described in this specification, in other embodiments, may be described as being split into multiple steps; while various steps described in this specification may be combined into a single step in other embodiments.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for a system or system embodiment, since it is substantially similar to a method embodiment, the description is relatively simple, with reference to the description of the method embodiment being made in part. The system and system embodiments described above are merely illustrative, and some or all of the modules may be selected according to actual needs to achieve the objectives of the present embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
Those of skill would appreciate that the elements and algorithm steps described in connection with the embodiments disclosed herein may be embodied in electronic hardware, in computer software, or in a combination of both, and that the elements and steps of each example have been generally described in terms of functions in the foregoing description to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.

Claims (7)

1. The method for realizing cloning of the virtual machine is characterized by comprising the following steps:
responding to a virtual machine cloning command, creating a temporary snapshot of a source virtual machine, creating a temporary disk as an active disk of the source virtual machine, and freezing a first disk, wherein the first disk is the active disk of the source virtual machine at the moment of creating the temporary snapshot, the temporary snapshot is of an external snapshot type, the source virtual machine at the moment of creating the temporary snapshot at least comprises a snapshot chain, the snapshot chain comprises a plurality of snapshot points, and the temporary snapshot and the snapshot points of the source virtual machine belong to the same snapshot chain;
cloning data of a first disk to create a target virtual machine disk;
creating a target virtual machine based on the target virtual machine disk, wherein the target virtual machine takes the target virtual machine disk as an operation disk;
deleting the temporary snapshot specifically comprises the following steps: submitting the disk data of the temporary disk to the first disk; deleting the temporary disk after the disk data of the temporary disk are submitted; switching the first disk to an active disk of a source virtual machine, modifying the disk attribute of the first disk to a read-write disk, wherein the first disk and a target virtual machine disk have the same father node disk,
and after the disk data is cloned successfully, the target virtual machine disk is taken as a leaf node, the corresponding parent node disk is traced back, the reference count of the parent node disk is accumulated, and the reference count of the disk referenced by the first disk is accumulated by 1.
2. The method of claim 1, wherein,
the method specifically comprises the steps of creating a temporary snapshot of a source virtual machine, creating a temporary disk as an active disk of the source virtual machine, and freezing a first disk which is the active disk of the source virtual machine at the moment of creating the temporary snapshot, wherein the method specifically comprises the following steps:
creating a temporary snapshot time;
creating a temporary disk;
modifying disk attributes, wherein the temporary disk is set as an active disk, the first disk is set as a frozen disk as a parent node disk of the temporary disk,
and switching the active disk of the source virtual machine to be a temporary disk.
3. The method for implementing virtual machine cloning according to claim 2, wherein,
the cloning the data of the first disk to create the target virtual machine specifically comprises the following steps:
searching a target virtual machine disk based on the target virtual machine ID, the source virtual machine ID and the temporary snapshot time;
if the target virtual machine disk does not exist, copying the first disk data based on the source virtual machine ID, and taking the disk created after the copying is completed as the target virtual machine disk;
and creating a target virtual machine running environment, taking a target virtual machine disk as an active disk of the target virtual machine, and starting the target virtual machine.
4. The method of claim 1, wherein,
the method further comprises the steps of responding to a virtual machine deleting command, and if the reference count of a corresponding disk on a snapshot chain included by the virtual machine is 1, deleting the disk data of the disk with the reference count of 1 while cleaning the virtual machine;
if the reference count of the corresponding disk on the snapshot chain included in the virtual machine is greater than 1, deleting the disk data with the reference count not being 1 when deleting the virtual machine.
5. The method of claim 4, further comprising selecting a disk with a reference count greater than 1 as a disk parent node of the other virtual machine when creating the virtual machine.
6. The method of claim 1, further comprising restoring the target virtual machine based on a snapshot restore point stored on a disk of the target virtual machine.
7. An implementation device of virtual machine cloning, which is used for running the implementation method of virtual machine cloning according to any one of claims 1-6 and is applied to a cloud computing platform, wherein the cloud computing platform at least comprises a plurality of physical servers, a cloud platform management and control module and a distributed storage module for providing block storage service for the cloud computing platform, the physical servers at least comprise host servers and summarizer servers, the distributed storage module at least comprises a plurality of distributed storage nodes, the summarizer servers are used for managing the distributed storage nodes, disk data of the virtual machine is stored in the distributed storage module, each disk of the virtual machine corresponds to one distributed storage node in the distributed storage,
the at least one host machine server is used for deploying a virtual machine, a virtual machine management module, a virtual machine snapshot management module and a virtual machine disk management module; wherein the virtual machines comprise source virtual machines and/or destination virtual machines,
the cloud platform management and control module responds to a clone virtual machine command and calls a virtual machine snapshot management module, a virtual machine disk management module and a virtual machine management module, wherein the cloud platform management and control module is used for cloning a source virtual machine to obtain a target virtual machine;
the virtual machine snapshot management module is used for creating a temporary snapshot and deleting the temporary snapshot;
the virtual machine disk management module is used for creating a virtual machine disk, copying the virtual machine disk and modifying the attribute of the virtual machine disk;
the virtual machine management module is used for responding to a clone virtual machine command of the cloud platform management and control module, calling the virtual machine snapshot management module to create a temporary snapshot, creating a temporary disk, creating a target virtual machine disk and modifying disk attributes, calling the virtual machine disk management module to copy first disk data to the target virtual machine disk, and starting the target virtual machine based on the target virtual machine disk.
CN202311363296.9A 2023-10-20 2023-10-20 Method and device for realizing cloning of virtual machine Active CN117093332B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311363296.9A CN117093332B (en) 2023-10-20 2023-10-20 Method and device for realizing cloning of virtual machine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311363296.9A CN117093332B (en) 2023-10-20 2023-10-20 Method and device for realizing cloning of virtual machine

Publications (2)

Publication Number Publication Date
CN117093332A CN117093332A (en) 2023-11-21
CN117093332B true CN117093332B (en) 2024-02-27

Family

ID=88775707

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311363296.9A Active CN117093332B (en) 2023-10-20 2023-10-20 Method and device for realizing cloning of virtual machine

Country Status (1)

Country Link
CN (1) CN117093332B (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101609419A (en) * 2009-06-29 2009-12-23 北京航空航天大学 The data back up method and the device of the migration of virtual machine consistently online
CN102520881A (en) * 2011-12-02 2012-06-27 中标软件有限公司 Virtual machine snapshot management method and system of cloud computing platform
CN102799464A (en) * 2012-06-25 2012-11-28 北京奇虎科技有限公司 Virtual machine creation method, virtual machine creation system, virtual machine resetting method and virtual machine resetting system
CN106569872A (en) * 2016-09-28 2017-04-19 浪潮电子信息产业股份有限公司 Method for shortening virtual machine snapshot chain
CN107643941A (en) * 2017-10-12 2018-01-30 郑州云海信息技术有限公司 The method and apparatus that virtual machine is managed in cloud data system
CN109189546A (en) * 2018-07-11 2019-01-11 新华三云计算技术有限公司 A kind of production method and device of the online snapshot of virtual machine
US10678651B1 (en) * 2014-12-30 2020-06-09 Acronis International Gmbh Backing up a virtual machine using a snapshot with memory
CN111984370A (en) * 2020-07-30 2020-11-24 苏州浪潮智能科技有限公司 Method and device for online migration of multi-disk virtual machine to different storage pools
CN112181596A (en) * 2020-10-10 2021-01-05 济南浪潮数据技术有限公司 Virtual machine cloning method, device, equipment and storage medium
CN112199162A (en) * 2020-10-16 2021-01-08 济南浪潮数据技术有限公司 Disk snapshot method, device and medium based on virtualized disk double-active disaster tolerance
CN113296716A (en) * 2021-07-09 2021-08-24 云宏信息科技股份有限公司 Virtual machine disk online migration method, computer readable storage medium and computer

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9116737B2 (en) * 2013-04-30 2015-08-25 Vmware, Inc. Conversion of virtual disk snapshots between redo and copy-on-write technologies
US9304705B2 (en) * 2013-09-06 2016-04-05 Vmware, Inc. Virtual machine cloning

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101609419A (en) * 2009-06-29 2009-12-23 北京航空航天大学 The data back up method and the device of the migration of virtual machine consistently online
CN102520881A (en) * 2011-12-02 2012-06-27 中标软件有限公司 Virtual machine snapshot management method and system of cloud computing platform
CN102799464A (en) * 2012-06-25 2012-11-28 北京奇虎科技有限公司 Virtual machine creation method, virtual machine creation system, virtual machine resetting method and virtual machine resetting system
US10678651B1 (en) * 2014-12-30 2020-06-09 Acronis International Gmbh Backing up a virtual machine using a snapshot with memory
CN106569872A (en) * 2016-09-28 2017-04-19 浪潮电子信息产业股份有限公司 Method for shortening virtual machine snapshot chain
CN107643941A (en) * 2017-10-12 2018-01-30 郑州云海信息技术有限公司 The method and apparatus that virtual machine is managed in cloud data system
CN109189546A (en) * 2018-07-11 2019-01-11 新华三云计算技术有限公司 A kind of production method and device of the online snapshot of virtual machine
CN111984370A (en) * 2020-07-30 2020-11-24 苏州浪潮智能科技有限公司 Method and device for online migration of multi-disk virtual machine to different storage pools
WO2022021856A1 (en) * 2020-07-30 2022-02-03 苏州浪潮智能科技有限公司 Method and apparatus for online migration of multi-disk virtual machine into different storage pools
CN112181596A (en) * 2020-10-10 2021-01-05 济南浪潮数据技术有限公司 Virtual machine cloning method, device, equipment and storage medium
CN112199162A (en) * 2020-10-16 2021-01-08 济南浪潮数据技术有限公司 Disk snapshot method, device and medium based on virtualized disk double-active disaster tolerance
CN113296716A (en) * 2021-07-09 2021-08-24 云宏信息科技股份有限公司 Virtual machine disk online migration method, computer readable storage medium and computer

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
云计算环境下的虚拟机快速克隆技术;郑婷婷;武延军;贺也平;;计算机工程与应用(第13期);全文 *
面向OpenStack/Ceph的虚拟机备份***研究;杨皓森;胡晓勤;黄传波;;计算机***应用(第11期);全文 *

Also Published As

Publication number Publication date
CN117093332A (en) 2023-11-21

Similar Documents

Publication Publication Date Title
US9037621B2 (en) Efficient reconstruction of virtual disk hierarchies across storage domains
US9569200B2 (en) Live operating system update mechanisms
US9619223B2 (en) Live operating system update mechanisms
US9400611B1 (en) Data migration in cluster environment using host copy and changed block tracking
CN107111533B (en) Virtual machine cluster backup
US9671967B2 (en) Method and system for implementing a distributed operations log
US10564996B2 (en) Parentless virtual machine forking
US8635395B2 (en) Method of suspending and resuming virtual machines
US8769226B2 (en) Discovering cluster resources to efficiently perform cluster backups and restores
US8191063B2 (en) Method for migrating a plurality of virtual machines by associating files and state information with a single logical container
US9460028B1 (en) Non-disruptive and minimally disruptive data migration in active-active clusters
US9529807B2 (en) Creating host-level application-consistent backups of virtual machines
US9852198B1 (en) Method and system for fast generation of file system snapshot bitmap in virtual environment
US8473463B1 (en) Method of avoiding duplicate backups in a computing system
US20130185509A1 (en) Computing machine migration
US10353872B2 (en) Method and apparatus for conversion of virtual machine formats utilizing deduplication metadata
WO2017132872A1 (en) Virtual machine backup method, backup device and host
JP2022546566A (en) System and method for marking application consistency points in time
US20160179437A1 (en) Consistent replication of virtual computing instance data
CN112328365A (en) Virtual machine migration method, device, equipment and storage medium
US11693689B2 (en) Online disk encryption using mirror driver
CN117093332B (en) Method and device for realizing cloning of virtual machine
US20220382648A1 (en) Method and apparatus for phased transition of legacy systems to a next generation backup infrastructure
CN117130980B (en) Virtual machine snapshot management method and device
WO2023121874A1 (en) Backup, restore, and migration of cloud managed configuration properties

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: 310000 room 611-612, Zhuoxin building, No. 3820, South Ring Road, Puyan street, Binjiang District, Hangzhou City, Zhejiang Province

Patentee after: Hangzhou Youyun Technology Co.,Ltd.

Country or region after: China

Address before: 310000 room 611-612, Zhuoxin building, No. 3820, South Ring Road, Puyan street, Binjiang District, Hangzhou City, Zhejiang Province

Patentee before: Hangzhou Youyun Technology Co.,Ltd.

Country or region before: China