diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c index d658be90f..2f43d9ec7 100644 --- a/fs/bcachefs/movinggc.c +++ b/fs/bcachefs/movinggc.c @@ -158,6 +158,20 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt, move_buckets_wait(ctxt, buckets_in_flight, false); + if (!buckets_in_flight || !buckets_in_flight->nr) { + // Initialize the structure + buckets_in_flight->nr = 0; + buckets_in_flight->sectors = 0; + buckets_in_flight->first = NULL; + buckets_in_flight->last = NULL; + + // Explicitly initialize the hash table instead of memset + ret = rhashtable_init(&buckets_in_flight->table, &bch_move_bucket_params); + if (ret) { + return ret; + } + } + ret = bch2_btree_write_buffer_tryflush(trans); if (bch2_err_matches(ret, EROFS)) return ret;