Message ID | 20240701-mgtime-v2-9-19d412a940d9@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | fs: multigrain timestamp redux | expand |
On Mon, Jul 01, 2024 at 06:26:45AM -0400, Jeff Layton wrote: > 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> > --- > fs/btrfs/file.c | 25 ++++--------------------- > fs/btrfs/super.c | 3 ++- > 2 files changed, 6 insertions(+), 22 deletions(-) > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > index d90138683a0a..409628c0c3cc 100644 > --- a/fs/btrfs/file.c > +++ b/fs/btrfs/file.c > @@ -1120,26 +1120,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, ts; > - > - if (IS_NOCMTIME(inode)) > - return; > - > - now = current_time(inode); > - ts = inode_get_mtime(inode); > - if (!timespec64_equal(&ts, &now)) > - inode_set_mtime_to_ts(inode, now); > - > - ts = inode_get_ctime(inode); > - if (!timespec64_equal(&ts, &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) > { > @@ -1171,7 +1151,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_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); > + inode_inc_iversion(inode); You've dropped the if (IS_I_VERSION(inode)) check here, and it doesn't appear to be in inode_inc_iversion. Is there a reason for this? Thanks, Josef
On Mon, 2024-07-01 at 09:49 -0400, Josef Bacik wrote: > On Mon, Jul 01, 2024 at 06:26:45AM -0400, Jeff Layton wrote: > > 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> > > --- > > fs/btrfs/file.c | 25 ++++--------------------- > > fs/btrfs/super.c | 3 ++- > > 2 files changed, 6 insertions(+), 22 deletions(-) > > > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > > index d90138683a0a..409628c0c3cc 100644 > > --- a/fs/btrfs/file.c > > +++ b/fs/btrfs/file.c > > @@ -1120,26 +1120,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, ts; > > - > > - if (IS_NOCMTIME(inode)) > > - return; > > - > > - now = current_time(inode); > > - ts = inode_get_mtime(inode); > > - if (!timespec64_equal(&ts, &now)) > > - inode_set_mtime_to_ts(inode, now); > > - > > - ts = inode_get_ctime(inode); > > - if (!timespec64_equal(&ts, &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) > > { > > @@ -1171,7 +1151,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_set_mtime_to_ts(inode, > > inode_set_ctime_current(inode)); > > + inode_inc_iversion(inode); > > You've dropped the > > if (IS_I_VERSION(inode)) > > check here, and it doesn't appear to be in inode_inc_iversion. Is > there a > reason for this? Thanks, > AFAICT, btrfs always sets SB_I_VERSION. Are there any cases where it isn't? If so, then I can put this check back. I'll make a note about it in the changelog if not.
On Mon, Jul 01, 2024 at 09:57:43AM -0400, Jeff Layton wrote: > On Mon, 2024-07-01 at 09:49 -0400, Josef Bacik wrote: > > On Mon, Jul 01, 2024 at 06:26:45AM -0400, Jeff Layton wrote: > > > 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> > > > --- > > > fs/btrfs/file.c | 25 ++++--------------------- > > > fs/btrfs/super.c | 3 ++- > > > 2 files changed, 6 insertions(+), 22 deletions(-) > > > > > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > > > index d90138683a0a..409628c0c3cc 100644 > > > --- a/fs/btrfs/file.c > > > +++ b/fs/btrfs/file.c > > > @@ -1120,26 +1120,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, ts; > > > - > > > - if (IS_NOCMTIME(inode)) > > > - return; > > > - > > > - now = current_time(inode); > > > - ts = inode_get_mtime(inode); > > > - if (!timespec64_equal(&ts, &now)) > > > - inode_set_mtime_to_ts(inode, now); > > > - > > > - ts = inode_get_ctime(inode); > > > - if (!timespec64_equal(&ts, &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) > > > { > > > @@ -1171,7 +1151,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_set_mtime_to_ts(inode, > > > inode_set_ctime_current(inode)); > > > + inode_inc_iversion(inode); > > > > You've dropped the > > > > if (IS_I_VERSION(inode)) > > > > check here, and it doesn't appear to be in inode_inc_iversion. Is > > there a > > reason for this? Thanks, > > > > AFAICT, btrfs always sets SB_I_VERSION. Are there any cases where it > isn't? If so, then I can put this check back. I'll make a note about it > in the changelog if not. Yes it's always set and I don't see anything in the generic code that would unset it so it's safe to drop the IS_I_VERSION check. The check was originally added in November 2012 by 6c760c072403f4 ("Btrfs: do not call file_update_time in aio_write") and then moved a few times. Enabling the super block flags was added in May 2012 by 0c4d2d95d06e92 ("Btrfs: use i_version instead of our own sequence") so the check was not necessary from the beginning.
On Mon, Jul 01, 2024 at 09:57:43AM -0400, Jeff Layton wrote: > On Mon, 2024-07-01 at 09:49 -0400, Josef Bacik wrote: > > On Mon, Jul 01, 2024 at 06:26:45AM -0400, Jeff Layton wrote: > > > 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> > > > --- > > > fs/btrfs/file.c | 25 ++++--------------------- > > > fs/btrfs/super.c | 3 ++- > > > 2 files changed, 6 insertions(+), 22 deletions(-) > > > > > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > > > index d90138683a0a..409628c0c3cc 100644 > > > --- a/fs/btrfs/file.c > > > +++ b/fs/btrfs/file.c > > > @@ -1120,26 +1120,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, ts; > > > - > > > - if (IS_NOCMTIME(inode)) > > > - return; > > > - > > > - now = current_time(inode); > > > - ts = inode_get_mtime(inode); > > > - if (!timespec64_equal(&ts, &now)) > > > - inode_set_mtime_to_ts(inode, now); > > > - > > > - ts = inode_get_ctime(inode); > > > - if (!timespec64_equal(&ts, &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) > > > { > > > @@ -1171,7 +1151,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_set_mtime_to_ts(inode, > > > inode_set_ctime_current(inode)); > > > + inode_inc_iversion(inode); > > > > You've dropped the > > > > if (IS_I_VERSION(inode)) > > > > check here, and it doesn't appear to be in inode_inc_iversion. Is > > there a > > reason for this? Thanks, > > > > AFAICT, btrfs always sets SB_I_VERSION. Are there any cases where it > isn't? If so, then I can put this check back. I'll make a note about it > in the changelog if not. Ah ok I'm dumb, ignore me, thanks, Josef
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index d90138683a0a..409628c0c3cc 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1120,26 +1120,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, ts; - - if (IS_NOCMTIME(inode)) - return; - - now = current_time(inode); - ts = inode_get_mtime(inode); - if (!timespec64_equal(&ts, &now)) - inode_set_mtime_to_ts(inode, now); - - ts = inode_get_ctime(inode); - if (!timespec64_equal(&ts, &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) { @@ -1171,7 +1151,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_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); + inode_inc_iversion(inode); + } start_pos = round_down(pos, fs_info->sectorsize); oldsize = i_size_read(inode); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index f05cce7c8b8d..1cd50293b98d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2173,7 +2173,8 @@ static struct file_system_type btrfs_fs_type = { .init_fs_context = btrfs_init_fs_context, .parameters = btrfs_fs_parameters, .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");
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> --- fs/btrfs/file.c | 25 ++++--------------------- fs/btrfs/super.c | 3 ++- 2 files changed, 6 insertions(+), 22 deletions(-)