Methods, equipment, and computer-readable media for processing internal snapshots
By introducing a global snapshot ID and asynchronously updating the COW tag and reference count, the problem of time-consuming internal snapshot creation in the qcow2 format was solved, performance was improved, the impact on virtual machine services was reduced, and rapid internal snapshot creation was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI YUNZHOU INFORMATION & TECH LTD
- Filing Date
- 2024-01-08
- Publication Date
- 2026-05-26
AI Technical Summary
The existing qcow2 format internal snapshot creation process requires traversing a large number of allocated clusters' COW tags and reference counts, resulting in excessively long creation time and impacting virtual machine service performance.
A global snapshot ID is introduced. When creating a cluster, a COW (Copy-on-Write) flag is added to the new cluster and the cluster snapshot ID is set. When overwriting a cluster, the cluster snapshot ID is compared with the global snapshot ID, triggering the COW mechanism to generate a new cluster and asynchronously updating the reference count, reducing the need for real-time traversal of the index table.
It significantly improves the performance of internal snapshot creation, reduces the impact on virtual machine services, and reduces the creation speed from seconds or minutes to milliseconds, meeting the second-level snapshot requirements of data center disaster recovery and CDP.
Smart Images

Figure CN117873961B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information technology, and in particular to a method, apparatus and computer-readable medium for processing internal snapshots in qcow2 format. Background Technology
[0002] qcow2 is a storage format based on COW (Copy On Write) and is widely used in virtualized cloud computing environments. Its main advantages include:
[0003] 1) Supports copy-on-write technology, which can save storage space;
[0004] 2) Supports compression, which can further save storage space;
[0005] 3) Supports snapshot technology, enabling the rapid creation of virtual machine backups, testing, and development environments;
[0006] 4) Supports encryption, which can protect sensitive data in the virtual machine;
[0007] 5) Supports dynamic adjustment of virtual machine size, allowing you to increase or decrease the storage space of the virtual machine as needed;
[0008] 6) Supports multiple operating systems and can run a variety of different operating systems.
[0009] like Figure 1 As shown, qcow2, a mainstream virtual machine image storage format, establishes a mapping between images and clusters through two-level index tables, namely L1 table and L2 table. When accessing a qcow2 image, only the L1 table and L2 table need to be traversed to access the cluster containing all data. Currently, qcow2 supports both external and internal snapshots, which can be used to create backup copies of virtual machine data and quickly recover data in case of loss or corruption, thereby improving the reliability and availability of virtual machines.
[0010] To support internal snapshots, qcow2 introduces a COW flag in the index table entries (L1 and L2 table entries) to indicate the read-only attribute of a cluster. When creating an internal snapshot, all allocated clusters pointed to by the currently active L1 and L2 tables are marked with the COW flag, such as... Figure 2As shown. When new data needs to be written to a cluster with a COW (Copy-on-Write) flag, qcow2's COW mechanism is triggered, creating a new cluster and copying the data from the original cluster. The new cluster does not have a COW flag, and new data is written to the new cluster, not the original cluster, to ensure that the data in the original cluster does not change. When an internal snapshot is created next time, the newly created cluster will be marked with a COW flag to ensure that the content of the cluster referenced by the internal snapshot does not change subsequently. Since the same cluster can be referenced by multiple internal snapshots during this process, a single COW flag is insufficient. Therefore, qcow2 further introduces a cluster reference count to record the number of times the current activeL1, L2table, and all internal snapshots reference it. Figure 3 As shown in the diagram, each box represents a cluster, and the specific values represent the cluster's reference count after data is written, an internal snapshot is created, and an internal snapshot is deleted. When an internal snapshot is created, the reference count of each cluster referenced by that internal snapshot is incremented by 1, and when an internal snapshot is deleted, the reference count of each cluster referenced by that internal snapshot is decremented by 1. When a cluster is allocated a new cluster due to triggering the COW mechanism, the new cluster's reference count is initialized to 1 (indicating it is referenced by the current active L1 and L2 tables), while the original cluster's reference count is decremented by 1.
[0011] Because creating an internal snapshot requires traversing the active L1 and L2 tables to update the COW flags and reference counts for all allocated clusters, and given the large amount of data in the qcow2 image and the large number of allocated clusters, each internal snapshot creation requires a significant amount of time to iterate and update the COW flags and reference counts of the clusters. This results in a very lengthy internal snapshot creation process, degrading the performance of qcow2 internal snapshots. Furthermore, during the internal snapshot creation period, virtual machine service requests will be temporarily unavailable, which can severely impact virtual machine services. Summary of the Invention
[0012] One object of this application is to provide a method, apparatus, and computer-readable medium for processing internal snapshots in qcow2 format.
[0013] To achieve the above objectives, this application provides a method for processing internal snapshots in qcow2 format, the method comprising:
[0014] When creating a cluster, add a COW tag to the first newly created cluster and set the cluster snapshot ID of the first cluster to the current global snapshot ID;
[0015] When creating an internal snapshot, increment the current global snapshot ID by a preset value;
[0016] When overwriting a cluster, the cluster snapshot ID of the second cluster that needs to be written with new data is obtained, and the second cluster snapshot ID is compared with the current global snapshot ID. If the second cluster snapshot ID is inconsistent with the current global snapshot ID, a new third cluster is generated based on the COW mechanism, new data is written to the third cluster, a COW mark is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID. At the same time, the COW mark of the second cluster is removed, and the reference count of the second cluster is updated according to the number of internal snapshots of the second cluster that are currently referenced.
[0017] Furthermore, the method also includes:
[0018] If the cluster snapshot ID of the second cluster is the same as the current global snapshot ID, write new data to the second cluster.
[0019] Furthermore, a new third cluster is generated based on the COW mechanism, new data is written to the third cluster, a COW tag is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID, including:
[0020] Create a new third cluster, copy the current data from the second cluster to the third cluster, write new data to the third cluster, add a COW tag to the third cluster, and set the cluster snapshot ID of the third cluster to the current global snapshot ID.
[0021] Furthermore, the reference count of the second cluster is updated based on the number of internal snapshots currently referencing the second cluster, including:
[0022] Iterate through the internal snapshot table to find all internal snapshots that reference the second cluster;
[0023] The number of internal snapshots that reference the second cluster is set as the reference count of the second cluster.
[0024] Furthermore, the method also includes:
[0025] When deleting an internal snapshot, determine the fourth cluster referenced by that internal snapshot;
[0026] If the fourth cluster does not have a COW tag, decrement the reference count of the fourth cluster by 1.
[0027] Furthermore, the method also includes:
[0028] Determine the reference count of the cluster; if the reference count is 0, release the cluster.
[0029] Furthermore, the method also includes:
[0030] If the fourth cluster has a COW tag, skip the fourth cluster.
[0031] The initial value of the reference count in the newly created cluster is set to 1.
[0032] Based on another aspect of this application, a processing apparatus for an internal snapshot in qcow2 format is also provided. The apparatus includes a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the apparatus is triggered to execute the processing method for the internal snapshot in qcow2 format.
[0033] This application also provides a computer-readable medium storing computer program instructions that can be executed by a processor to implement the method for processing internal snapshots in the qcow2 format.
[0034] Compared with existing technologies, this application provides a processing scheme for internal snapshots in qcow2 format. When creating a cluster, this scheme adds a COW (Copy-on-Write) tag to the newly created first cluster and sets the cluster snapshot ID of the first cluster to the current global snapshot ID. When creating an internal snapshot, the current global snapshot ID is incremented by a preset value. When overwriting a cluster, the cluster snapshot ID of the second cluster to which new data needs to be written is obtained, and the second cluster snapshot ID is compared with the current global snapshot ID. If the cluster snapshot ID of the second cluster is inconsistent with the current global snapshot ID, a new third cluster is generated based on the COW mechanism, new data is written to the third cluster, a COW tag is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID. Simultaneously, the COW tag of the second cluster is removed, and the reference count of the second cluster is updated according to the number of internal snapshots currently referencing the second cluster. Therefore, when creating an internal snapshot, this solution does not need to traverse the index table to update the COW mark and index count of all clusters in real time. Instead, it uses an additional global snapshot ID to make the judgment and updates the COW mark and reference count asynchronously at other time periods. This can significantly improve the performance of creating internal snapshots and reduce the impact on virtual machine services. Attached Figure Description
[0035] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0036] Figure 1 A schematic diagram illustrating the indexing principle of qcow2 format image files;
[0037] Figure 2 A diagram illustrating the index table entries for a qcow2 format image file;
[0038] Figure 3 A schematic diagram illustrating the reference count change process of a qcow2 format image file;
[0039] Figure 4 This is a schematic diagram of the expanded index table entry information in an embodiment of this application;
[0040] Figure 5 This is a schematic diagram showing the specific state of the qcow2 image after the first data write in this embodiment of the application;
[0041] Figure 6 This document describes the specific state of the qcow2 image after the first internal snapshot is created in the embodiments of this application.
[0042] intention;
[0043] Figure 7 This is a schematic diagram showing the specific state of the qcow2 image after the second data write in the embodiments of this application;
[0044] Figure 8 This is a schematic diagram showing the specific state of the qcow2 image after the second internal snapshot is created in this embodiment of the application.
[0045] Figure 9 This is a schematic diagram showing the specific state of the qcow2 image after the third data write in this embodiment of the application;
[0046] Figure 10 This is a schematic diagram illustrating the specific state of the qcow2 image after deleting the internal snapshot 1 in an embodiment of this application.
[0047] The same or similar reference numerals in the accompanying drawings represent the same or similar parts. Detailed Implementation
[0048] The present application will now be described in further detail with reference to the accompanying drawings.
[0049] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0050] In a typical configuration of this application, the terminal and the service network devices each include one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0051] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0052] Computer-readable media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, read-only optical disc (CD-ROM), digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0053] This application provides a processing scheme for internal snapshots in qcow2 format. When creating an internal snapshot, this scheme does not need to traverse the index table to update the COW tags and index counts of all clusters in real time. Instead, it uses an additionally introduced global snapshot ID to make a judgment and asynchronously updates the COW tags and reference counts at other time periods. This can significantly improve the performance when creating internal snapshots and reduce the impact on virtual machine services.
[0054] In practical scenarios, the execution subject of this method can be a user device, a network device, or a device composed of user devices and network devices integrated through a network, or it can be an application running on the aforementioned devices. The user device includes, but is not limited to, various terminal devices such as computers, mobile phones, and tablets; the network device includes, but is not limited to, network hosts, single network servers, multiple network server sets, or cloud computing-based computer sets. Here, the cloud consists of a large number of hosts or network servers based on cloud computing, where cloud computing is a type of distributed computing, consisting of a virtual computer composed of a group of loosely coupled computer sets.
[0055] This application provides a method for processing internal snapshots in qcow2 format. This method introduces a global snapshot ID (identity), which is denoted as the fast snapshot id. This fast snapshot id monotonically increments by a preset value each time an internal snapshot is created, and remains unchanged under other circumstances, such as when deleting a snapshot. In practical scenarios, for ease of calculation, the preset increment can be set to 1, and the initial value of the fast snapshot id can be set to 0. Furthermore, since the existing index table entry information L1tableentry and L2tableentry have a data length of 64 bits, they can be extended to 128 bits to facilitate recording the fast snapshot id in the L1 and L2 table entries corresponding to the cluster. Figure 4 As shown.
[0056] Unlike existing internal snapshot schemes, this embodiment adds a COW (Choose-Own-Write) tag to the newly created first cluster and sets the cluster snapshot ID of the first cluster to the current global snapshot ID. In contrast, existing internal snapshot schemes do not add a COW tag to the newly created first cluster; the COW tag is added during internal snapshot creation, and the additional cluster snapshot ID is not recorded.
[0057] The cluster snapshot ID refers to the global snapshot ID at the time of cluster creation, which can be recorded in the L1 and L2 table entries corresponding to the first cluster. For example, if a cluster1 is created at time t1, this...
[0058] If the fast snapshot ID at that time is 1, then that fast snapshot ID can be written into the L1 and L2 table entries corresponding to cluster1 as the cluster snapshot ID of cluster1. Therefore, the cluster snapshot ID of cluster1 is 1.
[0059] In the scheme of this application embodiment, when creating an internal snapshot, it is only necessary to increment the current global snapshot ID by a preset value, without traversing the L1table and L2table to update the COW flag and reference count of each cluster. For example, if the current fast snapshot ID is 1 and the preset increment value is 1, and an internal snapshot is created, the fast snapshot ID will increment from 1 to 2. Before the next internal snapshot is created, if a new cluster is created, the cluster snapshot IDs of all clusters created during this period will be set to 2.
[0060] When overwriting a cluster, the cluster snapshot ID of the second cluster to which new data needs to be written can be obtained and compared with the current global snapshot ID. If the cluster snapshot ID of the second cluster is inconsistent with the current global snapshot ID, a new third cluster is generated based on the Copy-on-Write (COW) mechanism, new data is written to the third cluster, a COW tag is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID. At the same time, the COW tag of the second cluster is removed, and the reference count of the second cluster is updated according to the number of internal snapshots of the second cluster that currently reference it.
[0061] In this context, "overwrite cluster" refers to writing new data to an existing cluster. Taking a cluster called cluster2 as an example, if the cluster snapshot ID of cluster2 is 2 and the current fast snapshot ID is 3, it means that after cluster2 was created, a new internal snapshot has already been created. Therefore, cluster2 was not created in the currently active qcow2 image and has been referenced by a previously created internal snapshot. Thus, the COW mechanism needs to be triggered. Based on the COW mechanism, a new third cluster is generated, new data is written to the third cluster, a COW tag is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID.
[0062] The specific execution process of the COW mechanism includes: creating a new third cluster, copying the current data from the second cluster to the third cluster, writing new data to the third cluster, adding a COW tag to the third cluster, and setting the cluster snapshot ID of the third cluster to the current global snapshot ID. For example, in this embodiment, the third cluster created is cluster3. The current data from the second cluster, cluster2, can be copied to cluster3. Since cluster3 is a newly created cluster, the cluster snapshot ID of cluster3 can be set to the current fast snapshot ID (which is 3 in this case) according to the aforementioned cluster creation process. The new data to be written can be written to cluster3 instead of the original cluster2.
[0063] Meanwhile, for the original cluster2, the COW (Copy-on-Write) flag of cluster2 can be removed, and the reference count of the second cluster can be updated based on the number of internal snapshots currently referencing cluster2. Thus, this solution shifts the processing of updating the COW flag and reference count from the internal snapshot creation phase to the data writing phase triggered by the COW mechanism. It no longer requires traversing the index table to update the COW flag and index count of all clusters in real time when creating an internal snapshot. Instead, it uses the additionally set global snapshot ID in this solution to determine whether the COW mechanism has been triggered, and asynchronously updates the COW flag and reference count when triggered. This significantly improves the performance of creating internal snapshots and reduces the impact on virtual machine services.
[0064] In another scenario, if the cluster snapshot ID of the second cluster matches the current global snapshot ID, then new data is written to the second cluster. For example, if the cluster snapshot ID of cluster2 is 2, and the current fast snapshot ID is also 2, it means that no new internal snapshots have been created since the creation of cluster2. Therefore, cluster2 was created in the currently active qcow2 image and is not referenced by any internal snapshot, so the COW mechanism will not be triggered, and new data can be written directly to cluster2.
[0065] In some embodiments of this application, when updating the reference count of the second cluster based on the number of internal snapshots currently referencing the second cluster, the internal snapshot table can be traversed first to find all internal snapshots referencing the second cluster, and then the number of internal snapshots referencing the second cluster can be set as the reference count of the second cluster. For example, for the aforementioned cluster2, after triggering the COW mechanism to overwrite data, if two internal snapshots referencing cluster2 are found by traversing the internal snapshot table, then the reference count of cluster2 can be set to 2.
[0066] In practical scenarios, the internal snapshot table contains currently created internal snapshots, such as snapshot1, snapshot2, and snapshot3. When accessing an internal snapshot, the L1 table pointed to by a specific internal snapshot is loaded from the snapshot table. Then, by traversing the L2 table based on this L1 table, all clusters corresponding to the internal snapshot can be determined. Therefore, the snapshot table can be used to find all internal snapshots that reference a particular cluster.
[0067] When deleting an internal snapshot, the fourth cluster referenced by the internal snapshot is determined. If the fourth cluster does not have a COW (Copy-on-Write) flag, its reference count is decremented by 1. In practical scenarios, the fourth cluster can be found by traversing the L1 and L2 tables. That is, first find the L1 table pointed to by the internal snapshot, and then traverse the L2 table according to the L1 table to determine all clusters corresponding to the internal snapshot. Taking one of the fourth clusters, cluster4, as an example, it is determined whether cluster4 has a COW flag. If it does not have a COW flag, it means that cluster4 has already triggered the COW mechanism, and its reference count has been updated, which can correctly represent the number of internal snapshots of cluster4 referenced before the current deletion operation. Therefore, decrementing the reference count of cluster4 by 1 can correctly represent the number of internal snapshots of cluster4 referenced after the current deletion operation.
[0068] Furthermore, in the scheme of this application embodiment, the reference count of the cluster can be further determined. If the reference count is 0, the cluster is released. Taking cluster4 as an example again, if the reference count of cluster4 is decremented by 1 and the reference count is 0, it means that no internal snapshots reference cluster4 at this time, so cluster4 can be released to free up available capacity. Conversely, if the reference count of cluster4 is not 0 after decrementing by 1, it means that there are still internal snapshots referencing cluster4, and their number is equal to the specific value of the reference count. It should be noted that the first cluster, second cluster, third cluster, and fourth cluster mentioned in the embodiments of this application are only used to distinguish different stages of cluster processing to facilitate the explanation of the above different processing stages. The above different names can refer to the same specific cluster or different clusters.
[0069] Furthermore, to prevent clusters from being mistakenly deleted, the reference count in newly created clusters cannot be set to 0. Therefore, the initial value of the reference count in newly created clusters is set to a non-zero integer. For example, in this embodiment, the initial value of the reference count can be uniformly set to 1. Taking the previous cluster1 as an example, when cluster1 is created at time t1, if the fast snapshot ID at this time is 1, then the fast snapshot ID at this time can be written into the L1 and L2 table entries corresponding to cluster1 as the cluster snapshot ID of cluster1, and at the same time, the reference COW flag is set and its reference count is set to 1.
[0070] Taking a qcow2 image as an example, the internal snapshot processing procedure provided in this application embodiment is described. This process includes three data writes, two internal snapshot creations, and one internal snapshot deletion. The detailed process is as follows:
[0071] 1. First Data Write. During the first data write, three clusters are created: cluster1, cluster2, and cluster3. Since no internal snapshots have been created at this time, the current fast snapshot ID is set to the initial value of 0. Therefore, the cluster snapshot IDs in cluster1, cluster2, and cluster3 are set to 0 upon creation. In this embodiment, the cluster snapshot ID is recorded as id = 0. The COW flag is represented by a COW flag bit; a COW flag bit of 1 indicates the presence of a COW flag, and a COW flag bit of 0 indicates the absence of a COW flag. The reference count is set to the initial value of 1. Therefore, the specific state of the qcow2 image at this time is as follows: Figure 5 As shown.
[0072] 2. First internal snapshot creation. During this internal snapshot creation, snapshot1 references cluster1, cluster2, and cluster3. While updating the index table, the fast snapshot ID is incremented by 1 (from 0 to 1). There is no need to update the reference counts and COW flags for each cluster. At this point, the specific status of the qcow2 image is as follows: Figure 6 As shown.
[0073] 3. Second Data Write. During this data write, a new cluster, cluster4, was created and data was written to it. Data was not overwritten to clusters1, 2, and 3. Therefore, the information for clusters1, 2, and 3 remained unchanged. For cluster4, since the current FastSnapshot ID is 1, the cluster snapshot ID in cluster4 is set to 1 upon creation, the COW flag is set to 1 (indicating COW), and the reference count is set to the initial value of 1. Thus, the specific status of the qcow2 image at this time is as follows: Figure 7 As shown.
[0074] 4. Second internal snapshot creation. During this internal snapshot creation, snapshot2 references cluster1, cluster2, cluster3, and cluster4. While updating the index table, the fast snapshot ID is incremented by 1 (from 1 to 2). It is not necessary to update the reference counts and COW flags for each cluster. The specific status of the qcow2 image at this time is as follows: Figure 8 As shown.
[0075] 5. Third Data Write. During this write, data is overwritten to cluster 3. Therefore, the information for clusters 1, 2, and 4 remains unchanged. For the Gates overwrite, a new cluster, cluster 5, is created. The current data from cluster 3 is copied to cluster 5, and the new data to be written for this overwrite is written to cluster 5. Since the current fast snapshot ID is 2, the cluster snapshot ID in cluster 5 is set to 2 upon creation, the COW flag is set to 1, indicating a COW tag, and the reference count is set to the initial value of 1. For cluster 3, the cluster's COW tag is removed, its COW flag is set to 0, and its reference count is updated to 2 based on the number of internal snapshots currently referencing cluster 3 (including snapshot 1 and snapshot 2). At this point, the specific status of the qcow2 image is as follows: Figure 9 As shown.
[0076] 6. Delete internal snapshot 1. When deleting snapshot 1, by traversing the index table, it can be determined that the clusters it references are cluster1, cluster2, and cluster3. Cluster1 and cluster2, since they haven't triggered the COW mechanism, still have COW tags, so they are skipped without processing. Cluster3, however, triggered the COW mechanism during the third data write and no longer has a COW tag, so its reference count is decremented by 1, updating from 2 to 1. At this point, the specific state of the qcow2 image is as follows: Figure 10 As shown, since the reference count of no cluster is 0, there is no need to release the cluster.
[0077] The above solution effectively addresses the shortcomings of existing qcow2 internal snapshot technology, realizing a new type of internal snapshot processing technology. It solves the problem of uncontrollable performance during internal snapshot creation, ensuring that the creation of internal snapshots does not affect the operation of virtual machine services. The creation performance of internal snapshots is no longer affected by the total allocated cluster size, and the response speed during creation is reduced from uncontrollable seconds or even minutes to milliseconds. It can be used for data center disaster recovery and disaster recovery scenarios, and can also meet the second-level snapshot requirements of CDP (Continuous Data Protection).
[0078] Based on the same inventive concept, this application also provides a processing device for qcow2 format internal snapshots. The method corresponding to this device is the qcow2 format internal snapshot processing method in the aforementioned embodiments, and its problem-solving principle is similar to that method. The qcow2 format internal snapshot processing device provided in this application includes a memory for storing computer program instructions and a processor for executing the computer program instructions. When the computer program instructions are executed by the processor, the device is triggered to implement the methods and / or technical solutions of the aforementioned multiple embodiments of this application.
[0079] The device can be specifically implemented as a user device, a network device, or a device composed of user devices and network devices integrated through a network, or it can be an application running on the aforementioned device. The user device includes, but is not limited to, various terminal devices such as computers, mobile phones, and tablets; the network device includes, but is not limited to, implementations such as network hosts, single network servers, multiple network server sets, or cloud computing-based computer sets. Here, the cloud consists of a large number of hosts or network servers based on cloud computing, where cloud computing is a type of distributed computing, a virtual computer composed of a group of loosely coupled computer sets.
[0080] In particular, the methods and / or embodiments in this application can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowchart. When the computer program is executed by a processing unit, it performs the functions defined in the methods of this application.
[0081] It should be noted that the computer-readable medium described in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0082] In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, capable of transmitting, propagating, or transmitting a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wireline, optical fiber, RF, etc., or any suitable combination thereof.
[0083] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0084] The flowcharts or block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of devices, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-specific system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0085] In another aspect, this application also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The aforementioned computer-readable medium carries one or more computer program instructions, which may be executed by a processor to implement the methods and / or technical solutions of the various embodiments of this application.
[0086] It should be noted that this application can be implemented in software and / or a combination of software and hardware, for example, using an application-specific integrated circuit (ASIC), a general-purpose computer, or any other similar hardware device. In some embodiments, the software program of this application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of this application (including related data structures) can be stored in a computer-readable recording medium, such as RAM memory, magnetic or optical drives, floppy disks, and similar devices. Furthermore, some steps or functions of this application can be implemented in hardware, for example, as circuitry that cooperates with a processor to perform the various steps or functions.
[0087] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within this application. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in the apparatus claims may also be implemented by a single unit or device through software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order. The numerical order of the sequence numbers corresponding to the steps does not indicate any particular execution order; the steps may be executed in any combination of orders provided that the execution logic is followed.
Claims
1. A method for processing internal snapshots in qcow2 format, characterized in that, The method includes: When creating a cluster, add a COW tag to the first newly created cluster and set the cluster snapshot ID of the first cluster to the current global snapshot ID; When creating an internal snapshot, increment the current global snapshot ID by a preset value; When overwriting a cluster, the cluster snapshot ID of the second cluster that needs to be written with new data is obtained, and the second cluster snapshot ID is compared with the current global snapshot ID. If the second cluster snapshot ID is inconsistent with the current global snapshot ID, a new third cluster is generated based on the COW mechanism, new data is written to the third cluster, a COW mark is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID. At the same time, the COW mark of the second cluster is removed, and the reference count of the second cluster is updated according to the number of internal snapshots of the second cluster that are currently referenced.
2. The method according to claim 1, characterized in that, The method further includes: If the cluster snapshot ID of the second cluster is the same as the current global snapshot ID, write new data to the second cluster.
3. The method according to claim 1, characterized in that, A new third cluster is generated based on the Copy-on-Write (COW) mechanism. New data is written to the third cluster, a COW tag is added to the third cluster, and the cluster snapshot ID of the third cluster is set to the current global snapshot ID, including: Create a new third cluster, copy the current data from the second cluster to the third cluster, write new data to the third cluster, add a COW tag to the third cluster, and set the cluster snapshot ID of the third cluster to the current global snapshot ID.
4. The method according to claim 1, characterized in that, The reference count of the second cluster is updated based on the number of internal snapshots of the second cluster that are currently referenced, including: Iterate through the internal snapshot table to find all internal snapshots that reference the second cluster; The number of internal snapshots that reference the second cluster is set as the reference count of the second cluster.
5. The method according to claim 1, characterized in that, The method further includes: When deleting an internal snapshot, determine the fourth cluster referenced by that internal snapshot; If the fourth cluster does not have a COW tag, decrement the reference count of the fourth cluster by 1.
6. The method according to claim 5, characterized in that, The method further includes: Determine the reference count of the cluster; if the reference count is 0, release the cluster.
7. The method according to claim 5, characterized in that, The method further includes: If the fourth cluster has a COW tag, skip the fourth cluster.
8. The method according to claim 1, characterized in that, The initial value of the reference count in the newly created cluster is set to 1.
9. A processing apparatus for internal snapshots in qcow2 format, the apparatus comprising a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein, When the computer program instructions are executed by the processor, the device is triggered to perform the method of any one of claims 1 to 8.
10. A computer-readable medium having stored thereon computer program instructions that can be executed by a processor to implement the method as described in any one of claims 1 to 8.