Skip to content

Commit 12f2930

Browse files
author
Darrick J. Wong
committed
xfs: port xfs_ioc_start_commit to multigrain timestamps
Take advantage of the multigrain timestamp APIs to ensure that nobody can sneak in and write things to a file between starting a file update operation and committing the results. This should have been part of the multigrain timestamp merge, but I forgot to fling it at jlayton when he resubmitted the patchset due to developer bandwidth problems. Cc: <[email protected]> # v6.13-rc1 Fixes: 4e40eff ("fs: add infrastructure for multigrain timestamps") Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jeff Layton <[email protected]>
1 parent 7f8b718 commit 12f2930

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/xfs/xfs_exchrange.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ xfs_ioc_start_commit(
854854
struct xfs_commit_range __user *argp)
855855
{
856856
struct xfs_commit_range args = { };
857-
struct timespec64 ts;
857+
struct kstat kstat = { };
858858
struct xfs_commit_range_fresh *kern_f;
859859
struct xfs_commit_range_fresh __user *user_f;
860860
struct inode *inode2 = file_inode(file);
@@ -871,12 +871,12 @@ xfs_ioc_start_commit(
871871
memcpy(&kern_f->fsid, ip2->i_mount->m_fixedfsid, sizeof(xfs_fsid_t));
872872

873873
xfs_ilock(ip2, lockflags);
874-
ts = inode_get_ctime(inode2);
875-
kern_f->file2_ctime = ts.tv_sec;
876-
kern_f->file2_ctime_nsec = ts.tv_nsec;
877-
ts = inode_get_mtime(inode2);
878-
kern_f->file2_mtime = ts.tv_sec;
879-
kern_f->file2_mtime_nsec = ts.tv_nsec;
874+
/* Force writing of a distinct ctime if any writes happen. */
875+
fill_mg_cmtime(&kstat, STATX_CTIME | STATX_MTIME, inode2);
876+
kern_f->file2_ctime = kstat.ctime.tv_sec;
877+
kern_f->file2_ctime_nsec = kstat.ctime.tv_nsec;
878+
kern_f->file2_mtime = kstat.mtime.tv_sec;
879+
kern_f->file2_mtime_nsec = kstat.mtime.tv_nsec;
880880
kern_f->file2_ino = ip2->i_ino;
881881
kern_f->file2_gen = inode2->i_generation;
882882
kern_f->magic = XCR_FRESH_MAGIC;

0 commit comments

Comments
 (0)