Delay segmented copy-on-write method and device for file system

By creating a copy of the file that has not been allocated physical disk space in the file system and delaying the allocation of space during writes, the existing CoW mechanism cannot achieve simple, cross-file system and low I/O and disk consumption, and efficient data sharing and storage optimization is achieved.

CN120066422AActive Publication Date: 2025-05-30BEIJING HAIYUDONGXIANG TECH CO LTD

Patent Information

Application Number
CN202510553089.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-29
Publication Date
2025-05-30
Estimated Expiration
2045-04-29

AI Technical Summary

Technical Problem

When the prior art implements the Copy-on-Write (CoW) mechanism in a file system, it is impossible to realize simple, cross-file system and low I/O and disk consumption of partial file data sharing.

Method used

By creating a copy of the file in which the logical data segment is not allocated for physical disk space in the readable and writeable directory, when the application opens the file in a write mode, the physical disk space is delayed and the corresponding data is copied and written.

Benefits of technology

It realizes data sharing across file systems, reduces I/O and storage consumption, and simplifies the implementation of the CoW mechanism.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066422A_ABST
    Figure CN120066422A_ABST
Patent Text Reader

Abstract

The invention provides a delayed segmented copy-on-write method and device for a file system, and the method comprises the steps: when an application opens a first file under a first directory in a writing manner, if it is judged that a second file exists under a read-only second directory and a third file does not exist under a readable-writable third directory, opening the first file under the first directory; if yes, creating a third file in a third directory according to the second file, and opening the third file; when a first file is written into the application, determining a first target logic data segment, and if it is judged that the first target logic data segment which is not allocated with the physical disk space exists, allocating the physical disk space to the first target logic data segment which is not allocated with the physical disk space, and copying the corresponding data of the second file to the allocated physical disk space, and writing the physical disk space, so that an optimized CoW mechanism can be provided, the implementation is simple, cross-file system implementation can be realized, and relatively low I / O overhead and disk consumption are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and particularly to a method and apparatus for delayed segmented copy-on-write for a file system. Background Art

[0002] Currently, the Copy-on-Write (CoW) mechanism is widely used in file systems and there are two implementation methods, each with its own unique advantages and applicable scenarios. For example, for the OverlayFS file system, the CoW mechanism is as follows: when a file is opened in read-write (ReadWrite) or write-only (WriteOnly) mode, if the file exists in the LowerDir directory, the OverlayFS file system will copy the entire file from the LowerDir directory to the UpperDir directory and then perform write operations in the UpperDir directory, while the original file in the LowerDir directory remains unchanged. The CoW mechanism under the OverlayFS file system is simple to implement, easy to understand and use, suitable for scenarios that require a layered file system, and can be implemented across file systems, but it can only copy the entire file and does not support sharing of partial file data, resulting in relatively large I / O overhead and disk consumption. Another example is for file systems such as Btrfs, ZFS, and XFS. The CoW mechanism is as follows: a new copy of a file is created through the reflink mechanism of cloning ranges. The new copy and the original file share the same data blocks. When a write operation is performed on the shared data blocks, the file system will copy the data blocks to be written, perform write operations on the copied data blocks, and update the metadata of the corresponding data blocks of the new copy. The CoW mechanisms under these file systems are suitable for scenarios that require efficient storage and data sharing, support fine-grained data sharing, can reduce I / O overhead and disk consumption, but are complex to implement, require support from the file system, and have certain requirements for the performance of the file system, especially in the case of high-concurrency write operations, and can only be applied to the same file system and cannot be implemented across file systems.

[0003] Therefore, how to provide an optimized CoW mechanism that is simple to implement, can be implemented across file systems, and ensures relatively low I / O overhead and disk consumption has become a technical problem to be urgently solved. Summary of the Invention

[0004] In view of the technical problems existing in the prior art, embodiments of the present application provide a method and apparatus for delayed segmented copy-on-write for a file system.

