* [PATCH 1/2] btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on relocation tree
@ 2020-07-08 7:50 Qu Wenruo
0 siblings, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2020-07-08 7:50 UTC (permalink / raw)
To: linux-btrfs
[BUG]
There is a bug report about bad signal timing could lead to read-only
fs during balance:
BTRFS info (device xvdb): balance: start -d -m -s
BTRFS info (device xvdb): relocating block group 73001861120 flags metadata
BTRFS info (device xvdb): found 12236 extents, stage: move data extents
BTRFS info (device xvdb): relocating block group 71928119296 flags data
BTRFS info (device xvdb): found 3 extents, stage: move data extents
BTRFS info (device xvdb): found 3 extents, stage: update data pointers
BTRFS info (device xvdb): relocating block group 60922265600 flags metadata
BTRFS: error (device xvdb) in btrfs_drop_snapshot:5505: errno=-4 unknown
BTRFS info (device xvdb): forced readonly
BTRFS info (device xvdb): balance: ended with status: -4
[CAUSE]
The direct cause is the -EINTR from the following call chain when a
fatal signal is pending:
relocate_block_group()
|- clean_dirty_subvols()
|- btrfs_drop_snapshot()
|- btrfs_start_transaction()
|- btrfs_delayed_refs_rsv_refill()
|- btrfs_reserve_metadata_bytes()
|- __reserve_metadata_bytes()
|- wait_reserve_ticket()
|- prepare_to_wait_event();
|- ticket->error = -EINTR;
Normally this behavior is fine for most btrfs_start_transaction()
callers, as they need to catch the fatal signal and exit asap.
However to balance, especially for the clean_dirty_subvols() case, we're
already doing cleanup works, such -EINTR from btrfs_drop_snapshot()
could cause a lot of unexpected problems.
From the mentioned forced read-only, to later balance error due to half
dropped reloc trees.
[FIX]
Fix this problem by using btrfs_join_transaction() if
btrfs_drop_snapshot() is called from relocation context.
As btrfs_join_transaction() won't wait full tickets, it won't get
interrupted from signal.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/extent-tree.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c0bc35f932bf..d8ef48a807d1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5298,7 +5298,10 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
goto out;
}
- trans = btrfs_start_transaction(tree_root, 0);
+ if (for_reloc)
+ trans = btrfs_join_transaction(tree_root);
+ else
+ trans = btrfs_start_transaction(tree_root, 0);
if (IS_ERR(trans)) {
err = PTR_ERR(trans);
goto out_free;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 1/2] btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on relocation tree
@ 2020-07-08 10:00 Qu Wenruo
2020-07-08 14:13 ` Josef Bacik
0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2020-07-08 10:00 UTC (permalink / raw)
To: linux-btrfs
[BUG]
There is a bug report about bad signal timing could lead to read-only
fs during balance:
BTRFS info (device xvdb): balance: start -d -m -s
BTRFS info (device xvdb): relocating block group 73001861120 flags metadata
BTRFS info (device xvdb): found 12236 extents, stage: move data extents
BTRFS info (device xvdb): relocating block group 71928119296 flags data
BTRFS info (device xvdb): found 3 extents, stage: move data extents
BTRFS info (device xvdb): found 3 extents, stage: update data pointers
BTRFS info (device xvdb): relocating block group 60922265600 flags metadata
BTRFS: error (device xvdb) in btrfs_drop_snapshot:5505: errno=-4 unknown
BTRFS info (device xvdb): forced readonly
BTRFS info (device xvdb): balance: ended with status: -4
[CAUSE]
The direct cause is the -EINTR from the following call chain when a
fatal signal is pending:
relocate_block_group()
|- clean_dirty_subvols()
|- btrfs_drop_snapshot()
|- btrfs_start_transaction()
|- btrfs_delayed_refs_rsv_refill()
|- btrfs_reserve_metadata_bytes()
|- __reserve_metadata_bytes()
|- wait_reserve_ticket()
|- prepare_to_wait_event();
|- ticket->error = -EINTR;
Normally this behavior is fine for most btrfs_start_transaction()
callers, as they need to catch the fatal signal and exit asap.
However to balance, especially for the clean_dirty_subvols() case, we're
already doing cleanup works, such -EINTR from btrfs_drop_snapshot()
could cause a lot of unexpected problems.
From the mentioned forced read-only, to later balance error due to half
dropped reloc trees.
[FIX]
Fix this problem by using btrfs_join_transaction() if
btrfs_drop_snapshot() is called from relocation context.
As btrfs_join_transaction() won't wait full tickets, it won't get
interrupted from signal.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/extent-tree.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c0bc35f932bf..d8ef48a807d1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5298,7 +5298,10 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
goto out;
}
- trans = btrfs_start_transaction(tree_root, 0);
+ if (for_reloc)
+ trans = btrfs_join_transaction(tree_root);
+ else
+ trans = btrfs_start_transaction(tree_root, 0);
if (IS_ERR(trans)) {
err = PTR_ERR(trans);
goto out_free;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on relocation tree
2020-07-08 10:00 Qu Wenruo
@ 2020-07-08 14:13 ` Josef Bacik
0 siblings, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2020-07-08 14:13 UTC (permalink / raw)
To: Qu Wenruo, linux-btrfs
On 7/8/20 6:00 AM, Qu Wenruo wrote:
> [BUG]
> There is a bug report about bad signal timing could lead to read-only
> fs during balance:
>
> BTRFS info (device xvdb): balance: start -d -m -s
> BTRFS info (device xvdb): relocating block group 73001861120 flags metadata
> BTRFS info (device xvdb): found 12236 extents, stage: move data extents
> BTRFS info (device xvdb): relocating block group 71928119296 flags data
> BTRFS info (device xvdb): found 3 extents, stage: move data extents
> BTRFS info (device xvdb): found 3 extents, stage: update data pointers
> BTRFS info (device xvdb): relocating block group 60922265600 flags metadata
> BTRFS: error (device xvdb) in btrfs_drop_snapshot:5505: errno=-4 unknown
> BTRFS info (device xvdb): forced readonly
> BTRFS info (device xvdb): balance: ended with status: -4
>
> [CAUSE]
> The direct cause is the -EINTR from the following call chain when a
> fatal signal is pending:
>
> relocate_block_group()
> |- clean_dirty_subvols()
> |- btrfs_drop_snapshot()
> |- btrfs_start_transaction()
> |- btrfs_delayed_refs_rsv_refill()
> |- btrfs_reserve_metadata_bytes()
> |- __reserve_metadata_bytes()
> |- wait_reserve_ticket()
> |- prepare_to_wait_event();
> |- ticket->error = -EINTR;
>
> Normally this behavior is fine for most btrfs_start_transaction()
> callers, as they need to catch the fatal signal and exit asap.
>
> However to balance, especially for the clean_dirty_subvols() case, we're
> already doing cleanup works, such -EINTR from btrfs_drop_snapshot()
> could cause a lot of unexpected problems.
>
> From the mentioned forced read-only, to later balance error due to half
> dropped reloc trees.
>
> [FIX]
> Fix this problem by using btrfs_join_transaction() if
> btrfs_drop_snapshot() is called from relocation context.
>
> As btrfs_join_transaction() won't wait full tickets, it won't get
> interrupted from signal.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-08 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-08 7:50 [PATCH 1/2] btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on relocation tree Qu Wenruo
-- strict thread matches above, loose matches on Subject: below --
2020-07-08 10:00 Qu Wenruo
2020-07-08 14:13 ` Josef Bacik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox