Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BE9727CCD3 for ; Thu, 24 Apr 2025 13:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745502679; cv=none; b=YklesJrnaO+26Uv2zU3gexn3GGQEIKWN6aB6SaV5CW1Hg5dH2qjYuvJ8UU+mM1wcnnb/Ejxt4jbDmQMYjmSSxme+qFL/zBeTIVhe5HMUgXLpIqFxR6HOzfMj2GLC7NU30TnSex6C1V+m6nzMSU3rsOBfmYbVncby/b+oD1IqFwc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745502679; c=relaxed/simple; bh=tIb618SVINwuTStGolSK+a8puP1P9Uj1T1fbAvmrJpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=URIwbflaEAG+yBnkssOzaAb6n5sDFei7IgMkkvFPbZqQcQVG4IzzlGxaaovKBiuSB2SoX9nTAGKztLe+f6928OU2feftSCfHk6gl8gxXhd77YbUlgroxu+6d2tjZTxRxN1JqH6lfJCSq240ojbx/nboLHV07WeDIbsR5aXMfCzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JxyLDWus; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JxyLDWus" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745502676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qD/UpRkz2a+d2aIW1RIhEkplQolvjFOHogsVje60F7M=; b=JxyLDWusIx+knM+3hOtrPL7Fv69yHnIN3EsWkQm7jVX+IyWbjPiMLnnZHLW94XIWRIwn6N MUc6OPlQsnOVcvFJSIz/R94SKoDgZosJeo7u6yJ1roVBl0OTlGJt0MOjM7VIIhr1M/E4Gd 86nYG3ndAU/6ALtQOO+Qy36UlktYuLs= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-O97B21IrMh-QoP-qpn2WOg-1; Thu, 24 Apr 2025 09:51:14 -0400 X-MC-Unique: O97B21IrMh-QoP-qpn2WOg-1 X-Mimecast-MFC-AGG-ID: O97B21IrMh-QoP-qpn2WOg_1745502673 Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-72ab21098efso713375a34.1 for ; Thu, 24 Apr 2025 06:51:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745502673; x=1746107473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qD/UpRkz2a+d2aIW1RIhEkplQolvjFOHogsVje60F7M=; b=p4bPF+z6eydJzEF4qE/KuH4yZWD4euIwn5HgudKXR1dIy+QYxY0xfZ7KE/xPmG7Gqy V8/dTJGG5waI7rtj5oSUU7hBbMAWmBFvrV5ybGZYgHQlsqRBWkGsMG/G1Mgek15Izluj 3u5Kn7sfOwRra8B49b6WgytOU32Fi/m6Ot1MMCKiXexb+u/lIG3ZSZgckDZ7copYBQBz RohyjPcpgDXuUIivclbiKy+c8oZ2KZtDdegetiiNXHUvgr/L+/jwiOBHmOm1SU74jEQ6 xR9gxNIiK8hgnwa4ujC+utSWnBS+91iI5HE3RaWsDdI7lk1CBZtF60FKFIicBiaMSMsE AfyQ== X-Gm-Message-State: AOJu0YyRDbZ4HFO7ULpXnHaiO9gq+qSQbtYXslllPXUlPhGA2uVrxpNr vZWh6+fB3Ddyy8MR7Huemw7mp/D49pEOMPrn5J1AM88X5yEh779D/dYfXrodxt2Tvg0Bl9Xhy6N J/taDvA/ZaAfgFUGW/hnxHVKCf1rNsQSsnpjtK2nKGqiF83gOTPhMph6VsQD5574= X-Gm-Gg: ASbGncsq0QemOi1Vew2HNIIV1LkKKENTBwY/l1KpApy2QgbCR7iGwBwZulbTwQqoyM+ 16OwZTYTR2XU1tTpnws9mmlbApb3eLDOb6WWc91ofKWhGR3GOckWYZVvuDS0cqTIqdKA4nv+Jj1 RkLLP9+Z+jqia+DEmDHVdGzB/pkswdetYcYvSphBrLrjxE2zonwDO3nuRNGSaEnc0RK/piBdBqg hYHuqVot8hRKtAjDiMS7mCN76Bl/qnE44lcorjHISNfL+vOfa4c1wOIY3iIL5udswM0YOIMY0oc fhDpWQAb8cSHaiADvE4uzWJwY5o9IGrhgg9/L4or4g2fB/9PoUVHpR4= X-Received: by 2002:a05:6830:618c:b0:72a:e65:e65c with SMTP id 46e09a7af769-7304fab5704mr1176357a34.11.1745502673505; Thu, 24 Apr 2025 06:51:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqdp/zmGLzm0p+gVfTAYfpYlsy7eePgp2zekm+QON25Nv3dcA5h2QMfOFAj0V5RY3L0sw/bg== X-Received: by 2002:a05:6830:618c:b0:72a:e65:e65c with SMTP id 46e09a7af769-7304fab5704mr1176346a34.11.1745502673151; Thu, 24 Apr 2025 06:51:13 -0700 (PDT) Received: from localhost.localdomain (nwtn-09-2828.dsl.iowatelecom.net. [67.224.43.12]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7304f37b158sm233595a34.49.2025.04.24.06.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 06:51:12 -0700 (PDT) From: Eric Sandeen To: linux-f2fs-devel@lists.sourceforge.net Cc: linux-fsdevel@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, lihongbo22@huawei.com, Eric Sandeen Subject: [PATCH V3 7/7] f2fs: switch to the new mount api Date: Wed, 23 Apr 2025 12:08:51 -0500 Message-ID: <20250423170926.76007-8-sandeen@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250423170926.76007-1-sandeen@redhat.com> References: <20250423170926.76007-1-sandeen@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hongbo Li The new mount api will execute .parse_param, .init_fs_context, .get_tree and will call .remount if remount happened. So we add the necessary functions for the fs_context_operations. If .init_fs_context is added, the old .mount should remove. See Documentation/filesystems/mount_api.rst for more information. Signed-off-by: Hongbo Li [sandeen: forward port] Signed-off-by: Eric Sandeen --- fs/f2fs/super.c | 156 +++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 94 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 37497fd80bb9..041bd6c482a0 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1141,47 +1141,6 @@ static int f2fs_parse_param(struct fs_context *fc, struct fs_parameter *param) return 0; } -static int parse_options(struct fs_context *fc, char *options) -{ - struct fs_parameter param; - char *key; - int ret; - - if (!options) - return 0; - - while ((key = strsep(&options, ",")) != NULL) { - if (*key) { - size_t v_len = 0; - char *value = strchr(key, '='); - - param.type = fs_value_is_flag; - param.string = NULL; - - if (value) { - if (value == key) - continue; - - *value++ = 0; - v_len = strlen(value); - param.string = kmemdup_nul(value, v_len, GFP_KERNEL); - if (!param.string) - return -ENOMEM; - param.type = fs_value_is_string; - } - - param.key = key; - param.size = v_len; - - ret = f2fs_parse_param(fc, ¶m); - kfree(param.string); - if (ret < 0) - return ret; - } - } - return 0; -} - /* * Check quota settings consistency. */ @@ -2583,13 +2542,12 @@ static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) f2fs_flush_ckpt_thread(sbi); } -static int f2fs_remount(struct super_block *sb, int *flags, char *data) +static int __f2fs_remount(struct fs_context *fc, struct super_block *sb) { struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_mount_info org_mount_opt; - struct f2fs_fs_context ctx; - struct fs_context fc; unsigned long old_sb_flags; + unsigned int flags = fc->sb_flags; int err; bool need_restart_gc = false, need_stop_gc = false; bool need_restart_flush = false, need_stop_flush = false; @@ -2635,7 +2593,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) #endif /* recover superblocks we couldn't write due to previous RO mount */ - if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { + if (!(flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { err = f2fs_commit_super(sbi, false); f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", err); @@ -2645,21 +2603,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) default_options(sbi, true); - memset(&fc, 0, sizeof(fc)); - memset(&ctx, 0, sizeof(ctx)); - fc.fs_private = &ctx; - fc.purpose = FS_CONTEXT_FOR_RECONFIGURE; - - /* parse mount options */ - err = parse_options(&fc, data); - if (err) - goto restore_opts; - - err = f2fs_check_opt_consistency(&fc, sb); + err = f2fs_check_opt_consistency(fc, sb); if (err < 0) goto restore_opts; - f2fs_apply_options(&fc, sb); + f2fs_apply_options(fc, sb); #ifdef CONFIG_BLK_DEV_ZONED if (f2fs_sb_has_blkzoned(sbi) && @@ -2678,20 +2626,20 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) * Previous and new state of filesystem is RO, * so skip checking GC and FLUSH_MERGE conditions. */ - if (f2fs_readonly(sb) && (*flags & SB_RDONLY)) + if (f2fs_readonly(sb) && (flags & SB_RDONLY)) goto skip; - if (f2fs_dev_is_readonly(sbi) && !(*flags & SB_RDONLY)) { + if (f2fs_dev_is_readonly(sbi) && !(flags & SB_RDONLY)) { err = -EROFS; goto restore_opts; } #ifdef CONFIG_QUOTA - if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) { + if (!f2fs_readonly(sb) && (flags & SB_RDONLY)) { err = dquot_suspend(sb, -1); if (err < 0) goto restore_opts; - } else if (f2fs_readonly(sb) && !(*flags & SB_RDONLY)) { + } else if (f2fs_readonly(sb) && !(flags & SB_RDONLY)) { /* dquot_resume needs RW */ sb->s_flags &= ~SB_RDONLY; if (sb_any_quota_suspended(sb)) { @@ -2747,7 +2695,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) goto restore_opts; } - if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { + if ((flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { err = -EINVAL; f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); goto restore_opts; @@ -2758,7 +2706,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) * or if background_gc = off is passed in mount * option. Also sync the filesystem. */ - if ((*flags & SB_RDONLY) || + if ((flags & SB_RDONLY) || (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && !test_opt(sbi, GC_MERGE))) { if (sbi->gc_thread) { @@ -2772,7 +2720,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) need_stop_gc = true; } - if (*flags & SB_RDONLY) { + if (flags & SB_RDONLY) { sync_inodes_sb(sb); set_sbi_flag(sbi, SBI_IS_DIRTY); @@ -2785,7 +2733,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) * We stop issue flush thread if FS is mounted as RO * or if flush_merge is not passed in mount option. */ - if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { + if ((flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { clear_opt(sbi, FLUSH_MERGE); f2fs_destroy_flush_cmd_control(sbi, false); need_restart_flush = true; @@ -2827,7 +2775,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) * triggered while remount and we need to take care of it before * returning from remount. */ - if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || + if ((flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || !test_opt(sbi, MERGE_CHECKPOINT)) { f2fs_stop_ckpt_thread(sbi); } else { @@ -2854,7 +2802,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); limit_reserve_root(sbi); - *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); + fc->sb_flags = (flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); sbi->umount_lock_holder = NULL; return 0; @@ -3523,7 +3471,6 @@ static const struct super_operations f2fs_sops = { .freeze_fs = f2fs_freeze, .unfreeze_fs = f2fs_unfreeze, .statfs = f2fs_statfs, - .remount_fs = f2fs_remount, .shutdown = f2fs_shutdown, }; @@ -4745,16 +4692,13 @@ static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) sbi->readdir_ra = true; } -static int f2fs_fill_super(struct super_block *sb, void *data, int silent) +static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) { struct f2fs_sb_info *sbi; struct f2fs_super_block *raw_super; - struct f2fs_fs_context ctx; - struct fs_context fc; struct inode *root; int err; bool skip_recovery = false, need_fsck = false; - char *options = NULL; int recovery, i, valid_super_block; struct curseg_info *seg_i; int retry_cnt = 1; @@ -4767,9 +4711,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) raw_super = NULL; valid_super_block = -1; recovery = 0; - memset(&fc, 0, sizeof(fc)); - memset(&ctx, 0, sizeof(ctx)); - fc.fs_private = &ctx; /* allocate memory for f2fs-specific super block info */ sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); @@ -4820,22 +4761,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) sizeof(raw_super->uuid)); default_options(sbi, false); - /* parse mount options */ - options = kstrdup((const char *)data, GFP_KERNEL); - if (data && !options) { - err = -ENOMEM; - goto free_sb_buf; - } - - err = parse_options(&fc, options); - if (err) - goto free_options; - err = f2fs_check_opt_consistency(&fc, sb); + err = f2fs_check_opt_consistency(fc, sb); if (err < 0) - goto free_options; + goto free_sb_buf; - f2fs_apply_options(&fc, sb); + f2fs_apply_options(fc, sb); sb->s_maxbytes = max_file_blocks(NULL) << le32_to_cpu(raw_super->log_blocksize); @@ -5160,7 +5091,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) if (err) goto sync_free_meta; } - kvfree(options); /* recover broken superblock */ if (recovery) { @@ -5255,7 +5185,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) kfree(F2FS_OPTION(sbi).s_qf_names[i]); #endif fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); - kvfree(options); free_sb_buf: kfree(raw_super); free_sbi: @@ -5271,14 +5200,39 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) return err; } -static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags, - const char *dev_name, void *data) +static int f2fs_get_tree(struct fs_context *fc) { - return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super); + return get_tree_bdev(fc, f2fs_fill_super); +} + +static int f2fs_reconfigure(struct fs_context *fc) +{ + struct super_block *sb = fc->root->d_sb; + + return __f2fs_remount(fc, sb); +} + +static void f2fs_fc_free(struct fs_context *fc) +{ + struct f2fs_fs_context *ctx = fc->fs_private; + int i; + + if (!ctx) + return; + +#ifdef CONFIG_QUOTA + for (i = 0; i < MAXQUOTAS; i++) + kfree(F2FS_CTX_INFO(ctx).s_qf_names[i]); +#endif + fscrypt_free_dummy_policy(&F2FS_CTX_INFO(ctx).dummy_enc_policy); + kfree(ctx); } static const struct fs_context_operations f2fs_context_ops = { .parse_param = f2fs_parse_param, + .get_tree = f2fs_get_tree, + .reconfigure = f2fs_reconfigure, + .free = f2fs_fc_free, }; static void kill_f2fs_super(struct super_block *sb) @@ -5322,10 +5276,24 @@ static void kill_f2fs_super(struct super_block *sb) } } +static int f2fs_init_fs_context(struct fs_context *fc) +{ + struct f2fs_fs_context *ctx; + + ctx = kzalloc(sizeof(struct f2fs_fs_context), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + fc->fs_private = ctx; + fc->ops = &f2fs_context_ops; + + return 0; +} + static struct file_system_type f2fs_fs_type = { .owner = THIS_MODULE, .name = "f2fs", - .mount = f2fs_mount, + .init_fs_context = f2fs_init_fs_context, .kill_sb = kill_f2fs_super, .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, }; -- 2.49.0