bcachefs: Set the last mount time using the realtime clock
authorTim Schlueter <schlueter.tim@linux.com>
Mon, 5 Nov 2018 04:14:46 +0000 (20:14 -0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:11 +0000 (17:08 -0400)
This way the last mount time is actually meaningful instead of just being
various times from 1970 (which happens with the monotonic clock).

Also, roundup_pow_of_two() is undefined when passed in 0, so check before
calling it.

Signed-off-by: Tim Schlueter <schlueter.tim@linux.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fifo.h
fs/bcachefs/super.c

index 00d245efe72a2dfadb6057318cf1edb90b15c03b..0cd5f1931aac2a1d193074eb7d81b7e322e27122 100644 (file)
@@ -13,7 +13,9 @@ struct {                                                              \
 #define DECLARE_FIFO(type, name)       FIFO(type) name
 
 #define fifo_buf_size(fifo)                                            \
-       (roundup_pow_of_two((fifo)->size) * sizeof((fifo)->data[0]))
+       ((fifo)->size                                                   \
+        ? roundup_pow_of_two((fifo)->size) * sizeof((fifo)->data[0])   \
+        : 0)
 
 #define init_fifo(fifo, _size, _gfp)                                   \
 ({                                                                     \
index a2ee698970a80b7bf8548f96bd04dfd209443363..54d23cf46f95dc96de726c71600248024317b399 100644 (file)
@@ -654,7 +654,7 @@ const char *bch2_fs_start(struct bch_fs *c)
        const char *err = "cannot allocate memory";
        struct bch_sb_field_members *mi;
        struct bch_dev *ca;
-       time64_t now = ktime_get_seconds();
+       time64_t now = ktime_get_real_seconds();
        unsigned i;
        int ret = -EINVAL;
 
@@ -1418,7 +1418,7 @@ have_slot:
        /* success: */
 
        mi->members[dev_idx] = dev_mi;
-       mi->members[dev_idx].last_mount = cpu_to_le64(ktime_get_seconds());
+       mi->members[dev_idx].last_mount = cpu_to_le64(ktime_get_real_seconds());
        c->disk_sb.sb->nr_devices       = nr_devices;
 
        ca->disk_sb.sb->dev_idx = dev_idx;
@@ -1494,7 +1494,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
        mi = bch2_sb_get_members(c->disk_sb.sb);
 
        mi->members[ca->dev_idx].last_mount =
-               cpu_to_le64(ktime_get_seconds());
+               cpu_to_le64(ktime_get_real_seconds());
 
        bch2_write_super(c);
        mutex_unlock(&c->sb_lock);