Skip to content

Commit 86c4f6d

Browse files
committed
ext3: Fix fs corruption when make_indexed_dir() fails
When make_indexed_dir() fails (e.g. because of ENOSPC) after it has allocated block for index tree root, we did not properly mark all changed buffers dirty. This lead to only some of these buffers being written out and thus effectively corrupting the directory. Fix the issue by marking all changed data dirty even in the error failure case. CC: [email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent ae54870 commit 86c4f6d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/ext3/namei.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,19 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
14161416
frame->at = entries;
14171417
frame->bh = bh;
14181418
bh = bh2;
1419+
/*
1420+
* Mark buffers dirty here so that if do_split() fails we write a
1421+
* consistent set of buffers to disk.
1422+
*/
1423+
ext3_journal_dirty_metadata(handle, frame->bh);
1424+
ext3_journal_dirty_metadata(handle, bh);
14191425
de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1420-
dx_release (frames);
1421-
if (!(de))
1426+
if (!de) {
1427+
ext3_mark_inode_dirty(handle, dir);
1428+
dx_release(frames);
14221429
return retval;
1430+
}
1431+
dx_release(frames);
14231432

14241433
return add_dirent_to_buf(handle, dentry, inode, de, bh);
14251434
}
@@ -2282,7 +2291,7 @@ static int ext3_symlink (struct inode * dir,
22822291
return err;
22832292
err_drop_inode:
22842293
unlock_new_inode(inode);
2285-
iput (inode);
2294+
iput(inode);
22862295
return err;
22872296
}
22882297

0 commit comments

Comments
 (0)