]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: bch2_dev_in_target() no longer takes rcu_read_lock()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 4 May 2025 18:45:54 +0000 (14:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:45 +0000 (20:14 -0400)
Minor optimization, the caller generally has it already.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_groups.c
fs/bcachefs/rebalance.c

index c1a2a957c884eeb35237f2409fe5078c43b92e9e..c20ecf5e5381b04d07d8162516b247177a318c88 100644 (file)
@@ -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();
index 26c87ab019e87712f70bb5ce643ff82d8231fde0..7bcebcac2e1ad1f825443f86a59f423aecd88ce3 100644 (file)
@@ -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;
 }