ubifs: tnc: use monotonic znode timestamp
authorArnd Bergmann <arnd@arndb.de>
Fri, 13 Jul 2018 14:31:56 +0000 (16:31 +0200)
committerRichard Weinberger <richard@nod.at>
Tue, 14 Aug 2018 22:06:16 +0000 (00:06 +0200)
The tnc uses get_seconds() based timestamps to check the age of a znode,
which has two problems: on 32-bit architectures this may overflow in
2038 or 2106, and it gives incorrect information when the system time
is updated using settimeofday().

Using montonic timestamps with ktime_get_seconds() solves both thes
problems.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/shrinker.c
fs/ubifs/tnc.c
fs/ubifs/tnc_misc.c
fs/ubifs/ubifs.h

index 9a9fb94a41c6823fdd5c4a4908af6f3e8bb604d1..9d10cbdec2cce466307963b2371b27d0a5a7b66f 100644 (file)
@@ -71,7 +71,7 @@ static int shrink_tnc(struct ubifs_info *c, int nr, int age, int *contention)
 {
        int total_freed = 0;
        struct ubifs_znode *znode, *zprev;
-       int time = get_seconds();
+       time64_t time = ktime_get_seconds();
 
        ubifs_assert(mutex_is_locked(&c->umount_mutex));
        ubifs_assert(mutex_is_locked(&c->tnc_mutex));
index 4a21e7f75e7a16537353c90bf850e52709252a34..6c497fb48b987140b0e6164748b5a91e9ab82ec8 100644 (file)
@@ -1179,7 +1179,7 @@ int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
 {
        int err, exact;
        struct ubifs_znode *znode;
-       unsigned long time = get_seconds();
+       time64_t time = ktime_get_seconds();
 
        dbg_tnck(key, "search key ");
        ubifs_assert(key_type(c, key) < UBIFS_INVALID_KEY);
@@ -1315,7 +1315,7 @@ static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key,
 {
        int err, exact;
        struct ubifs_znode *znode;
-       unsigned long time = get_seconds();
+       time64_t time = ktime_get_seconds();
 
        dbg_tnck(key, "search and dirty key ");
 
index 93f5b7859e6f0ddc31acab9e75b3af3434b1ea2b..49f647bc88f05a5fad518fe26d5873d81136b13b 100644 (file)
@@ -435,7 +435,7 @@ struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
 
        zbr->znode = znode;
        znode->parent = parent;
-       znode->time = get_seconds();
+       znode->time = ktime_get_seconds();
        znode->iip = iip;
 
        return znode;
index 04bf84d71e7bbae5339d4f7ceea70406be7d1cc8..54fb6b1cd042ab66dae3cfb9aa1514dc48ea429f 100644 (file)
@@ -758,7 +758,7 @@ struct ubifs_znode {
        struct ubifs_znode *parent;
        struct ubifs_znode *cnext;
        unsigned long flags;
-       unsigned long time;
+       time64_t time;
        int level;
        int child_cnt;
        int iip;