1515#include <linux/writeback.h>
1616#include <linux/quotaops.h>
1717#include <linux/seq_file.h>
18- #include <linux/parser.h>
1918#include <linux/uio.h>
2019#include <linux/mman.h>
2120#include <linux/sched/mm.h>
2221#include <linux/crc32.h>
2322#include <linux/task_io_accounting_ops.h>
23+ #include <linux/fs_parser.h>
24+ #include <linux/fs_context.h>
2425
2526#include "zonefs.h"
2627
@@ -470,58 +471,47 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
470471}
471472
472473enum {
473- Opt_errors_ro , Opt_errors_zro , Opt_errors_zol , Opt_errors_repair ,
474- Opt_explicit_open , Opt_err ,
474+ Opt_errors , Opt_explicit_open ,
475475};
476476
477- static const match_table_t tokens = {
478- { Opt_errors_ro , "errors=remount-ro" },
479- { Opt_errors_zro , "errors=zone-ro" },
480- { Opt_errors_zol , "errors=zone-offline" },
481- { Opt_errors_repair , "errors=repair" },
482- { Opt_explicit_open , "explicit-open" },
483- { Opt_err , NULL }
477+ struct zonefs_context {
478+ unsigned long s_mount_opts ;
484479};
485480
486- static int zonefs_parse_options (struct super_block * sb , char * options )
487- {
488- struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
489- substring_t args [MAX_OPT_ARGS ];
490- char * p ;
491-
492- if (!options )
493- return 0 ;
494-
495- while ((p = strsep (& options , "," )) != NULL ) {
496- int token ;
481+ static const struct constant_table zonefs_param_errors [] = {
482+ {"remount-ro" , ZONEFS_MNTOPT_ERRORS_RO },
483+ {"zone-ro" , ZONEFS_MNTOPT_ERRORS_ZRO },
484+ {"zone-offline" , ZONEFS_MNTOPT_ERRORS_ZOL },
485+ {"repair" , ZONEFS_MNTOPT_ERRORS_REPAIR },
486+ {}
487+ };
497488
498- if (!* p )
499- continue ;
489+ static const struct fs_parameter_spec zonefs_param_spec [] = {
490+ fsparam_enum ("errors" , Opt_errors , zonefs_param_errors ),
491+ fsparam_flag ("explicit-open" , Opt_explicit_open ),
492+ {}
493+ };
500494
501- token = match_token (p , tokens , args );
502- switch (token ) {
503- case Opt_errors_ro :
504- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
505- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_RO ;
506- break ;
507- case Opt_errors_zro :
508- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
509- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZRO ;
510- break ;
511- case Opt_errors_zol :
512- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
513- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZOL ;
514- break ;
515- case Opt_errors_repair :
516- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
517- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_REPAIR ;
518- break ;
519- case Opt_explicit_open :
520- sbi -> s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN ;
521- break ;
522- default :
523- return - EINVAL ;
524- }
495+ static int zonefs_parse_param (struct fs_context * fc , struct fs_parameter * param )
496+ {
497+ struct zonefs_context * ctx = fc -> fs_private ;
498+ struct fs_parse_result result ;
499+ int opt ;
500+
501+ opt = fs_parse (fc , zonefs_param_spec , param , & result );
502+ if (opt < 0 )
503+ return opt ;
504+
505+ switch (opt ) {
506+ case Opt_errors :
507+ ctx -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
508+ ctx -> s_mount_opts |= result .uint_32 ;
509+ break ;
510+ case Opt_explicit_open :
511+ ctx -> s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN ;
512+ break ;
513+ default :
514+ return - EINVAL ;
525515 }
526516
527517 return 0 ;
@@ -543,13 +533,6 @@ static int zonefs_show_options(struct seq_file *seq, struct dentry *root)
543533 return 0 ;
544534}
545535
546- static int zonefs_remount (struct super_block * sb , int * flags , char * data )
547- {
548- sync_filesystem (sb );
549-
550- return zonefs_parse_options (sb , data );
551- }
552-
553536static int zonefs_inode_setattr (struct mnt_idmap * idmap ,
554537 struct dentry * dentry , struct iattr * iattr )
555538{
@@ -1205,7 +1188,6 @@ static const struct super_operations zonefs_sops = {
12051188 .alloc_inode = zonefs_alloc_inode ,
12061189 .free_inode = zonefs_free_inode ,
12071190 .statfs = zonefs_statfs ,
1208- .remount_fs = zonefs_remount ,
12091191 .show_options = zonefs_show_options ,
12101192};
12111193
@@ -1250,9 +1232,10 @@ static void zonefs_release_zgroup_inodes(struct super_block *sb)
12501232 * sub-directories and files according to the device zone configuration and
12511233 * format options.
12521234 */
1253- static int zonefs_fill_super (struct super_block * sb , void * data , int silent )
1235+ static int zonefs_fill_super (struct super_block * sb , struct fs_context * fc )
12541236{
12551237 struct zonefs_sb_info * sbi ;
1238+ struct zonefs_context * ctx = fc -> fs_private ;
12561239 struct inode * inode ;
12571240 enum zonefs_ztype ztype ;
12581241 int ret ;
@@ -1289,7 +1272,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
12891272 sbi -> s_uid = GLOBAL_ROOT_UID ;
12901273 sbi -> s_gid = GLOBAL_ROOT_GID ;
12911274 sbi -> s_perm = 0640 ;
1292- sbi -> s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO ;
1275+ sbi -> s_mount_opts = ctx -> s_mount_opts ;
12931276
12941277 atomic_set (& sbi -> s_wro_seq_files , 0 );
12951278 sbi -> s_max_wro_seq_files = bdev_max_open_zones (sb -> s_bdev );
@@ -1300,10 +1283,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
13001283 if (ret )
13011284 return ret ;
13021285
1303- ret = zonefs_parse_options (sb , data );
1304- if (ret )
1305- return ret ;
1306-
13071286 zonefs_info (sb , "Mounting %u zones" , bdev_nr_zones (sb -> s_bdev ));
13081287
13091288 if (!sbi -> s_max_wro_seq_files &&
@@ -1364,12 +1343,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
13641343 return ret ;
13651344}
13661345
1367- static struct dentry * zonefs_mount (struct file_system_type * fs_type ,
1368- int flags , const char * dev_name , void * data )
1369- {
1370- return mount_bdev (fs_type , flags , dev_name , data , zonefs_fill_super );
1371- }
1372-
13731346static void zonefs_kill_super (struct super_block * sb )
13741347{
13751348 struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
@@ -1384,15 +1357,65 @@ static void zonefs_kill_super(struct super_block *sb)
13841357 kfree (sbi );
13851358}
13861359
1360+ static void zonefs_free_fc (struct fs_context * fc )
1361+ {
1362+ struct zonefs_context * ctx = fc -> fs_private ;
1363+
1364+ kfree (ctx );
1365+ }
1366+
1367+ static int zonefs_get_tree (struct fs_context * fc )
1368+ {
1369+ return get_tree_bdev (fc , zonefs_fill_super );
1370+ }
1371+
1372+ static int zonefs_reconfigure (struct fs_context * fc )
1373+ {
1374+ struct zonefs_context * ctx = fc -> fs_private ;
1375+ struct super_block * sb = fc -> root -> d_sb ;
1376+ struct zonefs_sb_info * sbi = sb -> s_fs_info ;
1377+
1378+ sync_filesystem (fc -> root -> d_sb );
1379+ /* Copy new options from ctx into sbi. */
1380+ sbi -> s_mount_opts = ctx -> s_mount_opts ;
1381+
1382+ return 0 ;
1383+ }
1384+
1385+ static const struct fs_context_operations zonefs_context_ops = {
1386+ .parse_param = zonefs_parse_param ,
1387+ .get_tree = zonefs_get_tree ,
1388+ .reconfigure = zonefs_reconfigure ,
1389+ .free = zonefs_free_fc ,
1390+ };
1391+
1392+ /*
1393+ * Set up the filesystem mount context.
1394+ */
1395+ static int zonefs_init_fs_context (struct fs_context * fc )
1396+ {
1397+ struct zonefs_context * ctx ;
1398+
1399+ ctx = kzalloc (sizeof (struct zonefs_context ), GFP_KERNEL );
1400+ if (!ctx )
1401+ return - ENOMEM ;
1402+ ctx -> s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO ;
1403+ fc -> ops = & zonefs_context_ops ;
1404+ fc -> fs_private = ctx ;
1405+
1406+ return 0 ;
1407+ }
1408+
13871409/*
13881410 * File system definition and registration.
13891411 */
13901412static struct file_system_type zonefs_type = {
1391- .owner = THIS_MODULE ,
1392- .name = "zonefs" ,
1393- .mount = zonefs_mount ,
1394- .kill_sb = zonefs_kill_super ,
1395- .fs_flags = FS_REQUIRES_DEV ,
1413+ .owner = THIS_MODULE ,
1414+ .name = "zonefs" ,
1415+ .kill_sb = zonefs_kill_super ,
1416+ .fs_flags = FS_REQUIRES_DEV ,
1417+ .init_fs_context = zonefs_init_fs_context ,
1418+ .parameters = zonefs_param_spec ,
13961419};
13971420
13981421static int __init zonefs_init_inodecache (void )
0 commit comments