]> 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 e884324bd2fa3e742e17c46522ba47b921b8e21a..fd239a261aca054b22072716e6d2ef7d49791e6a 100644 (file)
@@ -91,7 +91,7 @@ static int bch2_bucket_is_movable(struct btree_trans *trans,
 
        a = bch2_alloc_to_v4(k, &_a);
        b->k.gen        = a->gen;
-       b->sectors      = a->dirty_sectors;
+       b->sectors      = bch2_bucket_sectors_dirty(*a);
 
        ret = data_type_movable(a->data_type) &&
                a->fragmentation_lru &&
@@ -170,15 +170,23 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
 
                saw++;
 
-               if (!bch2_bucket_is_movable(trans, &b, lru_pos_time(k.k->p)))
+               ret2 = bch2_bucket_is_movable(trans, &b, lru_pos_time(k.k->p));
+               if (ret2 < 0)
+                       goto err;
+
+               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;
                }
+
+               ret2 = buckets->nr >= nr_to_get;
+err:
                ret2;
        }));
 
@@ -210,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);
@@ -224,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;
@@ -337,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))) {