All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Btrfs: fix return value on rename exchange failure
@ 2018-06-11 18:24 fdmanana
  2018-06-19 13:38 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: fdmanana @ 2018-06-11 18:24 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

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.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 89b208201783..2bb893aa54da 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9445,6 +9445,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 	u64 new_idx = 0;
 	u64 root_objectid;
 	int ret;
+	int ret2;
 	bool root_log_pinned = false;
 	bool dest_log_pinned = false;
 
@@ -9641,7 +9642,8 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 			dest_log_pinned = false;
 		}
 	}
-	ret = btrfs_end_transaction(trans);
+	ret2 = btrfs_end_transaction(trans);
+	ret = ret ? ret : ret2;
 out_notrans:
 	if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
 		up_read(&fs_info->subvol_sem);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Btrfs: fix return value on rename exchange failure
  2018-06-11 18:24 [PATCH 1/2] Btrfs: fix return value on rename exchange failure fdmanana
@ 2018-06-19 13:38 ` David Sterba
  2018-06-21 16:36   ` Filipe Manana
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2018-06-19 13:38 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Mon, Jun 11, 2018 at 07:24:16PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> 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.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

1 and 2 queued for 4.18, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Btrfs: fix return value on rename exchange failure
  2018-06-19 13:38 ` David Sterba
@ 2018-06-21 16:36   ` Filipe Manana
  0 siblings, 0 replies; 3+ messages in thread
From: Filipe Manana @ 2018-06-21 16:36 UTC (permalink / raw)
  To: dsterba, Filipe Manana, linux-btrfs

On Tue, Jun 19, 2018 at 2:38 PM, David Sterba <dsterba@suse.cz> wrote:
> On Mon, Jun 11, 2018 at 07:24:16PM +0100, fdmanana@kernel.org wrote:
>> From: Filipe Manana <fdmanana@suse.com>
>>
>> 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.
>>
>> Signed-off-by: Filipe Manana <fdmanana@suse.com>
>
> 1 and 2 queued for 4.18, thanks.

Please removed the 2nd patch, because I just ran into a deadlock
between syncing the log and transaction kthread commiting the
transaction while a rename was in progress.
I'll send a v2 once I understand better the problem and have a fix. Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-21 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11 18:24 [PATCH 1/2] Btrfs: fix return value on rename exchange failure fdmanana
2018-06-19 13:38 ` David Sterba
2018-06-21 16:36   ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.