@@ -532,6 +532,14 @@ static int f2fs_unnote_qf_name(struct fs_context *fc, int qtype)
532532 ctx -> qname_mask |= 1 << qtype ;
533533 return 0 ;
534534}
535+
536+ static void f2fs_unnote_qf_name_all (struct fs_context * fc )
537+ {
538+ int i ;
539+
540+ for (i = 0 ; i < MAXQUOTAS ; i ++ )
541+ f2fs_unnote_qf_name (fc , i );
542+ }
535543#endif
536544
537545static int f2fs_parse_test_dummy_encryption (const struct fs_parameter * param ,
@@ -1139,47 +1147,6 @@ static int f2fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
11391147 return 0 ;
11401148}
11411149
1142- static int parse_options (struct fs_context * fc , char * options )
1143- {
1144- struct fs_parameter param ;
1145- char * key ;
1146- int ret ;
1147-
1148- if (!options )
1149- return 0 ;
1150-
1151- while ((key = strsep (& options , "," )) != NULL ) {
1152- if (* key ) {
1153- size_t v_len = 0 ;
1154- char * value = strchr (key , '=' );
1155-
1156- param .type = fs_value_is_flag ;
1157- param .string = NULL ;
1158-
1159- if (value ) {
1160- if (value == key )
1161- continue ;
1162-
1163- * value ++ = 0 ;
1164- v_len = strlen (value );
1165- param .string = kmemdup_nul (value , v_len , GFP_KERNEL );
1166- if (!param .string )
1167- return - ENOMEM ;
1168- param .type = fs_value_is_string ;
1169- }
1170-
1171- param .key = key ;
1172- param .size = v_len ;
1173-
1174- ret = f2fs_parse_param (fc , & param );
1175- kfree (param .string );
1176- if (ret < 0 )
1177- return ret ;
1178- }
1179- }
1180- return 0 ;
1181- }
1182-
11831150/*
11841151 * Check quota settings consistency.
11851152 */
@@ -2621,13 +2588,12 @@ static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
26212588 f2fs_flush_ckpt_thread (sbi );
26222589}
26232590
2624- static int f2fs_remount (struct super_block * sb , int * flags , char * data )
2591+ static int __f2fs_remount (struct fs_context * fc , struct super_block * sb )
26252592{
26262593 struct f2fs_sb_info * sbi = F2FS_SB (sb );
26272594 struct f2fs_mount_info org_mount_opt ;
2628- struct f2fs_fs_context ctx ;
2629- struct fs_context fc ;
26302595 unsigned long old_sb_flags ;
2596+ unsigned int flags = fc -> sb_flags ;
26312597 int err ;
26322598 bool need_restart_gc = false, need_stop_gc = false;
26332599 bool need_restart_flush = false, need_stop_flush = false;
@@ -2673,7 +2639,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
26732639#endif
26742640
26752641 /* recover superblocks we couldn't write due to previous RO mount */
2676- if (!(* flags & SB_RDONLY ) && is_sbi_flag_set (sbi , SBI_NEED_SB_WRITE )) {
2642+ if (!(flags & SB_RDONLY ) && is_sbi_flag_set (sbi , SBI_NEED_SB_WRITE )) {
26772643 err = f2fs_commit_super (sbi , false);
26782644 f2fs_info (sbi , "Try to recover all the superblocks, ret: %d" ,
26792645 err );
@@ -2683,21 +2649,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
26832649
26842650 default_options (sbi , true);
26852651
2686- memset (& fc , 0 , sizeof (fc ));
2687- memset (& ctx , 0 , sizeof (ctx ));
2688- fc .fs_private = & ctx ;
2689- fc .purpose = FS_CONTEXT_FOR_RECONFIGURE ;
2690-
2691- /* parse mount options */
2692- err = parse_options (& fc , data );
2652+ err = f2fs_check_opt_consistency (fc , sb );
26932653 if (err )
26942654 goto restore_opts ;
26952655
2696- err = f2fs_check_opt_consistency (& fc , sb );
2697- if (err )
2698- goto restore_opts ;
2699-
2700- f2fs_apply_options (& fc , sb );
2656+ f2fs_apply_options (fc , sb );
27012657
27022658 err = f2fs_sanity_check_options (sbi , true);
27032659 if (err )
@@ -2710,20 +2666,20 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
27102666 * Previous and new state of filesystem is RO,
27112667 * so skip checking GC and FLUSH_MERGE conditions.
27122668 */
2713- if (f2fs_readonly (sb ) && (* flags & SB_RDONLY ))
2669+ if (f2fs_readonly (sb ) && (flags & SB_RDONLY ))
27142670 goto skip ;
27152671
2716- if (f2fs_dev_is_readonly (sbi ) && !(* flags & SB_RDONLY )) {
2672+ if (f2fs_dev_is_readonly (sbi ) && !(flags & SB_RDONLY )) {
27172673 err = - EROFS ;
27182674 goto restore_opts ;
27192675 }
27202676
27212677#ifdef CONFIG_QUOTA
2722- if (!f2fs_readonly (sb ) && (* flags & SB_RDONLY )) {
2678+ if (!f2fs_readonly (sb ) && (flags & SB_RDONLY )) {
27232679 err = dquot_suspend (sb , -1 );
27242680 if (err < 0 )
27252681 goto restore_opts ;
2726- } else if (f2fs_readonly (sb ) && !(* flags & SB_RDONLY )) {
2682+ } else if (f2fs_readonly (sb ) && !(flags & SB_RDONLY )) {
27272683 /* dquot_resume needs RW */
27282684 sb -> s_flags &= ~SB_RDONLY ;
27292685 if (sb_any_quota_suspended (sb )) {
@@ -2773,7 +2729,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
27732729 goto restore_opts ;
27742730 }
27752731
2776- if ((* flags & SB_RDONLY ) && test_opt (sbi , DISABLE_CHECKPOINT )) {
2732+ if ((flags & SB_RDONLY ) && test_opt (sbi , DISABLE_CHECKPOINT )) {
27772733 err = - EINVAL ;
27782734 f2fs_warn (sbi , "disabling checkpoint not compatible with read-only" );
27792735 goto restore_opts ;
@@ -2784,7 +2740,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
27842740 * or if background_gc = off is passed in mount
27852741 * option. Also sync the filesystem.
27862742 */
2787- if ((* flags & SB_RDONLY ) ||
2743+ if ((flags & SB_RDONLY ) ||
27882744 (F2FS_OPTION (sbi ).bggc_mode == BGGC_MODE_OFF &&
27892745 !test_opt (sbi , GC_MERGE ))) {
27902746 if (sbi -> gc_thread ) {
@@ -2798,7 +2754,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
27982754 need_stop_gc = true;
27992755 }
28002756
2801- if (* flags & SB_RDONLY ) {
2757+ if (flags & SB_RDONLY ) {
28022758 sync_inodes_sb (sb );
28032759
28042760 set_sbi_flag (sbi , SBI_IS_DIRTY );
@@ -2811,7 +2767,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
28112767 * We stop issue flush thread if FS is mounted as RO
28122768 * or if flush_merge is not passed in mount option.
28132769 */
2814- if ((* flags & SB_RDONLY ) || !test_opt (sbi , FLUSH_MERGE )) {
2770+ if ((flags & SB_RDONLY ) || !test_opt (sbi , FLUSH_MERGE )) {
28152771 clear_opt (sbi , FLUSH_MERGE );
28162772 f2fs_destroy_flush_cmd_control (sbi , false);
28172773 need_restart_flush = true;
@@ -2853,7 +2809,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
28532809 * triggered while remount and we need to take care of it before
28542810 * returning from remount.
28552811 */
2856- if ((* flags & SB_RDONLY ) || test_opt (sbi , DISABLE_CHECKPOINT ) ||
2812+ if ((flags & SB_RDONLY ) || test_opt (sbi , DISABLE_CHECKPOINT ) ||
28572813 !test_opt (sbi , MERGE_CHECKPOINT )) {
28582814 f2fs_stop_ckpt_thread (sbi );
28592815 } else {
@@ -2880,7 +2836,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
28802836 (test_opt (sbi , POSIX_ACL ) ? SB_POSIXACL : 0 );
28812837
28822838 limit_reserve_root (sbi );
2883- * flags = (* flags & ~SB_LAZYTIME ) | (sb -> s_flags & SB_LAZYTIME );
2839+ fc -> sb_flags = (flags & ~SB_LAZYTIME ) | (sb -> s_flags & SB_LAZYTIME );
28842840
28852841 sbi -> umount_lock_holder = NULL ;
28862842 return 0 ;
@@ -3551,7 +3507,6 @@ static const struct super_operations f2fs_sops = {
35513507 .freeze_fs = f2fs_freeze ,
35523508 .unfreeze_fs = f2fs_unfreeze ,
35533509 .statfs = f2fs_statfs ,
3554- .remount_fs = f2fs_remount ,
35553510 .shutdown = f2fs_shutdown ,
35563511};
35573512
@@ -4811,16 +4766,14 @@ static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
48114766 sbi -> readdir_ra = true;
48124767}
48134768
4814- static int f2fs_fill_super (struct super_block * sb , void * data , int silent )
4769+ static int f2fs_fill_super (struct super_block * sb , struct fs_context * fc )
48154770{
4771+ struct f2fs_fs_context * ctx = fc -> fs_private ;
48164772 struct f2fs_sb_info * sbi ;
48174773 struct f2fs_super_block * raw_super ;
4818- struct f2fs_fs_context ctx ;
4819- struct fs_context fc ;
48204774 struct inode * root ;
48214775 int err ;
48224776 bool skip_recovery = false, need_fsck = false;
4823- char * options = NULL ;
48244777 int recovery , i , valid_super_block ;
48254778 struct curseg_info * seg_i ;
48264779 int retry_cnt = 1 ;
@@ -4833,9 +4786,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
48334786 raw_super = NULL ;
48344787 valid_super_block = -1 ;
48354788 recovery = 0 ;
4836- memset (& fc , 0 , sizeof (fc ));
4837- memset (& ctx , 0 , sizeof (ctx ));
4838- fc .fs_private = & ctx ;
48394789
48404790 /* allocate memory for f2fs-specific super block info */
48414791 sbi = kzalloc (sizeof (struct f2fs_sb_info ), GFP_KERNEL );
@@ -4886,22 +4836,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
48864836 sizeof (raw_super -> uuid ));
48874837
48884838 default_options (sbi , false);
4889- /* parse mount options */
4890- options = kstrdup ((const char * )data , GFP_KERNEL );
4891- if (data && !options ) {
4892- err = - ENOMEM ;
4893- goto free_sb_buf ;
4894- }
48954839
4896- err = parse_options ( & fc , options );
4840+ err = f2fs_check_opt_consistency ( fc , sb );
48974841 if (err )
4898- goto free_options ;
4899-
4900- err = f2fs_check_opt_consistency (& fc , sb );
4901- if (err )
4902- goto free_options ;
4842+ goto free_sb_buf ;
49034843
4904- f2fs_apply_options (& fc , sb );
4844+ f2fs_apply_options (fc , sb );
49054845
49064846 err = f2fs_sanity_check_options (sbi , false);
49074847 if (err )
@@ -5234,7 +5174,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
52345174 if (err )
52355175 goto sync_free_meta ;
52365176 }
5237- kfree (options );
52385177
52395178 /* recover broken superblock */
52405179 if (recovery ) {
@@ -5329,8 +5268,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
53295268 kfree (F2FS_OPTION (sbi ).s_qf_names [i ]);
53305269#endif
53315270 /* no need to free dummy_enc_policy, we just keep it in ctx when failed */
5332- swap (F2FS_CTX_INFO (& ctx ).dummy_enc_policy , F2FS_OPTION (sbi ).dummy_enc_policy );
5333- kfree (options );
5271+ swap (F2FS_CTX_INFO (ctx ).dummy_enc_policy , F2FS_OPTION (sbi ).dummy_enc_policy );
53345272free_sb_buf :
53355273 kfree (raw_super );
53365274free_sbi :
@@ -5346,14 +5284,37 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
53465284 return err ;
53475285}
53485286
5349- static struct dentry * f2fs_mount (struct file_system_type * fs_type , int flags ,
5350- const char * dev_name , void * data )
5287+ static int f2fs_get_tree (struct fs_context * fc )
5288+ {
5289+ return get_tree_bdev (fc , f2fs_fill_super );
5290+ }
5291+
5292+ static int f2fs_reconfigure (struct fs_context * fc )
5293+ {
5294+ struct super_block * sb = fc -> root -> d_sb ;
5295+
5296+ return __f2fs_remount (fc , sb );
5297+ }
5298+
5299+ static void f2fs_fc_free (struct fs_context * fc )
53515300{
5352- return mount_bdev (fs_type , flags , dev_name , data , f2fs_fill_super );
5301+ struct f2fs_fs_context * ctx = fc -> fs_private ;
5302+
5303+ if (!ctx )
5304+ return ;
5305+
5306+ #ifdef CONFIG_QUOTA
5307+ f2fs_unnote_qf_name_all (fc );
5308+ #endif
5309+ fscrypt_free_dummy_policy (& F2FS_CTX_INFO (ctx ).dummy_enc_policy );
5310+ kfree (ctx );
53535311}
53545312
53555313static const struct fs_context_operations f2fs_context_ops = {
53565314 .parse_param = f2fs_parse_param ,
5315+ .get_tree = f2fs_get_tree ,
5316+ .reconfigure = f2fs_reconfigure ,
5317+ .free = f2fs_fc_free ,
53575318};
53585319
53595320static void kill_f2fs_super (struct super_block * sb )
@@ -5397,10 +5358,24 @@ static void kill_f2fs_super(struct super_block *sb)
53975358 }
53985359}
53995360
5361+ static int f2fs_init_fs_context (struct fs_context * fc )
5362+ {
5363+ struct f2fs_fs_context * ctx ;
5364+
5365+ ctx = kzalloc (sizeof (struct f2fs_fs_context ), GFP_KERNEL );
5366+ if (!ctx )
5367+ return - ENOMEM ;
5368+
5369+ fc -> fs_private = ctx ;
5370+ fc -> ops = & f2fs_context_ops ;
5371+
5372+ return 0 ;
5373+ }
5374+
54005375static struct file_system_type f2fs_fs_type = {
54015376 .owner = THIS_MODULE ,
54025377 .name = "f2fs" ,
5403- .mount = f2fs_mount ,
5378+ .init_fs_context = f2fs_init_fs_context ,
54045379 .kill_sb = kill_f2fs_super ,
54055380 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP ,
54065381};
0 commit comments