btrfs: use monotonic time for transaction handling
PATCH v2 1/2 btrfs: use monotonic time for transaction handling
The transaction times were changed to ktime_get_real_seconds to avoid the y2038 overflow, but they still have a minor problem when they go backwards or jump due to settimeofday() or leap seconds.
This changes the transaction handling to instead use ktime_get_seconds(), which returns a CLOCK_MONOTONIC timestamp that has neither of those problems.
---
v2: Rebased on top of an earlier patch by Allen Pais, which
also obsoleted the original patch 2/3
--- fs/btrfs/disk-io.c | 2 +- fs/btrfs/transaction.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +1 -1
@@ -1819,7 +1819,7 @@ static int transaction_kthread(void *arg) goto sleep; } - now =ktime_get_real_seconds (); + now =ktime_get_seconds (); if (cur->state < TRANS_STATE_BLOCKED && !test_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags) && (now < cur->start_time ||
fs/btrfs/transaction.c +1 -1
@@ -241,7 +241,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,refcount_set (&cur_trans->use_count,2 );atomic_set (&cur_trans->pending_ordered,0 ); cur_trans->flags =0 ; - cur_trans->start_time =ktime_get_real_seconds (); + cur_trans->start_time =ktime_get_seconds ();memset (&cur_trans->delayed_refs,0 ,sizeof (cur_trans->delayed_refs));
Signature · 1 line
2.9.0
PATCH v2 2/2 btrfs: use timespec64 for i_otime
While the regular inode timestamps all use timespec64 now, the i_otime field is btrfs specific and still needs to be converted to correctly represent times beyond 2038.
---
v2: no changes
--- fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/inode.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/btrfs_inode.h +1 -1
@@ -178,7 +178,7 @@ struct btrfs_inode {struct btrfs_delayed_node *delayed_node;/* File creation time. */ -struct timespec i_otime; +struct timespec64 i_otime;/* Hook into fs_info->delayed_iputs */ struct list_head delayed_iput;
fs/btrfs/inode.c +2 -2
@@ -5745,7 +5745,7 @@ static struct inode *new_simple_dir(struct super_block *s, inode->i_mtime =current_time (inode); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; -BTRFS_I (inode)->i_otime =timespec64_to_timespec (inode->i_mtime); +BTRFS_I (inode)->i_otime = inode->i_mtime;return inode; }
@@ -6349,7 +6349,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, inode->i_mtime =current_time (inode); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; -BTRFS_I (inode)->i_otime =timespec64_to_timespec (inode->i_mtime); +BTRFS_I (inode)->i_otime = inode->i_mtime; inode_item =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_inode_item);
Signature · 1 line
2.9.0
Quoted 9 lines · Arnd Bergmann
The transaction times were changed to
ktime_get_real_secondsto avoid the y2038 overflow, but they still have a minor problem when they go backwards or jump due tosettimeofday()or leap seconds.This changes the transaction handling to instead use
ktime_get_seconds(), which returns aCLOCK_MONOTONICtimestamp that has neither of those problems.Signed-off-by Arnd Bergmann <[email protected]>
Quoted 35 lines
---
v2: Rebased on top of an earlier patch by Allen Pais, which
also obsoleted the original patch 2/3--- fs/btrfs/disk-io.c | 2 +- fs/btrfs/transaction.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/btrfs/disk-io.c +1
-1@@ -1819,7 +1819,7 @@ static int transaction_kthread(void *arg) goto sleep; } - now =ktime_get_real_seconds (); + now =ktime_get_seconds (); if (cur->state < TRANS_STATE_BLOCKED && !test_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags) && (now < cur->start_time ||fs/btrfs/transaction.c +1
-1@@ -241,7 +241,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,refcount_set (&cur_trans->use_count,2 );atomic_set (&cur_trans->pending_ordered,0 ); cur_trans->flags =0 ; - cur_trans->start_time =ktime_get_real_seconds (); + cur_trans->start_time =ktime_get_seconds ();memset (&cur_trans->delayed_refs,0 ,sizeof (cur_trans->delayed_refs));
Re: [PATCH 2/2] [v2] btrfs: use timespec64 for i_otime
In reply to Arnd BergmannQuoted 5 lines · Arnd Bergmann
While the regular inode timestamps all use timespec64 now, the
i_otimefield is btrfs specific and still needs to be converted to correctly represent times beyond 2038.Signed-off-by Arnd Bergmann <[email protected]>
Quoted 43 lines
---
v2: no changes--- fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/inode.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)fs/btrfs/btrfs_inode.h +1
-1@@ -178,7 +178,7 @@ struct btrfs_inode {struct btrfs_delayed_node *delayed_node;/* File creation time. */ -struct timespec i_otime; +struct timespec64 i_otime;/* Hook into fs_info->delayed_iputs */ struct list_head delayed_iput;fs/btrfs/inode.c +2
-2@@ -5745,7 +5745,7 @@ static struct inode *new_simple_dir(struct super_block *s, inode->i_mtime =current_time (inode); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; -BTRFS_I (inode)->i_otime =timespec64_to_timespec (inode->i_mtime); +BTRFS_I (inode)->i_otime = inode->i_mtime;return inode; }@@ -6349,7 +6349,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, inode->i_mtime =current_time (inode); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; -BTRFS_I (inode)->i_otime =timespec64_to_timespec (inode->i_mtime); +BTRFS_I (inode)->i_otime = inode->i_mtime; inode_item =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_inode_item);
Quoted 4 lines · Arnd Bergmann
The transaction times were changed to
ktime_get_real_secondsto avoid the y2038 overflow, but they still have a minor problem when they go backwards or jump due tosettimeofday()or leap seconds.
Quoted 8 lines
This changes the transaction handling to instead use
ktime_get_seconds(), which returns aCLOCK_MONOTONICtimestamp that has neither of those problems.Signed-off-by Arnd Bergmann <[email protected]>---
v2: Rebased on top of an earlier patch by Allen Pais, which
also obsoleted the original patch 2/3
1 and 2 added to patch queue, thanks.