Skip to content

Commit d7ae1cf

Browse files
committed
btrfs: convert to multigrain timestamps
JIRA: https://issues.redhat.com/browse/RHEL-121527 Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Beyond enabling the FS_MGTIME flag, this patch eliminates update_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally. Note that this also drops the IS_I_VERSION check and unconditionally bumps the change attribute, since SB_I_VERSION is always set on btrfs. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Tested-by: Randy Dunlap <rdunlap@infradead.org> # documentation bits Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/20241002-mgtime-v10-11-d1c4717f5284@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org> (cherry picked from commit e2e801d) Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
1 parent d7c7099 commit d7ae1cf

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

fs/btrfs/file.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,26 +1120,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)
11201120
btrfs_drew_write_unlock(&inode->root->snapshot_lock);
11211121
}
11221122

1123-
static void update_time_for_write(struct inode *inode)
1124-
{
1125-
struct timespec64 now, ts;
1126-
1127-
if (IS_NOCMTIME(inode))
1128-
return;
1129-
1130-
now = current_time(inode);
1131-
ts = inode_get_mtime(inode);
1132-
if (!timespec64_equal(&ts, &now))
1133-
inode_set_mtime_to_ts(inode, now);
1134-
1135-
ts = inode_get_ctime(inode);
1136-
if (!timespec64_equal(&ts, &now))
1137-
inode_set_ctime_to_ts(inode, now);
1138-
1139-
if (IS_I_VERSION(inode))
1140-
inode_inc_iversion(inode);
1141-
}
1142-
11431123
int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count)
11441124
{
11451125
struct file *file = iocb->ki_filp;
@@ -1170,7 +1150,10 @@ int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count)
11701150
* need to start yet another transaction to update the inode as we will
11711151
* update the inode when we finish writing whatever data we write.
11721152
*/
1173-
update_time_for_write(inode);
1153+
if (!IS_NOCMTIME(inode)) {
1154+
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
1155+
inode_inc_iversion(inode);
1156+
}
11741157

11751158
start_pos = round_down(pos, fs_info->sectorsize);
11761159
oldsize = i_size_read(inode);

fs/btrfs/super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,8 @@ static struct file_system_type btrfs_fs_type = {
21912191
.init_fs_context = btrfs_init_fs_context,
21922192
.parameters = btrfs_fs_parameters,
21932193
.kill_sb = btrfs_kill_super,
2194-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
2194+
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA |
2195+
FS_ALLOW_IDMAP | FS_MGTIME,
21952196
};
21962197

21972198
MODULE_ALIAS_FS("btrfs");

0 commit comments

Comments
 (0)