return ret;
}
+/*
+ * A balance item written by a kernel without the vrange bound has no vrange
+ * filter. Resume it as those kernels did. A chunk type with a vrange relies
+ * on it and is resumed unchanged.
+ */
+static void update_legacy_balance_args(struct btrfs_balance_args *bargs)
+{
+ if (bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)
+ return;
+
+ /* Turn on soft mode for chunk types that were being converted. */
+ if (bargs->flags & BTRFS_BALANCE_ARGS_CONVERT) {
+ bargs->flags |= BTRFS_BALANCE_ARGS_SOFT;
+ return;
+ }
+
+ /*
+ * Turn on the usage filter if it is not already used. The idea is
+ * that chunks that we have already balanced should be reasonably full.
+ */
+ if (!(bargs->flags & (BTRFS_BALANCE_ARGS_USAGE |
+ BTRFS_BALANCE_ARGS_USAGE_RANGE))) {
+ bargs->flags |= BTRFS_BALANCE_ARGS_USAGE;
+ bargs->usage = 90;
+ }
+}
+
+/* Update the arguments of a balance item recovered at mount. */
+static void update_balance_args(struct btrfs_balance_control *bctl)
+{
+ update_legacy_balance_args(&bctl->data);
+ update_legacy_balance_args(&bctl->sys);
+ update_legacy_balance_args(&bctl->meta);
+}
+
static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
{
if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
* end of the last chunk, and lowering a vend above it drops no block
* group from the range. The bound is written back to the item when
* the balance resumes, so a resume that is interrupted again keeps it.
+ * Adjust the chunk types that have no vrange on disk first.
*/
+ update_balance_args(bctl);
bctl->update_item = limit_balance_to_existing_chunks(fs_info, bctl);
WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));