return false;
}
+/*
+ * The minimum of a limit range: skip the chunk if the counting pass found
+ * fewer chunks than limit_min. A single limit has no minimum, and its value
+ * shares its bytes with limit_min and limit_max. When both flags are set,
+ * should_balance_chunk() applies the single limit, so the minimum does not
+ * apply then either.
+ */
+static bool chunk_limit_min_filter(const struct btrfs_balance_args *bargs, u32 count)
+{
+ if ((bargs->flags & BTRFS_BALANCE_ARGS_LIMIT) ||
+ !(bargs->flags & BTRFS_BALANCE_ARGS_LIMIT_RANGE))
+ return false;
+
+ return count < bargs->limit_min;
+}
+
static bool should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *chunk,
u64 chunk_offset)
{
goto loop;
}
- /*
- * Apply limit_min filter, no need to check if the LIMITS
- * filter is used, limit_min is 0 by default
- */
+ /* Apply the limit_min filter of a limit range. */
if (((chunk_type & BTRFS_BLOCK_GROUP_DATA) &&
- count_data < bctl->data.limit_min)
- || ((chunk_type & BTRFS_BLOCK_GROUP_METADATA) &&
- count_meta < bctl->meta.limit_min)
- || ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) &&
- count_sys < bctl->sys.limit_min)) {
+ chunk_limit_min_filter(&bctl->data, count_data)) ||
+ ((chunk_type & BTRFS_BLOCK_GROUP_METADATA) &&
+ chunk_limit_min_filter(&bctl->meta, count_meta)) ||
+ ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) &&
+ chunk_limit_min_filter(&bctl->sys, count_sys))) {
mutex_unlock(&fs_info->reclaim_bgs_lock);
goto loop;
}