Skip to content

Commit e2e801d

Browse files
jtlaytonbrauner
authored andcommitted
btrfs: convert to multigrain timestamps
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 <[email protected]> Tested-by: Randy Dunlap <[email protected]> # documentation bits Signed-off-by: Jeff Layton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent d0382c6 commit e2e801d

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
@@ -2198,7 +2198,8 @@ static struct file_system_type btrfs_fs_type = {
21982198
.init_fs_context = btrfs_init_fs_context,
21992199
.parameters = btrfs_fs_parameters,
22002200
.kill_sb = btrfs_kill_super,
2201-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
2201+
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA |
2202+
FS_ALLOW_IDMAP | FS_MGTIME,
22022203
};
22032204

22042205
MODULE_ALIAS_FS("btrfs");

0 commit comments

Comments
 (0)