From 70e1e1af77787dbbfc559cdab323c44f7bc68ba5 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 17 Nov 2024 23:58:21 -0500 Subject: [PATCH 213/233] bcachefs: bch2_extent_ptr_to_bp() no longer depends on device Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit bch_backpointer no longer contains the bucket_offset field, it's just a direct LBA mapping (with low bits to account for compressed extent splitting), so we don't need to refer to the device to construct it anymore. Signed-off-by: Kent Overstreet Signed-off-by: Alexander Miroshnichenko --- fs/bcachefs/backpointers.c | 26 ++++---------------------- fs/bcachefs/backpointers.h | 17 ++++++----------- fs/bcachefs/buckets.c | 7 ++++--- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/fs/bcachefs/backpointers.c b/fs/bcachefs/backpointers.c index b19719b02df8..98d89133fc75 100644 --- a/fs/bcachefs/backpointers.c +++ b/fs/bcachefs/backpointers.c @@ -73,26 +73,14 @@ static bool extent_matches_bp(struct bch_fs *c, const union bch_extent_entry *entry; struct extent_ptr_decoded p; - rcu_read_lock(); bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { - struct bpos bucket2; struct bkey_i_backpointer bp2; + bch2_extent_ptr_to_bp(c, btree_id, level, k, p, entry, &bp2); - if (p.ptr.cached) - continue; - - struct bch_dev *ca = bch2_dev_rcu(c, p.ptr.dev); - if (!ca) - continue; - - bch2_extent_ptr_to_bp(c, ca, btree_id, level, k, p, entry, &bucket2, &bp2); if (bpos_eq(bp.k->p, bp2.k.p) && - !memcmp(bp.v, &bp2.v, sizeof(bp2.v))) { - rcu_read_unlock(); + !memcmp(bp.v, &bp2.v, sizeof(bp2.v))) return true; - } } - rcu_read_unlock(); return false; } @@ -586,21 +574,15 @@ static int check_extent_to_backpointers(struct btree_trans *trans, ptrs = bch2_bkey_ptrs_c(k); bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { - struct bpos bucket_pos; struct bkey_i_backpointer bp; if (p.ptr.cached) continue; - rcu_read_lock(); - struct bch_dev *ca = bch2_dev_rcu_noerror(c, p.ptr.dev); - if (ca) - bch2_extent_ptr_to_bp(c, ca, btree, level, k, p, entry, &bucket_pos, &bp); - rcu_read_unlock(); - - if (!ca) + if (p.ptr.dev == BCH_SB_MEMBER_INVALID) continue; + bch2_extent_ptr_to_bp(c, btree, level, k, p, entry, &bp); ret = check_bp_exists(trans, s, &bp, k); if (ret) return ret; diff --git a/fs/bcachefs/backpointers.h b/fs/bcachefs/backpointers.h index caffc68407ab..d126d40dda99 100644 --- a/fs/bcachefs/backpointers.h +++ b/fs/bcachefs/backpointers.h @@ -140,20 +140,15 @@ static inline enum bch_data_type bch2_bkey_ptr_data_type(struct bkey_s_c k, } } -static inline void __bch2_extent_ptr_to_bp(struct bch_fs *c, struct bch_dev *ca, +static inline void __bch2_extent_ptr_to_bp( enum btree_id btree_id, unsigned level, struct bkey_s_c k, struct extent_ptr_decoded p, const union bch_extent_entry *entry, - struct bpos *bucket, struct bkey_i_backpointer *bp, + struct bkey_i_backpointer *bp, u64 sectors) { - u32 bucket_offset; - *bucket = PTR_BUCKET_POS_OFFSET(ca, &p.ptr, &bucket_offset); - - u64 bp_bucket_offset = ((u64) bucket_offset << MAX_EXTENT_COMPRESS_RATIO_SHIFT) + p.crc.offset; - bkey_backpointer_init(&bp->k_i); - bp->k.p = bucket_pos_to_bp(ca, *bucket, bp_bucket_offset); + bp->k.p = POS(p.ptr.dev, ((u64) p.ptr.offset << MAX_EXTENT_COMPRESS_RATIO_SHIFT) + p.crc.offset); bp->v = (struct bch_backpointer) { .btree_id = btree_id, .level = level, @@ -164,15 +159,15 @@ static inline void __bch2_extent_ptr_to_bp(struct bch_fs *c, struct bch_dev *ca, }; } -static inline void bch2_extent_ptr_to_bp(struct bch_fs *c, struct bch_dev *ca, +static inline void bch2_extent_ptr_to_bp(struct bch_fs *c, enum btree_id btree_id, unsigned level, struct bkey_s_c k, struct extent_ptr_decoded p, const union bch_extent_entry *entry, - struct bpos *bucket_pos, struct bkey_i_backpointer *bp) + struct bkey_i_backpointer *bp) { u64 sectors = ptr_disk_sectors(level ? btree_sectors(c) : k.k->size, p); - __bch2_extent_ptr_to_bp(c, ca, btree_id, level, k, p, entry, bucket_pos, bp, sectors); + __bch2_extent_ptr_to_bp(btree_id, level, k, p, entry, bp, sectors); } struct bkey_s_c bch2_backpointer_get_key(struct btree_trans *, struct bkey_s_c_backpointer, diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index bbd37b1ed5d2..30b983cf9780 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -572,6 +572,9 @@ static int bch2_trigger_pointer(struct btree_trans *trans, u64 abs_sectors = ptr_disk_sectors(level ? btree_sectors(c) : k.k->size, p); *sectors = insert ? abs_sectors : -abs_sectors; + struct bkey_i_backpointer bp; + __bch2_extent_ptr_to_bp(btree_id, level, k, p, entry, &bp, abs_sectors); + struct bch_dev *ca = bch2_dev_tryget(c, p.ptr.dev); if (unlikely(!ca)) { if (insert && p.ptr.dev != BCH_SB_MEMBER_INVALID) @@ -579,9 +582,7 @@ static int bch2_trigger_pointer(struct btree_trans *trans, goto err; } - struct bpos bucket; - struct bkey_i_backpointer bp; - __bch2_extent_ptr_to_bp(trans->c, ca, btree_id, level, k, p, entry, &bucket, &bp, abs_sectors); + struct bpos bucket = PTR_BUCKET_POS(ca, &p.ptr); if (flags & BTREE_TRIGGER_transactional) { struct bkey_i_alloc_v4 *a = bch2_trans_start_alloc_update(trans, bucket, 0); -- 2.45.2