Lines Matching +full:mi +full:- +full:v

1 // SPDX-License-Identifier: GPL-2.0
24 bkey_fsck_err_on(bp.v->level > BTREE_MAX_DEPTH, in bch2_backpointer_validate()
27 bp.v->level, BTREE_MAX_DEPTH); in bch2_backpointer_validate()
29 bkey_fsck_err_on(bp.k->p.inode == BCH_SB_MEMBER_INVALID, in bch2_backpointer_validate()
41 struct bch_dev *ca = bch2_dev_rcu_noerror(c, bp.k->p.inode); in bch2_backpointer_to_text()
44 struct bpos bucket = bp_pos_to_bucket_and_offset(ca, bp.k->p, &bucket_offset); in bch2_backpointer_to_text()
49 …prt_printf(out, "sector=%llu:%llu ", bp.k->p.inode, bp.k->p.offset >> MAX_EXTENT_COMPRESS_RATIO_SH… in bch2_backpointer_to_text()
52 bch2_btree_id_level_to_text(out, bp.v->btree_id, bp.v->level); in bch2_backpointer_to_text()
54 bch2_prt_data_type(out, bp.v->data_type); in bch2_backpointer_to_text()
56 (u32) bp.k->p.offset & ~(~0U << MAX_EXTENT_COMPRESS_RATIO_SHIFT), in bch2_backpointer_to_text()
57 bp.v->bucket_len, in bch2_backpointer_to_text()
58 bp.v->bucket_gen); in bch2_backpointer_to_text()
59 bch2_bpos_to_text(out, bp.v->pos); in bch2_backpointer_to_text()
66 bp.v->bucket_len = swab32(bp.v->bucket_len); in bch2_backpointer_swab()
67 bch2_bpos_swab(&bp.v->pos); in bch2_backpointer_swab()
83 if (bpos_eq(bp.k->p, bp2.k.p) && in extent_matches_bp()
84 !memcmp(bp.v, &bp2.v, sizeof(bp2.v))) in extent_matches_bp()
97 struct bch_fs *c = trans->c; in backpointer_mod_err()
103 bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&new_bp->k_i)); in backpointer_mod_err()
115 } else if (c->curr_recovery_pass > BCH_RECOVERY_PASS_check_extents_to_backpointers) { in backpointer_mod_err()
120 bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&new_bp->k_i)); in backpointer_mod_err()
131 if (c->curr_recovery_pass > BCH_RECOVERY_PASS_check_extents_to_backpointers && in backpointer_mod_err()
133 ret = -BCH_ERR_erofs_unfixed_errors; in backpointer_mod_err()
147 bp->k.p, in bch2_bucket_backpointer_mod_nowritebuffer()
156 ? k.k->type in bch2_bucket_backpointer_mod_nowritebuffer()
157 : (k.k->type != KEY_TYPE_backpointer || in bch2_bucket_backpointer_mod_nowritebuffer()
158 memcmp(bkey_s_c_to_backpointer(k).v, &bp->v, sizeof(bp->v)))) { in bch2_bucket_backpointer_mod_nowritebuffer()
165 bp->k.type = KEY_TYPE_deleted; in bch2_bucket_backpointer_mod_nowritebuffer()
166 set_bkey_val_u64s(&bp->k, 0); in bch2_bucket_backpointer_mod_nowritebuffer()
169 ret = bch2_trans_update(trans, &bp_iter, &bp->k_i, 0); in bch2_bucket_backpointer_mod_nowritebuffer()
198 struct bch_fs *c = trans->c; in backpointer_target_not_found()
204 * looking at may have already been deleted - failure to find what it in backpointer_target_not_found()
214 bp.v->level ? "btree node" : "extent"); in backpointer_target_not_found()
224 if (p.ptr.dev == bp.k->p.inode) { in backpointer_target_not_found()
227 bch2_extent_ptr_to_bp(c, bp.v->btree_id, bp.v->level, target_k, p, entry, &bp2); in backpointer_target_not_found()
233 ret = bch2_backpointer_del(trans, bp.k->p); in backpointer_target_not_found()
239 * we'll return -BCH_ERR_transaction_restart_nested, since a in backpointer_target_not_found()
245 * buffer flush - and those are expensive. in backpointer_target_not_found()
265 struct bch_fs *c = trans->c; in __bch2_backpointer_get_node()
267 BUG_ON(!bp.v->level); in __bch2_backpointer_get_node()
270 bp.v->btree_id, in __bch2_backpointer_get_node()
271 bp.v->pos, in __bch2_backpointer_get_node()
273 bp.v->level - 1, in __bch2_backpointer_get_node()
279 BUG_ON(b->c.level != bp.v->level - 1); in __bch2_backpointer_get_node()
281 if (extent_matches_bp(c, bp.v->btree_id, bp.v->level, in __bch2_backpointer_get_node()
282 bkey_i_to_s_c(&b->key), bp)) in __bch2_backpointer_get_node()
286 b = ERR_PTR(-BCH_ERR_backpointer_to_overwritten_btree_node); in __bch2_backpointer_get_node()
288 int ret = backpointer_target_not_found(trans, bp, bkey_i_to_s_c(&b->key), in __bch2_backpointer_get_node()
304 struct bch_fs *c = trans->c; in __bch2_backpointer_get_key()
306 if (unlikely(bp.v->btree_id >= btree_id_nr_alive(c))) in __bch2_backpointer_get_key()
310 bp.v->btree_id, in __bch2_backpointer_get_key()
311 bp.v->pos, in __bch2_backpointer_get_key()
313 bp.v->level, in __bch2_backpointer_get_key()
322 * peek_slot() doesn't normally return NULL - except when we ask for a in __bch2_backpointer_get_key()
328 bkey_init(&iter->k); in __bch2_backpointer_get_key()
329 iter->k.p = bp.v->pos; in __bch2_backpointer_get_key()
330 k.k = &iter->k; in __bch2_backpointer_get_key()
334 extent_matches_bp(c, bp.v->btree_id, bp.v->level, k, bp)) in __bch2_backpointer_get_key()
339 if (!bp.v->level) { in __bch2_backpointer_get_key()
344 if (b == ERR_PTR(-BCH_ERR_backpointer_to_overwritten_btree_node)) in __bch2_backpointer_get_key()
349 return bkey_i_to_s_c(&b->key); in __bch2_backpointer_get_key()
373 if (k.k->type != KEY_TYPE_backpointer) in bch2_check_backpointer_has_valid_bucket()
376 struct bch_fs *c = trans->c; in bch2_check_backpointer_has_valid_bucket()
383 if (!bp_pos_to_bucket_nodev_noerror(c, k.k->p, &bucket)) { in bch2_check_backpointer_has_valid_bucket()
391 ret = bch2_backpointer_del(trans, k.k->p); in bch2_check_backpointer_has_valid_bucket()
400 if (alloc_k.k->type != KEY_TYPE_alloc_v4) { in bch2_check_backpointer_has_valid_bucket()
409 ret = bch2_backpointer_del(trans, k.k->p); in bch2_check_backpointer_has_valid_bucket()
423 bkey_init(&last_flushed.k->k); in bch2_check_btree_backpointers()
458 struct bch_fs *c = trans->c; in check_extent_checksum()
487 ret = -ENOMEM; in check_extent_checksum()
491 bio = bio_alloc(ca->disk_sb.bdev, buf_pages(data_buf, bytes), REQ_OP_READ, GFP_KERNEL); in check_extent_checksum()
492 bio->bi_iter.bi_sector = p.ptr.offset; in check_extent_checksum()
507 struct nonce nonce = extent_nonce(extent.k->bversion, p.crc); in check_extent_checksum()
518 percpu_ref_put(&ca->io_ref[READ]); in check_extent_checksum()
528 struct bch_fs *c = trans->c; in check_bp_exists()
532 if (bpos_lt(bp->k.p, s->bp_start) || in check_bp_exists()
533 bpos_gt(bp->k.p, s->bp_end)) in check_bp_exists()
537 struct bkey_s_c bp_k = bch2_bkey_get_iter(trans, &bp_iter, BTREE_ID_backpointers, bp->k.p, 0); in check_bp_exists()
542 if (bp_k.k->type != KEY_TYPE_backpointer || in check_bp_exists()
543 memcmp(bkey_s_c_to_backpointer(bp_k).v, &bp->v, sizeof(bp->v))) { in check_bp_exists()
544 ret = bch2_btree_write_buffer_maybe_flush(trans, orig_k, &s->last_flushed); in check_bp_exists()
559 if (bp_k.k->type != KEY_TYPE_backpointer) in check_bp_exists()
567 if (ret == -BCH_ERR_backpointer_to_overwritten_btree_node) in check_bp_exists()
576 struct bch_dev *ca = bch2_dev_rcu_noerror(c, bp->k.p.inode); in check_bp_exists()
580 if (ptr->dev == bp->k.p.inode && in check_bp_exists()
582 ret = drop_dev_and_update(trans, other_bp.v->btree_id, in check_bp_exists()
583 other_extent, bp->k.p.inode); in check_bp_exists()
599 if (other_extent.k->size <= orig_k.k->size) { in check_bp_exists()
600 ret = drop_dev_and_update(trans, other_bp.v->btree_id, in check_bp_exists()
601 other_extent, bp->k.p.inode); in check_bp_exists()
606 ret = drop_dev_and_update(trans, bp->v.btree_id, orig_k, bp->k.p.inode); in check_bp_exists()
614 other_bp.v->btree_id, other_extent, in check_bp_exists()
615 bp->v.btree_id, orig_k, in check_bp_exists()
616 bp->k.p.inode); in check_bp_exists()
624 ret = check_extent_checksum(trans, bp->v.btree_id, orig_k, in check_bp_exists()
625 other_bp.v->btree_id, other_extent, bp->k.p.inode); in check_bp_exists()
634 prt_printf(&buf, "duplicate extents pointing to same space on dev %llu\n", bp->k.p.inode); in check_bp_exists()
639 ret = -BCH_ERR_fsck_repair_unimplemented; in check_bp_exists()
646 bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&bp->k_i)); in check_bp_exists()
661 struct bch_fs *c = trans->c; in check_extent_to_backpointers()
672 bool check = ca && test_bit(PTR_BUCKET_NR(ca, &p.ptr), ca->bucket_backpointer_mismatches); in check_extent_to_backpointers()
673 bool empty = ca && test_bit(PTR_BUCKET_NR(ca, &p.ptr), ca->bucket_backpointer_empty); in check_extent_to_backpointers()
698 struct bch_fs *c = trans->c; in check_btree_root_to_backpointers()
705 0, bch2_btree_id_root(c, btree_id)->b->c.level, 0); in check_btree_root_to_backpointers()
716 *level = b->c.level; in check_btree_root_to_backpointers()
718 k = bkey_i_to_s_c(&b->key); in check_btree_root_to_backpointers()
719 ret = check_extent_to_backpointers(trans, s, btree_id, b->c.level + 1, k); in check_btree_root_to_backpointers()
739 return div_u64(mem_bytes * c->opts.fsck_memory_usage_percent, 100); in mem_may_pin_bytes()
744 return div_u64(mem_may_pin_bytes(c), c->opts.btree_node_size); in btree_nodes_fit_in_ram()
752 struct bch_fs *c = trans->c; in bch2_get_btree_in_memory_pos()
760 c->btree_cache.pinned_nodes_mask[0] = btree_leaf_mask; in bch2_get_btree_in_memory_pos()
761 c->btree_cache.pinned_nodes_mask[1] = btree_interior_mask; in bch2_get_btree_in_memory_pos()
762 c->btree_cache.pinned_nodes_start = start; in bch2_get_btree_in_memory_pos()
763 c->btree_cache.pinned_nodes_end = *end = BBPOS_MAX; in bch2_get_btree_in_memory_pos()
777 mem_may_pin -= btree_buf_bytes(b); in bch2_get_btree_in_memory_pos()
779 c->btree_cache.pinned_nodes_end = *end = in bch2_get_btree_in_memory_pos()
780 BBPOS(btree, b->key.k.p); in bch2_get_btree_in_memory_pos()
794 struct bch_fs *c = trans->c; in bch2_check_extents_to_backpointers_pass()
798 bch2_progress_init(&progress, trans->c, BIT_ULL(BTREE_ID_extents)|BIT_ULL(BTREE_ID_reflink)); in bch2_check_extents_to_backpointers_pass()
824 --level; in bch2_check_extents_to_backpointers_pass()
850 return -1; in data_type_to_alloc_counter()
859 struct bch_fs *c = trans->c; in check_bucket_backpointer_mismatch()
864 if (a->data_type == BCH_DATA_sb || in check_bucket_backpointer_mismatch()
865 a->data_type == BCH_DATA_journal || in check_bucket_backpointer_mismatch()
866 a->data_type == BCH_DATA_parity) in check_bucket_backpointer_mismatch()
872 struct bch_dev *ca = bch2_dev_bucket_tryget_noerror(trans->c, alloc_k.k->p); in check_bucket_backpointer_mismatch()
880 bucket_pos_to_bp_start(ca, alloc_k.k->p), in check_bucket_backpointer_mismatch()
881 bucket_pos_to_bp_end(ca, alloc_k.k->p), 0, bp_k, ret) { in check_bucket_backpointer_mismatch()
882 if (bp_k.k->type != KEY_TYPE_backpointer) in check_bucket_backpointer_mismatch()
887 if (c->sb.version_upgrade_complete >= bcachefs_metadata_version_backpointer_bucket_gen && in check_bucket_backpointer_mismatch()
888 (bp.v->bucket_gen != a->gen || in check_bucket_backpointer_mismatch()
889 bp.v->pad)) { in check_bucket_backpointer_mismatch()
890 ret = bch2_backpointer_del(trans, bp_k.k->p); in check_bucket_backpointer_mismatch()
898 if (bp.v->bucket_gen != a->gen) in check_bucket_backpointer_mismatch()
901 int alloc_counter = data_type_to_alloc_counter(bp.v->data_type); in check_bucket_backpointer_mismatch()
905 sectors[alloc_counter] += bp.v->bucket_len; in check_bucket_backpointer_mismatch()
917 if (sectors[ALLOC_dirty] != a->dirty_sectors || in check_bucket_backpointer_mismatch()
918 sectors[ALLOC_cached] != a->cached_sectors || in check_bucket_backpointer_mismatch()
919 sectors[ALLOC_stripe] != a->stripe_sectors) { in check_bucket_backpointer_mismatch()
920 if (c->sb.version_upgrade_complete >= bcachefs_metadata_version_backpointer_bucket_gen) { in check_bucket_backpointer_mismatch()
926 if (sectors[ALLOC_dirty] > a->dirty_sectors || in check_bucket_backpointer_mismatch()
927 sectors[ALLOC_cached] > a->cached_sectors || in check_bucket_backpointer_mismatch()
928 sectors[ALLOC_stripe] > a->stripe_sectors) { in check_bucket_backpointer_mismatch()
929 ret = check_bucket_backpointers_to_extents(trans, ca, alloc_k.k->p) ?: in check_bucket_backpointer_mismatch()
930 -BCH_ERR_transaction_restart_nested; in check_bucket_backpointer_mismatch()
937 __set_bit(alloc_k.k->p.offset, ca->bucket_backpointer_empty); in check_bucket_backpointer_mismatch()
939 __set_bit(alloc_k.k->p.offset, ca->bucket_backpointer_mismatches); in check_bucket_backpointer_mismatch()
948 switch (k.k->type) { in backpointer_node_has_missing()
953 struct bpos pos = bkey_s_c_to_btree_ptr_v2(k).v->min_key; in backpointer_node_has_missing()
954 while (pos.inode <= k.k->p.inode) { in backpointer_node_has_missing()
955 if (pos.inode >= c->sb.nr_devices) in backpointer_node_has_missing()
963 bucket.offset = find_next_bit(ca->bucket_backpointer_mismatches, in backpointer_node_has_missing()
964 ca->mi.nbuckets, bucket.offset); in backpointer_node_has_missing()
965 if (bucket.offset == ca->mi.nbuckets) in backpointer_node_has_missing()
968 ret = bpos_le(bucket_pos_to_bp_end(ca, bucket), k.k->p); in backpointer_node_has_missing()
989 bch2_trans_node_iter_init(trans, &iter, btree, k->k.p, 0, level, 0); in btree_node_get_and_pin()
996 bch2_node_pin(trans->c, b); in btree_node_get_and_pin()
1005 struct bch_fs *c = trans->c; in bch2_pin_backpointer_nodes_with_missing()
1023 mem_may_pin -= c->opts.btree_node_size; in bch2_pin_backpointer_nodes_with_missing()
1030 BUG_ON(path->level != 1); in bch2_pin_backpointer_nodes_with_missing()
1032 bch2_btree_node_prefetch(trans, path, tmp.k, path->btree_id, path->level - 1); in bch2_pin_backpointer_nodes_with_missing()
1045 mem_may_pin -= c->opts.btree_node_size; in bch2_pin_backpointer_nodes_with_missing()
1054 BUG_ON(path->level != 1); in bch2_pin_backpointer_nodes_with_missing()
1056 int ret2 = btree_node_get_and_pin(trans, tmp.k, path->btree_id, path->level - 1); in bch2_pin_backpointer_nodes_with_missing()
1059 pinned = tmp.k->k.p; in bch2_pin_backpointer_nodes_with_missing()
1077 down_read(&c->state_lock); in bch2_check_extents_to_backpointers()
1080 BUG_ON(ca->bucket_backpointer_mismatches); in bch2_check_extents_to_backpointers()
1081 ca->bucket_backpointer_mismatches = kvcalloc(BITS_TO_LONGS(ca->mi.nbuckets), in bch2_check_extents_to_backpointers()
1084 ca->bucket_backpointer_empty = kvcalloc(BITS_TO_LONGS(ca->mi.nbuckets), in bch2_check_extents_to_backpointers()
1087 if (!ca->bucket_backpointer_mismatches || in bch2_check_extents_to_backpointers()
1088 !ca->bucket_backpointer_empty) { in bch2_check_extents_to_backpointers()
1090 ret = -BCH_ERR_ENOMEM_backpointer_mismatches_bitmap; in bch2_check_extents_to_backpointers()
1099 bkey_init(&s.last_flushed.k->k); in bch2_check_extents_to_backpointers()
1110 nr_buckets += ca->mi.nbuckets; in bch2_check_extents_to_backpointers()
1111 nr_mismatches += bitmap_weight(ca->bucket_backpointer_mismatches, ca->mi.nbuckets); in bch2_check_extents_to_backpointers()
1112 nr_empty += bitmap_weight(ca->bucket_backpointer_empty, ca->mi.nbuckets); in bch2_check_extents_to_backpointers()
1137 prt_str(&buf, "-"); in bch2_check_extents_to_backpointers()
1156 kvfree(ca->bucket_backpointer_empty); in bch2_check_extents_to_backpointers()
1157 ca->bucket_backpointer_empty = NULL; in bch2_check_extents_to_backpointers()
1158 kvfree(ca->bucket_backpointer_mismatches); in bch2_check_extents_to_backpointers()
1159 ca->bucket_backpointer_mismatches = NULL; in bch2_check_extents_to_backpointers()
1162 up_read(&c->state_lock); in bch2_check_extents_to_backpointers()
1173 if (bp_k.k->type != KEY_TYPE_backpointer) in check_one_backpointer()
1177 struct bbpos pos = bp_to_bbpos(*bp.v); in check_one_backpointer()
1186 if (ret == -BCH_ERR_backpointer_to_overwritten_btree_node) in check_one_backpointer()
1198 u32 restart_count = trans->restart_count; in check_bucket_backpointers_to_extents()
1201 bkey_init(&last_flushed.k->k); in check_bucket_backpointers_to_extents()
1210 bch2_bkey_buf_exit(&last_flushed, trans->c); in check_bucket_backpointers_to_extents()
1218 struct bch_fs *c = trans->c; in bch2_check_backpointers_to_extents_pass()
1223 bkey_init(&last_flushed.k->k); in bch2_check_backpointers_to_extents_pass()
1224 bch2_progress_init(&progress, trans->c, BIT_ULL(BTREE_ID_backpointers)); in bch2_check_backpointers_to_extents_pass()
1262 prt_str(&buf, "-"); in bch2_check_backpointers_to_extents()