Skip to content

Commit 01acccf

Browse files
Lukas Czernersashalevin
authored andcommitted
ext4: make fsync to sync parent dir in no-journal for real this time
[ Upstream commit e12fb97 ] 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 Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 25a1a0e commit 01acccf

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
@@ -1865,7 +1865,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
18651865
struct inode *inode)
18661866
{
18671867
struct inode *dir = dentry->d_parent->d_inode;
1868-
struct buffer_head *bh;
1868+
struct buffer_head *bh = NULL;
18691869
struct ext4_dir_entry_2 *de;
18701870
struct ext4_dir_entry_tail *t;
18711871
struct super_block *sb;
@@ -1889,14 +1889,14 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
18891889
return retval;
18901890
if (retval == 1) {
18911891
retval = 0;
1892-
return retval;
1892+
goto out;
18931893
}
18941894
}
18951895

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

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

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

19331934
retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
1935+
out:
19341936
brelse(bh);
19351937
if (retval == 0)
19361938
ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY);

0 commit comments

Comments
 (0)