]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Store logical location of journal entries
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 19 Feb 2022 06:18:18 +0000 (01:18 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:24 +0000 (17:09 -0400)
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>
fs/bcachefs/journal_io.c
fs/bcachefs/journal_io.h

index 231f2e4bd1b979ec8f10058ad8d14da712b32ea7..56ba82156c702ec138f442ffc310681351282a17 100644 (file)
@@ -46,12 +46,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;
@@ -871,9 +871,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);
 
@@ -964,8 +967,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;
 
@@ -973,13 +976,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);
        }
 }
 
index d8425fe0d67b6826c2de50196d3af23d95f16d55..f2001835e43e215f725331f1cc591f736a29b6ef 100644 (file)
@@ -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 *);