aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2009-11-23 07:17:34 -0500
committerTheodore Ts'o <tytso@mit.edu>2009-11-23 07:17:34 -0500
commit50689696867d95b38d9c7be640a311494a04fb86 (patch)
tree69e582bb6c95d8d0ac59bcad97b5f7f1d79e7126 /fs
parentbeac2da7565e42be59963824899825d0cc624295 (diff)
ext4: make sure directory and symlink blocks are revoked
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> Cc: stable@kernel.org
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/extents.c2
-rw-r--r--fs/ext4/inode.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 715264b4bae4..74dcff84c3a8 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2074,7 +2074,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2074 ext_debug("free last %u blocks starting %llu\n", num, start); 2074 ext_debug("free last %u blocks starting %llu\n", num, start);
2075 for (i = 0; i < num; i++) { 2075 for (i = 0; i < num; i++) {
2076 bh = sb_find_get_block(inode->i_sb, start + i); 2076 bh = sb_find_get_block(inode->i_sb, start + i);
2077 ext4_forget(handle, 0, inode, bh, start + i); 2077 ext4_forget(handle, metadata, inode, bh, start + i);
2078 } 2078 }
2079 ext4_free_blocks(handle, inode, start, num, metadata); 2079 ext4_free_blocks(handle, inode, start, num, metadata);
2080 } else if (from == le32_to_cpu(ex->ee_block) 2080 } else if (from == le32_to_cpu(ex->ee_block)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 13de1dd751f5..c420aaba6e9c 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4121,6 +4121,8 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
4121 __le32 *last) 4121 __le32 *last)
4122{ 4122{
4123 __le32 *p; 4123 __le32 *p;
4124 int is_metadata = S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode);
4125
4124 if (try_to_extend_transaction(handle, inode)) { 4126 if (try_to_extend_transaction(handle, inode)) {
4125 if (bh) { 4127 if (bh) {
4126 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 4128 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
@@ -4151,11 +4153,11 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
4151 4153
4152 *p = 0; 4154 *p = 0;
4153 tbh = sb_find_get_block(inode->i_sb, nr); 4155 tbh = sb_find_get_block(inode->i_sb, nr);
4154 ext4_forget(handle, 0, inode, tbh, nr); 4156 ext4_forget(handle, is_metadata, inode, tbh, nr);
4155 } 4157 }
4156 } 4158 }
4157 4159
4158 ext4_free_blocks(handle, inode, block_to_free, count, 0); 4160 ext4_free_blocks(handle, inode, block_to_free, count, is_metadata);
4159} 4161}
4160 4162
4161/** 4163/**