All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: linux-btrfs@vger.kernel.org
Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org,
	viro@zeniv.linux.org.uk, david@fromorbit.com,
	Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH v4 3/3] btrfs: assert that relocation is protected with sb_start_write()
Date: Tue, 29 Mar 2022 15:56:00 +0900	[thread overview]
Message-ID: <28e3e02ed14fe7c0859707e1a10a447fe4338c16.1648535838.git.naohiro.aota@wdc.com> (raw)
In-Reply-To: <cover.1648535838.git.naohiro.aota@wdc.com>

Relocation of a data block group creates ordered extents. They can cause a
hang when a process is trying to thaw the filesystem.

We should have called sb_start_write(), so the filesystem is not being
frozen. Add an ASSERT to check it is protected.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/relocation.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index fdc2c4b411f0..5e52cd8d5f23 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3977,6 +3977,16 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
 	if (!bg)
 		return -ENOENT;
 
+	/*
+	 * Relocation of a data block group creates ordered extents.
+	 * Without sb_start_write(), we can freeze the FS while unfinished
+	 * ordered extents are left. Such ordered extents can cause a
+	 * deadlock e.g, when syncfs() is trying to finish them because
+	 * they never finish as the FS is already frozen.
+	 */
+	if (bg->flags & BTRFS_BLOCK_GROUP_DATA)
+		ASSERT(sb_write_started(fs_info->sb));
+
 	if (btrfs_pinned_by_swapfile(fs_info, bg)) {
 		btrfs_put_block_group(bg);
 		return -ETXTBSY;
-- 
2.35.1


  parent reply	other threads:[~2022-03-29  6:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  6:55 [PATCH v4 0/3] protect relocation with sb_start_write Naohiro Aota
2022-03-29  6:55 ` [PATCH v4 1/3] btrfs: mark resumed async balance as writing Naohiro Aota
2022-03-29  6:55 ` [PATCH v4 2/3] fs: add a check function for sb_start_write() Naohiro Aota
2022-03-29  6:56 ` Naohiro Aota [this message]
2022-03-29 10:10   ` [PATCH v4 3/3] btrfs: assert that relocation is protected with sb_start_write() Filipe Manana
2022-03-30 14:19 ` [PATCH v4 0/3] protect relocation with sb_start_write David Sterba

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=28e3e02ed14fe7c0859707e1a10a447fe4338c16.1648535838.git.naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=david@fromorbit.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 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.