Skip to content

Commit 567e629

Browse files
Bill O'Donnelldamien-lemoal
authored andcommitted
zonefs: convert zonefs to use the new mount api
Convert the zonefs filesystem to use the new mount API. Tested using the zonefs test suite from: https://github.com/damien-lemoal/zonefs-tools Signed-off-by: Bill O'Donnell <[email protected]> Reviewed-by: Ian Kent <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 841c351 commit 567e629

File tree

1 file changed

+95
-72
lines changed

1 file changed

+95
-72
lines changed

fs/zonefs/super.c

Lines changed: 95 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
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

@@ -460,58 +461,47 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
460461
}
461462

462463
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,
465465
};
466466

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;
474469
};
475470

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+
};
487478

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+
};
490484

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;
515505
}
516506

517507
return 0;
@@ -533,13 +523,6 @@ static int zonefs_show_options(struct seq_file *seq, struct dentry *root)
533523
return 0;
534524
}
535525

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-
543526
static int zonefs_inode_setattr(struct mnt_idmap *idmap,
544527
struct dentry *dentry, struct iattr *iattr)
545528
{
@@ -1195,7 +1178,6 @@ static const struct super_operations zonefs_sops = {
11951178
.alloc_inode = zonefs_alloc_inode,
11961179
.free_inode = zonefs_free_inode,
11971180
.statfs = zonefs_statfs,
1198-
.remount_fs = zonefs_remount,
11991181
.show_options = zonefs_show_options,
12001182
};
12011183

@@ -1240,9 +1222,10 @@ static void zonefs_release_zgroup_inodes(struct super_block *sb)
12401222
* sub-directories and files according to the device zone configuration and
12411223
* format options.
12421224
*/
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)
12441226
{
12451227
struct zonefs_sb_info *sbi;
1228+
struct zonefs_context *ctx = fc->fs_private;
12461229
struct inode *inode;
12471230
enum zonefs_ztype ztype;
12481231
int ret;
@@ -1279,7 +1262,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
12791262
sbi->s_uid = GLOBAL_ROOT_UID;
12801263
sbi->s_gid = GLOBAL_ROOT_GID;
12811264
sbi->s_perm = 0640;
1282-
sbi->s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO;
1265+
sbi->s_mount_opts = ctx->s_mount_opts;
12831266

12841267
atomic_set(&sbi->s_wro_seq_files, 0);
12851268
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)
12901273
if (ret)
12911274
return ret;
12921275

1293-
ret = zonefs_parse_options(sb, data);
1294-
if (ret)
1295-
return ret;
1296-
12971276
zonefs_info(sb, "Mounting %u zones", bdev_nr_zones(sb->s_bdev));
12981277

12991278
if (!sbi->s_max_wro_seq_files &&
@@ -1354,12 +1333,6 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
13541333
return ret;
13551334
}
13561335

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-
13631336
static void zonefs_kill_super(struct super_block *sb)
13641337
{
13651338
struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
@@ -1374,15 +1347,65 @@ static void zonefs_kill_super(struct super_block *sb)
13741347
kfree(sbi);
13751348
}
13761349

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+
13771399
/*
13781400
* File system definition and registration.
13791401
*/
13801402
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,
13861409
};
13871410

13881411
static int __init zonefs_init_inodecache(void)

0 commit comments

Comments
 (0)