[0005] In a first aspect, embodiments of the present application provide a method for delayed segmented copy-on-write for a file system, including: When an application opens a first file in a first directory in write mode, if it is determined that a second file exists in a read-only second directory and a third file does not exist in a writable third directory, a third file is created in the third directory based on the second file and the third file is opened. Here, the relative path of the first file with respect to the first directory, the relative path of the second file with respect to the second directory, and the relative path of the third file with respect to the third directory are the same. The total size of the logical data segments of the third file is the same as the total size of the logical data segments of the second file, and at least one logical data segment in the logical data segments of the third file has not been allocated physical disk space; When the application writes to the first file, a first target logical data segment is determined according to the logical data segments of the third file. If it is determined that there is a first target logical data segment in the first target logical data segment that has not been allocated physical disk space, physical disk space is allocated to the first target logical data segment that has not been allocated physical disk space, the data of the second file corresponding to the first target logical data segment that has not been allocated physical disk space is copied to the allocated physical disk space, and the allocated physical disk space is written according to the content that the application wants to write to the first file.

[0006] In a second aspect, an embodiment of the present application further provides a time-delay segmented copy-on-write device for a file system, including: A creation unit, configured to, when an application opens a first file in a first directory in write mode, if it is determined that a second file exists in a read-only second directory and a third file does not exist in a writable third directory, create a third file in the third directory based on the second file and open the third file. Here, the relative path of the first file with respect to the first directory, the relative path of the second file with respect to the second directory, and the relative path of the third file with respect to the third directory are the same. The total size of the logical data segments of the third file is the same as the total size of the logical data segments of the second file, and at least one logical data segment in the logical data segments of the third file has not been allocated physical disk space; A writing unit, configured to, when the application writes to the first file, determine a first target logical data segment according to the logical data segments of the third file. If it is determined that there is a first target logical data segment in the first target logical data segment that has not been allocated physical disk space, allocate physical disk space to the first target logical data segment that has not been allocated physical disk space, copy the data of the second file corresponding to the first target logical data segment that has not been allocated physical disk space to the allocated physical disk space, and write the allocated physical disk space according to the content that the application wants to write to the first file.

[0007] In summary, for the delayed segmented copy-on-write method and apparatus for a file system provided in the embodiments of the present application, when an application opens a first file in a first directory in a write mode, if a second file exists in a read-only second directory and a third file does not exist in a writable third directory, a third file will first be created in the third directory and the third file will be opened. Since a small amount of disk space is allocated to the logical data segment of the third file or no disk space is allocated, physical disk space is allocated to the first target logical data segment that has no allocated physical disk space only when the application writes to the first file, and the physical disk space is written to. That is, in this solution, at least the allocation timing of the physical disk space of a part of the logical data segment is delayed until the application actually writes. In this way, I / O and storage consumption can be reduced. Moreover, since when the application writes to the first file, the actual writing is to the third file, the same physical data segment can be shared between the file system to which the first directory belongs and the file system to which the third directory belongs. Therefore, it can be implemented across file systems. That is, this solution can be implemented across file systems, ensuring a relatively low I / O overhead and disk consumption, and is relatively simple to implement. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] Figure 1 FIG. is a schematic flowchart of an embodiment of a delayed segmented copy-on-write method for a file system provided in an embodiment of the present application; Figure 2 FIG. is a schematic structural diagram of an embodiment of a delayed segmented copy-on-write apparatus for a file system provided in an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0009] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. It should be understood that the accompanying drawings in the present application are only for the purposes of illustration and description, and are not used to limit the protection scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to actual scale. The flowcharts used in the present application illustrate the operations implemented according to some embodiments of the present application. It should be understood that the operations in the flowchart may not be implemented in sequence, and steps without a logical context relationship may be reversed or implemented simultaneously. In addition, those skilled in the art may add one or more other operations to the flowchart or remove one or more operations from the flowchart under the guidance of the content of the present application.

[0010] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and illustrated herein can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the present application claimed, but merely represents the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts fall within the scope of protection of the present application.

