mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	bcachefs: fsck_err() may now take a btree_trans
fsck_err() now optionally takes a btree_trans; if the current thread has one, it is required that it be passed. The next patch will use this to unlock when waiting for user input. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
		
							parent
							
								
									38e3ca275c
								
							
						
					
					
						commit
						a850bde649
					
				
					 17 changed files with 200 additions and 162 deletions
				
			
		| 
						 | 
				
			
			@ -1114,7 +1114,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	struct bch_dev *ca = bch2_dev_bucket_tryget_noerror(c, alloc_k.k->p);
 | 
			
		||||
	if (fsck_err_on(!ca,
 | 
			
		||||
			c, alloc_key_to_missing_dev_bucket,
 | 
			
		||||
			trans, alloc_key_to_missing_dev_bucket,
 | 
			
		||||
			"alloc key for invalid device:bucket %llu:%llu",
 | 
			
		||||
			alloc_k.k->p.inode, alloc_k.k->p.offset))
 | 
			
		||||
		ret = bch2_btree_delete_at(trans, alloc_iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -1134,7 +1134,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(k.k->type != discard_key_type,
 | 
			
		||||
			c, need_discard_key_wrong,
 | 
			
		||||
			trans, need_discard_key_wrong,
 | 
			
		||||
			"incorrect key in need_discard btree (got %s should be %s)\n"
 | 
			
		||||
			"  %s",
 | 
			
		||||
			bch2_bkey_types[k.k->type],
 | 
			
		||||
| 
						 | 
				
			
			@ -1164,7 +1164,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(k.k->type != freespace_key_type,
 | 
			
		||||
			c, freespace_key_wrong,
 | 
			
		||||
			trans, freespace_key_wrong,
 | 
			
		||||
			"incorrect key in freespace btree (got %s should be %s)\n"
 | 
			
		||||
			"  %s",
 | 
			
		||||
			bch2_bkey_types[k.k->type],
 | 
			
		||||
| 
						 | 
				
			
			@ -1195,7 +1195,7 @@ int bch2_check_alloc_key(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(a->gen != alloc_gen(k, gens_offset),
 | 
			
		||||
			c, bucket_gens_key_wrong,
 | 
			
		||||
			trans, bucket_gens_key_wrong,
 | 
			
		||||
			"incorrect gen in bucket_gens btree (got %u should be %u)\n"
 | 
			
		||||
			"  %s",
 | 
			
		||||
			alloc_gen(k, gens_offset), a->gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -1236,7 +1236,6 @@ int bch2_check_alloc_hole_freespace(struct btree_trans *trans,
 | 
			
		|||
				    struct bpos *end,
 | 
			
		||||
				    struct btree_iter *freespace_iter)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct bkey_s_c k;
 | 
			
		||||
	struct printbuf buf = PRINTBUF;
 | 
			
		||||
	int ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -1254,7 +1253,7 @@ int bch2_check_alloc_hole_freespace(struct btree_trans *trans,
 | 
			
		|||
	*end = bkey_min(k.k->p, *end);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(k.k->type != KEY_TYPE_set,
 | 
			
		||||
			c, freespace_hole_missing,
 | 
			
		||||
			trans, freespace_hole_missing,
 | 
			
		||||
			"hole in alloc btree missing in freespace btree\n"
 | 
			
		||||
			"  device %llu buckets %llu-%llu",
 | 
			
		||||
			freespace_iter->pos.inode,
 | 
			
		||||
| 
						 | 
				
			
			@ -1290,7 +1289,6 @@ int bch2_check_alloc_hole_bucket_gens(struct btree_trans *trans,
 | 
			
		|||
				      struct bpos *end,
 | 
			
		||||
				      struct btree_iter *bucket_gens_iter)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct bkey_s_c k;
 | 
			
		||||
	struct printbuf buf = PRINTBUF;
 | 
			
		||||
	unsigned i, gens_offset, gens_end_offset;
 | 
			
		||||
| 
						 | 
				
			
			@ -1314,7 +1312,7 @@ int bch2_check_alloc_hole_bucket_gens(struct btree_trans *trans,
 | 
			
		|||
		bkey_reassemble(&g.k_i, k);
 | 
			
		||||
 | 
			
		||||
		for (i = gens_offset; i < gens_end_offset; i++) {
 | 
			
		||||
			if (fsck_err_on(g.v.gens[i], c,
 | 
			
		||||
			if (fsck_err_on(g.v.gens[i], trans,
 | 
			
		||||
					bucket_gens_hole_wrong,
 | 
			
		||||
					"hole in alloc btree at %llu:%llu with nonzero gen in bucket_gens btree (%u)",
 | 
			
		||||
					bucket_gens_pos_to_alloc(k.k->p, i).inode,
 | 
			
		||||
| 
						 | 
				
			
			@ -1372,8 +1370,8 @@ static noinline_for_stack int bch2_check_discard_freespace_key(struct btree_tran
 | 
			
		|||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!bch2_dev_bucket_exists(c, pos), c,
 | 
			
		||||
			need_discard_freespace_key_to_invalid_dev_bucket,
 | 
			
		||||
	if (fsck_err_on(!bch2_dev_bucket_exists(c, pos),
 | 
			
		||||
			trans, need_discard_freespace_key_to_invalid_dev_bucket,
 | 
			
		||||
			"entry in %s btree for nonexistant dev:bucket %llu:%llu",
 | 
			
		||||
			bch2_btree_id_str(iter->btree_id), pos.inode, pos.offset))
 | 
			
		||||
		goto delete;
 | 
			
		||||
| 
						 | 
				
			
			@ -1382,8 +1380,8 @@ static noinline_for_stack int bch2_check_discard_freespace_key(struct btree_tran
 | 
			
		|||
 | 
			
		||||
	if (fsck_err_on(a->data_type != state ||
 | 
			
		||||
			(state == BCH_DATA_free &&
 | 
			
		||||
			 genbits != alloc_freespace_genbits(*a)), c,
 | 
			
		||||
			need_discard_freespace_key_bad,
 | 
			
		||||
			 genbits != alloc_freespace_genbits(*a)),
 | 
			
		||||
			trans, need_discard_freespace_key_bad,
 | 
			
		||||
			"%s\n  incorrectly set at %s:%llu:%llu:0 (free %u, genbits %llu should be %llu)",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf),
 | 
			
		||||
			bch2_btree_id_str(iter->btree_id),
 | 
			
		||||
| 
						 | 
				
			
			@ -1430,7 +1428,7 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	struct bch_dev *ca = bch2_dev_tryget_noerror(c, k.k->p.inode);
 | 
			
		||||
	if (!ca) {
 | 
			
		||||
		if (fsck_err(c, bucket_gens_to_invalid_dev,
 | 
			
		||||
		if (fsck_err(trans, bucket_gens_to_invalid_dev,
 | 
			
		||||
			     "bucket_gens key for invalid device:\n  %s",
 | 
			
		||||
			     (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
 | 
			
		||||
			ret = bch2_btree_delete_at(trans, iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -1438,8 +1436,8 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(end <= ca->mi.first_bucket ||
 | 
			
		||||
			start >= ca->mi.nbuckets, c,
 | 
			
		||||
			bucket_gens_to_invalid_buckets,
 | 
			
		||||
			start >= ca->mi.nbuckets,
 | 
			
		||||
			trans, bucket_gens_to_invalid_buckets,
 | 
			
		||||
			"bucket_gens key for invalid buckets:\n  %s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
		ret = bch2_btree_delete_at(trans, iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -1447,16 +1445,16 @@ int bch2_check_bucket_gens_key(struct btree_trans *trans,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	for (b = start; b < ca->mi.first_bucket; b++)
 | 
			
		||||
		if (fsck_err_on(g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK], c,
 | 
			
		||||
				bucket_gens_nonzero_for_invalid_buckets,
 | 
			
		||||
		if (fsck_err_on(g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK],
 | 
			
		||||
				trans, bucket_gens_nonzero_for_invalid_buckets,
 | 
			
		||||
				"bucket_gens key has nonzero gen for invalid bucket")) {
 | 
			
		||||
			g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK] = 0;
 | 
			
		||||
			need_update = true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	for (b = ca->mi.nbuckets; b < end; b++)
 | 
			
		||||
		if (fsck_err_on(g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK], c,
 | 
			
		||||
				bucket_gens_nonzero_for_invalid_buckets,
 | 
			
		||||
		if (fsck_err_on(g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK],
 | 
			
		||||
				trans, bucket_gens_nonzero_for_invalid_buckets,
 | 
			
		||||
				"bucket_gens key has nonzero gen for invalid bucket")) {
 | 
			
		||||
			g.v.gens[b & KEY_TYPE_BUCKET_GENS_MASK] = 0;
 | 
			
		||||
			need_update = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -1636,8 +1634,8 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
 | 
			
		|||
	if (a->data_type != BCH_DATA_cached)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!a->io_time[READ], c,
 | 
			
		||||
			alloc_key_cached_but_read_time_zero,
 | 
			
		||||
	if (fsck_err_on(!a->io_time[READ],
 | 
			
		||||
			trans, alloc_key_cached_but_read_time_zero,
 | 
			
		||||
			"cached bucket with read_time 0\n"
 | 
			
		||||
			"  %s",
 | 
			
		||||
		(printbuf_reset(&buf),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -395,7 +395,7 @@ static int bch2_check_btree_backpointer(struct btree_trans *trans, struct btree_
 | 
			
		|||
 | 
			
		||||
	struct bpos bucket;
 | 
			
		||||
	if (!bp_pos_to_bucket_nodev_noerror(c, k.k->p, &bucket)) {
 | 
			
		||||
		if (fsck_err(c, backpointer_to_missing_device,
 | 
			
		||||
		if (fsck_err(trans, backpointer_to_missing_device,
 | 
			
		||||
			     "backpointer for missing device:\n%s",
 | 
			
		||||
			     (bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
 | 
			
		||||
			ret = bch2_btree_delete_at(trans, bp_iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -407,8 +407,8 @@ static int bch2_check_btree_backpointer(struct btree_trans *trans, struct btree_
 | 
			
		|||
	if (ret)
 | 
			
		||||
		goto out;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(alloc_k.k->type != KEY_TYPE_alloc_v4, c,
 | 
			
		||||
			backpointer_to_missing_alloc,
 | 
			
		||||
	if (fsck_err_on(alloc_k.k->type != KEY_TYPE_alloc_v4,
 | 
			
		||||
			trans, backpointer_to_missing_alloc,
 | 
			
		||||
			"backpointer for nonexistent alloc key: %llu:%llu:0\n%s",
 | 
			
		||||
			alloc_iter.pos.inode, alloc_iter.pos.offset,
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -505,7 +505,7 @@ static int check_extent_checksum(struct btree_trans *trans,
 | 
			
		|||
	struct nonce nonce = extent_nonce(extent.k->version, p.crc);
 | 
			
		||||
	struct bch_csum csum = bch2_checksum(c, p.crc.csum_type, nonce, data_buf, bytes);
 | 
			
		||||
	if (fsck_err_on(bch2_crc_cmp(csum, p.crc.csum),
 | 
			
		||||
			c, dup_backpointer_to_bad_csum_extent,
 | 
			
		||||
			trans, dup_backpointer_to_bad_csum_extent,
 | 
			
		||||
			"%s", buf.buf))
 | 
			
		||||
		ret = drop_dev_and_update(trans, btree, extent, dev) ?: 1;
 | 
			
		||||
fsck_err:
 | 
			
		||||
| 
						 | 
				
			
			@ -647,7 +647,7 @@ static int check_bp_exists(struct btree_trans *trans,
 | 
			
		|||
	prt_printf(&buf, "\n  want:  ");
 | 
			
		||||
	bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&n_bp_k.k_i));
 | 
			
		||||
 | 
			
		||||
	if (fsck_err(c, ptr_to_missing_backpointer, "%s", buf.buf))
 | 
			
		||||
	if (fsck_err(trans, ptr_to_missing_backpointer, "%s", buf.buf))
 | 
			
		||||
		ret = bch2_bucket_backpointer_mod(trans, ca, bucket, bp, orig_k, true);
 | 
			
		||||
 | 
			
		||||
	goto out;
 | 
			
		||||
| 
						 | 
				
			
			@ -908,7 +908,7 @@ static int check_one_backpointer(struct btree_trans *trans,
 | 
			
		|||
		if (ret)
 | 
			
		||||
			goto out;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err(c, backpointer_to_missing_ptr,
 | 
			
		||||
		if (fsck_err(trans, backpointer_to_missing_ptr,
 | 
			
		||||
			     "backpointer for missing %s\n  %s",
 | 
			
		||||
			     bp.v->level ? "btree node" : "extent",
 | 
			
		||||
			     (bch2_bkey_val_to_text(&buf, c, bp.s_c), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -175,10 +175,11 @@ static int set_node_max(struct bch_fs *c, struct btree *b, struct bpos new_max)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int btree_check_node_boundaries(struct bch_fs *c, struct btree *b,
 | 
			
		||||
static int btree_check_node_boundaries(struct btree_trans *trans, struct btree *b,
 | 
			
		||||
				       struct btree *prev, struct btree *cur,
 | 
			
		||||
				       struct bpos *pulled_from_scan)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct bpos expected_start = !prev
 | 
			
		||||
		? b->data->min_key
 | 
			
		||||
		: bpos_successor(prev->key.k.p);
 | 
			
		||||
| 
						 | 
				
			
			@ -216,29 +217,29 @@ static int btree_check_node_boundaries(struct bch_fs *c, struct btree *b,
 | 
			
		|||
			*pulled_from_scan = cur->data->min_key;
 | 
			
		||||
			ret = DID_FILL_FROM_SCAN;
 | 
			
		||||
		} else {
 | 
			
		||||
			if (mustfix_fsck_err(c, btree_node_topology_bad_min_key,
 | 
			
		||||
			if (mustfix_fsck_err(trans, btree_node_topology_bad_min_key,
 | 
			
		||||
					     "btree node with incorrect min_key%s", buf.buf))
 | 
			
		||||
				ret = set_node_min(c, cur, expected_start);
 | 
			
		||||
		}
 | 
			
		||||
	} else {									/* overlap */
 | 
			
		||||
		if (prev && BTREE_NODE_SEQ(cur->data) > BTREE_NODE_SEQ(prev->data)) {	/* cur overwrites prev */
 | 
			
		||||
			if (bpos_ge(prev->data->min_key, cur->data->min_key)) {		/* fully? */
 | 
			
		||||
				if (mustfix_fsck_err(c, btree_node_topology_overwritten_by_next_node,
 | 
			
		||||
				if (mustfix_fsck_err(trans, btree_node_topology_overwritten_by_next_node,
 | 
			
		||||
						     "btree node overwritten by next node%s", buf.buf))
 | 
			
		||||
					ret = DROP_PREV_NODE;
 | 
			
		||||
			} else {
 | 
			
		||||
				if (mustfix_fsck_err(c, btree_node_topology_bad_max_key,
 | 
			
		||||
				if (mustfix_fsck_err(trans, btree_node_topology_bad_max_key,
 | 
			
		||||
						     "btree node with incorrect max_key%s", buf.buf))
 | 
			
		||||
					ret = set_node_max(c, prev,
 | 
			
		||||
							   bpos_predecessor(cur->data->min_key));
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			if (bpos_ge(expected_start, cur->data->max_key)) {		/* fully? */
 | 
			
		||||
				if (mustfix_fsck_err(c, btree_node_topology_overwritten_by_prev_node,
 | 
			
		||||
				if (mustfix_fsck_err(trans, btree_node_topology_overwritten_by_prev_node,
 | 
			
		||||
						     "btree node overwritten by prev node%s", buf.buf))
 | 
			
		||||
					ret = DROP_THIS_NODE;
 | 
			
		||||
			} else {
 | 
			
		||||
				if (mustfix_fsck_err(c, btree_node_topology_bad_min_key,
 | 
			
		||||
				if (mustfix_fsck_err(trans, btree_node_topology_bad_min_key,
 | 
			
		||||
						     "btree node with incorrect min_key%s", buf.buf))
 | 
			
		||||
					ret = set_node_min(c, cur, expected_start);
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -250,9 +251,10 @@ static int btree_check_node_boundaries(struct bch_fs *c, struct btree *b,
 | 
			
		|||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int btree_repair_node_end(struct bch_fs *c, struct btree *b,
 | 
			
		||||
static int btree_repair_node_end(struct btree_trans *trans, struct btree *b,
 | 
			
		||||
				 struct btree *child, struct bpos *pulled_from_scan)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct printbuf buf = PRINTBUF;
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -266,7 +268,7 @@ static int btree_repair_node_end(struct bch_fs *c, struct btree *b,
 | 
			
		|||
	prt_str(&buf, "\n  child: ");
 | 
			
		||||
	bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&child->key));
 | 
			
		||||
 | 
			
		||||
	if (mustfix_fsck_err(c, btree_node_topology_bad_max_key,
 | 
			
		||||
	if (mustfix_fsck_err(trans, btree_node_topology_bad_max_key,
 | 
			
		||||
			     "btree node with incorrect max_key%s", buf.buf)) {
 | 
			
		||||
		if (b->c.level == 1 &&
 | 
			
		||||
		    bpos_lt(*pulled_from_scan, b->key.k.p)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -325,8 +327,8 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
 | 
			
		|||
		printbuf_reset(&buf);
 | 
			
		||||
		bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(cur_k.k));
 | 
			
		||||
 | 
			
		||||
		if (mustfix_fsck_err_on(bch2_err_matches(ret, EIO), c,
 | 
			
		||||
				btree_node_unreadable,
 | 
			
		||||
		if (mustfix_fsck_err_on(bch2_err_matches(ret, EIO),
 | 
			
		||||
				trans, btree_node_unreadable,
 | 
			
		||||
				"Topology repair: unreadable btree node at btree %s level %u:\n"
 | 
			
		||||
				"  %s",
 | 
			
		||||
				bch2_btree_id_str(b->c.btree_id),
 | 
			
		||||
| 
						 | 
				
			
			@ -363,7 +365,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
 | 
			
		|||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ret = btree_check_node_boundaries(c, b, prev, cur, pulled_from_scan);
 | 
			
		||||
		ret = btree_check_node_boundaries(trans, b, prev, cur, pulled_from_scan);
 | 
			
		||||
		if (ret == DID_FILL_FROM_SCAN) {
 | 
			
		||||
			new_pass = true;
 | 
			
		||||
			ret = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -404,7 +406,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
 | 
			
		|||
 | 
			
		||||
	if (!ret && !IS_ERR_OR_NULL(prev)) {
 | 
			
		||||
		BUG_ON(cur);
 | 
			
		||||
		ret = btree_repair_node_end(c, b, prev, pulled_from_scan);
 | 
			
		||||
		ret = btree_repair_node_end(trans, b, prev, pulled_from_scan);
 | 
			
		||||
		if (ret == DID_FILL_FROM_SCAN) {
 | 
			
		||||
			new_pass = true;
 | 
			
		||||
			ret = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -462,8 +464,8 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
 | 
			
		|||
	printbuf_reset(&buf);
 | 
			
		||||
	bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
 | 
			
		||||
 | 
			
		||||
	if (mustfix_fsck_err_on(!have_child, c,
 | 
			
		||||
			btree_node_topology_interior_node_empty,
 | 
			
		||||
	if (mustfix_fsck_err_on(!have_child,
 | 
			
		||||
			trans, btree_node_topology_interior_node_empty,
 | 
			
		||||
			"empty interior btree node at btree %s level %u\n"
 | 
			
		||||
			"  %s",
 | 
			
		||||
			bch2_btree_id_str(b->c.btree_id),
 | 
			
		||||
| 
						 | 
				
			
			@ -510,7 +512,7 @@ int bch2_check_topology(struct bch_fs *c)
 | 
			
		|||
			r->error = 0;
 | 
			
		||||
 | 
			
		||||
			if (!bch2_btree_has_scanned_nodes(c, i)) {
 | 
			
		||||
				mustfix_fsck_err(c, btree_root_unreadable_and_scan_found_nothing,
 | 
			
		||||
				mustfix_fsck_err(trans, btree_root_unreadable_and_scan_found_nothing,
 | 
			
		||||
						 "no nodes found for btree %s, continue?", bch2_btree_id_str(i));
 | 
			
		||||
				bch2_btree_root_alloc_fake_trans(trans, i, 0);
 | 
			
		||||
			} else {
 | 
			
		||||
| 
						 | 
				
			
			@ -585,8 +587,8 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
 | 
			
		|||
		       k.k->version.lo > atomic64_read(&c->journal.seq));
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(btree_id != BTREE_ID_accounting &&
 | 
			
		||||
				k.k->version.lo > atomic64_read(&c->key_version), c,
 | 
			
		||||
				bkey_version_in_future,
 | 
			
		||||
				k.k->version.lo > atomic64_read(&c->key_version),
 | 
			
		||||
				trans, bkey_version_in_future,
 | 
			
		||||
				"key version number higher than recorded %llu\n  %s",
 | 
			
		||||
				atomic64_read(&c->key_version),
 | 
			
		||||
				(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
 | 
			
		||||
| 
						 | 
				
			
			@ -594,7 +596,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (mustfix_fsck_err_on(level && !bch2_dev_btree_bitmap_marked(c, k),
 | 
			
		||||
				c, btree_bitmap_not_marked,
 | 
			
		||||
				trans, btree_bitmap_not_marked,
 | 
			
		||||
				"btree ptr not marked in member info btree allocated bitmap\n  %s",
 | 
			
		||||
				(printbuf_reset(&buf),
 | 
			
		||||
				 bch2_bkey_val_to_text(&buf, c, k),
 | 
			
		||||
| 
						 | 
				
			
			@ -710,7 +712,7 @@ static int bch2_gc_btrees(struct bch_fs *c)
 | 
			
		|||
		ret = bch2_gc_btree(trans, btree, true);
 | 
			
		||||
 | 
			
		||||
		if (mustfix_fsck_err_on(bch2_err_matches(ret, EIO),
 | 
			
		||||
					c, btree_node_read_error,
 | 
			
		||||
					trans, btree_node_read_error,
 | 
			
		||||
			       "btree node read error for %s",
 | 
			
		||||
			       bch2_btree_id_str(btree)))
 | 
			
		||||
			ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_check_topology);
 | 
			
		||||
| 
						 | 
				
			
			@ -816,8 +818,8 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	gc.fragmentation_lru = alloc_lru_idx_fragmentation(gc, ca);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(new.data_type != gc.data_type, c,
 | 
			
		||||
			alloc_key_data_type_wrong,
 | 
			
		||||
	if (fsck_err_on(new.data_type != gc.data_type,
 | 
			
		||||
			trans, alloc_key_data_type_wrong,
 | 
			
		||||
			"bucket %llu:%llu gen %u has wrong data_type"
 | 
			
		||||
			": got %s, should be %s",
 | 
			
		||||
			iter->pos.inode, iter->pos.offset,
 | 
			
		||||
| 
						 | 
				
			
			@ -827,7 +829,8 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
 | 
			
		|||
		new.data_type = gc.data_type;
 | 
			
		||||
 | 
			
		||||
#define copy_bucket_field(_errtype, _f)					\
 | 
			
		||||
	if (fsck_err_on(new._f != gc._f, c, _errtype,			\
 | 
			
		||||
	if (fsck_err_on(new._f != gc._f,				\
 | 
			
		||||
			trans, _errtype,				\
 | 
			
		||||
			"bucket %llu:%llu gen %u data type %s has wrong " #_f	\
 | 
			
		||||
			": got %llu, should be %llu",			\
 | 
			
		||||
			iter->pos.inode, iter->pos.offset,		\
 | 
			
		||||
| 
						 | 
				
			
			@ -939,8 +942,8 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
 | 
			
		|||
		return -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(r->refcount != le64_to_cpu(*refcount), c,
 | 
			
		||||
			reflink_v_refcount_wrong,
 | 
			
		||||
	if (fsck_err_on(r->refcount != le64_to_cpu(*refcount),
 | 
			
		||||
			trans, reflink_v_refcount_wrong,
 | 
			
		||||
			"reflink key has wrong refcount:\n"
 | 
			
		||||
			"  %s\n"
 | 
			
		||||
			"  should be %u",
 | 
			
		||||
| 
						 | 
				
			
			@ -1038,7 +1041,8 @@ static int bch2_gc_write_stripes_key(struct btree_trans *trans,
 | 
			
		|||
	if (bad)
 | 
			
		||||
		bch2_bkey_val_to_text(&buf, c, k);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(bad, c, stripe_sector_count_wrong,
 | 
			
		||||
	if (fsck_err_on(bad,
 | 
			
		||||
			trans, stripe_sector_count_wrong,
 | 
			
		||||
			"%s", buf.buf)) {
 | 
			
		||||
		struct bkey_i_stripe *new;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -585,7 +585,7 @@ static int __btree_err(int ret,
 | 
			
		|||
	switch (ret) {
 | 
			
		||||
	case -BCH_ERR_btree_node_read_err_fixable:
 | 
			
		||||
		ret = !silent
 | 
			
		||||
			? bch2_fsck_err(c, FSCK_CAN_FIX, err_type, "%s", out.buf)
 | 
			
		||||
			? __bch2_fsck_err(c, NULL, FSCK_CAN_FIX, err_type, "%s", out.buf)
 | 
			
		||||
			: -BCH_ERR_fsck_fix;
 | 
			
		||||
		if (ret != -BCH_ERR_fsck_fix &&
 | 
			
		||||
		    ret != -BCH_ERR_fsck_ignore)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3275,6 +3275,20 @@ void bch2_trans_put(struct btree_trans *trans)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool bch2_current_has_btree_trans(struct bch_fs *c)
 | 
			
		||||
{
 | 
			
		||||
	seqmutex_lock(&c->btree_trans_lock);
 | 
			
		||||
	struct btree_trans *trans;
 | 
			
		||||
	bool ret = false;
 | 
			
		||||
	list_for_each_entry(trans, &c->btree_trans_list, list)
 | 
			
		||||
		if (trans->locking_wait.task == current) {
 | 
			
		||||
			ret = true;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	seqmutex_unlock(&c->btree_trans_lock);
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void __maybe_unused
 | 
			
		||||
bch2_btree_bkey_cached_common_to_text(struct printbuf *out,
 | 
			
		||||
				      struct btree_bkey_cached_common *b)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -883,6 +883,8 @@ void bch2_dump_trans_paths_updates(struct btree_trans *);
 | 
			
		|||
struct btree_trans *__bch2_trans_get(struct bch_fs *, unsigned);
 | 
			
		||||
void bch2_trans_put(struct btree_trans *);
 | 
			
		||||
 | 
			
		||||
bool bch2_current_has_btree_trans(struct bch_fs *);
 | 
			
		||||
 | 
			
		||||
extern const char *bch2_btree_transaction_fns[BCH_TRANSACTIONS_NR];
 | 
			
		||||
unsigned bch2_trans_get_fn_idx(const char *);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
 | 
			
		|||
		if (!bpos_eq(b->data->min_key, POS_MIN)) {
 | 
			
		||||
			printbuf_reset(&buf);
 | 
			
		||||
			bch2_bpos_to_text(&buf, b->data->min_key);
 | 
			
		||||
			need_fsck_err(c, btree_root_bad_min_key,
 | 
			
		||||
			need_fsck_err(trans, btree_root_bad_min_key,
 | 
			
		||||
				      "btree root with incorrect min_key: %s", buf.buf);
 | 
			
		||||
			goto topology_repair;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +69,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
 | 
			
		|||
		if (!bpos_eq(b->data->max_key, SPOS_MAX)) {
 | 
			
		||||
			printbuf_reset(&buf);
 | 
			
		||||
			bch2_bpos_to_text(&buf, b->data->max_key);
 | 
			
		||||
			need_fsck_err(c, btree_root_bad_max_key,
 | 
			
		||||
			need_fsck_err(trans, btree_root_bad_max_key,
 | 
			
		||||
				      "btree root with incorrect max_key: %s", buf.buf);
 | 
			
		||||
			goto topology_repair;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -105,7 +105,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
 | 
			
		|||
			prt_str(&buf, "\n  next ");
 | 
			
		||||
			bch2_bkey_val_to_text(&buf, c, k);
 | 
			
		||||
 | 
			
		||||
			need_fsck_err(c, btree_node_topology_bad_min_key, "%s", buf.buf);
 | 
			
		||||
			need_fsck_err(trans, btree_node_topology_bad_min_key, "%s", buf.buf);
 | 
			
		||||
			goto topology_repair;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -122,7 +122,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
 | 
			
		|||
			   bch2_btree_id_str(b->c.btree_id), b->c.level);
 | 
			
		||||
		bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
 | 
			
		||||
 | 
			
		||||
		need_fsck_err(c, btree_node_topology_empty_interior_node, "%s", buf.buf);
 | 
			
		||||
		need_fsck_err(trans, btree_node_topology_empty_interior_node, "%s", buf.buf);
 | 
			
		||||
		goto topology_repair;
 | 
			
		||||
	} else if (!bpos_eq(prev.k->k.p, b->key.k.p)) {
 | 
			
		||||
		bch2_topology_error(c);
 | 
			
		||||
| 
						 | 
				
			
			@ -135,7 +135,7 @@ int bch2_btree_node_check_topology(struct btree_trans *trans, struct btree *b)
 | 
			
		|||
		prt_str(&buf, "\n  last key ");
 | 
			
		||||
		bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(prev.k));
 | 
			
		||||
 | 
			
		||||
		need_fsck_err(c, btree_node_topology_bad_max_key, "%s", buf.buf);
 | 
			
		||||
		need_fsck_err(trans, btree_node_topology_bad_max_key, "%s", buf.buf);
 | 
			
		||||
		goto topology_repair;
 | 
			
		||||
	}
 | 
			
		||||
out:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -96,7 +96,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	struct bch_dev *ca = bch2_dev_tryget(c, p.ptr.dev);
 | 
			
		||||
	if (!ca) {
 | 
			
		||||
		if (fsck_err(c, ptr_to_invalid_device,
 | 
			
		||||
		if (fsck_err(trans, ptr_to_invalid_device,
 | 
			
		||||
			     "pointer to missing device %u\n"
 | 
			
		||||
			     "while marking %s",
 | 
			
		||||
			     p.ptr.dev,
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +108,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	struct bucket *g = PTR_GC_BUCKET(ca, &p.ptr);
 | 
			
		||||
	if (!g) {
 | 
			
		||||
		if (fsck_err(c, ptr_to_invalid_device,
 | 
			
		||||
		if (fsck_err(trans, ptr_to_invalid_device,
 | 
			
		||||
			     "pointer to invalid bucket on device %u\n"
 | 
			
		||||
			     "while marking %s",
 | 
			
		||||
			     p.ptr.dev,
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +121,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
	enum bch_data_type data_type = bch2_bkey_ptr_data_type(k, p, entry);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!g->gen_valid,
 | 
			
		||||
			c, ptr_to_missing_alloc_key,
 | 
			
		||||
			trans, ptr_to_missing_alloc_key,
 | 
			
		||||
			"bucket %u:%zu data type %s ptr gen %u missing in alloc btree\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +138,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(gen_cmp(p.ptr.gen, g->gen) > 0,
 | 
			
		||||
			c, ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
			trans, ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
			"bucket %u:%zu data type %s ptr gen in the future: %u > %u\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
 | 
			
		||||
| 
						 | 
				
			
			@ -161,7 +161,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(gen_cmp(g->gen, p.ptr.gen) > BUCKET_GC_GEN_MAX,
 | 
			
		||||
			c, ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
			trans, ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
			"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->gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -172,7 +172,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
		*do_update = true;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!p.ptr.cached && gen_cmp(p.ptr.gen, g->gen) < 0,
 | 
			
		||||
			c, stale_dirty_ptr,
 | 
			
		||||
			trans, stale_dirty_ptr,
 | 
			
		||||
			"bucket %u:%zu data type %s stale dirty ptr: %u < %u\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
 | 
			
		||||
| 
						 | 
				
			
			@ -186,7 +186,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
		goto out;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(bucket_data_type_mismatch(g->data_type, data_type),
 | 
			
		||||
			c, ptr_bucket_data_type_mismatch,
 | 
			
		||||
			trans, ptr_bucket_data_type_mismatch,
 | 
			
		||||
			"bucket %u:%zu gen %u different types of data in same bucket: %s, %s\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr), g->gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +210,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
		struct gc_stripe *m = genradix_ptr(&c->gc_stripes, p.ec.idx);
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(!m || !m->alive,
 | 
			
		||||
				c, ptr_to_missing_stripe,
 | 
			
		||||
				trans, ptr_to_missing_stripe,
 | 
			
		||||
				"pointer to nonexistent stripe %llu\n"
 | 
			
		||||
				"while marking %s",
 | 
			
		||||
				(u64) p.ec.idx,
 | 
			
		||||
| 
						 | 
				
			
			@ -219,7 +219,7 @@ static int bch2_check_fix_ptr(struct btree_trans *trans,
 | 
			
		|||
			*do_update = true;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(m && m->alive && !bch2_ptr_matches_stripe_m(m, p),
 | 
			
		||||
				c, ptr_to_incorrect_stripe,
 | 
			
		||||
				trans, ptr_to_incorrect_stripe,
 | 
			
		||||
				"pointer does not match stripe %llu\n"
 | 
			
		||||
				"while marking %s",
 | 
			
		||||
				(u64) p.ec.idx,
 | 
			
		||||
| 
						 | 
				
			
			@ -387,8 +387,8 @@ int bch2_bucket_ref_update(struct btree_trans *trans, struct bch_dev *ca,
 | 
			
		|||
	BUG_ON(!sectors);
 | 
			
		||||
 | 
			
		||||
	if (gen_after(ptr->gen, b_gen)) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
		bch2_fsck_err(trans, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      ptr_gen_newer_than_bucket_gen,
 | 
			
		||||
			"bucket %u:%zu gen %u data type %s: ptr gen %u newer than bucket gen\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			ptr->dev, bucket_nr, b_gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -401,8 +401,8 @@ int bch2_bucket_ref_update(struct btree_trans *trans, struct bch_dev *ca,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (gen_cmp(b_gen, ptr->gen) > BUCKET_GC_GEN_MAX) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_ptr_too_stale,
 | 
			
		||||
		bch2_fsck_err(trans, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      ptr_too_stale,
 | 
			
		||||
			"bucket %u:%zu gen %u data type %s: ptr gen %u too stale\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			ptr->dev, bucket_nr, b_gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -421,8 +421,8 @@ int bch2_bucket_ref_update(struct btree_trans *trans, struct bch_dev *ca,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (b_gen != ptr->gen) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_stale_dirty_ptr,
 | 
			
		||||
		bch2_fsck_err(trans, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      stale_dirty_ptr,
 | 
			
		||||
			"bucket %u:%zu gen %u (mem gen %u) data type %s: stale dirty ptr (gen %u)\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			ptr->dev, bucket_nr, b_gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -437,8 +437,8 @@ int bch2_bucket_ref_update(struct btree_trans *trans, struct bch_dev *ca,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (bucket_data_type_mismatch(bucket_data_type, ptr_data_type)) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_ptr_bucket_data_type_mismatch,
 | 
			
		||||
		bch2_fsck_err(trans, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      ptr_bucket_data_type_mismatch,
 | 
			
		||||
			"bucket %u:%zu gen %u different types of data in same bucket: %s, %s\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			ptr->dev, bucket_nr, b_gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -452,8 +452,8 @@ int bch2_bucket_ref_update(struct btree_trans *trans, struct bch_dev *ca,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if ((u64) *bucket_sectors + sectors > U32_MAX) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_bucket_sector_count_overflow,
 | 
			
		||||
		bch2_fsck_err(trans, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      bucket_sector_count_overflow,
 | 
			
		||||
			"bucket %u:%zu gen %u data type %s sector count overflow: %u + %lli > U32_MAX\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			ptr->dev, bucket_nr, b_gen,
 | 
			
		||||
| 
						 | 
				
			
			@ -908,7 +908,7 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (a->v.data_type && type && a->v.data_type != type) {
 | 
			
		||||
		bch2_fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK,
 | 
			
		||||
			      BCH_FSCK_ERR_bucket_metadata_type_mismatch,
 | 
			
		||||
			      bucket_metadata_type_mismatch,
 | 
			
		||||
			"bucket %llu:%llu gen %u different types of data in same bucket: %s, %s\n"
 | 
			
		||||
			"while marking %s",
 | 
			
		||||
			iter.pos.inode, iter.pos.offset, a->v.gen,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -433,7 +433,7 @@ int bch2_accounting_gc_done(struct bch_fs *c)
 | 
			
		|||
			for (unsigned j = 0; j < nr; j++)
 | 
			
		||||
				src_v[j] -= dst_v[j];
 | 
			
		||||
 | 
			
		||||
			if (fsck_err(c, accounting_mismatch, "%s", buf.buf)) {
 | 
			
		||||
			if (fsck_err(trans, accounting_mismatch, "%s", buf.buf)) {
 | 
			
		||||
				ret = commit_do(trans, NULL, NULL, 0,
 | 
			
		||||
						bch2_disk_accounting_mod(trans, &acc_k, src_v, nr, false));
 | 
			
		||||
				if (ret)
 | 
			
		||||
| 
						 | 
				
			
			@ -464,8 +464,9 @@ int bch2_accounting_gc_done(struct bch_fs *c)
 | 
			
		|||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int accounting_read_key(struct bch_fs *c, struct bkey_s_c k)
 | 
			
		||||
static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct printbuf buf = PRINTBUF;
 | 
			
		||||
 | 
			
		||||
	if (k.k->type != KEY_TYPE_accounting)
 | 
			
		||||
| 
						 | 
				
			
			@ -483,7 +484,7 @@ static int accounting_read_key(struct bch_fs *c, struct bkey_s_c k)
 | 
			
		|||
	bpos_to_disk_accounting_pos(&acc, k.k->p);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(ret == -BCH_ERR_btree_insert_need_mark_replicas,
 | 
			
		||||
			c, accounting_replicas_not_marked,
 | 
			
		||||
			trans, accounting_replicas_not_marked,
 | 
			
		||||
			"accounting not marked in superblock replicas\n  %s",
 | 
			
		||||
			(bch2_accounting_key_to_text(&buf, &acc),
 | 
			
		||||
			 buf.buf)))
 | 
			
		||||
| 
						 | 
				
			
			@ -500,15 +501,15 @@ static int accounting_read_key(struct bch_fs *c, struct bkey_s_c k)
 | 
			
		|||
int bch2_accounting_read(struct bch_fs *c)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_accounting_mem *acc = &c->accounting[0];
 | 
			
		||||
	struct btree_trans *trans = bch2_trans_get(c);
 | 
			
		||||
 | 
			
		||||
	int ret = bch2_trans_run(c,
 | 
			
		||||
		for_each_btree_key(trans, iter,
 | 
			
		||||
	int ret = for_each_btree_key(trans, iter,
 | 
			
		||||
				BTREE_ID_accounting, POS_MIN,
 | 
			
		||||
				BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k, ({
 | 
			
		||||
			struct bkey u;
 | 
			
		||||
			struct bkey_s_c k = bch2_btree_path_peek_slot_exact(btree_iter_path(trans, &iter), &u);
 | 
			
		||||
			accounting_read_key(c, k);
 | 
			
		||||
		})));
 | 
			
		||||
			accounting_read_key(trans, k);
 | 
			
		||||
		}));
 | 
			
		||||
	if (ret)
 | 
			
		||||
		goto err;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -541,7 +542,7 @@ int bch2_accounting_read(struct bch_fs *c)
 | 
			
		|||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			ret = accounting_read_key(c, k);
 | 
			
		||||
			ret = accounting_read_key(trans, k);
 | 
			
		||||
			if (ret)
 | 
			
		||||
				goto err;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -588,6 +589,7 @@ int bch2_accounting_read(struct bch_fs *c)
 | 
			
		|||
	preempt_enable();
 | 
			
		||||
	percpu_up_read(&c->mark_lock);
 | 
			
		||||
err:
 | 
			
		||||
	bch2_trans_put(trans);
 | 
			
		||||
	bch_err_fn(c, ret);
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0
 | 
			
		||||
#include "bcachefs.h"
 | 
			
		||||
#include "btree_iter.h"
 | 
			
		||||
#include "error.h"
 | 
			
		||||
#include "journal.h"
 | 
			
		||||
#include "recovery_passes.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -198,7 +199,8 @@ static const u8 fsck_flags_extra[] = {
 | 
			
		|||
#undef x
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int bch2_fsck_err(struct bch_fs *c,
 | 
			
		||||
int __bch2_fsck_err(struct bch_fs *c,
 | 
			
		||||
		  struct btree_trans *trans,
 | 
			
		||||
		  enum bch_fsck_flags flags,
 | 
			
		||||
		  enum bch_sb_error_id err,
 | 
			
		||||
		  const char *fmt, ...)
 | 
			
		||||
| 
						 | 
				
			
			@ -215,6 +217,11 @@ int bch2_fsck_err(struct bch_fs *c,
 | 
			
		|||
	if (!WARN_ON(err >= ARRAY_SIZE(fsck_flags_extra)))
 | 
			
		||||
		flags |= fsck_flags_extra[err];
 | 
			
		||||
 | 
			
		||||
	if (!c)
 | 
			
		||||
		c = trans->c;
 | 
			
		||||
 | 
			
		||||
	WARN_ON(!trans && bch2_current_has_btree_trans(c));
 | 
			
		||||
 | 
			
		||||
	if ((flags & FSCK_CAN_FIX) &&
 | 
			
		||||
	    test_bit(err, c->sb.errors_silent))
 | 
			
		||||
		return -BCH_ERR_fsck_fix;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,18 +110,21 @@ struct fsck_err_state {
 | 
			
		|||
 | 
			
		||||
#define fsck_err_count(_c, _err)	bch2_sb_err_count(_c, BCH_FSCK_ERR_##_err)
 | 
			
		||||
 | 
			
		||||
__printf(4, 5) __cold
 | 
			
		||||
int bch2_fsck_err(struct bch_fs *,
 | 
			
		||||
__printf(5, 6) __cold
 | 
			
		||||
int __bch2_fsck_err(struct bch_fs *, struct btree_trans *,
 | 
			
		||||
		  enum bch_fsck_flags,
 | 
			
		||||
		  enum bch_sb_error_id,
 | 
			
		||||
		  const char *, ...);
 | 
			
		||||
#define bch2_fsck_err(c, _flags, _err_type, ...)				\
 | 
			
		||||
	__bch2_fsck_err(type_is(c, struct bch_fs *) ? (struct bch_fs *) c : NULL,\
 | 
			
		||||
			type_is(c, struct btree_trans *) ? (struct btree_trans *) c : NULL,\
 | 
			
		||||
			_flags, BCH_FSCK_ERR_##_err_type, __VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
void bch2_flush_fsck_errs(struct bch_fs *);
 | 
			
		||||
 | 
			
		||||
#define __fsck_err(c, _flags, _err_type, ...)				\
 | 
			
		||||
({									\
 | 
			
		||||
	int _ret = bch2_fsck_err(c, _flags, BCH_FSCK_ERR_##_err_type,	\
 | 
			
		||||
				 __VA_ARGS__);				\
 | 
			
		||||
									\
 | 
			
		||||
	int _ret = bch2_fsck_err(c, _flags, _err_type, __VA_ARGS__);	\
 | 
			
		||||
	if (_ret != -BCH_ERR_fsck_fix &&				\
 | 
			
		||||
	    _ret != -BCH_ERR_fsck_ignore) {				\
 | 
			
		||||
		ret = _ret;						\
 | 
			
		||||
| 
						 | 
				
			
			@ -138,8 +141,12 @@ void bch2_flush_fsck_errs(struct bch_fs *);
 | 
			
		|||
#define __fsck_err_on(cond, c, _flags, _err_type, ...)			\
 | 
			
		||||
({									\
 | 
			
		||||
	might_sleep();							\
 | 
			
		||||
									\
 | 
			
		||||
	if (type_is(c, struct bch_fs *))				\
 | 
			
		||||
		WARN_ON(bch2_current_has_btree_trans((struct bch_fs *) c));\
 | 
			
		||||
									\
 | 
			
		||||
	(unlikely(cond) ? __fsck_err(c, _flags, _err_type, __VA_ARGS__) : false);\
 | 
			
		||||
})									\
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
#define need_fsck_err_on(cond, c, _err_type, ...)				\
 | 
			
		||||
	__fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, _err_type, __VA_ARGS__)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -835,8 +835,8 @@ static int hash_check_key(struct btree_trans *trans,
 | 
			
		|||
			break;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(k.k->type == desc.key_type &&
 | 
			
		||||
				!desc.cmp_bkey(k, hash_k), c,
 | 
			
		||||
				hash_table_key_duplicate,
 | 
			
		||||
				!desc.cmp_bkey(k, hash_k),
 | 
			
		||||
				trans, hash_table_key_duplicate,
 | 
			
		||||
				"duplicate hash table keys:\n%s",
 | 
			
		||||
				(printbuf_reset(&buf),
 | 
			
		||||
				 bch2_bkey_val_to_text(&buf, c, hash_k),
 | 
			
		||||
| 
						 | 
				
			
			@ -855,7 +855,7 @@ static int hash_check_key(struct btree_trans *trans,
 | 
			
		|||
	printbuf_exit(&buf);
 | 
			
		||||
	return ret;
 | 
			
		||||
bad_hash:
 | 
			
		||||
	if (fsck_err(c, hash_table_key_wrong_offset,
 | 
			
		||||
	if (fsck_err(trans, hash_table_key_wrong_offset,
 | 
			
		||||
		     "hash table key at wrong offset: btree %s inode %llu offset %llu, hashed to %llu\n%s",
 | 
			
		||||
		     bch2_btree_id_str(desc.btree_id), hash_k.k->p.inode, hash_k.k->p.offset, hash,
 | 
			
		||||
		     (printbuf_reset(&buf),
 | 
			
		||||
| 
						 | 
				
			
			@ -930,11 +930,11 @@ static int check_inode_dirent_inode(struct btree_trans *trans, struct bkey_s_c i
 | 
			
		|||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(ret,
 | 
			
		||||
			c, inode_points_to_missing_dirent,
 | 
			
		||||
			trans, inode_points_to_missing_dirent,
 | 
			
		||||
			"inode points to missing dirent\n%s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, inode_k), buf.buf)) ||
 | 
			
		||||
	    fsck_err_on(!ret && !dirent_points_to_inode(d, inode),
 | 
			
		||||
			c, inode_points_to_wrong_dirent,
 | 
			
		||||
			trans, inode_points_to_wrong_dirent,
 | 
			
		||||
			"inode points to dirent that does not point back:\n%s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, inode_k),
 | 
			
		||||
			 prt_newline(&buf),
 | 
			
		||||
| 
						 | 
				
			
			@ -997,7 +997,7 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (fsck_err_on(prev->bi_hash_seed	!= u.bi_hash_seed ||
 | 
			
		||||
			inode_d_type(prev)	!= inode_d_type(&u),
 | 
			
		||||
			c, inode_snapshot_mismatch,
 | 
			
		||||
			trans, inode_snapshot_mismatch,
 | 
			
		||||
			"inodes in different snapshots don't match")) {
 | 
			
		||||
		bch_err(c, "repair not implemented yet");
 | 
			
		||||
		return -BCH_ERR_fsck_repair_unimplemented;
 | 
			
		||||
| 
						 | 
				
			
			@ -1029,7 +1029,8 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
		if (ret < 0)
 | 
			
		||||
			return ret;
 | 
			
		||||
 | 
			
		||||
		fsck_err_on(!ret, c, unlinked_inode_not_on_deleted_list,
 | 
			
		||||
		fsck_err_on(!ret,
 | 
			
		||||
			    trans, unlinked_inode_not_on_deleted_list,
 | 
			
		||||
			    "inode %llu:%u unlinked, but not on deleted list",
 | 
			
		||||
			    u.bi_inum, k.k->p.snapshot);
 | 
			
		||||
		ret = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -1037,7 +1038,7 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (u.bi_flags & BCH_INODE_unlinked &&
 | 
			
		||||
	    (!c->sb.clean ||
 | 
			
		||||
	     fsck_err(c, inode_unlinked_but_clean,
 | 
			
		||||
	     fsck_err(trans, inode_unlinked_but_clean,
 | 
			
		||||
		      "filesystem marked clean, but inode %llu unlinked",
 | 
			
		||||
		      u.bi_inum))) {
 | 
			
		||||
		ret = bch2_inode_rm_snapshot(trans, u.bi_inum, iter->pos.snapshot);
 | 
			
		||||
| 
						 | 
				
			
			@ -1047,7 +1048,7 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (u.bi_flags & BCH_INODE_i_size_dirty &&
 | 
			
		||||
	    (!c->sb.clean ||
 | 
			
		||||
	     fsck_err(c, inode_i_size_dirty_but_clean,
 | 
			
		||||
	     fsck_err(trans, inode_i_size_dirty_but_clean,
 | 
			
		||||
		      "filesystem marked clean, but inode %llu has i_size dirty",
 | 
			
		||||
		      u.bi_inum))) {
 | 
			
		||||
		bch_verbose(c, "truncating inode %llu", u.bi_inum);
 | 
			
		||||
| 
						 | 
				
			
			@ -1077,7 +1078,7 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (u.bi_flags & BCH_INODE_i_sectors_dirty &&
 | 
			
		||||
	    (!c->sb.clean ||
 | 
			
		||||
	     fsck_err(c, inode_i_sectors_dirty_but_clean,
 | 
			
		||||
	     fsck_err(trans, inode_i_sectors_dirty_but_clean,
 | 
			
		||||
		      "filesystem marked clean, but inode %llu has i_sectors dirty",
 | 
			
		||||
		      u.bi_inum))) {
 | 
			
		||||
		s64 sectors;
 | 
			
		||||
| 
						 | 
				
			
			@ -1112,7 +1113,7 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
	if (fsck_err_on(u.bi_parent_subvol &&
 | 
			
		||||
			(u.bi_subvol == 0 ||
 | 
			
		||||
			 u.bi_subvol == BCACHEFS_ROOT_SUBVOL),
 | 
			
		||||
			c, inode_bi_parent_nonzero,
 | 
			
		||||
			trans, inode_bi_parent_nonzero,
 | 
			
		||||
			"inode %llu:%u has subvol %u but nonzero parent subvol %u",
 | 
			
		||||
			u.bi_inum, k.k->p.snapshot, u.bi_subvol, u.bi_parent_subvol)) {
 | 
			
		||||
		u.bi_parent_subvol = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -1132,13 +1133,13 @@ static int check_inode(struct btree_trans *trans,
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(ret,
 | 
			
		||||
				c, inode_bi_subvol_missing,
 | 
			
		||||
				trans, inode_bi_subvol_missing,
 | 
			
		||||
				"inode %llu:%u bi_subvol points to missing subvolume %u",
 | 
			
		||||
				u.bi_inum, k.k->p.snapshot, u.bi_subvol) ||
 | 
			
		||||
		    fsck_err_on(le64_to_cpu(s.inode) != u.bi_inum ||
 | 
			
		||||
				!bch2_snapshot_is_ancestor(c, le32_to_cpu(s.snapshot),
 | 
			
		||||
							   k.k->p.snapshot),
 | 
			
		||||
				c, inode_bi_subvol_wrong,
 | 
			
		||||
				trans, inode_bi_subvol_wrong,
 | 
			
		||||
				"inode %llu:%u points to subvol %u, but subvol points to %llu:%u",
 | 
			
		||||
				u.bi_inum, k.k->p.snapshot, u.bi_subvol,
 | 
			
		||||
				le64_to_cpu(s.inode),
 | 
			
		||||
| 
						 | 
				
			
			@ -1221,14 +1222,15 @@ static int check_key_has_inode(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!i, c, key_in_missing_inode,
 | 
			
		||||
	if (fsck_err_on(!i,
 | 
			
		||||
			trans, key_in_missing_inode,
 | 
			
		||||
			"key in missing inode:\n  %s",
 | 
			
		||||
			(printbuf_reset(&buf),
 | 
			
		||||
			 bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
 | 
			
		||||
		goto delete;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(i && !btree_matches_i_mode(iter->btree_id, i->inode.bi_mode),
 | 
			
		||||
			c, key_in_wrong_inode_type,
 | 
			
		||||
			trans, key_in_wrong_inode_type,
 | 
			
		||||
			"key for wrong inode mode %o:\n  %s",
 | 
			
		||||
			i->inode.bi_mode,
 | 
			
		||||
			(printbuf_reset(&buf),
 | 
			
		||||
| 
						 | 
				
			
			@ -1267,7 +1269,7 @@ static int check_i_sectors_notnested(struct btree_trans *trans, struct inode_wal
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_i_sectors_dirty),
 | 
			
		||||
				c, inode_i_sectors_wrong,
 | 
			
		||||
				trans, inode_i_sectors_wrong,
 | 
			
		||||
				"inode %llu:%u has incorrect i_sectors: got %llu, should be %llu",
 | 
			
		||||
				w->last_pos.inode, i->snapshot,
 | 
			
		||||
				i->inode.bi_sectors, i->count)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1415,7 +1417,7 @@ static int overlapping_extents_found(struct btree_trans *trans,
 | 
			
		|||
	prt_printf(&buf, "\n  overwriting %s extent",
 | 
			
		||||
		   pos1.snapshot >= pos2.p.snapshot ? "first" : "second");
 | 
			
		||||
 | 
			
		||||
	if (fsck_err(c, extent_overlapping,
 | 
			
		||||
	if (fsck_err(trans, extent_overlapping,
 | 
			
		||||
		     "overlapping extents%s", buf.buf)) {
 | 
			
		||||
		struct btree_iter *old_iter = &iter1;
 | 
			
		||||
		struct disk_reservation res = { 0 };
 | 
			
		||||
| 
						 | 
				
			
			@ -1590,7 +1592,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
 | 
			
		|||
			if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_i_size_dirty) &&
 | 
			
		||||
					k.k->p.offset > round_up(i->inode.bi_size, block_bytes(c)) >> 9 &&
 | 
			
		||||
					!bkey_extent_is_reservation(k),
 | 
			
		||||
					c, extent_past_end_of_inode,
 | 
			
		||||
					trans, extent_past_end_of_inode,
 | 
			
		||||
					"extent type past end of inode %llu:%u, i_size %llu\n  %s",
 | 
			
		||||
					i->inode.bi_inum, i->snapshot, i->inode.bi_size,
 | 
			
		||||
					(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1705,7 +1707,7 @@ static int check_subdir_count_notnested(struct btree_trans *trans, struct inode_
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(i->inode.bi_nlink != i->count,
 | 
			
		||||
				c, inode_dir_wrong_nlink,
 | 
			
		||||
				trans, inode_dir_wrong_nlink,
 | 
			
		||||
				"directory %llu:%u with wrong i_nlink: got %u, should be %llu",
 | 
			
		||||
				w->last_pos.inode, i->snapshot, i->inode.bi_nlink, i->count)) {
 | 
			
		||||
			i->inode.bi_nlink = i->count;
 | 
			
		||||
| 
						 | 
				
			
			@ -1741,7 +1743,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
 | 
			
		|||
		return 0;
 | 
			
		||||
 | 
			
		||||
	if (bch2_inode_should_have_bp(target) &&
 | 
			
		||||
	    !fsck_err(c, inode_wrong_backpointer,
 | 
			
		||||
	    !fsck_err(trans, inode_wrong_backpointer,
 | 
			
		||||
		      "dirent points to inode that does not point back:\n  %s",
 | 
			
		||||
		      (bch2_bkey_val_to_text(&buf, c, d.s_c),
 | 
			
		||||
		       prt_printf(&buf, "\n  "),
 | 
			
		||||
| 
						 | 
				
			
			@ -1767,7 +1769,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
 | 
			
		|||
	ret = 0;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!backpointer_exists,
 | 
			
		||||
			c, inode_wrong_backpointer,
 | 
			
		||||
			trans, inode_wrong_backpointer,
 | 
			
		||||
			"inode %llu:%u has wrong backpointer:\n"
 | 
			
		||||
			"got       %llu:%llu\n"
 | 
			
		||||
			"should be %llu:%llu",
 | 
			
		||||
| 
						 | 
				
			
			@ -1790,7 +1792,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
 | 
			
		|||
	if (fsck_err_on(backpointer_exists &&
 | 
			
		||||
			(S_ISDIR(target->bi_mode) ||
 | 
			
		||||
			 target->bi_subvol),
 | 
			
		||||
			c, inode_dir_multiple_links,
 | 
			
		||||
			trans, inode_dir_multiple_links,
 | 
			
		||||
			"%s %llu:%u with multiple links\n%s",
 | 
			
		||||
			S_ISDIR(target->bi_mode) ? "directory" : "subvolume",
 | 
			
		||||
			target->bi_inum, target_snapshot, buf.buf)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1804,7 +1806,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
 | 
			
		|||
	 * it up, it ignores inodes with nlink 0
 | 
			
		||||
	 */
 | 
			
		||||
	if (fsck_err_on(backpointer_exists && !target->bi_nlink,
 | 
			
		||||
			c, inode_multiple_links_but_nlink_0,
 | 
			
		||||
			trans, inode_multiple_links_but_nlink_0,
 | 
			
		||||
			"inode %llu:%u type %s has multiple links but i_nlink 0\n%s",
 | 
			
		||||
			target->bi_inum, target_snapshot, bch2_d_types[d.v->d_type], buf.buf)) {
 | 
			
		||||
		target->bi_nlink++;
 | 
			
		||||
| 
						 | 
				
			
			@ -1840,7 +1842,7 @@ static int check_dirent_target(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(d.v->d_type != inode_d_type(target),
 | 
			
		||||
			c, dirent_d_type_wrong,
 | 
			
		||||
			trans, dirent_d_type_wrong,
 | 
			
		||||
			"incorrect d_type: got %s, should be %s:\n%s",
 | 
			
		||||
			bch2_d_type_str(d.v->d_type),
 | 
			
		||||
			bch2_d_type_str(inode_d_type(target)),
 | 
			
		||||
| 
						 | 
				
			
			@ -1938,11 +1940,12 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
 | 
			
		|||
		parent_snapshot = d.k->p.snapshot;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(ret, c, dirent_to_missing_parent_subvol,
 | 
			
		||||
	if (fsck_err_on(ret,
 | 
			
		||||
			trans, dirent_to_missing_parent_subvol,
 | 
			
		||||
			"dirent parent_subvol points to missing subvolume\n%s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, d.s_c), buf.buf)) ||
 | 
			
		||||
	    fsck_err_on(!ret && !bch2_snapshot_is_ancestor(c, parent_snapshot, d.k->p.snapshot),
 | 
			
		||||
			c, dirent_not_visible_in_parent_subvol,
 | 
			
		||||
			trans, dirent_not_visible_in_parent_subvol,
 | 
			
		||||
			"dirent not visible in parent_subvol (not an ancestor of subvol snap %u)\n%s",
 | 
			
		||||
			parent_snapshot,
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, d.s_c), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1968,7 +1971,7 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
 | 
			
		|||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (ret) {
 | 
			
		||||
		if (fsck_err(c, dirent_to_missing_subvol,
 | 
			
		||||
		if (fsck_err(trans, dirent_to_missing_subvol,
 | 
			
		||||
			     "dirent points to missing subvolume\n%s",
 | 
			
		||||
			     (bch2_bkey_val_to_text(&buf, c, d.s_c), buf.buf)))
 | 
			
		||||
			return __remove_dirent(trans, d.k->p);
 | 
			
		||||
| 
						 | 
				
			
			@ -1977,7 +1980,7 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(le32_to_cpu(s.v->fs_path_parent) != parent_subvol,
 | 
			
		||||
			c, subvol_fs_path_parent_wrong,
 | 
			
		||||
			trans, subvol_fs_path_parent_wrong,
 | 
			
		||||
			"subvol with wrong fs_path_parent, should be be %u\n%s",
 | 
			
		||||
			parent_subvol,
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, s.s_c), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2005,7 +2008,7 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!ret && parent_subvol != subvol_root.bi_parent_subvol,
 | 
			
		||||
			c, inode_bi_parent_wrong,
 | 
			
		||||
			trans, inode_bi_parent_wrong,
 | 
			
		||||
			"subvol root %llu has wrong bi_parent_subvol: got %u, should be %u",
 | 
			
		||||
			target_inum,
 | 
			
		||||
			subvol_root.bi_parent_subvol, parent_subvol)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2098,7 +2101,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
 | 
			
		|||
			goto err;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(!target->inodes.nr,
 | 
			
		||||
				c, dirent_to_missing_inode,
 | 
			
		||||
				trans, dirent_to_missing_inode,
 | 
			
		||||
				"dirent points to missing inode:\n%s",
 | 
			
		||||
				(printbuf_reset(&buf),
 | 
			
		||||
				 bch2_bkey_val_to_text(&buf, c, k),
 | 
			
		||||
| 
						 | 
				
			
			@ -2226,7 +2229,7 @@ static int check_root_trans(struct btree_trans *trans)
 | 
			
		|||
	if (ret && !bch2_err_matches(ret, ENOENT))
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (mustfix_fsck_err_on(ret, c, root_subvol_missing,
 | 
			
		||||
	if (mustfix_fsck_err_on(ret, trans, root_subvol_missing,
 | 
			
		||||
				"root subvol missing")) {
 | 
			
		||||
		struct bkey_i_subvolume *root_subvol =
 | 
			
		||||
			bch2_trans_kmalloc(trans, sizeof(*root_subvol));
 | 
			
		||||
| 
						 | 
				
			
			@ -2252,10 +2255,11 @@ static int check_root_trans(struct btree_trans *trans)
 | 
			
		|||
	if (ret && !bch2_err_matches(ret, ENOENT))
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (mustfix_fsck_err_on(ret, c, root_dir_missing,
 | 
			
		||||
	if (mustfix_fsck_err_on(ret,
 | 
			
		||||
				trans, root_dir_missing,
 | 
			
		||||
				"root directory missing") ||
 | 
			
		||||
	    mustfix_fsck_err_on(!S_ISDIR(root_inode.bi_mode),
 | 
			
		||||
				c, root_inode_not_dir,
 | 
			
		||||
				trans, root_inode_not_dir,
 | 
			
		||||
				"root inode not a directory")) {
 | 
			
		||||
		bch2_inode_init(c, &root_inode, 0, 0, S_IFDIR|0755,
 | 
			
		||||
				0, NULL);
 | 
			
		||||
| 
						 | 
				
			
			@ -2327,7 +2331,7 @@ static int check_subvol_path(struct btree_trans *trans, struct btree_iter *iter,
 | 
			
		|||
			break;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(!ret,
 | 
			
		||||
				c, subvol_unreachable,
 | 
			
		||||
				trans, subvol_unreachable,
 | 
			
		||||
				"unreachable subvolume %s",
 | 
			
		||||
				(bch2_bkey_val_to_text(&buf, c, s.s_c),
 | 
			
		||||
				 buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2352,7 +2356,7 @@ static int check_subvol_path(struct btree_trans *trans, struct btree_iter *iter,
 | 
			
		|||
			goto err;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(k.k->type != KEY_TYPE_subvolume,
 | 
			
		||||
				c, subvol_unreachable,
 | 
			
		||||
				trans, subvol_unreachable,
 | 
			
		||||
				"unreachable subvolume %s",
 | 
			
		||||
				(bch2_bkey_val_to_text(&buf, c, s.s_c),
 | 
			
		||||
				 buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2431,7 +2435,7 @@ static int check_path(struct btree_trans *trans, pathbuf *p, struct bkey_s_c ino
 | 
			
		|||
 | 
			
		||||
		if (bch2_err_matches(ret, ENOENT)) {
 | 
			
		||||
			ret = 0;
 | 
			
		||||
			if (fsck_err(c, inode_unreachable,
 | 
			
		||||
			if (fsck_err(trans, inode_unreachable,
 | 
			
		||||
				     "unreachable inode\n%s",
 | 
			
		||||
				     (printbuf_reset(&buf),
 | 
			
		||||
				      bch2_bkey_val_to_text(&buf, c, inode_k),
 | 
			
		||||
| 
						 | 
				
			
			@ -2477,7 +2481,7 @@ static int check_path(struct btree_trans *trans, pathbuf *p, struct bkey_s_c ino
 | 
			
		|||
				pr_err("%llu:%u", i->inum, i->snapshot);
 | 
			
		||||
			pr_err("%llu:%u", inode.bi_inum, snapshot);
 | 
			
		||||
 | 
			
		||||
			if (fsck_err(c, dir_loop, "directory structure loop")) {
 | 
			
		||||
			if (fsck_err(trans, dir_loop, "directory structure loop")) {
 | 
			
		||||
				ret = remove_backpointer(trans, &inode);
 | 
			
		||||
				bch_err_msg(c, ret, "removing dirent");
 | 
			
		||||
				if (ret)
 | 
			
		||||
| 
						 | 
				
			
			@ -2683,7 +2687,6 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite
 | 
			
		|||
				     struct nlink_table *links,
 | 
			
		||||
				     size_t *idx, u64 range_end)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct bch_inode_unpacked u;
 | 
			
		||||
	struct nlink *link = &links->d[*idx];
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -2709,7 +2712,7 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(bch2_inode_nlink_get(&u) != link->count,
 | 
			
		||||
			c, inode_wrong_nlink,
 | 
			
		||||
			trans, inode_wrong_nlink,
 | 
			
		||||
			"inode %llu type %s has wrong i_nlink (%u, should be %u)",
 | 
			
		||||
			u.bi_inum, bch2_d_types[mode_to_type(u.bi_mode)],
 | 
			
		||||
			bch2_inode_nlink_get(&u), link->count)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1087,8 +1087,8 @@ static int may_delete_deleted_inode(struct btree_trans *trans,
 | 
			
		|||
		return ret;
 | 
			
		||||
 | 
			
		||||
	ret = bkey_is_inode(k.k) ? 0 : -BCH_ERR_ENOENT_inode;
 | 
			
		||||
	if (fsck_err_on(!bkey_is_inode(k.k), c,
 | 
			
		||||
			deleted_inode_missing,
 | 
			
		||||
	if (fsck_err_on(!bkey_is_inode(k.k),
 | 
			
		||||
			trans, deleted_inode_missing,
 | 
			
		||||
			"nonexistent inode %llu:%u in deleted_inodes btree",
 | 
			
		||||
			pos.offset, pos.snapshot))
 | 
			
		||||
		goto delete;
 | 
			
		||||
| 
						 | 
				
			
			@ -1100,7 +1100,7 @@ static int may_delete_deleted_inode(struct btree_trans *trans,
 | 
			
		|||
	if (S_ISDIR(inode.bi_mode)) {
 | 
			
		||||
		ret = bch2_empty_dir_snapshot(trans, pos.offset, 0, pos.snapshot);
 | 
			
		||||
		if (fsck_err_on(bch2_err_matches(ret, ENOTEMPTY),
 | 
			
		||||
				c, deleted_inode_is_dir,
 | 
			
		||||
				trans, deleted_inode_is_dir,
 | 
			
		||||
				"non empty directory %llu:%u in deleted_inodes btree",
 | 
			
		||||
				pos.offset, pos.snapshot))
 | 
			
		||||
			goto delete;
 | 
			
		||||
| 
						 | 
				
			
			@ -1108,15 +1108,14 @@ static int may_delete_deleted_inode(struct btree_trans *trans,
 | 
			
		|||
			goto out;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!(inode.bi_flags & BCH_INODE_unlinked), c,
 | 
			
		||||
			deleted_inode_not_unlinked,
 | 
			
		||||
	if (fsck_err_on(!(inode.bi_flags & BCH_INODE_unlinked),
 | 
			
		||||
			trans, deleted_inode_not_unlinked,
 | 
			
		||||
			"non-deleted inode %llu:%u in deleted_inodes btree",
 | 
			
		||||
			pos.offset, pos.snapshot))
 | 
			
		||||
		goto delete;
 | 
			
		||||
 | 
			
		||||
	if (c->sb.clean &&
 | 
			
		||||
	    !fsck_err(c,
 | 
			
		||||
		      deleted_inode_but_clean,
 | 
			
		||||
	    !fsck_err(trans, deleted_inode_but_clean,
 | 
			
		||||
		      "filesystem marked as clean but have deleted inode %llu:%u",
 | 
			
		||||
		      pos.offset, pos.snapshot)) {
 | 
			
		||||
		ret = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -99,7 +99,7 @@ int bch2_lru_check_set(struct btree_trans *trans,
 | 
			
		|||
		if (ret)
 | 
			
		||||
			goto err;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err(c, alloc_key_to_missing_lru_entry,
 | 
			
		||||
		if (fsck_err(trans, alloc_key_to_missing_lru_entry,
 | 
			
		||||
			     "missing %s lru entry\n"
 | 
			
		||||
			     "  %s",
 | 
			
		||||
			     bch2_lru_types[lru_type(lru_k)],
 | 
			
		||||
| 
						 | 
				
			
			@ -133,8 +133,8 @@ static int bch2_check_lru_key(struct btree_trans *trans,
 | 
			
		|||
	u64 idx;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!bch2_dev_bucket_exists(c, alloc_pos), c,
 | 
			
		||||
			lru_entry_to_invalid_bucket,
 | 
			
		||||
	if (fsck_err_on(!bch2_dev_bucket_exists(c, alloc_pos),
 | 
			
		||||
			trans, lru_entry_to_invalid_bucket,
 | 
			
		||||
			"lru key points to nonexistent device:bucket %llu:%llu",
 | 
			
		||||
			alloc_pos.inode, alloc_pos.offset))
 | 
			
		||||
		return bch2_btree_delete_at(trans, lru_iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +164,7 @@ static int bch2_check_lru_key(struct btree_trans *trans,
 | 
			
		|||
			goto out;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (fsck_err(c, lru_entry_bad,
 | 
			
		||||
		if (fsck_err(trans, lru_entry_bad,
 | 
			
		||||
			     "incorrect lru entry: lru %s time %llu\n"
 | 
			
		||||
			     "  %s\n"
 | 
			
		||||
			     "  for %s",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -171,7 +171,7 @@ static s64 gc_trigger_reflink_p_segment(struct btree_trans *trans,
 | 
			
		|||
not_found:
 | 
			
		||||
	BUG_ON(!(flags & BTREE_TRIGGER_check_repair));
 | 
			
		||||
 | 
			
		||||
	if (fsck_err(c, reflink_p_to_missing_reflink_v,
 | 
			
		||||
	if (fsck_err(trans, reflink_p_to_missing_reflink_v,
 | 
			
		||||
		     "pointer to missing indirect extent\n"
 | 
			
		||||
		     "  %s\n"
 | 
			
		||||
		     "  missing range %llu-%llu",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -552,7 +552,7 @@ static int check_snapshot_tree(struct btree_trans *trans,
 | 
			
		|||
	if (fsck_err_on(ret ||
 | 
			
		||||
			root_id != bch2_snapshot_root(c, root_id) ||
 | 
			
		||||
			st.k->p.offset != le32_to_cpu(s.tree),
 | 
			
		||||
			c, snapshot_tree_to_missing_snapshot,
 | 
			
		||||
			trans, snapshot_tree_to_missing_snapshot,
 | 
			
		||||
			"snapshot tree points to missing/incorrect snapshot:\n  %s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, st.s_c), buf.buf))) {
 | 
			
		||||
		ret = bch2_btree_delete_at(trans, iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -565,19 +565,19 @@ static int check_snapshot_tree(struct btree_trans *trans,
 | 
			
		|||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(ret,
 | 
			
		||||
			c, snapshot_tree_to_missing_subvol,
 | 
			
		||||
			trans, snapshot_tree_to_missing_subvol,
 | 
			
		||||
			"snapshot tree points to missing subvolume:\n  %s",
 | 
			
		||||
			(printbuf_reset(&buf),
 | 
			
		||||
			 bch2_bkey_val_to_text(&buf, c, st.s_c), buf.buf)) ||
 | 
			
		||||
	    fsck_err_on(!bch2_snapshot_is_ancestor(c,
 | 
			
		||||
						le32_to_cpu(subvol.snapshot),
 | 
			
		||||
						root_id),
 | 
			
		||||
			c, snapshot_tree_to_wrong_subvol,
 | 
			
		||||
			trans, snapshot_tree_to_wrong_subvol,
 | 
			
		||||
			"snapshot tree points to subvolume that does not point to snapshot in this tree:\n  %s",
 | 
			
		||||
			(printbuf_reset(&buf),
 | 
			
		||||
			 bch2_bkey_val_to_text(&buf, c, st.s_c), buf.buf)) ||
 | 
			
		||||
	    fsck_err_on(BCH_SUBVOLUME_SNAP(&subvol),
 | 
			
		||||
			c, snapshot_tree_to_snapshot_subvol,
 | 
			
		||||
			trans, snapshot_tree_to_snapshot_subvol,
 | 
			
		||||
			"snapshot tree points to snapshot subvolume:\n  %s",
 | 
			
		||||
			(printbuf_reset(&buf),
 | 
			
		||||
			 bch2_bkey_val_to_text(&buf, c, st.s_c), buf.buf))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -814,7 +814,7 @@ static int check_snapshot(struct btree_trans *trans,
 | 
			
		|||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if (fsck_err_on(s.subvol,
 | 
			
		||||
				c, snapshot_should_not_have_subvol,
 | 
			
		||||
				trans, snapshot_should_not_have_subvol,
 | 
			
		||||
				"snapshot should not point to subvol:\n  %s",
 | 
			
		||||
				(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
			u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
 | 
			
		||||
| 
						 | 
				
			
			@ -831,7 +831,8 @@ static int check_snapshot(struct btree_trans *trans,
 | 
			
		|||
	if (ret < 0)
 | 
			
		||||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!ret, c, snapshot_to_bad_snapshot_tree,
 | 
			
		||||
	if (fsck_err_on(!ret,
 | 
			
		||||
			trans, snapshot_to_bad_snapshot_tree,
 | 
			
		||||
			"snapshot points to missing/incorrect tree:\n  %s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
		ret = snapshot_tree_ptr_repair(trans, iter, k, &s);
 | 
			
		||||
| 
						 | 
				
			
			@ -843,7 +844,7 @@ static int check_snapshot(struct btree_trans *trans,
 | 
			
		|||
	real_depth = bch2_snapshot_depth(c, parent_id);
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(le32_to_cpu(s.depth) != real_depth,
 | 
			
		||||
			c, snapshot_bad_depth,
 | 
			
		||||
			trans, snapshot_bad_depth,
 | 
			
		||||
			"snapshot with incorrect depth field, should be %u:\n  %s",
 | 
			
		||||
			real_depth, (bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
		u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
 | 
			
		||||
| 
						 | 
				
			
			@ -859,7 +860,8 @@ static int check_snapshot(struct btree_trans *trans,
 | 
			
		|||
	if (ret < 0)
 | 
			
		||||
		goto err;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!ret, c, snapshot_bad_skiplist,
 | 
			
		||||
	if (fsck_err_on(!ret,
 | 
			
		||||
			trans, snapshot_bad_skiplist,
 | 
			
		||||
			"snapshot with bad skiplist field:\n  %s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
		u = bch2_bkey_make_mut_typed(trans, iter, &k, 0, snapshot);
 | 
			
		||||
| 
						 | 
				
			
			@ -1021,7 +1023,7 @@ int bch2_reconstruct_snapshots(struct bch_fs *c)
 | 
			
		|||
 | 
			
		||||
		darray_for_each(*t, id) {
 | 
			
		||||
			if (fsck_err_on(!bch2_snapshot_equiv(c, *id),
 | 
			
		||||
					c, snapshot_node_missing,
 | 
			
		||||
					trans, snapshot_node_missing,
 | 
			
		||||
					"snapshot node %u from tree %s missing, recreate?", *id, buf.buf)) {
 | 
			
		||||
				if (t->nr > 1) {
 | 
			
		||||
					bch_err(c, "cannot reconstruct snapshot trees with multiple nodes");
 | 
			
		||||
| 
						 | 
				
			
			@ -1053,8 +1055,8 @@ int bch2_check_key_has_snapshot(struct btree_trans *trans,
 | 
			
		|||
	struct printbuf buf = PRINTBUF;
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(!bch2_snapshot_equiv(c, k.k->p.snapshot), c,
 | 
			
		||||
			bkey_in_missing_snapshot,
 | 
			
		||||
	if (fsck_err_on(!bch2_snapshot_equiv(c, k.k->p.snapshot),
 | 
			
		||||
			trans, bkey_in_missing_snapshot,
 | 
			
		||||
			"key in missing snapshot %s, delete?",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
 | 
			
		||||
		ret = bch2_btree_delete_at(trans, iter,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,7 +57,7 @@ static int check_subvol(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (fsck_err_on(subvol.k->p.offset == BCACHEFS_ROOT_SUBVOL &&
 | 
			
		||||
			subvol.v->fs_path_parent,
 | 
			
		||||
			c, subvol_root_fs_path_parent_nonzero,
 | 
			
		||||
			trans, subvol_root_fs_path_parent_nonzero,
 | 
			
		||||
			"root subvolume has nonzero fs_path_parent\n%s",
 | 
			
		||||
			(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
 | 
			
		||||
		struct bkey_i_subvolume *n =
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +80,7 @@ static int check_subvol(struct btree_trans *trans,
 | 
			
		|||
			goto err;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(subvol_children_k.k->type != KEY_TYPE_set,
 | 
			
		||||
				c, subvol_children_not_set,
 | 
			
		||||
				trans, subvol_children_not_set,
 | 
			
		||||
				"subvolume not set in subvolume_children btree at %llu:%llu\n%s",
 | 
			
		||||
				pos.inode, pos.offset,
 | 
			
		||||
				(printbuf_reset(&buf),
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +101,8 @@ static int check_subvol(struct btree_trans *trans,
 | 
			
		|||
	if (ret && !bch2_err_matches(ret, ENOENT))
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(ret, c, subvol_to_missing_root,
 | 
			
		||||
	if (fsck_err_on(ret,
 | 
			
		||||
			trans, subvol_to_missing_root,
 | 
			
		||||
			"subvolume %llu points to missing subvolume root %llu:%u",
 | 
			
		||||
			k.k->p.offset, le64_to_cpu(subvol.v->inode),
 | 
			
		||||
			le32_to_cpu(subvol.v->snapshot))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +112,7 @@ static int check_subvol(struct btree_trans *trans,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (fsck_err_on(inode.bi_subvol != subvol.k->p.offset,
 | 
			
		||||
			c, subvol_root_wrong_bi_subvol,
 | 
			
		||||
			trans, subvol_root_wrong_bi_subvol,
 | 
			
		||||
			"subvol root %llu:%u has wrong bi_subvol field: got %u, should be %llu",
 | 
			
		||||
			inode.bi_inum, inode_iter.k.p.snapshot,
 | 
			
		||||
			inode.bi_subvol, subvol.k->p.offset)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +140,7 @@ static int check_subvol(struct btree_trans *trans,
 | 
			
		|||
			return ret;
 | 
			
		||||
 | 
			
		||||
		if (fsck_err_on(le32_to_cpu(st.master_subvol) != subvol.k->p.offset,
 | 
			
		||||
				c, subvol_not_master_and_not_snapshot,
 | 
			
		||||
				trans, subvol_not_master_and_not_snapshot,
 | 
			
		||||
				"subvolume %llu is not set as snapshot but is not master subvolume",
 | 
			
		||||
				k.k->p.offset)) {
 | 
			
		||||
			struct bkey_i_subvolume *s =
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +174,6 @@ static int check_subvol_child(struct btree_trans *trans,
 | 
			
		|||
			      struct btree_iter *child_iter,
 | 
			
		||||
			      struct bkey_s_c child_k)
 | 
			
		||||
{
 | 
			
		||||
	struct bch_fs *c = trans->c;
 | 
			
		||||
	struct bch_subvolume s;
 | 
			
		||||
	int ret = bch2_bkey_get_val_typed(trans, BTREE_ID_subvolumes, POS(0, child_k.k->p.offset),
 | 
			
		||||
					  0, subvolume, &s);
 | 
			
		||||
| 
						 | 
				
			
			@ -182,7 +182,7 @@ static int check_subvol_child(struct btree_trans *trans,
 | 
			
		|||
 | 
			
		||||
	if (fsck_err_on(ret ||
 | 
			
		||||
			le32_to_cpu(s.fs_path_parent) != child_k.k->p.inode,
 | 
			
		||||
			c, subvol_children_bad,
 | 
			
		||||
			trans, subvol_children_bad,
 | 
			
		||||
			"incorrect entry in subvolume_children btree %llu:%llu",
 | 
			
		||||
			child_k.k->p.inode, child_k.k->p.offset)) {
 | 
			
		||||
		ret = bch2_btree_delete_at(trans, child_iter, 0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue