btrfs: use monotonic time for transaction handling
authorArnd Bergmann <arnd@arndb.de>
Thu, 21 Jun 2018 16:04:05 +0000 (18:04 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 6 Aug 2018 11:12:38 +0000 (13:12 +0200)
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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/transaction.c

index 6318ac2539d328a2757edd09316c505acdcba125..2de3da7b7bdcc01fd3e6aadd37f6bf9120010182 100644 (file)
@@ -1805,7 +1805,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 ||
index 56c8bab0b8162ef3056754b753a8ff611b9f14cc..ebe50dfb894777cf509b4cb2a5f4e901bdb9c24a 100644 (file)
@@ -241,7 +241,7 @@ loop:
        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));