[0011] It should be noted that the term "including" will be used in the embodiments of the present application to indicate the existence of the features stated thereafter, but does not exclude the addition of other features.

[0012] Referring to Figure 1 As shown, the embodiments of the present application provide a schematic flowchart of a method for delayed segmented copy-on-write for a file system. The method includes: S10. When an application opens a first file in a first directory in a write mode, if it is determined that there is a second file in a read-only second directory and there is no third file in a writable third directory, then create a third file in the third directory according to the second file and open the third file. The relative path of the first file with respect to the first directory, the relative path of the second file with respect to the second directory, and the relative path of the third file with respect to the third directory are the same. The total size of the logical data segments of the third file is the same as the total size of the logical data segments of the second file, and at least one logical data segment in the logical data segments of the third file has not been allocated physical disk space. In this embodiment, it should be noted that the application can directly access the first directory, but cannot directly access the second directory and the third directory. The files in the read-only second directory are read-only, and the files in the read-write third directory are read-write. Taking the OverlayFS file system as an example, the first directory can be the merge layer directory, the second directory can be the lower layer directory, and the third directory can be the upper layer directory; taking the AUFS file system as an example, the first directory can be the mount point directory, the second directory can be the read-only branch directory, and the third directory can be the read-write branch directory. When the application opens the first file in the first directory in a write mode (including read-write mode and write-only mode), if the condition for creating the third file is met, the third file is created; otherwise, the third file is not created. The total size of the logical data segments of the third file is the same as that of the second file, and the number of logical data segments of the third file can be the same as or different from that of the second file. At least one of the logical data segments of the third file is not allocated physical disk space. For example, the third file can be a sparse file, and it can be obtained through the attributes of the third file whether each logical data segment of the third file is allocated physical disk space, or it can also be recorded through the extended attributes of the third file whether each logical data segment of the third file is allocated physical disk space.

[0013] S11. When the application writes to the first file, determine the first target logical data segment according to the logical data segments of the third file. If it is judged that there is a first target logical data segment in the first target logical data segment that is not allocated physical disk space, allocate physical disk space for the first target logical data segment that is not allocated physical disk space, copy the data corresponding to the first target logical data segment that is not allocated physical disk space of the second file to the allocated physical disk space, and write to the allocated physical disk space according to the content that the application wants to write to the first file.

[0014] In this embodiment, it should be noted that when an application writes to the first file, the logical data segment of the third file corresponding to the write position and the corresponding position on the logical data segment of the third file can be determined according to the correspondence between the write position of the application and the position of the logical data segment of the third file. The determined logical data segment is the first target logical data segment. Alternatively, the determined logical data segment can be split, and the logical data segment where the determined position is located is retained as the first target logical data segment. For the first target logical data segment in which the physical disk space has not been allocated, physical disk space needs to be allocated to the first target logical data segment where the physical disk space has not been allocated, and the data in the physical disk space of the corresponding logical data segment of the second file is copied to the allocated physical disk space, and then the allocated physical disk space is directly written according to the data to be written by the application. For example, the write position of the application is from the 4090th byte to the 4096th byte. The third file has only one logical data segment, and the physical disk space of this logical data segment has not been allocated. The size of this logical data segment is 8192 bytes, including the 1st byte to the 8192nd byte. The Nth byte written by the application corresponds to the Nth byte on the logical data segment of the third file, where N is a positive integer. Then the logical data segment of the third file can be split into logical data segment 1 and logical data segment 2. Logical data segment 1 includes the 1st byte to the 4096th byte, and logical data segment 2 includes the 4097th byte to the 8192nd byte. The write position of the application corresponds to the position on logical data segment 1. Therefore, logical data segment 1 is retained as the first target logical data segment, disk space is allocated to the first target logical data segment, and the data in the position range from the 1st byte to the 4096th byte corresponding to logical data segment 1 in the second file is copied to the allocated physical disk space, and the allocated physical disk space is written with the data to be written by the application.

