Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH V2 0/6] add a mutex lock to avoid race condition and  have all the ioctls check
@ 2013-03-28 10:54 Wang Shilong
  2013-03-28 10:53 ` [PATCH V2 1/6] Btrfs: introduce a mutex lock for btrfs quota operations Wang Shilong
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Wang Shilong @ 2013-03-28 10:54 UTC (permalink / raw)
  To: linux-btrfs; +Cc: sensille, miaox, wangsl-fnst

The original code has only one spin_lock 'qgroup_lock' to protect quota
configurations on memory. If we want to add a BTRFS_QGROUP_INFO_KEY,
it will be added to Btree firstly and then update quota configurations
on memory, however,a race condition may happen between these operations.
For example:
	->add_qqroup_info_item()
		->add_qgroup_rb()

For the above case, del_qgroup_info_item() may happen before add_qgroup_rb().

What's worse, when we want to add a qgroup relations:
	->add_qgroup_relation_item()
		->add_qgroup_relations()

We don't have any checks whether 'src' and 'dst' exists before
add_qgroup_relation_item(), a race condition can also happen for the above case.

To avoid race conditions and have all the necessay checks, we introduce
a mutex 'quota_lock', and we make all the user change operations protected by
the mutex_lock.

The benefit of mutex_lock is more, with a mutex lock, we can remove
some spin_lock usages thus easing the burden of spin_lock 'qgroup_lock'.

V1->V2:
	use quota configurations on memory to speed up ioctl checks
Wang Shilong (6):
  Btrfs: introduce a mutex lock for btrfs quota operations
  Btrfs: remove some unnecessary spin_lock usages
  Btrfs: fix missing check before updating qgroup limit
  Btrfs: fix missing check before creating/destroying a qgroup
  Btrfs: fix missing check before assigning/removing qgroup relation
  Btrfs: fix missing check before btrfs_qgroup_inherit()

 fs/btrfs/ctree.h   |   10 +++
 fs/btrfs/disk-io.c |    1 +
 fs/btrfs/ioctl.c   |   43 ++++++++++----
 fs/btrfs/qgroup.c  |  167 +++++++++++++++++++++++++++++++++-------------------
 4 files changed, 150 insertions(+), 71 deletions(-)

-- 
1.7.7.6


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-04-02 12:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 10:54 [PATCH V2 0/6] add a mutex lock to avoid race condition and have all the ioctls check Wang Shilong
2013-03-28 10:53 ` [PATCH V2 1/6] Btrfs: introduce a mutex lock for btrfs quota operations Wang Shilong
2013-03-30 23:41   ` Arne Jansen
2013-03-31  1:12     ` Wang Shilong
2013-04-02 12:19   ` Jan Schmidt
2013-04-02 12:26     ` Wang Shilong
2013-03-28 10:54 ` [PATCH V2 2/6] Btrfs: remove some unnecessary spin_lock usages Wang Shilong
2013-03-30 23:41   ` Arne Jansen
2013-03-28 10:54 ` [PATCH V2 3/6] Btrfs: fix missing check before updating qgroup limit Wang Shilong
2013-03-28 10:54 ` [PATCH V2 4/6] Btrfs: fix missing check before creating/destroying a qgroup Wang Shilong
2013-03-28 10:54 ` [PATCH V2 5/6] Btrfs: fix missing check before assigning/removing qgroup relation Wang Shilong
2013-03-28 13:21   ` Josef Bacik
2013-03-28 14:06     ` Wang Shilong
2013-03-28 10:54 ` [PATCH V2 6/6] Btrfs: fix missing check before btrfs_qgroup_inherit() Wang Shilong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox