ocfs2: Fix possible deadlock with quotas in ocfs2_setattr()
authorJan Kara <jack@suse.cz>
Tue, 2 Jun 2009 12:24:01 +0000 (14:24 +0200)
committerJoel Becker <joel.becker@oracle.com>
Thu, 4 Jun 2009 02:14:29 +0000 (19:14 -0700)
commit65bac575e35915801ea518b9d8d8824367d125c8
treebce57755cf8b9f783cdab046ea519c0e41f595e1
parentb4c30de39a2596503e888a7b47d19792f25913d6
ocfs2: Fix possible deadlock with quotas in ocfs2_setattr()

We called vfs_dq_transfer() with global quota file lock held. This can lead
to deadlocks as if vfs_dq_transfer() has to allocate new quota structure,
it calls ocfs2_dquot_acquire() which tries to get quota file lock again and
this can block if another node requested the lock in the mean time.

Since we have to call vfs_dq_transfer() with transaction already started
and quota file lock ranks above the transaction start, we cannot just rely
on ocfs2_dquot_acquire() or ocfs2_dquot_release() on getting the lock
if they need it. We fix the problem by acquiring pointers to all quota
structures needed by vfs_dq_transfer() already before calling the function.
By this we are sure that all quota structures are properly allocated and
they can be freed only after we drop references to them. Thus we don't need
quota file lock anywhere inside vfs_dq_transfer().

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
fs/ocfs2/file.c