[0015] Taking the OverlayFS file system as an example, assume that an application opens the first file in the merge layer directory of the OverlayFS file system in write mode. Then, the OverlayFS file system extracts the relative path of the first file from the path of the first file, and determines whether there is a second file in the lower layer directory whose relative path is the same as that of the first file. If there is a second file in the lower layer directory whose relative path is the same as that of the first file, it determines whether there is a third file in the upper layer directory whose relative path is the same as that of the first file. If there is no third file in the upper layer directory whose relative path is the same as that of the first file, it creates a third file in the upper layer directory whose relative path is the same as that of the first file. The relative path of the first file is the relative path with respect to the merge layer directory, the relative path of the second file is the relative path with respect to the lower layer directory, and the relative path of the third file is the relative path with respect to the upper layer directory. Assume that the logical data segments of the second file include logical data segment 1, logical data segment 2, logical data segment 3, and logical data segment 4, and the logical data segments of the created third file include logical data segment 5, logical data segment 6, logical data segment 7, and logical data segment 8. Logical data segments 5, 6, and 7 are not allocated physical disk space, and logical data segment 8 is allocated physical disk space. Logical data segment 1 corresponds to logical data segment 5, logical data segment 2 corresponds to logical data segment 6, logical data segment 3 corresponds to logical data segment 7, and logical data segment 4 corresponds to logical data segment 8. The sizes of logical data segments 1, 2, 3, 5, 6, and 7 are all 4096 bytes, and the sizes of logical data segments 4 and 8 are both 10 bytes. When the application writes to the first file, assume that the write position of the application is from the 3000th byte to the 4000th byte of logical data segment 5. Then, it is necessary to allocate physical disk space for logical data segment 5, copy the data in the physical disk space of logical data segment 1 to the physical disk space of logical data segment 5, and write data to the physical disk space of logical data segment 5 using the data to be written by the application.

[0016] Taking the AUFS file system as an example again, assume that an application opens the first file in the mount point directory of the AUFS file system in write mode. Then, the AUFS file system extracts the relative path of the first file from the path of the first file and determines whether there is a second file in the read-only branch directory whose relative path is the same as that of the first file. If there is a second file in the read-only branch directory whose relative path is the same as that of the first file, it determines whether there is a third file in the read-write branch directory whose relative path is the same as that of the first file. If there is no third file in the read-write branch directory whose relative path is the same as that of the first file, a third file with the same relative path as that of the first file is created in the read-write branch directory. The relative path of the first file is the relative path relative to the mount point directory, the relative path of the second file is the relative path relative to the read-only branch directory, and the relative path of the third file is the relative path relative to the read-write branch directory. Assume that the logical data segment of the second file includes logical data segment 9 and logical data segment 10, and the logical data segment of the created third file includes logical data segment 11, logical data segment 12, and logical data segment 13. Physical disk space has not been allocated to logical data segment 11, logical data segment 12, and logical data segment 13. The sizes of logical data segment 9 and logical data segment 10 are 8192 bytes and 5 bytes respectively, and the sizes of logical data segment 11, logical data segment 12, and logical data segment 13 are 4096 bytes, 4096 bytes, and 5 bytes respectively. Logical data segment 11 corresponds to the first half of logical data segment 9, logical data segment 12 corresponds to the second half of logical data segment 9, and logical data segment 10 corresponds to logical data segment 13. When the application writes to the first file, assume that the write position of the application corresponds to the 2000th byte to the 3000th byte of logical data segment 12. Then, physical disk space can be allocated to logical data segment 12, the data corresponding to the second half of logical data segment 9 in the physical disk space of logical data segment 9 is copied to the physical disk space of logical data segment 12, and the physical disk space of logical data segment 12 is written with the data to be written by the application.

