bcachefs: bch2_journal_log_msg()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 10 Mar 2022 19:25:16 +0000 (14:25 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:27 +0000 (17:09 -0400)
This adds bch2_journal_log_msg(), which just logs a message to the
journal, and uses it to mark startup and when journal replay finishes.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/journal.c
fs/bcachefs/journal.h
fs/bcachefs/recovery.c

index 54a318a841a1b6219956bff40d3989014a836b4a..9d16b9d30ad70c568c46b213c86f12cff57c484f 100644 (file)
@@ -630,31 +630,6 @@ int bch2_journal_flush_seq(struct journal *j, u64 seq)
        return ret ?: ret2 < 0 ? ret2 : 0;
 }
 
-int bch2_journal_meta(struct journal *j)
-{
-       struct journal_buf *buf;
-       struct journal_res res;
-       int ret;
-
-       memset(&res, 0, sizeof(res));
-
-       ret = bch2_journal_res_get(j, &res, jset_u64s(0), 0);
-       if (ret)
-               return ret;
-
-       buf = j->buf + (res.seq & JOURNAL_BUF_MASK);
-       buf->must_flush = true;
-
-       if (!buf->flush_time) {
-               buf->flush_time = local_clock() ?: 1;
-               buf->expires = jiffies;
-       }
-
-       bch2_journal_res_put(j, &res);
-
-       return bch2_journal_flush_seq(j, res.seq);
-}
-
 /*
  * bch2_journal_flush_async - if there is an open journal entry, or a journal
  * still being written, write it and wait for the write to complete
@@ -707,6 +682,64 @@ out:
        return ret;
 }
 
+int bch2_journal_meta(struct journal *j)
+{
+       struct journal_buf *buf;
+       struct journal_res res;
+       int ret;
+
+       memset(&res, 0, sizeof(res));
+
+       ret = bch2_journal_res_get(j, &res, jset_u64s(0), 0);
+       if (ret)
+               return ret;
+
+       buf = j->buf + (res.seq & JOURNAL_BUF_MASK);
+       buf->must_flush = true;
+
+       if (!buf->flush_time) {
+               buf->flush_time = local_clock() ?: 1;
+               buf->expires = jiffies;
+       }
+
+       bch2_journal_res_put(j, &res);
+
+       return bch2_journal_flush_seq(j, res.seq);
+}
+
+int bch2_journal_log_msg(struct journal *j, const char *fmt, ...)
+{
+       struct jset_entry_log *entry;
+       struct journal_res res = { 0 };
+       unsigned msglen, u64s;
+       va_list args;
+       int ret;
+
+       va_start(args, fmt);
+       msglen = vsnprintf(NULL, 0, fmt, args) + 1;
+       va_end(args);
+
+       u64s = jset_u64s(DIV_ROUND_UP(msglen, sizeof(u64)));
+
+       ret = bch2_journal_res_get(j, &res, u64s, 0);
+       if (ret)
+               return ret;
+
+       entry = container_of(journal_res_entry(j, &res),
+                            struct jset_entry_log, entry);;
+       memset(entry, 0, u64s * sizeof(u64));
+       entry->entry.type = BCH_JSET_ENTRY_log;
+       entry->entry.u64s = u64s - 1;
+
+       va_start(args, fmt);
+       vsnprintf(entry->d, INT_MAX, fmt, args);
+       va_end(args);
+
+       bch2_journal_res_put(j, &res);
+
+       return bch2_journal_flush_seq(j, res.seq);
+}
+
 /* block/unlock the journal: */
 
 void bch2_journal_unblock(struct journal *j)
index 948e8b53dffd97b4b1aafea40d59b1638f64bf3d..243349f4ac1cc28e4bc09b81f133519d668c3b2d 100644 (file)
@@ -478,6 +478,7 @@ int bch2_journal_flush_seq(struct journal *, u64);
 int bch2_journal_flush(struct journal *);
 bool bch2_journal_noflush_seq(struct journal *, u64);
 int bch2_journal_meta(struct journal *);
+int bch2_journal_log_msg(struct journal *, const char *, ...);
 
 void bch2_journal_halt(struct journal *);
 
index 6c4ffc5abdc5a0a6a46526756604918e74e764b7..887971559214eb681e345328260ec12b67356823 100644 (file)
@@ -578,6 +578,9 @@ static int bch2_journal_replay(struct bch_fs *c)
        bch2_journal_set_replay_done(j);
        bch2_journal_flush_all_pins(j);
        ret = bch2_journal_error(j);
+
+       if (keys->nr && !ret)
+               bch2_journal_log_msg(&c->journal, "journal replay finished");
 err:
        kvfree(keys_sorted);
        return ret;