]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: make sure directory and symlink blocks are revoked
authorTheodore Ts'o <tytso@mit.edu>
Mon, 23 Nov 2009 12:17:34 +0000 (07:17 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 14 Dec 2009 16:07:28 +0000 (08:07 -0800)
(cherry picked from commit 50689696867d95b38d9c7be640a311494a04fb86)

When an inode gets unlinked, the functions ext4_clear_blocks() and
ext4_remove_blocks() call ext4_forget() for all the buffer heads
corresponding to the deleted inode's data blocks.  If the inode is a
directory or a symlink, the is_metadata parameter must be non-zero so
ext4_forget() will revoke them via jbd2_journal_revoke().  Otherwise,
if these blocks are reused for a data file, and the system crashes
before a journal checkpoint, the journal replay could end up
corrupting these data blocks.

Thanks to Curt Wohlgemuth for pointing out potential problems in this
area.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/ext4/extents.c
fs/ext4/inode.c

index 9cb1a078283af8829741f1ada9b09cec0d0b4159..e6a18a533eb230ca4524924e2816abcaa1723b48 100644 (file)
@@ -2055,7 +2055,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
                ext_debug("free last %u blocks starting %llu\n", num, start);
                for (i = 0; i < num; i++) {
                        bh = sb_find_get_block(inode->i_sb, start + i);
-                       ext4_forget(handle, 0, inode, bh, start + i);
+                       ext4_forget(handle, metadata, inode, bh, start + i);
                }
                ext4_free_blocks(handle, inode, start, num, metadata);
        } else if (from == le32_to_cpu(ex->ee_block)
index 8dd5b80cb7f2974addb7ebf3b2a8b5d4e220234f..f670f15c96fae6bc27927e570f29887519b3defd 100644 (file)
@@ -4110,6 +4110,8 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
                              __le32 *last)
 {
        __le32 *p;
+       int     is_metadata = S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode);
+
        if (try_to_extend_transaction(handle, inode)) {
                if (bh) {
                        BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
@@ -4140,11 +4142,11 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
 
                        *p = 0;
                        tbh = sb_find_get_block(inode->i_sb, nr);
-                       ext4_forget(handle, 0, inode, tbh, nr);
+                       ext4_forget(handle, is_metadata, inode, tbh, nr);
                }
        }
 
-       ext4_free_blocks(handle, inode, block_to_free, count, 0);
+       ext4_free_blocks(handle, inode, block_to_free, count, is_metadata);
 }
 
 /**