[0017] That is to say, by modifying the COW mechanism of the file system as follows: when an application opens the first file in the first directory in a write mode, if the second file exists in the read-only second directory and the third file does not exist in the writable third directory, instead of completely copying the second file to the third directory, a special file copy of the second file (i.e., the third file) is created in the third directory, and when the application actually writes to the first file, physical disk space is allocated to the corresponding data segment of the third file that does not occupy physical disk space, and after the content of the data segment is copied, the allocated physical disk space is written. In this way, physical disk space allocation can be delayed to the actual writing time in units of data segments, thereby reducing I / O and storage consumption. In addition, it should be noted that if the application opens the first file in a read-only mode, the existing processing logic of the file system is still used. When the application opens the first file in a write mode, if the second file does not exist in the second directory, the third file can be directly created in the third directory, and subsequent read / write operations on the first file will be directed to the read / write of the third file, and the second directory is no longer involved.

[0018] The delayed segmented copy-on-write method for a file system provided by an embodiment of this application, when an application opens the first file in the first directory in a write mode, if the second file exists in the read-only second directory and the third file does not exist in the writable third directory, first, the third file is created in the third directory and the third file is opened. Since a small amount of disk space is allocated or no disk space is allocated to the logical data segments of the third file, physical disk space is allocated to the first target logical data segment that has not been allocated physical disk space when the application writes to the first file, and the physical disk space is written, that is, at least the allocation time of the physical disk space of a part of the logical data segments is delayed to the actual writing time of the application. In this way, I / O and storage consumption can be reduced, and since when the application writes to the first file, the actual writing is to the third file, the same physical data segments can be shared between the file system to which the first directory belongs and the file system to which the third directory belongs. Therefore, it can be implemented across file systems, that is, this solution can be implemented across file systems, ensuring a relatively low I / O overhead and disk consumption, and the implementation is relatively simple.

[0019] Based on the foregoing method embodiment, no physical disk space is allocated to any of the logical data segments in the logical data segments of the third file.

[0020] Based on the foregoing method embodiment, if at least one of the logical data segments in the logical data segments of the third file is allocated physical disk space, the method may further include: If it is determined that there is a first target logical data segment in the first target logical data segment that has been allocated physical disk space, then copy the data of the physical disk space of the logical data segment corresponding to the first target logical data segment of the second file that has been allocated physical disk space to the physical disk space of the corresponding first target logical data segment, and write to the physical disk space of the first target logical data segment that has been allocated physical disk space according to the content to be written into the first file by the application.

[0021] In this embodiment, the foregoing example for the OverlayFS file system is used for illustration. When the application writes to the first file, assume that the write position of the application is from the 4000th byte to the 4096th byte of logical data segment 7 and from the 1st byte to the 10th byte of logical data segment 8. Then the first target logical data segments are logical data segment 7 and logical data segment 8. Physical disk space needs to be allocated for logical data segment 7, copy the data of the physical disk space of logical data segment 3 to the physical disk space of logical data segment 7, and write data to the physical disk spaces of logical data segment 7 and logical data segment 8 using the data to be written by the application. That is to say, for the first target logical data segment that has been allocated physical disk space, since its physical disk space has been allocated when creating the third file, there is no need to allocate physical disk space for it again when the application writes data.

[0022] Based on the foregoing method embodiment, at least one logical data segment in the logical data segments of the third file has been allocated physical disk space. The step of creating the third file in the third directory according to the second file and opening the third file may further include: Copy the data of the physical disk space of the logical data segment corresponding to the logical data segment that has been allocated physical disk space of the second file to the physical disk space of the corresponding logical data segment; The method may further include: If it is determined that there is a first target logical data segment in the first target logical data segment that has been allocated physical disk space, then write to the physical disk space of the first target logical data segment that has been allocated physical disk space according to the content to be written into the first file by the application.

[0023] In this embodiment, it should be noted that after allocating physical disk space to at least one logical data segment in the logical data segment of the third file, the corresponding data of the second file can be copied to the allocated physical disk space. Compared with the previous embodiment, for the first target logical data segment to which physical disk space has been allocated, since when creating the third file, not only physical disk space is allocated to it, but also the data of the second file corresponding to the first target logical data segment to which physical disk space has been allocated is copied to the allocated physical disk space. Thus, when the application writes data, there is no need to copy the corresponding data of the logical data segment of the second file again, and the physical disk space of the first target logical data segment to which physical disk space has been allocated can be directly written using the data to be written by the application.

