From: Kent Overstreet Date: Sun, 4 May 2025 18:45:54 +0000 (-0400) Subject: bcachefs: bch2_dev_in_target() no longer takes rcu_read_lock() X-Git-Tag: v6.16-rc1~211^2~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e02888faab24494f91016d578e3dc9dce81e3d71;p=thirdparty%2Flinux.git bcachefs: bch2_dev_in_target() no longer takes rcu_read_lock() Minor optimization, the caller generally has it already. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/disk_groups.c b/fs/bcachefs/disk_groups.c index c1a2a957c884e..c20ecf5e5381b 100644 --- a/fs/bcachefs/disk_groups.c +++ b/fs/bcachefs/disk_groups.c @@ -212,17 +212,13 @@ bool bch2_dev_in_target(struct bch_fs *c, unsigned dev, unsigned target) case TARGET_DEV: return dev == t.dev; case TARGET_GROUP: { - rcu_read_lock(); struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups); const struct bch_devs_mask *m = g && t.group < g->nr && !g->entries[t.group].deleted ? &g->entries[t.group].devs : NULL; - bool ret = m ? test_bit(dev, m->d) : false; - rcu_read_unlock(); - - return ret; + return m ? test_bit(dev, m->d) : false; } default: BUG(); diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c index 26c87ab019e87..7bcebcac2e1ad 100644 --- a/fs/bcachefs/rebalance.c +++ b/fs/bcachefs/rebalance.c @@ -80,11 +80,13 @@ static inline unsigned bch2_bkey_ptrs_need_move(struct bch_fs *c, unsigned ptr_bit = 1; unsigned rewrite_ptrs = 0; + rcu_read_lock(); bkey_for_each_ptr(ptrs, ptr) { if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, opts->background_target)) rewrite_ptrs |= ptr_bit; ptr_bit <<= 1; } + rcu_read_unlock(); return rewrite_ptrs; } @@ -132,10 +134,14 @@ u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k) } } incompressible: - if (opts->background_target) + if (opts->background_target) { + rcu_read_lock(); bkey_for_each_ptr_decode(k.k, ptrs, p, entry) - if (!p.ptr.cached && !bch2_dev_in_target(c, p.ptr.dev, opts->background_target)) + if (!p.ptr.cached && + !bch2_dev_in_target(c, p.ptr.dev, opts->background_target)) sectors += p.crc.compressed_size; + rcu_read_unlock(); + } return sectors; }