Method and apparatus for delayed segmented copy-on-write for file system
The delayed segmental write-time replication method addresses the challenge of cross-file system CoW by deferring disk allocation to write times, reducing I/O and storage costs while enabling data sharing across systems.
Patent Information
- Application Number
- CN202510553089.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2045-04-29
AI Technical Summary
The existing CoW mechanisms have problems in the file system with complex implementation, I/O overhead and large disk consumption across file systems, especially when high concurrent write operations are limited in performance.
Through the delayed segmented write-on-time copy method, when a file exists in a read-only directory but no file exists in a read-write directory, a copy of the file that has not allocated physical disk space for the logical data segment, and appoints the physical disk space for writing during actual writing, sharing the data segment across the file system.
It realizes simple and efficient write-on-time copy across file systems, reduces I/O and storage consumption, and is suitable for high concurrent write operation scenarios.
Smart Images

Figure CN120066422B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and particularly to a method and device 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 has two implementation methods, each with its unique advantages and applicable scenarios. For example, for the OverlayFS file system, the CoW mechanism is as follows: when opening a file 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, which will result 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 mechanism under these file systems is suitable for scenarios that require efficient storage and data sharing, supports fine-grained data sharing, can reduce I / O overhead and disk consumption, but is complex to implement, requires the support of the file system, and has 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 solved urgently. Summary of the Invention
[0004] In view of the technical problems existing in the prior art, an embodiment of the present application provides a method and device for delayed segmented copy-on-write for a file system.
[0005] In a first aspect, an embodiment of the present application provides a method for delayed segmented copy-on-write for a file system, including:
[0006] 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;
[0007] When the application writes to the first file, a first target logical data segment is determined based on 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 for the first target logical data segment that has not been allocated physical disk space. The data in 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.
[0008] In a second aspect, an embodiment of the present application further provides a delayed segmented copy-on-write device for a file system, including:
[0009] 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;
[0010] A writing unit, configured to, when the application writes to the first file, determine a first target logical data segment based on 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 for the first target logical data segment that has not been allocated physical disk space, copy the data in 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 to the allocated physical disk space according to the content that the application wants to write to the first file.
[0011] In summary, for the delayed segmented copy-on-write method and device 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 a 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, the allocation timing of at least a part of the physical disk space 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 low I / O overhead and disk consumption, and the implementation is relatively simple. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 It 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;
[0013] Figure 2 It is a schematic structural diagram of an embodiment of a delayed segmented copy-on-write device for a file system provided in an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0014] 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 in conjunction with 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 can 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.
[0015] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all embodiments. The components of the embodiments of the present application generally described and illustrated in the drawings here can 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 claimed present application, but merely represents 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 belong to the scope of protection of the present application.
[0016] 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 adding other features.
[0017] 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:
[0018] S10. When an application opens a first file in a first directory in a 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 according to the second file and open the third file, where 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 logical data segment in the logical data segments of the third file has not been allocated physical disk space;
[0019] In this embodiment, it should be noted that the application can directly access the first directory, but cannot directly access the second and third directories. The files in the read-only second directory are read-only, and the files in the writable third directory are writable. 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 writable 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.
[0020] 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 determined 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.
[0021] 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 in which 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, 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.
[0022] 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 then 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, a third file with the same relative path as the first file is created in the upper layer directory. The relative path of the first file is relative to the merge layer directory, the relative path of the second file is relative to the lower layer directory, and the relative path of the third file is relative 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, physical disk space needs to be allocated for logical data segment 5, the data in the physical disk space of logical data segment 1 is copied to the physical disk space of logical data segment 5, and the physical disk space of logical data segment 5 is written with the data to be written by the application.
[0023] Taking the AUFS file system as an example again, assume that an application opens the first file under 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 with respect to the mount point directory, the relative path of the second file is the relative path with respect to the read-only branch directory, and the relative path of the third file is the relative path with respect 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 for 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 for 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.
[0024] 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 segments of the third file that do not occupy physical disk space, and after the content of the data segments 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. Additionally, 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.
[0025] The method for delayed segmented copy-on-write for a file system provided by an embodiment of the present 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 a part of the physical disk space allocation timing 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.
[0026] 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.
[0027] Based on the foregoing method embodiment, at least one of the logical data segments in the logical data segments of the third file is allocated physical disk space, and the method may further include:
[0028] If it is determined that there is a first target logical data segment in the first target logical data segment for which physical disk space has been allocated, then copy the data in the physical disk space of the logical data segment corresponding to the first target logical data segment for which physical disk space has been allocated in the second file 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 for which physical disk space has been allocated according to the content to be written into the first file by the application.
[0029] 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 in 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 for which physical disk space has been allocated, since physical disk space has been allocated to it when creating the third file, there is no need to allocate physical disk space to it again when the application writes data.
[0030] 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 creating the third file according to the second file in the third directory and opening the third file may further include:
[0031] Copy the data in the physical disk space of the logical data segment corresponding to the logical data segment for which physical disk space has been allocated in the second file to the physical disk space of the corresponding logical data segment;
[0032] The method may further include:
[0033] If it is determined that there is a first target logical data segment in the first target logical data segment for which physical disk space has been allocated, then write to the physical disk space of the first target logical data segment for which physical disk space has been allocated according to the content to be written into the first file by the application.
[0034] 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 is 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 is allocated is copied to the allocated physical disk space. In this way, 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 is allocated can be directly written with the data to be written by the application.
[0035] Based on the foregoing method embodiment, after opening the third file, it may further include:
[0036] 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 is actually written by the application;
[0037] Read the data in 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 in the physical disk space of the logical data segment corresponding to the second target logical data segment not actually written by the application in the second file and return it to the application.
[0038] 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 segments 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 previous 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. Then 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.
[0039] Referring to Figure 2 As shown, it 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:
[0040] A creation unit 20, configured to, when an application opens a first file in a first directory in a write mode, if it is judged that there is a second file in a read-only second directory and there is no third file in a writable third directory, create a third file in the third directory according to the second file and open the third file, where 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 is not allocated physical disk space;
[0041] A writing unit 21 is configured to, when a first file is written by an application, 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.
[0042] In the 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 a small amount of disk space has been allocated or no disk space has been allocated to 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, so that 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, cross-file system implementation can be achieved, that is, this solution can achieve cross-file system implementation, ensure low I / O overhead and disk consumption, and is relatively simple to implement.
[0043] Based on the foregoing device embodiment, none of the logical data segments in the logical data segments of the third file have been allocated physical disk space.
[0044] Based on the foregoing device embodiment, at least one of the logical data segments in the logical data segments of the third file has been allocated physical disk space. The writing unit can also be configured to:
[0045] 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 corresponding to the first target logical data segment for which physical disk space has been allocated in the second file 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.
[0046] Based on the foregoing device embodiment, at least one of the logical data segments in the logical data segments of the third file has been allocated physical disk space. The creating unit can also be configured to:
[0047] Copy the data of 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;
[0048] The writing unit can also be used for:
[0049] 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.
[0050] Based on the foregoing device embodiments, the device may further include:
[0051] 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 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 in the second file that has not been actually written by the application in the second target logical data segment and return it to the application.
[0052] The delay-segmented copy-on-write device for a file system provided in the embodiments of the present application has the same implementation process as the 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 delay-segmented copy-on-write method for a file system provided in the embodiments of the present application, and will not be elaborated here.
[0053] 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 method for delayed segmented copy-on-write for a file system, characterized in that, 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, then create the third file in the third directory according to the second file and open the third file, where 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, at least one logical data segment in the logical data segments of the third file has not been allocated physical disk space, and the first directory is the combined directory of the second directory and the third directory; 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, then 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 to the allocated physical disk space according to the content that the application wants to write to the first file.
2. The method according to claim 1, wherein All logical data segments in the logical data segments of the third file have not been allocated physical disk space.
3. The method according to claim 1, wherein At least one logical data segment in the logical data segments of the third file has been allocated physical disk space, and the method further includes: 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 of the second file corresponding to the first target logical data segment 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 that the application wants to write to the first file.
4. The method according to claim 1, wherein At least one logical data segment in the logical data segments of the third file has been allocated physical disk space, and creating the third file in the third directory according to the second file and opening the third file further includes: Copy the data of the physical disk space of the logical data segment of the second file corresponding to the logical data segment that has been allocated physical disk space to the physical disk space of the corresponding logical data segment; The method further includes: 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 that the application wants to write to the first file.
5. The method according to any one of claims 1 to 4, characterized in that After opening the third file, it further includes: When the application reads the first file, determine a second target logical data segment according to the logical data segments 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 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 in the second file that has not been actually written by the application in the second target logical data segment and return it to the application.
6. A delayed segmented copy-on-write device for a file system, characterized in that, Comprising: A creation unit, configured to, when the application opens the first file in the first directory in a write mode, if it is determined that there is a second file in the read-only second directory and there is no third file in the writable third directory, create a third file in the third directory according to the second file and open the third file, where 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, at least one logical data segment in the logical data segments of the third file has not been allocated physical disk space, and the first directory is the combined directory of the second directory and the third directory; 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, and 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 for the first target logical data segment that has not been allocated physical disk space, copy the data corresponding to the first target logical data segment that has not been allocated physical disk space in the second file to the allocated physical disk space, and write the content to be written to the first file by the application to the allocated physical disk space.
7. The device according to claim 6, characterized in that, All logical data segments in the logical data segments of the third file have not been allocated physical disk space.
8. The device according to claim 6, wherein At least one logical data segment in the logical data segments of the third file has been allocated physical disk space, and the writing unit is further configured to: 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, copy the data of the physical disk space of the logical data segment corresponding to the first target logical data segment that has been allocated physical disk space in the second file to the physical disk space of the corresponding first target logical data segment, and write the content to be written to the first file by the application to the physical disk space of the first target logical data segment that has been allocated physical disk space.
9. The device according to claim 6, characterized in that, At least one logical data segment in the logical data segments of the third file has been allocated physical disk space, and the creation unit is further configured to: 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 in the second file to the physical disk space of the corresponding logical data segment; The writing unit is further configured to: 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 the content to be written to the first file by the application to the physical disk space of the first target logical data segment that has been allocated physical disk space.
10. The device according to any one of claims 6 to 9, characterized in that Further comprising: A reading unit, which is configured to, after opening a third file, when the application reads a 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 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 corresponding to the second target logical data segment not actually written by the application in the second file and return it to the application.
Citation Information
Patent Citations
File management method and device, equipment and medium
CN111813742A
Cloud mobile phone application increment updating method and device equipment, medium and product
CN114064099A