Skip to content

Commit e12fb97

Browse files
Lukas Czernertytso
authored andcommitted
ext4: make fsync to sync parent dir in no-journal for real this time
Previously commit 14ece10 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: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Frank Mayhar <fmayhar@google.com> Cc: stable@vger.kernel.org
1 parent 9d21c9f commit e12fb97

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎fs/ext4/namei.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
18641864
struct inode *inode)
18651865
{
18661866
struct inode *dir = dentry->d_parent->d_inode;
1867-
struct buffer_head *bh;
1867+
struct buffer_head *bh = NULL;
18681868
struct ext4_dir_entry_2 *de;
18691869
struct ext4_dir_entry_tail *t;
18701870
struct super_block *sb;
@@ -1888,14 +1888,14 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
18881888
return retval;
18891889
if (retval == 1) {
18901890
retval = 0;
1891-
return retval;
1891+
goto out;
18921892
}
18931893
}
18941894

18951895
if (is_dx(dir)) {
18961896
retval = ext4_dx_add_entry(handle, dentry, inode);
18971897
if (!retval || (retval != ERR_BAD_DX_DIR))
1898-
return retval;
1898+
goto out;
18991899
ext4_clear_inode_flag(dir, EXT4_INODE_INDEX);
19001900
dx_fallback++;
19011901
ext4_mark_inode_dirty(handle, dir);
@@ -1907,14 +1907,15 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
19071907
return PTR_ERR(bh);
19081908

19091909
retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1910-
if (retval != -ENOSPC) {
1911-
brelse(bh);
1912-
return retval;
1913-
}
1910+
if (retval != -ENOSPC)
1911+
goto out;
19141912

19151913
if (blocks == 1 && !dx_fallback &&
1916-
EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX))
1917-
return make_indexed_dir(handle, dentry, inode, bh);
1914+
EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
1915+
retval = make_indexed_dir(handle, dentry, inode, bh);
1916+
bh = NULL; /* make_indexed_dir releases bh */
1917+
goto out;
1918+
}
19181919
brelse(bh);
19191920
}
19201921
bh = ext4_append(handle, dir, &block);
@@ -1930,6 +1931,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
19301931
}
19311932

19321933
retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
1934+
out:
19331935
brelse(bh);
19341936
if (retval == 0)
19351937
ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY);

0 commit comments

Comments
 (0)