diff options
author | Wang Shilong <wangsl-fnst@cn.fujitsu.com> | 2013-04-07 06:50:17 -0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-05-06 15:54:39 -0400 |
commit | 58400fce5ac5939aadac8ce682edc192c6172f80 (patch) | |
tree | e50f657851833043afaf1ece49bc5e2b348c58a5 /fs | |
parent | f2f6ed3d54648ec19dcdeec30f66843cf7a38487 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/qgroup.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 0a1f6861ae9a..49c4e6398f18 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
@@ -98,7 +98,7 @@ struct btrfs_qgroup_list { | |||
98 | struct btrfs_qgroup *member; | 98 | struct btrfs_qgroup *member; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | /* must be called with qgroup_lock held */ | 101 | /* must be called with qgroup_ioctl_lock held */ |
102 | static struct btrfs_qgroup *find_qgroup_rb(struct btrfs_fs_info *fs_info, | 102 | static struct btrfs_qgroup *find_qgroup_rb(struct btrfs_fs_info *fs_info, |
103 | u64 qgroupid) | 103 | u64 qgroupid) |
104 | { | 104 | { |
@@ -792,13 +792,10 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, | |||
792 | int slot; | 792 | int slot; |
793 | 793 | ||
794 | mutex_lock(&fs_info->qgroup_ioctl_lock); | 794 | mutex_lock(&fs_info->qgroup_ioctl_lock); |
795 | spin_lock(&fs_info->qgroup_lock); | ||
796 | if (fs_info->quota_root) { | 795 | if (fs_info->quota_root) { |
797 | fs_info->pending_quota_state = 1; | 796 | fs_info->pending_quota_state = 1; |
798 | spin_unlock(&fs_info->qgroup_lock); | ||
799 | goto out; | 797 | goto out; |
800 | } | 798 | } |
801 | spin_unlock(&fs_info->qgroup_lock); | ||
802 | 799 | ||
803 | /* | 800 | /* |
804 | * initially create the quota tree | 801 | * initially create the quota tree |
@@ -860,14 +857,11 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, | |||
860 | if (ret) | 857 | if (ret) |
861 | goto out_free_path; | 858 | goto out_free_path; |
862 | 859 | ||
863 | spin_lock(&fs_info->qgroup_lock); | ||
864 | qgroup = add_qgroup_rb(fs_info, found_key.offset); | 860 | qgroup = add_qgroup_rb(fs_info, found_key.offset); |
865 | if (IS_ERR(qgroup)) { | 861 | if (IS_ERR(qgroup)) { |
866 | spin_unlock(&fs_info->qgroup_lock); | ||
867 | ret = PTR_ERR(qgroup); | 862 | ret = PTR_ERR(qgroup); |
868 | goto out_free_path; | 863 | goto out_free_path; |
869 | } | 864 | } |
870 | spin_unlock(&fs_info->qgroup_lock); | ||
871 | } | 865 | } |
872 | ret = btrfs_next_item(tree_root, path); | 866 | ret = btrfs_next_item(tree_root, path); |
873 | if (ret < 0) | 867 | if (ret < 0) |
@@ -882,13 +876,12 @@ out_add_root: | |||
882 | if (ret) | 876 | if (ret) |
883 | goto out_free_path; | 877 | goto out_free_path; |
884 | 878 | ||
885 | spin_lock(&fs_info->qgroup_lock); | ||
886 | qgroup = add_qgroup_rb(fs_info, BTRFS_FS_TREE_OBJECTID); | 879 | qgroup = add_qgroup_rb(fs_info, BTRFS_FS_TREE_OBJECTID); |
887 | if (IS_ERR(qgroup)) { | 880 | if (IS_ERR(qgroup)) { |
888 | spin_unlock(&fs_info->qgroup_lock); | ||
889 | ret = PTR_ERR(qgroup); | 881 | ret = PTR_ERR(qgroup); |
890 | goto out_free_path; | 882 | goto out_free_path; |
891 | } | 883 | } |
884 | spin_lock(&fs_info->qgroup_lock); | ||
892 | fs_info->quota_root = quota_root; | 885 | fs_info->quota_root = quota_root; |
893 | fs_info->pending_quota_state = 1; | 886 | fs_info->pending_quota_state = 1; |
894 | spin_unlock(&fs_info->qgroup_lock); | 887 | spin_unlock(&fs_info->qgroup_lock); |
@@ -913,11 +906,9 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans, | |||
913 | int ret = 0; | 906 | int ret = 0; |
914 | 907 | ||
915 | mutex_lock(&fs_info->qgroup_ioctl_lock); | 908 | mutex_lock(&fs_info->qgroup_ioctl_lock); |
916 | spin_lock(&fs_info->qgroup_lock); | 909 | if (!fs_info->quota_root) |
917 | if (!fs_info->quota_root) { | ||
918 | spin_unlock(&fs_info->qgroup_lock); | ||
919 | goto out; | 910 | goto out; |
920 | } | 911 | spin_lock(&fs_info->qgroup_lock); |
921 | fs_info->quota_enabled = 0; | 912 | fs_info->quota_enabled = 0; |
922 | fs_info->pending_quota_state = 0; | 913 | fs_info->pending_quota_state = 0; |
923 | quota_root = fs_info->quota_root; | 914 | quota_root = fs_info->quota_root; |
@@ -1060,16 +1051,13 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, | |||
1060 | } | 1051 | } |
1061 | 1052 | ||
1062 | /* check if there are no relations to this qgroup */ | 1053 | /* check if there are no relations to this qgroup */ |
1063 | spin_lock(&fs_info->qgroup_lock); | ||
1064 | qgroup = find_qgroup_rb(fs_info, qgroupid); | 1054 | qgroup = find_qgroup_rb(fs_info, qgroupid); |
1065 | if (qgroup) { | 1055 | if (qgroup) { |
1066 | if (!list_empty(&qgroup->groups) || !list_empty(&qgroup->members)) { | 1056 | if (!list_empty(&qgroup->groups) || !list_empty(&qgroup->members)) { |
1067 | spin_unlock(&fs_info->qgroup_lock); | ||
1068 | ret = -EBUSY; | 1057 | ret = -EBUSY; |
1069 | goto out; | 1058 | goto out; |
1070 | } | 1059 | } |
1071 | } | 1060 | } |
1072 | spin_unlock(&fs_info->qgroup_lock); | ||
1073 | 1061 | ||
1074 | ret = del_qgroup_item(trans, quota_root, qgroupid); | 1062 | ret = del_qgroup_item(trans, quota_root, qgroupid); |
1075 | 1063 | ||
@@ -1106,20 +1094,17 @@ int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, | |||
1106 | (unsigned long long)qgroupid); | 1094 | (unsigned long long)qgroupid); |
1107 | } | 1095 | } |
1108 | 1096 | ||
1109 | spin_lock(&fs_info->qgroup_lock); | ||
1110 | |||
1111 | qgroup = find_qgroup_rb(fs_info, qgroupid); | 1097 | qgroup = find_qgroup_rb(fs_info, qgroupid); |
1112 | if (!qgroup) { | 1098 | if (!qgroup) { |
1113 | ret = -ENOENT; | 1099 | ret = -ENOENT; |
1114 | goto unlock; | 1100 | goto out; |
1115 | } | 1101 | } |
1102 | spin_lock(&fs_info->qgroup_lock); | ||
1116 | qgroup->lim_flags = limit->flags; | 1103 | qgroup->lim_flags = limit->flags; |
1117 | qgroup->max_rfer = limit->max_rfer; | 1104 | qgroup->max_rfer = limit->max_rfer; |
1118 | qgroup->max_excl = limit->max_excl; | 1105 | qgroup->max_excl = limit->max_excl; |
1119 | qgroup->rsv_rfer = limit->rsv_rfer; | 1106 | qgroup->rsv_rfer = limit->rsv_rfer; |
1120 | qgroup->rsv_excl = limit->rsv_excl; | 1107 | qgroup->rsv_excl = limit->rsv_excl; |
1121 | |||
1122 | unlock: | ||
1123 | spin_unlock(&fs_info->qgroup_lock); | 1108 | spin_unlock(&fs_info->qgroup_lock); |
1124 | out: | 1109 | out: |
1125 | mutex_unlock(&fs_info->qgroup_ioctl_lock); | 1110 | mutex_unlock(&fs_info->qgroup_ioctl_lock); |