Commit e5464a37 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet
Browse files

bcachefs: Add a bit of missing repair code



This adds repair code to drop very stale pointers.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 9be1efe9
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -498,6 +498,10 @@ static int bch2_check_fix_ptrs(struct bch_fs *c, enum btree_id btree_id,
	char buf[200];
	int ret = 0;

	/*
	 * XXX
	 * use check_bucket_ref here
	 */
	bkey_for_each_ptr_decode(k->k, ptrs, p, entry) {
		struct bch_dev *ca = bch_dev_bkey_exists(c, p.ptr.dev);
		struct bucket *g = PTR_BUCKET(ca, &p.ptr, true);
@@ -553,6 +557,15 @@ static int bch2_check_fix_ptrs(struct bch_fs *c, enum btree_id btree_id,
			}
		}

		if (fsck_err_on(gen_cmp(g->mark.gen, p.ptr.gen) > BUCKET_GC_GEN_MAX, c,
				"bucket %u:%zu gen %u data type %s: ptr gen %u too stale\n"
				"while marking %s",
				p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr), g->mark.gen,
				bch2_data_types[ptr_data_type(k->k, &p.ptr)],
				p.ptr.gen,
				(bch2_bkey_val_to_text(&PBUF(buf), c, *k), buf)))
			do_update = true;

		if (fsck_err_on(!p.ptr.cached &&
				gen_cmp(p.ptr.gen, g->mark.gen) < 0, c,
				"bucket %u:%zu data type %s stale dirty ptr: %u < %u\n"
@@ -644,6 +657,7 @@ static int bch2_check_fix_ptrs(struct bch_fs *c, enum btree_id btree_id,
				 (!g->gen_valid || gen_cmp(ptr->gen, g->mark.gen) > 0)) ||
				(!ptr->cached &&
				 gen_cmp(ptr->gen, g->mark.gen) < 0) ||
				gen_cmp(g->mark.gen, ptr->gen) > BUCKET_GC_GEN_MAX ||
				(g->mark.data_type &&
				 g->mark.data_type != data_type);
			}));