[0024] Based on the foregoing method embodiment, after opening the third file, it may further include: When the application reads the first file, determine the second target logical data segment according to the logical data segment of the third file, and determine whether the second target logical data segment has been actually written by the application; Read the data of the physical disk space of the second target logical data segment that has been actually written by the application in the second target logical data segment and return it to the application, and / or read the data of the physical disk space of the logical data segment corresponding to the second target logical data segment that has not been actually written by the application in the second file and return it to the application.

[0025] In this embodiment, it should be noted that when reading the first file, the source of data reading needs to be determined. Specifically, the second target logical data segment can be determined according to the reading position of the application and the logical data segment of the third file, and it is judged whether the second target logical data segment is actually written by the application: if a certain second target logical data segment is actually written by the application, the data in the physical disk space of the second target logical data segment needs to be read; if a certain second target logical data segment is not actually written by the application, the data corresponding to the second target logical data segment in the second file needs to be read. Whether a logical data segment is actually written by the application means whether the physical disk space of the logical data segment is written with the data required to be written by the application: if the physical disk space of the logical data segment is written with the data required to be written by the application, it is determined that the logical data segment is actually written by the application, otherwise, it is determined that the logical data segment is not actually written by the application. The determination process of the second target logical data segment is the same as that of the first target logical data segment, which will not be elaborated here. Taking the aforementioned example of the AUFS file system as an illustration. Suppose after the third file is created, the data to be read by the application corresponds to the 1000th byte to the 2000th byte of logical data segment 11, then the second target logical data segment is logical data segment 11. Since logical data segment 11 is not actually written by the application, the data corresponding to the 1000th byte to the 2000th byte of logical data segment 9 needs to be read and returned to the application. Subsequently, suppose the data to be read by the application corresponds to the 1000th byte to the 2000th byte of logical data segment 12. Since logical data segment 12 is actually written by the application, the data corresponding to the 1000th byte to the 2000th byte of logical data segment 12 needs to be read and returned to the application. That is to say, when the application reads data, the real / latest data needs to be obtained from the second file or the third file according to the reading position and returned to the application.

[0026] Refer to Figure 2 As shown in Figure, which is a schematic structural diagram of a time-delay segmented copy-on-write device for a file system provided by an embodiment of the present application. The device includes: A writing unit 21, which is configured to, when writing a first file is applied, determine a first target logical data segment according to the logical data segments of a third file. If it is determined that there is a first target logical data segment in the first target logical data segments for which physical disk space has not been allocated, physical disk space is allocated for the first target logical data segments for which physical disk space has not been allocated, data of the second file corresponding to the first target logical data segments for which physical disk space has not been allocated is copied to the allocated physical disk space, and the allocated physical disk space is written according to the content to be written into the first file by the application.

[0027] The time-delay segmented copy-on-write device for a file system provided by an embodiment of the present application. When an application opens a first file in a first directory in a write mode, if there is a second file in a read-only second directory and there is no third file in a writable third directory, a third file will first be created in the third directory and the third file will be opened. Since only a small amount of disk space is allocated or no disk space is allocated for the logical data segments of the third file, physical disk space is allocated for the first target logical data segments for which physical disk space has not been allocated when the application writes the first file, and the physical disk space is written, that is, in this solution, the allocation timing of at least a part of the physical disk space of the logical data segments is delayed until the application actually writes. In this way, I / O and storage consumption can be reduced. Moreover, since when the application writes the first file, the actual writing is to the third file, the same physical data segments can be shared between the file system to which the first directory belongs and the file system to which the third directory belongs. Therefore, it can be implemented across file systems, that is, this solution can be implemented across file systems, ensuring low I / O overhead and disk consumption, and the implementation is relatively simple.

