Multigrain timestamps promise that a change after the ctime was queried shows a later ctime: inode_set_ctime_current() takes a fine-grained time when the coarse one isn't past the queried value. But it truncates that time to s_time_gran, and on a superblock with coarse granularity, such as ext4 with 128-byte inodes (one second), the truncated fine-grained time is no later than the coarse one, and the update is skipped. The inode is still flagged IOP_MGTIME, so a caller relying on is_mgtime() for that promise, such as nfsd deciding whether it can move the change attribute by moving ctime, is misled, and the multigrain machinery only costs a fine-grained clock read. Set IOP_MGTIME only on a superblock whose s_time_gran is 1. Every FS_MGTIME filesystem (btrfs, ext4, f2fs, tmpfs, xfs) sets s_time_gran before it allocates an inode; document that it must. Signed-off-by: Jeff Layton --- When I originally did the multigrain timestamp work, I missed the fact that ext4 can have an s_time_gran of NSEC_PER_SEC. I think this is a very uncommon setup, so I don't see a need for a huge rush for this one. Please consider for v7.5. --- Documentation/filesystems/multigrain-ts.rst | 6 ++++++ fs/inode.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst index c779e47284e8..81ea632c7a4b 100644 --- a/Documentation/filesystems/multigrain-ts.rst +++ b/Documentation/filesystems/multigrain-ts.rst @@ -123,3 +123,9 @@ inode_set_ctime_current(). If the filesystem has a ->getattr routine that doesn't call generic_fillattr, then it should call fill_mg_cmtime() to fill those values. For setattr, it should use setattr_copy() to update the timestamps, or otherwise mimic its behavior. + +Multigrain timestamps are only enabled on a superblock whose s_time_gran is 1: +a fine-grained timestamp truncated to a coarser granularity can be no later +than the coarse-grained one, so the kernel can't guarantee a visible change. +The filesystem must set s_time_gran before it allocates any inode, since +whether an inode uses multigrain timestamps is decided when it is allocated. diff --git a/fs/inode.c b/fs/inode.c index de207f2f95a9..9cc28306feda 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -239,7 +239,7 @@ int inode_init_always_gfp(struct super_block *sb, struct inode *inode, gfp_t gfp inode->i_opflags = 0; if (sb->s_xattr) inode->i_opflags |= IOP_XATTR; - if (sb->s_type->fs_flags & FS_MGTIME) + if ((sb->s_type->fs_flags & FS_MGTIME) && sb->s_time_gran == 1) inode->i_opflags |= IOP_MGTIME; i_uid_write(inode, 0); i_gid_write(inode, 0); --- base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854 change-id: 20261119-mgtime-fc070b268bdf Best regards, -- Jeff Layton