Commit 42244864 authored by Lukas Czerner's avatar Lukas Czerner Committed by Luis Henriques

ext4: make fsync to sync parent dir in no-journal for real this time

commit e12fb972 upstream.

Previously commit 14ece102 added a
support for for syncing parent directory of newly created inodes to
make sure that the inode is not lost after a power failure in
no-journal mode.

However this does not work in majority of cases, namely:
 - if the directory has inline data
 - if the directory is already indexed
 - if the directory already has at least one block and:
	- the new entry fits into it
	- or we've successfully converted it to indexed

So in those cases we might lose the inode entirely even after fsync in
the no-journal mode. This also includes ext2 default mode obviously.

I've noticed this while running xfstest generic/321 and even though the
test should fail (we need to run fsck after a crash in no-journal mode)
I could not find a newly created entries even when if it was fsynced
before.

Fix this by adjusting the ext4_add_entry() successful exit paths to set
the inode EXT4_STATE_NEWENTRY so that fsync has the chance to fsync the
parent directory as well.
Signed-off-by: default avatarLukas Czerner <lczerner@redhat.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Cc: Frank Mayhar <fmayhar@google.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent e894d071
...@@ -1889,7 +1889,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1889,7 +1889,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
struct inode *inode) struct inode *inode)
{ {
struct inode *dir = dentry->d_parent->d_inode; struct inode *dir = dentry->d_parent->d_inode;
struct buffer_head *bh; struct buffer_head *bh = NULL;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct ext4_dir_entry_tail *t; struct ext4_dir_entry_tail *t;
struct super_block *sb; struct super_block *sb;
...@@ -1913,14 +1913,14 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1913,14 +1913,14 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
return retval; return retval;
if (retval == 1) { if (retval == 1) {
retval = 0; retval = 0;
return retval; goto out;
} }
} }
if (is_dx(dir)) { if (is_dx(dir)) {
retval = ext4_dx_add_entry(handle, dentry, inode); retval = ext4_dx_add_entry(handle, dentry, inode);
if (!retval || (retval != ERR_BAD_DX_DIR)) if (!retval || (retval != ERR_BAD_DX_DIR))
return retval; goto out;
ext4_clear_inode_flag(dir, EXT4_INODE_INDEX); ext4_clear_inode_flag(dir, EXT4_INODE_INDEX);
dx_fallback++; dx_fallback++;
ext4_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
...@@ -1932,14 +1932,15 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1932,14 +1932,15 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
return PTR_ERR(bh); return PTR_ERR(bh);
retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh); retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
if (retval != -ENOSPC) { if (retval != -ENOSPC)
brelse(bh); goto out;
return retval;
}
if (blocks == 1 && !dx_fallback && if (blocks == 1 && !dx_fallback &&
EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
return make_indexed_dir(handle, dentry, inode, bh); retval = make_indexed_dir(handle, dentry, inode, bh);
bh = NULL; /* make_indexed_dir releases bh */
goto out;
}
brelse(bh); brelse(bh);
} }
bh = ext4_append(handle, dir, &block); bh = ext4_append(handle, dir, &block);
...@@ -1955,6 +1956,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1955,6 +1956,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
} }
retval = add_dirent_to_buf(handle, dentry, inode, de, bh); retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
out:
brelse(bh); brelse(bh);
if (retval == 0) if (retval == 0)
ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY); ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment