Skip to content

Commit c4aba95

Browse files
committed
Btrfs: pin log earlier when renaming
We were pinning the log right after the first step in the rename operation (inserting inode ref for the new name in the destination directory) instead of doing it before. This behaviour was introduced in 2009 for some reason that was not mentioned neither on the changelog nor any comment, with the drawback of a small time window where concurrent log writers can end up logging the new inode reference for the inode we are renaming while the rename operation is in progress (so that we can end up with a log containing both the new and old references). As of today there's no reason to not pin the log before that first step anymore, so just fix this. Signed-off-by: Filipe Manana <[email protected]>
1 parent 3dc9e8f commit c4aba95

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9479,22 +9479,15 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
94799479
/* force full log commit if subvolume involved. */
94809480
btrfs_set_log_full_commit(root->fs_info, trans);
94819481
} else {
9482+
btrfs_pin_log_trans(root);
9483+
log_pinned = true;
94829484
ret = btrfs_insert_inode_ref(trans, dest,
94839485
new_dentry->d_name.name,
94849486
new_dentry->d_name.len,
94859487
old_ino,
94869488
btrfs_ino(new_dir), index);
94879489
if (ret)
94889490
goto out_fail;
9489-
/*
9490-
* this is an ugly little race, but the rename is required
9491-
* to make sure that if we crash, the inode is either at the
9492-
* old name or the new one. pinning the log transaction lets
9493-
* us make sure we don't allow a log commit to come in after
9494-
* we unlink the name but before we add the new name back in.
9495-
*/
9496-
btrfs_pin_log_trans(root);
9497-
log_pinned = true;
94989491
}
94999492

95009493
inode_inc_iversion(old_dir);

0 commit comments

Comments
 (0)