return trapped;
}
+/*
+ * The legacy allocator parks a group's free space in an allocation cluster
+ * (for a metadata group, its whole initial extent), where the group's own
+ * tree no longer sees it and the stripe scan cannot count it.
+ * Stripe-exclusive allocation never uses clusters, so a group that is being
+ * armed -- or rescanned, if a legacy allocation was still in flight at a
+ * runtime enable -- hands the cluster's entries back first.
+ */
+static void stripe_return_clusters(struct btrfs_block_group *bg)
+{
+ struct btrfs_fs_info *fs_info = bg->fs_info;
+ struct btrfs_free_cluster *cluster;
+
+ if (list_empty_careful(&bg->cluster_list))
+ return;
+ cluster = &fs_info->data_alloc_cluster;
+ spin_lock(&cluster->refill_lock);
+ btrfs_return_cluster_to_free_space(bg, cluster);
+ spin_unlock(&cluster->refill_lock);
+ cluster = &fs_info->meta_alloc_cluster;
+ spin_lock(&cluster->refill_lock);
+ btrfs_return_cluster_to_free_space(bg, cluster);
+ spin_unlock(&cluster->refill_lock);
+}
+
/*
* Compute a stripe_alloc block group's initial trapped free space once its
* free space cache is loaded, and enable incremental accounting from here on.
if (!freep)
return;
+ stripe_return_clusters(bg);
spin_lock(&ctl->tree_lock);
if (bg->stripe_unusable_ready) {
spin_unlock(&ctl->tree_lock);
if (!freep)
return;
+ stripe_return_clusters(bg);
spin_lock(&ctl->tree_lock);
if (bg->stripe_unusable_ready) { /* skip if disarmed (read-only) */
u64 scanned;