ext3: Fix possible deadlock between ext3_truncate() and ext3_get_blocks()
authorJan Kara <jack@suse.cz>
Tue, 11 Aug 2009 17:06:10 +0000 (19:06 +0200)
committerJan Kara <jack@suse.cz>
Wed, 16 Sep 2009 15:44:11 +0000 (17:44 +0200)
commit00171d3c7e3b738ba582c7a9b37408e796f49046
tree4c43c59666d78ccb1522a99dd7966252d5878ccf
parent3adae9da0b35d2ca908039f42a1e90395c335181
ext3: Fix possible deadlock between ext3_truncate() and ext3_get_blocks()

During truncate we are sometimes forced to start a new transaction as the
amount of blocks to be journaled is both quite large and hard to predict. So
far we restarted a transaction while holding truncate_mutex and that violates
lock ordering because truncate_mutex ranks below transaction start (and it
can lead to a real deadlock with ext3_get_blocks() allocating new blocks
from ext3_writepage()).

Luckily, the problem is easy to fix: We just drop the truncate_mutex before
restarting the transaction and acquire it afterwards. We are safe to do this as
by the time ext3_truncate() is called, all the page cache for the truncated
part of the file is dropped and so writepage() cannot come and allocate new
blocks in the part of the file we are truncating. The rest of writers is
stopped by us holding i_mutex.

Signed-off-by: Jan Kara <jack@suse.cz>
fs/ext3/inode.c