Skip to content

Commit 50e9cee

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. Signed-off-by: Jeff Layton <[email protected]> Acked-by: David Sterba <[email protected]> Reviewed-by: Jan Kara <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 0269b58 commit 50e9cee

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

fs/btrfs/file.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,25 +1106,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)
11061106
btrfs_drew_write_unlock(&inode->root->snapshot_lock);
11071107
}
11081108

1109-
static void update_time_for_write(struct inode *inode)
1110-
{
1111-
struct timespec64 now, ctime;
1112-
1113-
if (IS_NOCMTIME(inode))
1114-
return;
1115-
1116-
now = current_time(inode);
1117-
if (!timespec64_equal(&inode->i_mtime, &now))
1118-
inode->i_mtime = now;
1119-
1120-
ctime = inode_get_ctime(inode);
1121-
if (!timespec64_equal(&ctime, &now))
1122-
inode_set_ctime_to_ts(inode, now);
1123-
1124-
if (IS_I_VERSION(inode))
1125-
inode_inc_iversion(inode);
1126-
}
1127-
11281109
static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
11291110
size_t count)
11301111
{
@@ -1156,7 +1137,10 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
11561137
* need to start yet another transaction to update the inode as we will
11571138
* update the inode when we finish writing whatever data we write.
11581139
*/
1159-
update_time_for_write(inode);
1140+
if (!IS_NOCMTIME(inode)) {
1141+
inode->i_mtime = inode_set_ctime_current(inode);
1142+
inode_inc_iversion(inode);
1143+
}
11601144

11611145
start_pos = round_down(pos, fs_info->sectorsize);
11621146
oldsize = i_size_read(inode);

fs/btrfs/super.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,15 +2144,16 @@ static struct file_system_type btrfs_fs_type = {
21442144
.name = "btrfs",
21452145
.mount = btrfs_mount,
21462146
.kill_sb = btrfs_kill_super,
2147-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
2147+
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_MGTIME,
21482148
};
21492149

21502150
static struct file_system_type btrfs_root_fs_type = {
21512151
.owner = THIS_MODULE,
21522152
.name = "btrfs",
21532153
.mount = btrfs_mount_root,
21542154
.kill_sb = btrfs_kill_super,
2155-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
2155+
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA |
2156+
FS_ALLOW_IDMAP | FS_MGTIME,
21562157
};
21572158

21582159
MODULE_ALIAS_FS("btrfs");

0 commit comments

Comments
 (0)