Skip to content

Commit c5b4a50

Browse files
fdmananakdave
authored andcommitted
Btrfs: fix return value on rename exchange failure
If we failed during a rename exchange operation after starting/joining a transaction, we would end up replacing the return value, stored in the local 'ret' variable, with the return value from btrfs_end_transaction(). So this could end up returning 0 (success) to user space despite the operation having failed and aborted the transaction, because if there are multiple tasks having a reference on the transaction at the time btrfs_end_transaction() is called by the rename exchange, that function returns 0 (otherwise it returns -EIO and not the original error value). So fix this by not overwriting the return value on error after getting a transaction handle. Fixes: cdd1fed ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT") CC: [email protected] # 4.9+ Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 22883dd commit c5b4a50

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/btrfs/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9443,6 +9443,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
94439443
u64 new_idx = 0;
94449444
u64 root_objectid;
94459445
int ret;
9446+
int ret2;
94469447
bool root_log_pinned = false;
94479448
bool dest_log_pinned = false;
94489449

@@ -9639,7 +9640,8 @@ static int btrfs_rename_exchange(struct inode *old_dir,
96399640
dest_log_pinned = false;
96409641
}
96419642
}
9642-
ret = btrfs_end_transaction(trans);
9643+
ret2 = btrfs_end_transaction(trans);
9644+
ret = ret ? ret : ret2;
96439645
out_notrans:
96449646
if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
96459647
up_read(&fs_info->subvol_sem);

0 commit comments

Comments
 (0)