[0028] Based on the foregoing device embodiment, none of the logical data segments in the logical data segments of the third file are allocated physical disk space.

[0029] Based on the foregoing device embodiment, at least one of the logical data segments in the logical data segments of the third file is allocated physical disk space. The writing unit can also be configured to: If it is determined that there is a first target logical data segment in the first target logical data segments for which physical disk space has been allocated, the data of the physical disk space of the logical data segment of the second file corresponding to the first target logical data segment for which physical disk space has been allocated is copied to the physical disk space of the corresponding first target logical data segment, and the physical disk space of the first target logical data segment for which physical disk space has been allocated is written according to the content to be written into the first file by the application.

[0030] Based on the foregoing device embodiment, at least one of the logical data segments in the logical data segments of the third file is allocated physical disk space. The creating unit can also be configured to: Copy the data in the physical disk space of the logical data segment corresponding to the logical data segment of the second file that has been allocated physical disk space to the physical disk space of the corresponding logical data segment; The writing unit may further be used for: If it is determined that there is a first target logical data segment in the first target logical data segment that has been allocated physical disk space, write to the physical disk space of the first target logical data segment that has been allocated physical disk space according to the content to be written into the first file by the application.

[0031] Based on the foregoing apparatus embodiments, the apparatus may further include: A reading unit, configured to, after opening a third file, when the application reads the first file, determine a second target logical data segment according to the logical data segment of the third file, and determine whether the second target logical data segment has been actually written by the application; and read the data in the physical disk space of the second target logical data segment that has been actually written by the application in the second target logical data segment and return it to the application, and / or read the data in the physical disk space of the logical data segment corresponding to the second target logical data segment that has not been actually written by the application in the second file and return it to the application.

[0032] The time-delay segmented copy-on-write apparatus for a file system provided in the embodiments of the present application has the same implementation process as the time-delay segmented copy-on-write method for a file system provided in the embodiments of the present application, and can achieve the same effects as the time-delay segmented copy-on-write method for a file system provided in the embodiments of the present application, which will not be elaborated herein.

[0033] The above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present application, and all should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A delayed segmented write-time copy method for a file system, characterized in that: include: When the application opens the first file in the first directory in write mode, if it is determined that the second file exists in the read-only second directory and the third file does not exist in the readable and writable third directory, a third file is created in the third directory according to the second file and the third file is opened, wherein the relative path of the first file relative to the first directory, the relative path of the second file relative to the second directory and the relative path of the third file relative to the third directory are the same, the total size of the logical data segments of the third file is the same as the total size of the logical data segments of the second file, and at least one of the logical data segments of the third file is not allocated physical disk space; When the application writes the first file, the first target logical data segment is determined based on the logical data segment of the third file. If it is determined that there is a first target logical data segment with no physical disk space allocated in the first target logical data segment, physical disk space is allocated to the first target logical data segment with no physical disk space allocated, data of the second file corresponding to the first target logical data segment with no physical disk space allocated is copied to the allocated physical disk space, and the allocated physical disk space is written according to the content to be written into the first file by the application.

2. The method according to claim 1, characterized in that No physical disk space is allocated to any of the logical data segments in the logical data segment of the third file.

3. The method according to claim 1, characterized in that At least one of the logical data segments of the third file is allocated physical disk space, and the method further includes: If it is determined that there is a first target logical data segment to which physical disk space is allocated in the first target logical data segment, the data of the physical disk space of the logical data segment of the second file corresponding to the first target logical data segment to which physical disk space is allocated is copied to the physical disk space of the corresponding first target logical data segment, and the physical disk space of the first target logical data segment to which physical disk space is allocated is written according to the content to be written into the first file by the application.

