fs: compare truncated timestamps in current_mgtime
PATCH 1/1 fs: compare truncated timestamps in current_mgtime
current_mgtime compares the ctime (which has already been truncated) to the value from ktime_get_coarse_real_ts64 (which has not). All of the existing filesystems that enable mgtime have 1ns granularity, so this is not a problem today, but it is more correct to compare truncated timestamps instead.
Do the truncate earlier, so we're comparing like things.
--- fs/inode.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
fs/inode.c +14 -14
@@ -2097,28 +2097,28 @@ EXPORT_SYMBOL(file_remove_privs);*/ static struct timespec64 current_mgtime (struct inode *inode) { -struct timespec64 now; +struct timespec64 now, ctime;atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec;long nsec =atomic_long_read (pnsec);if (nsec &I_CTIME_QUERIED ) {ktime_get_real_ts64 (&now); - }else { -struct timespec64 ctime; +return timestamp_truncate (now, inode); + } -ktime_get_coarse_real_ts64 (&now); +ktime_get_coarse_real_ts64 (&now); + now =timestamp_truncate (now, inode); -/* -* If we've recently fetched a fine-grained timestamp -* then the coarse-grained one may still be earlier than the -* existing one. Just keep the existing ctime if so. -*/ - ctime =inode_get_ctime (inode); -if (timespec64_compare (&ctime, &now) >0 ) - now = ctime; - } +/* +* If we've recently fetched a fine-grained timestamp +* then the coarse-grained one may still be earlier than the +* existing ctime. Just keep the existing value if so. +*/ + ctime =inode_get_ctime (inode); +if (timespec64_compare (&ctime, &now) >0 ) + now = ctime; -return timestamp_truncate (now, inode); +return now; }/**
---
base-commit: 4ce0966ed7c04881c5f352e0bb53af9b38f94253
change-id: 20230728-mgctime-5e0ec0e89b04
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 9 lines · Jeff Layton
current_mgtimecompares the ctime (which has already been truncated) to the value fromktime_get_coarse_real_ts64(which has not). All of the existing filesystems that enable mgtime have 1ns granularity, so this is not a problem today, but it is more correct to compare truncated timestamps instead.Do the truncate earlier, so we're comparing like things.
[...]
Applied to the vfs.ctime branch of the vfs/vfs.git tree. Patches in the vfs.ctime branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.ctime
[1/1] fs: compare truncated timestamps in current_mgtime
https://git.kernel.org/vfs/vfs/c/dec705a2d44a