15
15
#include <linux/writeback.h>
16
16
#include <linux/quotaops.h>
17
17
#include <linux/seq_file.h>
18
- #include <linux/parser.h>
19
18
#include <linux/uio.h>
20
19
#include <linux/mman.h>
21
20
#include <linux/sched/mm.h>
22
21
#include <linux/crc32.h>
23
22
#include <linux/task_io_accounting_ops.h>
23
+ #include <linux/fs_parser.h>
24
+ #include <linux/fs_context.h>
24
25
25
26
#include "zonefs.h"
26
27
@@ -470,58 +471,47 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
470
471
}
471
472
472
473
enum {
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 ,
475
475
};
476
476
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 ;
484
479
};
485
480
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
+ };
497
488
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
+ };
500
494
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 ;
525
515
}
526
516
527
517
return 0 ;
@@ -543,13 +533,6 @@ static int zonefs_show_options(struct seq_file *seq, struct dentry *root)
543
533
return 0 ;
544
534
}
545
535
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
-
553
536
static int zonefs_inode_setattr (struct mnt_idmap * idmap ,
554
537
struct dentry * dentry , struct iattr * iattr )
555
538
{
@@ -1205,7 +1188,6 @@ static const struct super_operations zonefs_sops = {
1205
1188
.alloc_inode = zonefs_alloc_inode ,
1206
1189
.free_inode = zonefs_free_inode ,
1207
1190
.statfs = zonefs_statfs ,
1208
- .remount_fs = zonefs_remount ,
1209
1191
.show_options = zonefs_show_options ,
1210
1192
};
1211
1193
@@ -1250,9 +1232,10 @@ static void zonefs_release_zgroup_inodes(struct super_block *sb)
1250
1232
* sub-directories and files according to the device zone configuration and
1251
1233
* format options.
1252
1234
*/
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 )
1254
1236
{
1255
1237
struct zonefs_sb_info * sbi ;
1238
+ struct zonefs_context * ctx = fc -> fs_private ;
1256
1239
struct inode * inode ;
1257
1240
enum zonefs_ztype ztype ;
1258
1241
int ret ;
@@ -1289,7 +1272,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
1289
1272
sbi -> s_uid = GLOBAL_ROOT_UID ;
1290
1273
sbi -> s_gid = GLOBAL_ROOT_GID ;
1291
1274
sbi -> s_perm = 0640 ;
1292
- sbi -> s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO ;
1275
+ sbi -> s_mount_opts = ctx -> s_mount_opts ;
1293
1276
1294
1277
atomic_set (& sbi -> s_wro_seq_files , 0 );
1295
1278
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)
1300
1283
if (ret )
1301
1284
return ret ;
1302
1285
1303
- ret = zonefs_parse_options (sb , data );
1304
- if (ret )
1305
- return ret ;
1306
-
1307
1286
zonefs_info (sb , "Mounting %u zones" , bdev_nr_zones (sb -> s_bdev ));
1308
1287
1309
1288
if (!sbi -> s_max_wro_seq_files &&
@@ -1364,12 +1343,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
1364
1343
return ret ;
1365
1344
}
1366
1345
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
-
1373
1346
static void zonefs_kill_super (struct super_block * sb )
1374
1347
{
1375
1348
struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
@@ -1384,15 +1357,65 @@ static void zonefs_kill_super(struct super_block *sb)
1384
1357
kfree (sbi );
1385
1358
}
1386
1359
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
+
1387
1409
/*
1388
1410
* File system definition and registration.
1389
1411
*/
1390
1412
static 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 ,
1396
1419
};
1397
1420
1398
1421
static int __init zonefs_init_inodecache (void )
0 commit comments