ext4: lock i_mutex when truncating orphan inodes
authorTheodore Ts'o <tytso@mit.edu>
Thu, 27 Dec 2012 06:42:48 +0000 (01:42 -0500)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 19 Jun 2013 01:16:46 +0000 (02:16 +0100)
commit 721e3eba21e43532e438652dd8f1fcdfce3187e7 upstream.

Commit c278531d39 added a warning when ext4_flush_unwritten_io() is
called without i_mutex being taken.  It had previously not been taken
during orphan cleanup since races weren't possible at that point in
the mount process, but as a result of this c278531d39, we will now see
a kernel WARN_ON in this case.  Take the i_mutex in
ext4_orphan_cleanup() to suppress this warning.

Reported-by: Alexander Beregalov <a.beregalov@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/super.c

index cc386b29d5e480d27100d9816cfe957cc8732cd2..259e950b3635bd35a8a7b137c94a9bb41248e629 100644 (file)
@@ -2260,7 +2260,9 @@ static void ext4_orphan_cleanup(struct super_block *sb,
                                __func__, inode->i_ino, inode->i_size);
                        jbd_debug(2, "truncating inode %lu to %lld bytes\n",
                                  inode->i_ino, inode->i_size);
+                       mutex_lock(&inode->i_mutex);
                        ext4_truncate(inode);
+                       mutex_unlock(&inode->i_mutex);
                        nr_truncates++;
                } else {
                        ext4_msg(sb, KERN_DEBUG,