]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/movinggc.c
Update bcachefs sources to 1a739db0b256 bcachefs; guard against overflow in btree...
[bcachefs-tools-debian] / libbcachefs / movinggc.c
index fd239a261aca054b22072716e6d2ef7d49791e6a..69e06a84dad4094847e8c737860d5acc37b25d79 100644 (file)
@@ -145,8 +145,6 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
 {
        struct btree_trans *trans = ctxt->trans;
        struct bch_fs *c = trans->c;
-       struct btree_iter iter;
-       struct bkey_s_c k;
        size_t nr_to_get = max_t(size_t, 16U, buckets_in_flight->nr / 4);
        size_t saw = 0, in_flight = 0, not_movable = 0, sectors = 0;
        int ret;
@@ -161,7 +159,7 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
                                 __func__, bch2_err_str(ret)))
                return ret;
 
-       ret = for_each_btree_key2_upto(trans, iter, BTREE_ID_lru,
+       ret = for_each_btree_key_upto(trans, iter, BTREE_ID_lru,
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, 0, 0),
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, U64_MAX, LRU_TIME_MAX),
                                  0, k, ({
@@ -209,7 +207,6 @@ static int bch2_copygc(struct moving_context *ctxt,
        };
        move_buckets buckets = { 0 };
        struct move_bucket_in_flight *f;
-       struct move_bucket *i;
        u64 moved = atomic64_read(&ctxt->stats->sectors_moved);
        int ret = 0;
 
@@ -270,19 +267,16 @@ err:
  */
 unsigned long bch2_copygc_wait_amount(struct bch_fs *c)
 {
-       struct bch_dev *ca;
-       unsigned dev_idx;
        s64 wait = S64_MAX, fragmented_allowed, fragmented;
-       unsigned i;
 
-       for_each_rw_member(ca, c, dev_idx) {
+       for_each_rw_member(c, ca) {
                struct bch_dev_usage usage = bch2_dev_usage_read(ca);
 
                fragmented_allowed = ((__dev_buckets_available(ca, usage, BCH_WATERMARK_stripe) *
                                       ca->mi.bucket_size) >> 1);
                fragmented = 0;
 
-               for (i = 0; i < BCH_DATA_NR; i++)
+               for (unsigned i = 0; i < BCH_DATA_NR; i++)
                        if (data_type_movable(i))
                                fragmented += usage.d[i].fragmented;
 
@@ -324,9 +318,9 @@ static int bch2_copygc_thread(void *arg)
        if (!buckets)
                return -ENOMEM;
        ret = rhashtable_init(&buckets->table, &bch_move_bucket_params);
+       bch_err_msg(c, ret, "allocating copygc buckets in flight");
        if (ret) {
                kfree(buckets);
-               bch_err_msg(c, ret, "allocating copygc buckets in flight");
                return ret;
        }
 
@@ -423,10 +417,9 @@ int bch2_copygc_start(struct bch_fs *c)
 
        t = kthread_create(bch2_copygc_thread, c, "bch-copygc/%s", c->name);
        ret = PTR_ERR_OR_ZERO(t);
-       if (ret) {
-               bch_err_msg(c, ret, "creating copygc thread");
+       bch_err_msg(c, ret, "creating copygc thread");
+       if (ret)
                return ret;
-       }
 
        get_task_struct(t);