ext4: Fix race between migration and mmap write
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Tue, 29 Apr 2008 12:11:12 +0000 (08:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 29 Apr 2008 12:11:12 +0000 (08:11 -0400)
commit267e4db9ac28a09973476e7ec2cb6807e609d35a
tree54eae44c7c0086800901866424ef1526e0ce863e
parent3977c965ec35ce1a7eac988ad313f0fc9aee9660
ext4: Fix race between migration and mmap write

Fail migrate if we allocated new blocks via mmap write.

If we write to holes in the file via mmap, we end up allocating
new blocks. This block allocation happens without taking inode->i_mutex.
Since migrate is protected by i_mutex and migrate expects that no
new blocks get allocated during migrate, fail migrate if new blocks
get allocated.

We can't take inode->i_mutex in the mmap write path because that
would result in a locking order violation between i_mutex and mmap_sem.
Also adding a separate rw_sempahore for protection is really high overhead
for a rare operation such as migrate.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/inode.c
fs/ext4/migrate.c
include/linux/ext4_fs.h