disk->stripes_max = cpu_to_le32(cpu->stripes_max);
}
+/*
+ * @queued_meta: metadata chunks the limit filter has counted that are queued
+ * but not processed yet. Their count is written back to the metadata limit.
+ */
static void set_balance_item(struct extent_buffer *leaf,
struct btrfs_balance_item *item,
- const struct btrfs_balance_control *bctl)
+ const struct btrfs_balance_control *bctl,
+ u32 queued_meta)
{
struct btrfs_disk_balance_args disk_bargs;
+ struct btrfs_balance_args meta = bctl->meta;
+
+ if (meta.flags & BTRFS_BALANCE_ARGS_LIMIT)
+ meta.limit += queued_meta;
+ else if (meta.flags & BTRFS_BALANCE_ARGS_LIMIT_RANGE)
+ meta.limit_max += queued_meta;
btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
btrfs_set_balance_data(leaf, item, &disk_bargs);
- btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
+ btrfs_cpu_balance_args_to_disk(&disk_bargs, &meta);
btrfs_set_balance_meta(leaf, item, &disk_bargs);
btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
btrfs_set_balance_sys(leaf, item, &disk_bargs);
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item));
- set_balance_item(leaf, item, bctl);
+ set_balance_item(leaf, item, bctl, 0);
out:
btrfs_free_path(path);
if (ret == 0)
}
/*
- * Write the arguments of a balance to its existing item. With @commit false
- * the update joins the running transaction and is committed with it.
+ * Write the arguments of a balance to its existing item, see
+ * set_balance_item() for @queued_meta. With @commit false the update joins
+ * the running transaction and is committed with it.
*/
static int update_balance_item(struct btrfs_fs_info *fs_info,
const struct btrfs_balance_control *bctl,
- bool commit)
+ u32 queued_meta, bool commit)
{
struct btrfs_root *root = fs_info->tree_root;
struct btrfs_trans_handle *trans;
set_balance_item(path->nodes[0],
btrfs_item_ptr(path->nodes[0], path->slots[0],
- struct btrfs_balance_item), bctl);
+ struct btrfs_balance_item), bctl, queued_meta);
btrfs_release_path(path);
if (!commit)
return btrfs_end_transaction(trans);
* balance resumed after an unmount or a crash processes only what is left of
* the request, as one resumed after a pause does. Chunk types without a limit
* filter write nothing.
+ *
+ * METADATA_REMAP chunks are counted when they are selected too, but they are
+ * queued and balanced only after the chunk walk. @queued_meta of them are
+ * waiting: the item gets them back on the metadata limit, so a balance that
+ * stops before it gets to them still processes them when it is resumed.
*/
-static int count_limited_chunk(struct btrfs_fs_info *fs_info, u64 chunk_type)
+static int count_limited_chunk(struct btrfs_fs_info *fs_info, u64 chunk_type,
+ u32 queued_meta)
{
struct btrfs_balance_control *bctl = fs_info->balance_ctl;
struct btrfs_balance_args *bargs;
* the last relocated chunk, and the resumed balance can then relocate
* one chunk more than requested, but never one fewer.
*/
- return update_balance_item(fs_info, bctl, false);
+ return update_balance_item(fs_info, bctl, queued_meta, false);
}
struct remap_chunk_info {
spin_unlock(&fs_info->balance_lock);
}
- ret = count_limited_chunk(fs_info, chunk_type);
+ ret = count_limited_chunk(fs_info, chunk_type, num_remap_chunks);
if (ret)
goto error;
loop:
* for the other errors here, the balance ends and its
* item is deleted.
*/
- ret = update_balance_item(fs_info, bctl, true);
+ ret = update_balance_item(fs_info, bctl, 0, true);
if (ret) {
btrfs_err(fs_info,
"balance: failed to write the bounded balance item: %d",