btrfs: fix get set label blocking against balance
btrfs_ioctl_get_fslabel() and btrfs_ioctl_set_fslabel() used root->fs_info->volume_mutex mutex which caused operations like balance to block set/get label operation until its completion and generally balance operation takes a long time to complete, so it will be annoying to the user when cli appears hung also this patch will add a bit of optimization within the btrfs_ioctl_get_falabel() function. v1->v2: use fs_info->super_lock instead of uuid_mutex Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
@@ -4042,18 +4042,22 @@ out:
|
|||||||
static int btrfs_ioctl_get_fslabel(struct file *file, void __user *arg)
|
static int btrfs_ioctl_get_fslabel(struct file *file, void __user *arg)
|
||||||
{
|
{
|
||||||
struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
|
struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
|
||||||
const char *label = root->fs_info->super_copy->label;
|
size_t len;
|
||||||
size_t len = strnlen(label, BTRFS_LABEL_SIZE);
|
|
||||||
int ret;
|
int ret;
|
||||||
|
char label[BTRFS_LABEL_SIZE];
|
||||||
|
|
||||||
|
spin_lock(&root->fs_info->super_lock);
|
||||||
|
memcpy(label, root->fs_info->super_copy->label, BTRFS_LABEL_SIZE);
|
||||||
|
spin_unlock(&root->fs_info->super_lock);
|
||||||
|
|
||||||
|
len = strnlen(label, BTRFS_LABEL_SIZE);
|
||||||
|
|
||||||
if (len == BTRFS_LABEL_SIZE) {
|
if (len == BTRFS_LABEL_SIZE) {
|
||||||
pr_warn("btrfs: label is too long, return the first %zu bytes\n",
|
pr_warn("btrfs: label is too long, return the first %zu bytes\n",
|
||||||
--len);
|
--len);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&root->fs_info->volume_mutex);
|
|
||||||
ret = copy_to_user(arg, label, len);
|
ret = copy_to_user(arg, label, len);
|
||||||
mutex_unlock(&root->fs_info->volume_mutex);
|
|
||||||
|
|
||||||
return ret ? -EFAULT : 0;
|
return ret ? -EFAULT : 0;
|
||||||
}
|
}
|
||||||
@@ -4082,18 +4086,18 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
mutex_lock(&root->fs_info->volume_mutex);
|
|
||||||
trans = btrfs_start_transaction(root, 0);
|
trans = btrfs_start_transaction(root, 0);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans)) {
|
||||||
ret = PTR_ERR(trans);
|
ret = PTR_ERR(trans);
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spin_lock(&root->fs_info->super_lock);
|
||||||
strcpy(super_block->label, label);
|
strcpy(super_block->label, label);
|
||||||
|
spin_unlock(&root->fs_info->super_lock);
|
||||||
ret = btrfs_end_transaction(trans, root);
|
ret = btrfs_end_transaction(trans, root);
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&root->fs_info->volume_mutex);
|
|
||||||
mnt_drop_write_file(file);
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user