From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: do not commit transaction canceling a suspended replace
Date: Thu, 27 Jul 2023 14:07:54 +0800 [thread overview]
Message-ID: <18f1e6d4afa0db4aad56569bbab15b220f03236f.1690437675.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1690437675.git.wqu@suse.com>
[BUG]
There is a very rare corner case that, if the filesystem falls into a
deadly ENOSPC trap (metadata is so full that committing a transaction
would trigger transaction abort and falls RO), and the user needs to
cancel a suspended dev-replace, it would fail.
This is because the dev-replace canceling itself would commit the
current transaction, and falls RO first.
[CAUSE]
There are two involved situations:
- Cancel a running dev-replace
We just call btrfs_scrub_cancel(), it doesn't commit transaction
anyway.
- Cancel a suspended dev-replace
We only need to cleanup the various in-memory replace structure, which
is no difference than the previous situation.
But in this case we commit transaction, and may trigger the deadly
ENOSPC trap.
[FIX]
Just follow the first case, do not commit transaction when not needed.
Link: https://lore.kernel.org/linux-btrfs/CA+W5K0pQyJH5zWxs4JxfHR06DSUWDOcDPNsKxbdKQ_CiUtpyUg@mail.gmail.com/
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/dev-replace.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index fff22ed55c42..35590f17a5d7 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -1056,8 +1056,6 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
struct btrfs_device *tgt_device = NULL;
struct btrfs_device *src_device = NULL;
- struct btrfs_trans_handle *trans;
- struct btrfs_root *root = fs_info->tree_root;
int result;
int ret;
@@ -1112,14 +1110,6 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
/* Scrub for replace must not be running in suspended state */
btrfs_scrub_cancel(fs_info);
- trans = btrfs_start_transaction(root, 0);
- if (IS_ERR(trans)) {
- mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
- return PTR_ERR(trans);
- }
- ret = btrfs_commit_transaction(trans);
- WARN_ON(ret);
-
btrfs_info_in_rcu(fs_info,
"suspended dev_replace from %s (devid %llu) to %s canceled",
btrfs_dev_name(src_device), src_device->devid,
--
2.41.0
next prev parent reply other threads:[~2023-07-27 6:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 6:07 [PATCH 0/2] btrfs: do not commit transaction to avoid deadly ENOSPC trap Qu Wenruo
2023-07-27 6:07 ` [PATCH 1/2] btrfs: do not commit transaction after adding one device Qu Wenruo
2023-07-27 6:07 ` Qu Wenruo [this message]
2023-07-27 12:09 ` [PATCH 2/2] btrfs: do not commit transaction canceling a suspended replace David Sterba
2023-07-27 22:26 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18f1e6d4afa0db4aad56569bbab15b220f03236f.1690437675.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).