bcachefs: Improve the backpointer to missing extent message
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 14 Mar 2023 18:39:54 +0000 (14:39 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:57 +0000 (17:09 -0400)
We now print the pos where the backpointer was found in the btree, as
well as the exact bucket:bucket_offset of the data, to aid in grepping
through logs.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/backpointers.c
fs/bcachefs/backpointers.h

index 8517c56352264451315103848521ad9a09f9d26a..740084b3ff12f448bda0b314c23ca5bb779c42bb 100644 (file)
@@ -298,11 +298,12 @@ err:
 /*
  * Find the next backpointer >= *bp_offset:
  */
-int bch2_get_next_backpointer(struct btree_trans *trans,
-                             struct bpos bucket, int gen,
-                             u64 *bp_offset,
-                             struct bch_backpointer *dst,
-                             unsigned iter_flags)
+int __bch2_get_next_backpointer(struct btree_trans *trans,
+                               struct bpos bucket, int gen,
+                               u64 *bp_offset,
+                               struct bpos *bp_pos_ret,
+                               struct bch_backpointer *dst,
+                               unsigned iter_flags)
 {
        struct bch_fs *c = trans->c;
        struct bpos bp_pos, bp_end_pos;
@@ -352,6 +353,7 @@ int bch2_get_next_backpointer(struct btree_trans *trans,
 
                *dst = *bkey_s_c_to_backpointer(k).v;
                *bp_offset = dst->bucket_offset + BACKPOINTER_OFFSET_MAX;
+               *bp_pos_ret = k.k->p;
                goto out;
        }
 done:
@@ -362,6 +364,19 @@ out:
        return ret;
 }
 
+int bch2_get_next_backpointer(struct btree_trans *trans,
+                             struct bpos bucket, int gen,
+                             u64 *bp_offset,
+                             struct bch_backpointer *dst,
+                             unsigned iter_flags)
+{
+       struct bpos bp_pos;
+
+       return __bch2_get_next_backpointer(trans, bucket, gen,
+                                          bp_offset, &bp_pos,
+                                          dst, iter_flags);
+}
+
 static void backpointer_not_found(struct btree_trans *trans,
                                  struct bpos bucket,
                                  u64 bp_offset,
@@ -952,7 +967,7 @@ static int check_one_backpointer(struct btree_trans *trans,
        struct printbuf buf = PRINTBUF;
        int ret;
 
-       ret = bch2_get_next_backpointer(trans, bucket, -1, bp_offset, &bp, 0);
+       ret = __bch2_get_next_backpointer(trans, bucket, -1, bp_offset, &bp_pos, &bp, 0);
        if (ret || *bp_offset == U64_MAX)
                return ret;
 
@@ -968,23 +983,17 @@ static int check_one_backpointer(struct btree_trans *trans,
        if (ret)
                return ret;
 
-       bp_pos = bucket_pos_to_bp(c, bucket,
-                       max(*bp_offset, BACKPOINTER_OFFSET_MAX) - BACKPOINTER_OFFSET_MAX);
-
        if (!k.k && !bpos_eq(*last_flushed_pos, bp_pos)) {
                *last_flushed_pos = bp_pos;
-               pr_info("flushing at %llu:%llu",
-                       last_flushed_pos->inode,
-                       last_flushed_pos->offset);
-
                ret = bch2_btree_write_buffer_flush_sync(trans) ?:
                        -BCH_ERR_transaction_restart_write_buffer_flush;
                goto out;
        }
 
        if (fsck_err_on(!k.k, c,
-                       "%s backpointer points to missing extent\n%s",
-                       *bp_offset < BACKPOINTER_OFFSET_MAX ? "alloc" : "btree",
+                       "backpointer for %llu:%llu:%llu (btree pos %llu:%llu) points to missing extent\n  %s",
+                       bucket.inode, bucket.offset, (u64) bp.bucket_offset,
+                       bp_pos.inode, bp_pos.offset,
                        (bch2_backpointer_to_text(&buf, &bp), buf.buf))) {
                ret = bch2_backpointer_del_by_offset(trans, bucket, *bp_offset, bp);
                if (ret == -ENOENT)
index 314fee21dc277210fcaac107be8f580b6ab43e23..d0ba5d8596c5715197ddd39e37d79fcbe1f8530a 100644 (file)
@@ -48,7 +48,7 @@ static inline struct bpos bucket_pos_to_bp(const struct bch_fs *c,
                  (bucket_to_sector(ca, bucket.offset) <<
                   MAX_EXTENT_COMPRESS_RATIO_SHIFT) + bucket_offset);
 
-       BUG_ON(!bkey_eq(bucket, bp_pos_to_bucket(c, ret)));
+       EBUG_ON(!bkey_eq(bucket, bp_pos_to_bucket(c, ret)));
 
        return ret;
 }