Skip to content
/ linux Public

Commit 1cf30c7

Browse files
fdmananagregkh
authored andcommitted
btrfs: log new dentries when logging parent dir of a conflicting inode
[ Upstream commit 9573a36 ] If we log the parent directory of a conflicting inode, we are not logging the new dentries of the directory, so when we finish we have the parent directory's inode marked as logged but we did not log its new dentries. As a consequence if the parent directory is explicitly fsynced later and it does not have any new changes since we logged it, the fsync is a no-op and after a power failure the new dentries are missing. Example scenario: $ mkdir foo $ sync $rmdir foo $ mkdir dir1 $ mkdir dir2 # A file with the same name and parent as the directory we just deleted # and was persisted in a past transaction. So the deleted directory's # inode is a conflicting inode of this new file's inode. $ touch foo $ ln foo dir2/link # The fsync on dir2 will log the parent directory (".") because the # conflicting inode (deleted directory) does not exists anymore, but it # it does not log its new dentries (dir1). $ xfs_io -c "fsync" dir2 # This fsync on the parent directory is no-op, since the previous fsync # logged it (but without logging its new dentries). $ xfs_io -c "fsync" . <power failure> # After log replay dir1 is missing. Fix this by ensuring we log new dir dentries whenever we log the parent directory of a no longer existing conflicting inode. A test case for fstests will follow soon. Reported-by: Vyacheslav Kovalevsky <slava.kovalevskiy.2014@gmail.com> Link: https://lore.kernel.org/linux-btrfs/182055fa-e9ce-4089-9f5f-4b8a23e8dd91@gmail.com/ Fixes: a3baaf0 ("Btrfs: fix fsync after succession of renames and unlink/rmdir") Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9691c50 commit 1cf30c7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/btrfs/tree-log.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,6 +6203,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
62036203
struct btrfs_root *root,
62046204
struct btrfs_log_ctx *ctx)
62056205
{
6206+
const bool orig_log_new_dentries = ctx->log_new_dentries;
62066207
int ret = 0;
62076208

62086209
/*
@@ -6264,7 +6265,11 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
62646265
* dir index key range logged for the directory. So we
62656266
* must make sure the deletion is recorded.
62666267
*/
6268+
ctx->log_new_dentries = false;
62676269
ret = btrfs_log_inode(trans, inode, LOG_INODE_ALL, ctx);
6270+
if (!ret && ctx->log_new_dentries)
6271+
ret = log_new_dir_dentries(trans, inode, ctx);
6272+
62686273
btrfs_add_delayed_iput(inode);
62696274
if (ret)
62706275
break;
@@ -6299,6 +6304,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
62996304
break;
63006305
}
63016306

6307+
ctx->log_new_dentries = orig_log_new_dentries;
63026308
ctx->logging_conflict_inodes = false;
63036309
if (ret)
63046310
free_conflicting_inodes(ctx);

0 commit comments

Comments
 (0)