summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-10 22:25:16 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:27 +0300
commitd5d3be7dc5d09f9cf8d12b3e3cefbcd8020cddae (patch)
tree825e7457732d027cd295247aa51301a587de49ea /fs
parenta9bae40fda067eae70751302cbbc9f362453f310 (diff)
downloadlinux-d5d3be7dc5d09f9cf8d12b3e3cefbcd8020cddae.tar.xz
bcachefs: bch2_journal_log_msg()
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/journal.c83
-rw-r--r--fs/bcachefs/journal.h1
-rw-r--r--fs/bcachefs/recovery.c3
3 files changed, 62 insertions, 25 deletions
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index 54a318a841a1..9d16b9d30ad7 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -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)
diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h
index 948e8b53dffd..243349f4ac1c 100644
--- a/fs/bcachefs/journal.h
+++ b/fs/bcachefs/journal.h
@@ -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 *);
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 6c4ffc5abdc5..887971559214 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -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;