Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Boris Burkov <boris@bur.io>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v7 04/12] btrfs: create free space tree on ro->rw remount
Date: Wed, 18 Nov 2020 15:06:19 -0800	[thread overview]
Message-ID: <464597922f2cb83486301a2ba6767cfbb9959c7e.1605736355.git.boris@bur.io> (raw)
In-Reply-To: <cover.1605736355.git.boris@bur.io>

When a user attempts to remount a btrfs filesystem with
'mount -o remount,space_cache=v2', that operation silently succeeds.
Unfortunately, this is misleading, because the remount does not create
the free space tree. /proc/mounts will incorrectly show space_cache=v2,
but on the next mount, the file system will revert to the old
space_cache.

For now, we handle only the easier case, where the existing mount is
read-only and the new mount is read-write. In that case, we can create
the free space tree without contending with the block groups changing
as we go.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/disk-io.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2cf81a4e9393..d934eb80ff49 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2912,6 +2912,17 @@ int btrfs_mount_rw(struct btrfs_fs_info *fs_info)
 		goto out;
 	}
 
+	if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
+	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
+		btrfs_info(fs_info, "creating free space tree");
+		ret = btrfs_create_free_space_tree(fs_info);
+		if (ret) {
+			btrfs_warn(fs_info,
+				"failed to create free space tree: %d", ret);
+			goto out;
+		}
+	}
+
 	ret = btrfs_resume_balance_async(fs_info);
 	if (ret)
 		goto out;
@@ -3376,18 +3387,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 		}
 	}
 
-	if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
-	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
-		btrfs_info(fs_info, "creating free space tree");
-		ret = btrfs_create_free_space_tree(fs_info);
-		if (ret) {
-			btrfs_warn(fs_info,
-				"failed to create free space tree: %d", ret);
-			close_ctree(fs_info);
-			return ret;
-		}
-	}
-
 	ret = btrfs_mount_rw(fs_info);
 	if (ret) {
 		close_ctree(fs_info);
-- 
2.24.1


  parent reply	other threads:[~2020-11-18 23:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 23:06 [PATCH v7 00/10] btrfs: free space tree mounting fixes Boris Burkov
2020-11-18 23:06 ` [PATCH v7 01/12] btrfs: lift rw mount setup from mount and remount Boris Burkov
2020-11-23 16:50   ` David Sterba
2020-11-30 23:31     ` Boris Burkov
2020-12-15 18:01       ` David Sterba
2020-11-23 16:57   ` David Sterba
2020-12-01  0:01     ` Boris Burkov
2020-12-15 17:50       ` David Sterba
2020-11-18 23:06 ` [PATCH v7 02/12] btrfs: cleanup all orphan inodes on ro->rw remount Boris Burkov
2020-11-18 23:06 ` [PATCH v7 03/12] btrfs: only mark bg->needs_free_space if free space tree is on Boris Burkov
2020-11-18 23:06 ` Boris Burkov [this message]
2020-11-18 23:06 ` [PATCH v7 05/12] btrfs: clear oneshot options on mount and remount Boris Burkov
2020-11-18 23:06 ` [PATCH v7 06/12] btrfs: clear free space tree on ro->rw remount Boris Burkov
2020-11-30 19:49   ` David Sterba
2020-11-18 23:06 ` [PATCH v7 07/12] btrfs: keep sb cache_generation consistent with space_cache Boris Burkov
2020-11-18 23:06 ` [PATCH v7 08/12] btrfs: use sb state to print space_cache mount option Boris Burkov
2020-11-18 23:06 ` [PATCH v7 09/12] btrfs: warn when remount will not change the free space tree Boris Burkov
2020-11-30 20:05   ` David Sterba
2020-11-18 23:06 ` [PATCH v7 10/12] btrfs: remove free space items when disabling space cache v1 Boris Burkov
2020-11-18 23:06 ` [PATCH v7 11/12] btrfs: skip space_cache v1 setup when not using it Boris Burkov
2020-11-18 23:06 ` [PATCH v7 12/12] btrfs: fix lockdep error creating free space tree Boris Burkov
2020-11-20 21:32 ` [PATCH v7 00/10] btrfs: free space tree mounting fixes David Sterba
2020-11-30 18:24   ` Boris Burkov
2020-11-30 20:29     ` David Sterba
2020-11-30 20:33 ` 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=464597922f2cb83486301a2ba6767cfbb9959c7e.1605736355.git.boris@bur.io \
    --to=boris@bur.io \
    --cc=kernel-team@fb.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