4. The method according to claim 1, characterized in that At least one of the logical data segments of the third file is allocated physical disk space, and the creating the third file in the third directory according to the second file and opening the third file also includes: Copying the data of the physical disk space of the logical data segment of the second file corresponding to the logical data segment to which the physical disk space is allocated to the physical disk space of the corresponding logical data segment; The method further comprises: If it is determined that there is a first target logical data segment to which physical disk space is allocated in the first target logical data segment, the physical disk space of the first target logical data segment to which physical disk space is allocated is written according to the content of the first file to be written by the application.

5. The method according to any one of claims 1 to 4, characterized in that: After opening the third file, also include: When the application reads the first file, a second target logical data segment is determined according to the logical data segment of the third file, and whether the second target logical data segment is actually written by the application; The data of the physical disk space of the second target logical data segment actually written by the application in the second target logical data segment is read and returned to the application, and / or the data of the physical disk space of the logical data segment of the second file corresponding to the second target logical data segment not actually written by the application in the second target logical data segment is read and returned to the application.

6. A delayed segmented write-time copy device for a file system, characterized in that: include: a creating unit, configured to, when an application opens a first file in a first directory in a write mode, create a third file in a third directory according to the second file and open the third file if it is determined that a second file exists in a read-only second directory and a third file does not exist in a readable and writable third directory, when the application opens a first file in a first directory in a write mode, wherein a relative path of the first file relative to the first directory, a relative path of the second file relative to the second directory and a relative path of the third file relative to the third directory are the same, a total size of the logical data segments of the third file is the same as a total size of the logical data segments of the second file, and at least one of the logical data segments of the third file is not allocated physical disk space; A writing unit is used to determine a first target logical data segment according to the logical data segment of a third file when an application writes a first file; if it is determined that there is a first target logical data segment with no physical disk space allocated in the first target logical data segment, physical disk space is allocated to the first target logical data segment with no physical disk space allocated, data of the second file corresponding to the first target logical data segment with no physical disk space allocated is copied to the allocated physical disk space, and the allocated physical disk space is written according to the content to be written into the first file by the application.

7. The device according to claim 6, characterized in that No physical disk space is allocated to any of the logical data segments in the logical data segment of the third file.

8. The device according to claim 6, characterized in that At least one of the logical data segments of the third file is allocated physical disk space, and the writing unit is further used for: If it is determined that there is a first target logical data segment to which physical disk space is allocated in the first target logical data segment, the data of the physical disk space of the logical data segment of the second file corresponding to the first target logical data segment to which physical disk space is allocated is copied to the physical disk space of the corresponding first target logical data segment, and the physical disk space of the first target logical data segment to which physical disk space is allocated is written according to the content to be written into the first file by the application.

9. The device according to claim 6, characterized in that At least one of the logical data segments of the third file is allocated physical disk space, and the creating unit is further used to: Copying the data of the physical disk space of the logical data segment of the second file corresponding to the logical data segment to which the physical disk space is allocated to the physical disk space of the corresponding logical data segment; The writing unit is further used for: If it is determined that there is a first target logical data segment to which physical disk space is allocated in the first target logical data segment, the physical disk space of the first target logical data segment to which physical disk space is allocated is written according to the content of the first file to be written by the application.

10. The device according to any one of claims 6 to 9, characterized in that Also includes: a reading unit, configured to determine the second target logical data segment according to the logical data segment of the third file when the application reads the first file after opening the third file, and to determine whether the second target logical data segment is actually written by the application; And read the data of the physical disk space of the second target logical data segment actually written by the application in the second target logical data segment and return it to the application, and / or read the data of the physical disk space of the logical data segment of the second file corresponding to the second target logical data segment not actually written by the application in the second target logical data segment and return it to the application.

Citation Information

Patent Citations

  • Multi-version control method of memory file system

    CN105868396A

  • File management method and device, equipment and medium

    CN111813742A

  • Cloud mobile phone application increment updating method and device equipment, medium and product

    CN114064099A

  • Mirror image processing method, computer program product, device and storage medium

    CN119356621A

  • Method and apparatus for two-layer copy-on-write

    US20190018790A1

Cited By

  • A range-level incremental copy-on-write method and system in a union file system

    CN122570436A