All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com,
	linux-fsdevel@vger.kernel.org, brauner@kernel.org
Subject: [PATCH 02/18] btrfs: split out the mount option validation code into its own helper
Date: Mon,  6 Nov 2023 17:08:10 -0500	[thread overview]
Message-ID: <83e9157999dd0bc41ef1c267a6d6c0a83b36340d.1699308010.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1699308010.git.josef@toxicpanda.com>

We're going to need to validate mount options after they're all parsed
with the new mount api, split this code out into its own helper so we
can use it when we swap over to the new mount api.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/super.c | 64 ++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6ecf78d09694..639601d346d0 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -233,6 +233,39 @@ static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt,
 	return false;
 }
 
+static bool check_options(struct btrfs_fs_info *info, unsigned long flags)
+{
+	if (!(flags & SB_RDONLY) &&
+	    (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") ||
+	     check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") ||
+	     check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums")))
+		return false;
+
+	if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) &&
+	    !btrfs_test_opt(info, FREE_SPACE_TREE) &&
+	    !btrfs_test_opt(info, CLEAR_CACHE)) {
+		btrfs_err(info, "cannot disable free space tree");
+		return false;
+	}
+	if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) &&
+	     !btrfs_test_opt(info, FREE_SPACE_TREE)) {
+		btrfs_err(info, "cannot disable free space tree with block-group-tree feature");
+		return false;
+	}
+
+	if (btrfs_check_mountopts_zoned(info))
+		return false;
+
+	if (!test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state)) {
+		if (btrfs_test_opt(info, SPACE_CACHE))
+			btrfs_info(info, "disk space caching is enabled");
+		if (btrfs_test_opt(info, FREE_SPACE_TREE))
+			btrfs_info(info, "using free space tree");
+	}
+
+	return true;
+}
+
 static int parse_rescue_options(struct btrfs_fs_info *info, const char *options)
 {
 	char *opts;
@@ -311,7 +344,6 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 	int saved_compress_level;
 	bool saved_compress_force;
 	int no_compress = 0;
-	const bool remounting = test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state);
 
 	if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
 		btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE);
@@ -330,7 +362,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 	 * against new flags
 	 */
 	if (!options)
-		goto check;
+		goto out;
 
 	while ((p = strsep(&options, ",")) != NULL) {
 		int token;
@@ -774,35 +806,9 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 			break;
 		}
 	}
-check:
-	/* We're read-only, don't have to check. */
-	if (new_flags & SB_RDONLY)
-		goto out;
-
-	if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") ||
-	    check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") ||
-	    check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums"))
-		ret = -EINVAL;
 out:
-	if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) &&
-	    !btrfs_test_opt(info, FREE_SPACE_TREE) &&
-	    !btrfs_test_opt(info, CLEAR_CACHE)) {
-		btrfs_err(info, "cannot disable free space tree");
+	if (!ret && !check_options(info, new_flags))
 		ret = -EINVAL;
-	}
-	if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) &&
-	     !btrfs_test_opt(info, FREE_SPACE_TREE)) {
-		btrfs_err(info, "cannot disable free space tree with block-group-tree feature");
-		ret = -EINVAL;
-	}
-	if (!ret)
-		ret = btrfs_check_mountopts_zoned(info);
-	if (!ret && !remounting) {
-		if (btrfs_test_opt(info, SPACE_CACHE))
-			btrfs_info(info, "disk space caching is enabled");
-		if (btrfs_test_opt(info, FREE_SPACE_TREE))
-			btrfs_info(info, "using free space tree");
-	}
 	return ret;
 }
 
-- 
2.41.0


  parent reply	other threads:[~2023-11-06 22:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 22:08 [PATCH 00/18] btrfs: convert to the new mount API Josef Bacik
2023-11-06 22:08 ` [PATCH 01/18] fs: indicate request originates from old mount api Josef Bacik
2023-11-08  7:59   ` Christoph Hellwig
2023-11-06 22:08 ` Josef Bacik [this message]
2023-11-06 22:08 ` [PATCH 03/18] btrfs: set default compress type at btrfs_init_fs_info time Josef Bacik
2023-11-06 22:08 ` [PATCH 04/18] btrfs: move space cache settings into open_ctree Josef Bacik
2023-11-07 15:14   ` Johannes Thumshirn
2023-11-06 22:08 ` [PATCH 05/18] btrfs: do not allow free space tree rebuild on extent tree v2 Josef Bacik
2023-11-06 22:08 ` [PATCH 06/18] btrfs: split out ro->rw and rw->ro helpers into their own functions Josef Bacik
2023-11-07 15:16   ` Johannes Thumshirn
2023-11-08 15:52     ` Josef Bacik
2023-11-06 22:08 ` [PATCH 07/18] btrfs: add a NOSPACECACHE mount option flag Josef Bacik
2023-11-06 22:08 ` [PATCH 08/18] btrfs: add fs_parameter definitions Josef Bacik
2023-11-06 22:08 ` [PATCH 09/18] btrfs: add parse_param callback for the new mount api Josef Bacik
2023-11-06 22:08 ` [PATCH 10/18] btrfs: add fs context handling functions Josef Bacik
2023-11-08  8:46   ` Christian Brauner
2023-11-06 22:08 ` [PATCH 11/18] btrfs: add reconfigure callback for fs_context Josef Bacik
2023-11-06 22:08 ` [PATCH 12/18] btrfs: add get_tree callback for new mount API Josef Bacik
2023-11-08  9:00   ` Christian Brauner
2023-11-06 22:08 ` [PATCH 13/18] btrfs: handle the ro->rw transition for mounting different subovls Josef Bacik
2023-11-08  8:41   ` Christian Brauner
2023-11-08 15:53     ` Josef Bacik
2023-11-06 22:08 ` [PATCH 14/18] btrfs: switch to the new mount API Josef Bacik
2023-11-08  9:03   ` Christian Brauner
2023-11-06 22:08 ` [PATCH 15/18] btrfs: move the device specific mount options to super.c Josef Bacik
2023-11-06 22:08 ` [PATCH 16/18] btrfs: remove old mount API code Josef Bacik
2023-11-06 22:08 ` [PATCH 17/18] btrfs: move one shot mount option clearing to super.c Josef Bacik
2023-11-06 22:08 ` [PATCH 18/18] btrfs: set clear_cache if we use usebackuproot Josef Bacik

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=83e9157999dd0bc41ef1c267a6d6c0a83b36340d.1699308010.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=brauner@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@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 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.