Skip to content

Commit 3f9749f

Browse files
committed
Btrfs: fix empty symlink after creating symlink and fsync parent dir
If we create a symlink, fsync its parent directory, crash/power fail and mount the filesystem, we end up with an empty symlink, which not only is useless it's also not allowed in linux (the man page symlink(2) is well explicit about that). So we just need to make sure to fully log an inode if it's a symlink, to ensure its inline extent gets logged, ensuring the same behaviour as ext3, ext4, xfs, reiserfs, f2fs, nilfs2, etc. Example reproducer: $ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ mkdir /mnt/testdir $ sync $ ln -s /mnt/foo /mnt/testdir/bar $ xfs_io -c fsync /mnt/testdir <power fail> $ mount /dev/sdb /mnt $ readlink /mnt/testdir/bar <empty string> A test case for fstests follows soon. Signed-off-by: Filipe Manana <[email protected]>
1 parent 657ed1a commit 3f9749f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/tree-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
51585158
}
51595159

51605160
ctx->log_new_dentries = false;
5161-
if (type == BTRFS_FT_DIR)
5161+
if (type == BTRFS_FT_DIR || type == BTRFS_FT_SYMLINK)
51625162
log_mode = LOG_INODE_ALL;
51635163
btrfs_release_path(path);
51645164
ret = btrfs_log_inode(trans, root, di_inode,

0 commit comments

Comments
 (0)