aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorWang Shilong <wangsl-fnst@cn.fujitsu.com>2013-04-07 06:50:16 -0400
committerJosef Bacik <jbacik@fusionio.com>2013-05-06 15:54:38 -0400
commitf2f6ed3d54648ec19dcdeec30f66843cf7a38487 (patch)
treecc82afe22a835994252961f21e422258393a8974 /fs/btrfs/ctree.h
parent7708f029dca5f1b9e9d6ea01ab10cd83e4c74ff2 (diff)
Btrfs: introduce a mutex lock for btrfs quota operations
The original code has one spin_lock 'qgroup_lock' to protect quota configurations in memory. If we want to add a BTRFS_QGROUP_INFO_KEY, it will be added to Btree firstly, and then update configurations in memory,however, a race condition may happen between these operations. For example: ->add_qgroup_info_item() ->add_qgroup_rb() For the above case, del_qgroup_info_item() may happen just before add_qgroup_rb(). What's worse, when we want to add a qgroup relation: ->add_qgroup_relation_item() ->add_qgroup_relations() We don't have any checks whether 'src' and 'dst' exist before add_qgroup_relation_item(), a race condition can also happen for the above case. To avoid race condition and have all the necessary checks, we introduce a mutex lock 'qgroup_ioctl_lock', and we make all the user change operations protected by the mutex lock. 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/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 075a8a0e49c4..1a850402937d 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1583,6 +1583,9 @@ struct btrfs_fs_info {
1583 struct rb_root qgroup_tree; 1583 struct rb_root qgroup_tree;
1584 spinlock_t qgroup_lock; 1584 spinlock_t qgroup_lock;
1585 1585
1586 /* protect user change for quota operations */
1587 struct mutex qgroup_ioctl_lock;
1588
1586 /* list of dirty qgroups to be written at next commit */ 1589 /* list of dirty qgroups to be written at next commit */
1587 struct list_head dirty_qgroups; 1590 struct list_head dirty_qgroups;
1588 1591