Skip to content

Commit 8c0be0b

Browse files
fdmananagregkh
authored andcommitted
btrfs: use btrfs_record_snapshot_destroy() during rmdir
[ Upstream commit 157501b0469969fc1ba53add5049575aadd79d80 ] We are setting the parent directory's last_unlink_trans directly which may result in a concurrent task starting to log the directory not see the update and therefore can log the directory after we removed a child directory which had a snapshot within instead of falling back to a transaction commit. Replaying such a log tree would result in a mount failure since we can't currently delete snapshots (and subvolumes) during log replay. This is the type of failure described in commit 1ec9a1a ("Btrfs: fix unreplayable log after snapshot delete + parent dir fsync"). Fix this by using btrfs_record_snapshot_destroy() which updates the last_unlink_trans field while holding the inode's log_mutex lock. Fixes: 44f714d ("Btrfs: improve performance on fsync against new inode after rename/unlink") Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 8217345 commit 8c0be0b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,7 +4856,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
48564856
struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
48574857
int err = 0;
48584858
struct btrfs_trans_handle *trans;
4859-
u64 last_unlink_trans;
48604859
struct fscrypt_name fname;
48614860

48624861
if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
@@ -4891,8 +4890,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
48914890
if (err)
48924891
goto out;
48934892

4894-
last_unlink_trans = BTRFS_I(inode)->last_unlink_trans;
4895-
48964893
/* now the directory is empty */
48974894
err = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(d_inode(dentry)),
48984895
&fname.disk_name);
@@ -4909,8 +4906,8 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
49094906
* 5) mkdir foo
49104907
* 6) fsync foo or some file inside foo
49114908
*/
4912-
if (last_unlink_trans >= trans->transid)
4913-
BTRFS_I(dir)->last_unlink_trans = last_unlink_trans;
4909+
if (BTRFS_I(inode)->last_unlink_trans >= trans->transid)
4910+
btrfs_record_snapshot_destroy(trans, BTRFS_I(dir));
49144911
}
49154912
out:
49164913
btrfs_end_transaction(trans);

0 commit comments

Comments
 (0)