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
@@ -460,58 +461,47 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
460
461
}
461
462
462
463
enum {
463
- Opt_errors_ro , Opt_errors_zro , Opt_errors_zol , Opt_errors_repair ,
464
- Opt_explicit_open , Opt_err ,
464
+ Opt_errors , Opt_explicit_open ,
465
465
};
466
466
467
- static const match_table_t tokens = {
468
- { Opt_errors_ro , "errors=remount-ro" },
469
- { Opt_errors_zro , "errors=zone-ro" },
470
- { Opt_errors_zol , "errors=zone-offline" },
471
- { Opt_errors_repair , "errors=repair" },
472
- { Opt_explicit_open , "explicit-open" },
473
- { Opt_err , NULL }
467
+ struct zonefs_context {
468
+ unsigned long s_mount_opts ;
474
469
};
475
470
476
- static int zonefs_parse_options (struct super_block * sb , char * options )
477
- {
478
- struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
479
- substring_t args [MAX_OPT_ARGS ];
480
- char * p ;
481
-
482
- if (!options )
483
- return 0 ;
484
-
485
- while ((p = strsep (& options , "," )) != NULL ) {
486
- int token ;
471
+ static const struct constant_table zonefs_param_errors [] = {
472
+ {"remount-ro" , ZONEFS_MNTOPT_ERRORS_RO },
473
+ {"zone-ro" , ZONEFS_MNTOPT_ERRORS_ZRO },
474
+ {"zone-offline" , ZONEFS_MNTOPT_ERRORS_ZOL },
475
+ {"repair" , ZONEFS_MNTOPT_ERRORS_REPAIR },
476
+ {}
477
+ };
487
478
488
- if (!* p )
489
- continue ;
479
+ static const struct fs_parameter_spec zonefs_param_spec [] = {
480
+ fsparam_enum ("errors" , Opt_errors , zonefs_param_errors ),
481
+ fsparam_flag ("explicit-open" , Opt_explicit_open ),
482
+ {}
483
+ };
490
484
491
- token = match_token (p , tokens , args );
492
- switch (token ) {
493
- case Opt_errors_ro :
494
- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
495
- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_RO ;
496
- break ;
497
- case Opt_errors_zro :
498
- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
499
- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZRO ;
500
- break ;
501
- case Opt_errors_zol :
502
- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
503
- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZOL ;
504
- break ;
505
- case Opt_errors_repair :
506
- sbi -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
507
- sbi -> s_mount_opts |= ZONEFS_MNTOPT_ERRORS_REPAIR ;
508
- break ;
509
- case Opt_explicit_open :
510
- sbi -> s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN ;
511
- break ;
512
- default :
513
- return - EINVAL ;
514
- }
485
+ static int zonefs_parse_param (struct fs_context * fc , struct fs_parameter * param )
486
+ {
487
+ struct zonefs_context * ctx = fc -> fs_private ;
488
+ struct fs_parse_result result ;
489
+ int opt ;
490
+
491
+ opt = fs_parse (fc , zonefs_param_spec , param , & result );
492
+ if (opt < 0 )
493
+ return opt ;
494
+
495
+ switch (opt ) {
496
+ case Opt_errors :
497
+ ctx -> s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK ;
498
+ ctx -> s_mount_opts |= result .uint_32 ;
499
+ break ;
500
+ case Opt_explicit_open :
501
+ ctx -> s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN ;
502
+ break ;
503
+ default :
504
+ return - EINVAL ;
515
505
}
516
506
517
507
return 0 ;
@@ -533,13 +523,6 @@ static int zonefs_show_options(struct seq_file *seq, struct dentry *root)
533
523
return 0 ;
534
524
}
535
525
536
- static int zonefs_remount (struct super_block * sb , int * flags , char * data )
537
- {
538
- sync_filesystem (sb );
539
-
540
- return zonefs_parse_options (sb , data );
541
- }
542
-
543
526
static int zonefs_inode_setattr (struct mnt_idmap * idmap ,
544
527
struct dentry * dentry , struct iattr * iattr )
545
528
{
@@ -1195,7 +1178,6 @@ static const struct super_operations zonefs_sops = {
1195
1178
.alloc_inode = zonefs_alloc_inode ,
1196
1179
.free_inode = zonefs_free_inode ,
1197
1180
.statfs = zonefs_statfs ,
1198
- .remount_fs = zonefs_remount ,
1199
1181
.show_options = zonefs_show_options ,
1200
1182
};
1201
1183
@@ -1240,9 +1222,10 @@ static void zonefs_release_zgroup_inodes(struct super_block *sb)
1240
1222
* sub-directories and files according to the device zone configuration and
1241
1223
* format options.
1242
1224
*/
1243
- static int zonefs_fill_super (struct super_block * sb , void * data , int silent )
1225
+ static int zonefs_fill_super (struct super_block * sb , struct fs_context * fc )
1244
1226
{
1245
1227
struct zonefs_sb_info * sbi ;
1228
+ struct zonefs_context * ctx = fc -> fs_private ;
1246
1229
struct inode * inode ;
1247
1230
enum zonefs_ztype ztype ;
1248
1231
int ret ;
@@ -1279,7 +1262,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
1279
1262
sbi -> s_uid = GLOBAL_ROOT_UID ;
1280
1263
sbi -> s_gid = GLOBAL_ROOT_GID ;
1281
1264
sbi -> s_perm = 0640 ;
1282
- sbi -> s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO ;
1265
+ sbi -> s_mount_opts = ctx -> s_mount_opts ;
1283
1266
1284
1267
atomic_set (& sbi -> s_wro_seq_files , 0 );
1285
1268
sbi -> s_max_wro_seq_files = bdev_max_open_zones (sb -> s_bdev );
@@ -1290,10 +1273,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
1290
1273
if (ret )
1291
1274
return ret ;
1292
1275
1293
- ret = zonefs_parse_options (sb , data );
1294
- if (ret )
1295
- return ret ;
1296
-
1297
1276
zonefs_info (sb , "Mounting %u zones" , bdev_nr_zones (sb -> s_bdev ));
1298
1277
1299
1278
if (!sbi -> s_max_wro_seq_files &&
@@ -1354,12 +1333,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
1354
1333
return ret ;
1355
1334
}
1356
1335
1357
- static struct dentry * zonefs_mount (struct file_system_type * fs_type ,
1358
- int flags , const char * dev_name , void * data )
1359
- {
1360
- return mount_bdev (fs_type , flags , dev_name , data , zonefs_fill_super );
1361
- }
1362
-
1363
1336
static void zonefs_kill_super (struct super_block * sb )
1364
1337
{
1365
1338
struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
@@ -1374,15 +1347,65 @@ static void zonefs_kill_super(struct super_block *sb)
1374
1347
kfree (sbi );
1375
1348
}
1376
1349
1350
+ static void zonefs_free_fc (struct fs_context * fc )
1351
+ {
1352
+ struct zonefs_context * ctx = fc -> fs_private ;
1353
+
1354
+ kfree (ctx );
1355
+ }
1356
+
1357
+ static int zonefs_get_tree (struct fs_context * fc )
1358
+ {
1359
+ return get_tree_bdev (fc , zonefs_fill_super );
1360
+ }
1361
+
1362
+ static int zonefs_reconfigure (struct fs_context * fc )
1363
+ {
1364
+ struct zonefs_context * ctx = fc -> fs_private ;
1365
+ struct super_block * sb = fc -> root -> d_sb ;
1366
+ struct zonefs_sb_info * sbi = sb -> s_fs_info ;
1367
+
1368
+ sync_filesystem (fc -> root -> d_sb );
1369
+ /* Copy new options from ctx into sbi. */
1370
+ sbi -> s_mount_opts = ctx -> s_mount_opts ;
1371
+
1372
+ return 0 ;
1373
+ }
1374
+
1375
+ static const struct fs_context_operations zonefs_context_ops = {
1376
+ .parse_param = zonefs_parse_param ,
1377
+ .get_tree = zonefs_get_tree ,
1378
+ .reconfigure = zonefs_reconfigure ,
1379
+ .free = zonefs_free_fc ,
1380
+ };
1381
+
1382
+ /*
1383
+ * Set up the filesystem mount context.
1384
+ */
1385
+ static int zonefs_init_fs_context (struct fs_context * fc )
1386
+ {
1387
+ struct zonefs_context * ctx ;
1388
+
1389
+ ctx = kzalloc (sizeof (struct zonefs_context ), GFP_KERNEL );
1390
+ if (!ctx )
1391
+ return - ENOMEM ;
1392
+ ctx -> s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO ;
1393
+ fc -> ops = & zonefs_context_ops ;
1394
+ fc -> fs_private = ctx ;
1395
+
1396
+ return 0 ;
1397
+ }
1398
+
1377
1399
/*
1378
1400
* File system definition and registration.
1379
1401
*/
1380
1402
static struct file_system_type zonefs_type = {
1381
- .owner = THIS_MODULE ,
1382
- .name = "zonefs" ,
1383
- .mount = zonefs_mount ,
1384
- .kill_sb = zonefs_kill_super ,
1385
- .fs_flags = FS_REQUIRES_DEV ,
1403
+ .owner = THIS_MODULE ,
1404
+ .name = "zonefs" ,
1405
+ .kill_sb = zonefs_kill_super ,
1406
+ .fs_flags = FS_REQUIRES_DEV ,
1407
+ .init_fs_context = zonefs_init_fs_context ,
1408
+ .parameters = zonefs_param_spec ,
1386
1409
};
1387
1410
1388
1411
static int __init zonefs_init_inodecache (void )
0 commit comments