ext4: fix error handling on inode bitmap corruption
authorJan Kara <jack@suse.cz>
Sun, 18 Dec 2011 22:37:02 +0000 (17:37 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 May 2012 16:40:04 +0000 (09:40 -0700)
commit acd6ad83517639e8f09a8c5525b1dccd81cd2a10 upstream.

When insert_inode_locked() fails in ext4_new_inode() it most likely means inode
bitmap got corrupted and we allocated again inode which is already in use. Also
doing unlock_new_inode() during error recovery is wrong since the inode does
not have I_NEW set. Fix the problem by jumping to fail: (instead of fail_drop:)
which declares filesystem error and does not call unlock_new_inode().

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/ialloc.c

index 21bb2f61e50223c2da0946c4b48db0e4c947e1a7..412469b241a8c3eba95307839e113b1142c24d22 100644 (file)
@@ -1021,8 +1021,12 @@ got:
        if (IS_DIRSYNC(inode))
                ext4_handle_sync(handle);
        if (insert_inode_locked(inode) < 0) {
-               err = -EINVAL;
-               goto fail_drop;
+               /*
+                * Likely a bitmap corruption causing inode to be allocated
+                * twice.
+                */
+               err = -EIO;
+               goto fail;
        }
        spin_lock(&sbi->s_next_gen_lock);
        inode->i_generation = sbi->s_next_generation++;