summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-02-19 01:18:18 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2022-02-19 01:23:20 -0500
commitda8056a215b89f229d33c89944d136190d71f2bc (patch)
tree235eec4e4e94948395381afe17ea8dfb30f3b6df
parentd988fef92a376355a7cd585f3ce0612fc4b88d73 (diff)
bcachefs: Store logical location of journal entries
When viewing what's in the journal, it's more useful to have the logical location - journal bucket and offset within that bucket - than just the offset on that device. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/journal_io.c25
-rw-r--r--fs/bcachefs/journal_io.h10
2 files changed, 24 insertions, 11 deletions
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index 2af344de2a3e..901e346684fb 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -47,12 +47,12 @@ struct journal_list {
* be replayed:
*/
static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
- struct bch_extent_ptr entry_ptr,
+ struct journal_ptr entry_ptr,
struct journal_list *jlist, struct jset *j,
bool bad)
{
struct journal_replay *i, *pos, *dup = NULL;
- struct bch_extent_ptr *ptr;
+ struct journal_ptr *ptr;
struct list_head *where;
size_t bytes = vstruct_bytes(j);
u64 last_seq = 0;
@@ -872,9 +872,12 @@ reread:
ja->bucket_seq[bucket] = le64_to_cpu(j->seq);
mutex_lock(&jlist->lock);
- ret = journal_entry_add(c, ca, (struct bch_extent_ptr) {
- .dev = ca->dev_idx,
- .offset = offset,
+ ret = journal_entry_add(c, ca, (struct journal_ptr) {
+ .dev = ca->dev_idx,
+ .bucket = bucket,
+ .bucket_offset = offset -
+ bucket_to_sector(ca, ja->buckets[bucket]),
+ .sector = offset,
}, jlist, j, ret != 0);
mutex_unlock(&jlist->lock);
@@ -965,8 +968,8 @@ err:
goto out;
}
-static void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
- struct journal_replay *j)
+void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
+ struct journal_replay *j)
{
unsigned i;
@@ -974,13 +977,15 @@ static void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
struct bch_dev *ca = bch_dev_bkey_exists(c, j->ptrs[i].dev);
u64 offset;
- div64_u64_rem(j->ptrs[i].offset, ca->mi.bucket_size, &offset);
+ div64_u64_rem(j->ptrs[i].sector, ca->mi.bucket_size, &offset);
if (i)
pr_buf(out, " ");
- pr_buf(out, "%u:%llu (offset %llu)",
+ pr_buf(out, "%u:%u:%u (sector %llu)",
j->ptrs[i].dev,
- (u64) j->ptrs[i].offset, offset);
+ j->ptrs[i].bucket,
+ j->ptrs[i].bucket_offset,
+ j->ptrs[i].sector);
}
}
diff --git a/fs/bcachefs/journal_io.h b/fs/bcachefs/journal_io.h
index d8425fe0d67b..f2001835e43e 100644
--- a/fs/bcachefs/journal_io.h
+++ b/fs/bcachefs/journal_io.h
@@ -8,7 +8,12 @@
*/
struct journal_replay {
struct list_head list;
- struct bch_extent_ptr ptrs[BCH_REPLICAS_MAX];
+ struct journal_ptr {
+ u8 dev;
+ u32 bucket;
+ u32 bucket_offset;
+ u64 sector;
+ } ptrs[BCH_REPLICAS_MAX];
unsigned nr_ptrs;
/* checksum error, but we may want to try using it anyways: */
@@ -45,6 +50,9 @@ int bch2_journal_entry_validate(struct bch_fs *, const char *,
void bch2_journal_entry_to_text(struct printbuf *, struct bch_fs *,
struct jset_entry *);
+void bch2_journal_ptrs_to_text(struct printbuf *, struct bch_fs *,
+ struct journal_replay *);
+
int bch2_journal_read(struct bch_fs *, struct list_head *, u64 *, u64 *);
void bch2_journal_write(struct closure *);