Skip to content

Commit e7c8f50

Browse files
committed
ext3: Add replace-on-rename hueristics for data=writeback mode
In data=writeback mode, start an asynchronous flush when renaming a file on top of an already-existing file. This lowers the probability of data loss in the case of applications that attempt to replace a file via using rename(). Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent f7ab34e commit e7c8f50

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎fs/ext3/namei.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
22652265
struct inode * old_inode, * new_inode;
22662266
struct buffer_head * old_bh, * new_bh, * dir_bh;
22672267
struct ext3_dir_entry_2 * old_de, * new_de;
2268-
int retval;
2268+
int retval, flush_file = 0;
22692269

22702270
old_bh = new_bh = dir_bh = NULL;
22712271

@@ -2401,6 +2401,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
24012401
ext3_mark_inode_dirty(handle, new_inode);
24022402
if (!new_inode->i_nlink)
24032403
ext3_orphan_add(handle, new_inode);
2404+
if (ext3_should_writeback_data(new_inode))
2405+
flush_file = 1;
24042406
}
24052407
retval = 0;
24062408

@@ -2409,6 +2411,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
24092411
brelse (old_bh);
24102412
brelse (new_bh);
24112413
ext3_journal_stop(handle);
2414+
if (retval == 0 && flush_file)
2415+
filemap_flush(old_inode->i_mapping);
24122416
return retval;
24132417
}
24142418

0 commit comments

Comments
 (0)