mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-17 20:44:37 +00:00
Btrfs: remove some unnecessary spin_lock usages
We use mutex lock to protect all the user change operations. So when we are calling find_qgroup_rb() to check whether qgroup exists, we don't have to hold spin_lock. Besides, when enabling/disabling quota, it must be single thread when operations come here. spin lock must be firstly used to clear quota_root when disabling quota, while enabling quota, spin lock must be used to complete the last assign work. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Reviewed-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
This commit is contained in:
parent
f2f6ed3d54
commit
58400fce5a
1 changed files with 6 additions and 21 deletions
|
@ -98,7 +98,7 @@ struct btrfs_qgroup_list {
|
||||||
struct btrfs_qgroup *member;
|
struct btrfs_qgroup *member;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* must be called with qgroup_lock held */
|
/* must be called with qgroup_ioctl_lock held */
|
||||||
static struct btrfs_qgroup *find_qgroup_rb(struct btrfs_fs_info *fs_info,
|
static struct btrfs_qgroup *find_qgroup_rb(struct btrfs_fs_info *fs_info,
|
||||||
u64 qgroupid)
|
u64 qgroupid)
|
||||||
{
|
{
|
||||||
|
@ -792,13 +792,10 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
|
||||||
int slot;
|
int slot;
|
||||||
|
|
||||||
mutex_lock(&fs_info->qgroup_ioctl_lock);
|
mutex_lock(&fs_info->qgroup_ioctl_lock);
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
|
||||||
if (fs_info->quota_root) {
|
if (fs_info->quota_root) {
|
||||||
fs_info->pending_quota_state = 1;
|
fs_info->pending_quota_state = 1;
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* initially create the quota tree
|
* initially create the quota tree
|
||||||
|
@ -860,14 +857,11 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_path;
|
goto out_free_path;
|
||||||
|
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
|
||||||
qgroup = add_qgroup_rb(fs_info, found_key.offset);
|
qgroup = add_qgroup_rb(fs_info, found_key.offset);
|
||||||
if (IS_ERR(qgroup)) {
|
if (IS_ERR(qgroup)) {
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
ret = PTR_ERR(qgroup);
|
ret = PTR_ERR(qgroup);
|
||||||
goto out_free_path;
|
goto out_free_path;
|
||||||
}
|
}
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
}
|
}
|
||||||
ret = btrfs_next_item(tree_root, path);
|
ret = btrfs_next_item(tree_root, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -882,13 +876,12 @@ out_add_root:
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_path;
|
goto out_free_path;
|
||||||
|
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
|
||||||
qgroup = add_qgroup_rb(fs_info, BTRFS_FS_TREE_OBJECTID);
|
qgroup = add_qgroup_rb(fs_info, BTRFS_FS_TREE_OBJECTID);
|
||||||
if (IS_ERR(qgroup)) {
|
if (IS_ERR(qgroup)) {
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
ret = PTR_ERR(qgroup);
|
ret = PTR_ERR(qgroup);
|
||||||
goto out_free_path;
|
goto out_free_path;
|
||||||
}
|
}
|
||||||
|
spin_lock(&fs_info->qgroup_lock);
|
||||||
fs_info->quota_root = quota_root;
|
fs_info->quota_root = quota_root;
|
||||||
fs_info->pending_quota_state = 1;
|
fs_info->pending_quota_state = 1;
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
spin_unlock(&fs_info->qgroup_lock);
|
||||||
|
@ -913,11 +906,9 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
mutex_lock(&fs_info->qgroup_ioctl_lock);
|
mutex_lock(&fs_info->qgroup_ioctl_lock);
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
if (!fs_info->quota_root)
|
||||||
if (!fs_info->quota_root) {
|
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
spin_lock(&fs_info->qgroup_lock);
|
||||||
fs_info->quota_enabled = 0;
|
fs_info->quota_enabled = 0;
|
||||||
fs_info->pending_quota_state = 0;
|
fs_info->pending_quota_state = 0;
|
||||||
quota_root = fs_info->quota_root;
|
quota_root = fs_info->quota_root;
|
||||||
|
@ -1060,16 +1051,13 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if there are no relations to this qgroup */
|
/* check if there are no relations to this qgroup */
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
|
||||||
qgroup = find_qgroup_rb(fs_info, qgroupid);
|
qgroup = find_qgroup_rb(fs_info, qgroupid);
|
||||||
if (qgroup) {
|
if (qgroup) {
|
||||||
if (!list_empty(&qgroup->groups) || !list_empty(&qgroup->members)) {
|
if (!list_empty(&qgroup->groups) || !list_empty(&qgroup->members)) {
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
|
||||||
|
|
||||||
ret = del_qgroup_item(trans, quota_root, qgroupid);
|
ret = del_qgroup_item(trans, quota_root, qgroupid);
|
||||||
|
|
||||||
|
@ -1106,20 +1094,17 @@ int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
|
||||||
(unsigned long long)qgroupid);
|
(unsigned long long)qgroupid);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&fs_info->qgroup_lock);
|
|
||||||
|
|
||||||
qgroup = find_qgroup_rb(fs_info, qgroupid);
|
qgroup = find_qgroup_rb(fs_info, qgroupid);
|
||||||
if (!qgroup) {
|
if (!qgroup) {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
goto unlock;
|
goto out;
|
||||||
}
|
}
|
||||||
|
spin_lock(&fs_info->qgroup_lock);
|
||||||
qgroup->lim_flags = limit->flags;
|
qgroup->lim_flags = limit->flags;
|
||||||
qgroup->max_rfer = limit->max_rfer;
|
qgroup->max_rfer = limit->max_rfer;
|
||||||
qgroup->max_excl = limit->max_excl;
|
qgroup->max_excl = limit->max_excl;
|
||||||
qgroup->rsv_rfer = limit->rsv_rfer;
|
qgroup->rsv_rfer = limit->rsv_rfer;
|
||||||
qgroup->rsv_excl = limit->rsv_excl;
|
qgroup->rsv_excl = limit->rsv_excl;
|
||||||
|
|
||||||
unlock:
|
|
||||||
spin_unlock(&fs_info->qgroup_lock);
|
spin_unlock(&fs_info->qgroup_lock);
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&fs_info->qgroup_ioctl_lock);
|
mutex_unlock(&fs_info->qgroup_ioctl_lock);
|
||||||
|
|
Loading…
Add table
Reference in a new issue