Skip to content

Commit

Permalink
btrfs: convert to multigrain timestamps
Browse files Browse the repository at this point in the history
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 <jlayton@kernel.org>
Acked-by: David Sterba <dsterba@suse.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Message-Id: <20230807-mgctime-v7-13-d1dec143a704@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Jeff Layton authored and Christian Brauner committed Aug 11, 2023
1 parent 0269b58 commit 50e9cee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
24 changes: 4 additions & 20 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,25 +1106,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)
btrfs_drew_write_unlock(&inode->root->snapshot_lock);
}

static void update_time_for_write(struct inode *inode)
{
struct timespec64 now, ctime;

if (IS_NOCMTIME(inode))
return;

now = current_time(inode);
if (!timespec64_equal(&inode->i_mtime, &now))
inode->i_mtime = now;

ctime = inode_get_ctime(inode);
if (!timespec64_equal(&ctime, &now))
inode_set_ctime_to_ts(inode, now);

if (IS_I_VERSION(inode))
inode_inc_iversion(inode);
}

static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
size_t count)
{
Expand Down Expand Up @@ -1156,7 +1137,10 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
* need to start yet another transaction to update the inode as we will
* update the inode when we finish writing whatever data we write.
*/
update_time_for_write(inode);
if (!IS_NOCMTIME(inode)) {
inode->i_mtime = inode_set_ctime_current(inode);
inode_inc_iversion(inode);
}

start_pos = round_down(pos, fs_info->sectorsize);
oldsize = i_size_read(inode);
Expand Down
5 changes: 3 additions & 2 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,15 +2144,16 @@ static struct file_system_type btrfs_fs_type = {
.name = "btrfs",
.mount = btrfs_mount,
.kill_sb = btrfs_kill_super,
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_MGTIME,
};

static struct file_system_type btrfs_root_fs_type = {
.owner = THIS_MODULE,
.name = "btrfs",
.mount = btrfs_mount_root,
.kill_sb = btrfs_kill_super,
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA |
FS_ALLOW_IDMAP | FS_MGTIME,
};

MODULE_ALIAS_FS("btrfs");
Expand Down

0 comments on commit 50e9cee

Please sign in to comment.