Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68310a5e authored by Ilya Dryomov's avatar Ilya Dryomov Committed by Chris Mason
Browse files

Btrfs: restore restriper state on all mounts



Fix a bug that triggered asserts in btrfs_balance() in both normal and
resume modes -- restriper state was not properly restored on read-only
mounts.  This factors out resuming code from btrfs_restore_balance(),
which is now also called earlier in the mount sequence to avoid the
problem of some early writes getting the old profile.

Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent c3473e83
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -2354,12 +2354,17 @@ retry_root_backup:
				  BTRFS_CSUM_TREE_OBJECTID, csum_root);
				  BTRFS_CSUM_TREE_OBJECTID, csum_root);
	if (ret)
	if (ret)
		goto recovery_tree_root;
		goto recovery_tree_root;

	csum_root->track_dirty = 1;
	csum_root->track_dirty = 1;


	fs_info->generation = generation;
	fs_info->generation = generation;
	fs_info->last_trans_committed = generation;
	fs_info->last_trans_committed = generation;


	ret = btrfs_recover_balance(fs_info);
	if (ret) {
		printk(KERN_WARNING "btrfs: failed to recover balance\n");
		goto fail_block_groups;
	}

	ret = btrfs_init_dev_stats(fs_info);
	ret = btrfs_init_dev_stats(fs_info);
	if (ret) {
	if (ret) {
		printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n",
		printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n",
@@ -2492,9 +2497,6 @@ retry_root_backup:
			err = btrfs_orphan_cleanup(fs_info->tree_root);
			err = btrfs_orphan_cleanup(fs_info->tree_root);
		up_read(&fs_info->cleanup_work_sem);
		up_read(&fs_info->cleanup_work_sem);


		if (!err)
			err = btrfs_recover_balance(fs_info->tree_root);

		if (err) {
		if (err) {
			close_ctree(tree_root);
			close_ctree(tree_root);
			return err;
			return err;
+19 −20
Original line number Original line Diff line number Diff line
@@ -2867,9 +2867,8 @@ static int balance_kthread(void *data)
	return ret;
	return ret;
}
}


int btrfs_recover_balance(struct btrfs_root *tree_root)
int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
{
{
	struct task_struct *tsk;
	struct btrfs_balance_control *bctl;
	struct btrfs_balance_control *bctl;
	struct btrfs_balance_item *item;
	struct btrfs_balance_item *item;
	struct btrfs_disk_balance_args disk_bargs;
	struct btrfs_disk_balance_args disk_bargs;
@@ -2882,29 +2881,30 @@ int btrfs_recover_balance(struct btrfs_root *tree_root)
	if (!path)
	if (!path)
		return -ENOMEM;
		return -ENOMEM;


	bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
	if (!bctl) {
		ret = -ENOMEM;
		goto out;
	}

	key.objectid = BTRFS_BALANCE_OBJECTID;
	key.objectid = BTRFS_BALANCE_OBJECTID;
	key.type = BTRFS_BALANCE_ITEM_KEY;
	key.type = BTRFS_BALANCE_ITEM_KEY;
	key.offset = 0;
	key.offset = 0;


	ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
	ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
	if (ret < 0)
	if (ret < 0)
		goto out_bctl;
		goto out;
	if (ret > 0) { /* ret = -ENOENT; */
	if (ret > 0) { /* ret = -ENOENT; */
		ret = 0;
		ret = 0;
		goto out_bctl;
		goto out;
	}

	bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
	if (!bctl) {
		ret = -ENOMEM;
		goto out;
	}
	}


	leaf = path->nodes[0];
	leaf = path->nodes[0];
	item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
	item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);


	bctl->fs_info = tree_root->fs_info;
	bctl->fs_info = fs_info;
	bctl->flags = btrfs_balance_flags(leaf, item) | BTRFS_BALANCE_RESUME;
	bctl->flags = btrfs_balance_flags(leaf, item);
	bctl->flags |= BTRFS_BALANCE_RESUME;


	btrfs_balance_data(leaf, item, &disk_bargs);
	btrfs_balance_data(leaf, item, &disk_bargs);
	btrfs_disk_balance_args_to_cpu(&bctl->data, &disk_bargs);
	btrfs_disk_balance_args_to_cpu(&bctl->data, &disk_bargs);
@@ -2913,14 +2913,13 @@ int btrfs_recover_balance(struct btrfs_root *tree_root)
	btrfs_balance_sys(leaf, item, &disk_bargs);
	btrfs_balance_sys(leaf, item, &disk_bargs);
	btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);
	btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);


	tsk = kthread_run(balance_kthread, bctl, "btrfs-balance");
	mutex_lock(&fs_info->volume_mutex);
	if (IS_ERR(tsk))
	mutex_lock(&fs_info->balance_mutex);
		ret = PTR_ERR(tsk);
	else
		goto out;


out_bctl:
	set_balance_control(bctl);
	kfree(bctl);

	mutex_unlock(&fs_info->balance_mutex);
	mutex_unlock(&fs_info->volume_mutex);
out:
out:
	btrfs_free_path(path);
	btrfs_free_path(path);
	return ret;
	return ret;
+1 −1
Original line number Original line Diff line number Diff line
@@ -281,7 +281,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
int btrfs_init_new_device(struct btrfs_root *root, char *path);
int btrfs_init_new_device(struct btrfs_root *root, char *path);
int btrfs_balance(struct btrfs_balance_control *bctl,
int btrfs_balance(struct btrfs_balance_control *bctl,
		  struct btrfs_ioctl_balance_args *bargs);
		  struct btrfs_ioctl_balance_args *bargs);
int btrfs_recover_balance(struct btrfs_root *tree_root);
int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);