All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: abort in rename_exchange if we fail to insert the second ref
@ 2021-05-19 18:04 Josef Bacik
  2021-05-21 13:12 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Bacik @ 2021-05-19 18:04 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Error injection stress uncovered a problem where we'd leave a dangling
inode ref if we failed during a rename_exchange.  This happens because
we insert the inode ref for one side of the rename, and then for the
other side.  If this second inode ref insert fails we'll leave the first
one dangling and leave a corrupt file system behind.  Fix this by
aborting if we did the insert for the first inode ref.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 32a62ec4f127..a443b0b0de82 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9095,6 +9095,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 	int ret2;
 	bool root_log_pinned = false;
 	bool dest_log_pinned = false;
+	bool need_abort = false;
 
 	/* we only allow rename subvolume link between subvolumes */
 	if (old_ino != BTRFS_FIRST_FREE_OBJECTID && root != dest)
@@ -9154,6 +9155,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 					     old_idx);
 		if (ret)
 			goto out_fail;
+		need_abort = true;
 	}
 
 	/* And now for the dest. */
@@ -9169,8 +9171,11 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 					     new_ino,
 					     btrfs_ino(BTRFS_I(old_dir)),
 					     new_idx);
-		if (ret)
+		if (ret) {
+			if (need_abort)
+				btrfs_abort_transaction(trans, ret);
 			goto out_fail;
+		}
 	}
 
 	/* Update inode version and ctime/mtime. */
-- 
2.26.3


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

* Re: [PATCH] btrfs: abort in rename_exchange if we fail to insert the second ref
  2021-05-19 18:04 [PATCH] btrfs: abort in rename_exchange if we fail to insert the second ref Josef Bacik
@ 2021-05-21 13:12 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-05-21 13:12 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Wed, May 19, 2021 at 02:04:21PM -0400, Josef Bacik wrote:
> Error injection stress uncovered a problem where we'd leave a dangling
> inode ref if we failed during a rename_exchange.  This happens because
> we insert the inode ref for one side of the rename, and then for the
> other side.  If this second inode ref insert fails we'll leave the first
> one dangling and leave a corrupt file system behind.  Fix this by
> aborting if we did the insert for the first inode ref.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2021-05-21 13:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 18:04 [PATCH] btrfs: abort in rename_exchange if we fail to insert the second ref Josef Bacik
2021-05-21 13:12 ` David Sterba

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.