summaryrefslogtreecommitdiff
tag nameatomic-file-updates_2021-03-25 (49f8d6e965364ab24daea5b5dd6c163973cb6b51)
tag date2021-03-25 17:10:22 -0700
tagged byDarrick J. Wong <djwong@kernel.org>
tagged objectcommit 0d41fde732...
xfs: atomic file updates
This series creates a new log incompat feature and log intent items to track high level progress of swapping ranges of two files and finish interrupted work if the system goes down. It then adds a new FISWAPRANGE ioctl so that userspace can access the atomic extent swapping feature. With this feature, user programs will be able to update files atomically by opening an O_TMPFILE, reflinking the source file to it, making whatever updates they want to make, and then atomically swap the changed bits back to the source file. It even has an optional ability to detect a changed source file and reject the update. The intent behind this new userspace functionality is to enable atomic rewrites of arbitrary parts of individual files. For years, application programmers wanting to ensure the atomicity of a file update had to write the changes to a new file in the same directory, fsync the new file, rename the new file on top of the old filename, and then fsync the directory. People get it wrong all the time, and $fs hacks abound. With atomic file updates, this is no longer necessary. Programmers create an O_TMPFILE, optionally FICLONE the file contents into the temporary file, make whatever changes they want to the tempfile, and FISWAPRANGE the contents from the tempfile into the regular file. The interface can optionally check the original file's [cm]time to reject the swap operation if the file has been modified by. There are no fsyncs to take care of; no directory operations at all; and the fs will take care of finishing the swap operation if the system goes down in the middle of the swap. Sample code can be found in the corresponding changes to xfs_io to exercise the use case mentioned above. Note that this function is /not/ the O_DIRECT atomic file writes concept that has been floating around for years. This is constructed entirely in software, which means that there are no limitations other than the regular filesystem limits. As a side note, there's an extra motivation behind the kernel functionality: online repair of file-based metadata. The atomic file swap is implemented as an atomic inode fork swap, which means that we can implement online reconstruction of extended attributes and directories by building a new one in another inode and atomically swap the contents. Next, we adapt the online filesystem repair code to use atomic extent swapping. This enables repair functions to construct a clean copy of a directory, xattr information, realtime bitmaps, and realtime summary information in a temporary inode. If this completes successfully, the new contents can be swapped atomically into the inode being repaired. This is essential to avoid making corruption problems worse if the system goes down in the middle of running repair.