]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/movinggc.c
Update bcachefs sources to 841a95c29f4c bcachefs: fix userspace build errors
[bcachefs-tools-debian] / libbcachefs / movinggc.c
index d079ba7aa65349bd8c6fbe73f65dee2872a249a0..fd239a261aca054b22072716e6d2ef7d49791e6a 100644 (file)
@@ -149,7 +149,6 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
        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;
-       struct bpos last_flushed_pos = POS_MIN;
        int ret;
 
        move_buckets_wait(ctxt, buckets_in_flight, false);
@@ -166,26 +165,28 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, 0, 0),
                                  lru_pos(BCH_LRU_FRAGMENTATION_START, U64_MAX, LRU_TIME_MAX),
                                  0, k, ({
-               int ret2 = bch2_check_lru_key(trans, &iter, k, &last_flushed_pos);
-               if (ret2) {
-                       ret2 = ret2 < 0 ? ret2 : 0;
-                       goto next;
-               }
+               struct move_bucket b = { .k.bucket = u64_to_bucket(k.k->p.offset) };
+               int ret2 = 0;
 
                saw++;
 
-               struct move_bucket b = { .k.bucket = u64_to_bucket(k.k->p.offset) };
+               ret2 = bch2_bucket_is_movable(trans, &b, lru_pos_time(k.k->p));
+               if (ret2 < 0)
+                       goto err;
 
-               if (!bch2_bucket_is_movable(trans, &b, lru_pos_time(k.k->p)))
+               if (!ret2)
                        not_movable++;
                else if (bucket_in_flight(buckets_in_flight, b.k))
                        in_flight++;
                else {
-                       ret2 = darray_push(buckets, b) ?: buckets->nr >= nr_to_get;
-                       if (ret2 >= 0)
-                               sectors += b.sectors;
+                       ret2 = darray_push(buckets, b);
+                       if (ret2)
+                               goto err;
+                       sectors += b.sectors;
                }
-next:
+
+               ret2 = buckets->nr >= nr_to_get;
+err:
                ret2;
        }));
 
@@ -217,7 +218,7 @@ static int bch2_copygc(struct moving_context *ctxt,
                goto err;
 
        darray_for_each(buckets, i) {
-               if (unlikely(freezing(current)))
+               if (kthread_should_stop() || freezing(current))
                        break;
 
                f = move_bucket_in_flight_add(buckets_in_flight, *i);
@@ -231,7 +232,7 @@ static int bch2_copygc(struct moving_context *ctxt,
                        break;
                }
 
-               ret = __bch2_evacuate_bucket(ctxt, f, f->bucket.k.bucket,
+               ret = bch2_evacuate_bucket(ctxt, f, f->bucket.k.bucket,
                                             f->bucket.k.gen, data_opts);
                if (ret)
                        goto err;
@@ -344,7 +345,8 @@ static int bch2_copygc_thread(void *arg)
 
                if (!c->copy_gc_enabled) {
                        move_buckets_wait(&ctxt, buckets, true);
-                       kthread_wait_freezable(c->copy_gc_enabled);
+                       kthread_wait_freezable(c->copy_gc_enabled ||
+                                              kthread_should_stop());
                }
 
                if (unlikely(freezing(current))) {