From 2710c957a8ef4fb00f21acb306e3bd6bcf80c81f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 6 Sep 2019 22:12:08 -0400 Subject: fs_parse: get rid of ->enums Don't do a single array; attach them to fsparam_enum() entry instead. And don't bother trying to embed the names into those - it actually loses memory, with no real speedup worth mentioning. Simplifies validation as well. Signed-off-by: Al Viro --- fs/afs/super.c | 19 +++++++------- fs/ceph/super.c | 11 ++++---- fs/fs_parser.c | 72 +++++++--------------------------------------------- fs/gfs2/ops_fstype.c | 38 ++++++++++++++++----------- fs/jffs2/super.c | 21 ++++++++------- fs/nfs/fs_context.c | 62 ++++++++++++++++++++++---------------------- 6 files changed, 88 insertions(+), 135 deletions(-) (limited to 'fs') diff --git a/fs/afs/super.c b/fs/afs/super.c index 7f8a9b3137bf..42bf63b82007 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c @@ -73,26 +73,25 @@ enum afs_param { Opt_source, }; +static const struct fs_parameter_enum afs_param_flock[] = { + {"local", afs_flock_mode_local }, + {"openafs", afs_flock_mode_openafs }, + {"strict", afs_flock_mode_strict }, + {"write", afs_flock_mode_write }, + {} +}; + static const struct fs_parameter_spec afs_param_specs[] = { fsparam_flag ("autocell", Opt_autocell), fsparam_flag ("dyn", Opt_dyn), - fsparam_enum ("flock", Opt_flock), + fsparam_enum ("flock", Opt_flock, afs_param_flock), fsparam_string("source", Opt_source), {} }; -static const struct fs_parameter_enum afs_param_enums[] = { - { Opt_flock, "local", afs_flock_mode_local }, - { Opt_flock, "openafs", afs_flock_mode_openafs }, - { Opt_flock, "strict", afs_flock_mode_strict }, - { Opt_flock, "write", afs_flock_mode_write }, - {} -}; - static const struct fs_parameter_description afs_fs_parameters = { .name = "kAFS", .specs = afs_param_specs, - .enums = afs_param_enums, }; /* diff --git a/fs/ceph/super.c b/fs/ceph/super.c index 29a795f975df..0f7c8913bb20 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c @@ -163,9 +163,9 @@ enum ceph_recover_session_mode { ceph_recover_session_clean }; -static const struct fs_parameter_enum ceph_mount_param_enums[] = { - { Opt_recover_session, "no", ceph_recover_session_no }, - { Opt_recover_session, "clean", ceph_recover_session_clean }, +static const struct fs_parameter_enum ceph_param_recover[] = { + { "no", ceph_recover_session_no }, + { "clean", ceph_recover_session_clean }, {} }; @@ -180,7 +180,7 @@ static const struct fs_parameter_spec ceph_mount_param_specs[] = { fsparam_flag_no ("dcache", Opt_dcache), fsparam_flag_no ("dirstat", Opt_dirstat), __fsparam (fs_param_is_string, "fsc", Opt_fscache, - fs_param_neg_with_no | fs_param_v_optional), + fs_param_neg_with_no | fs_param_v_optional, NULL), fsparam_flag_no ("ino32", Opt_ino32), fsparam_string ("mds_namespace", Opt_mds_namespace), fsparam_flag_no ("poolperm", Opt_poolperm), @@ -189,7 +189,7 @@ static const struct fs_parameter_spec ceph_mount_param_specs[] = { fsparam_flag_no ("rbytes", Opt_rbytes), fsparam_u32 ("readdir_max_bytes", Opt_readdir_max_bytes), fsparam_u32 ("readdir_max_entries", Opt_readdir_max_entries), - fsparam_enum ("recover_session", Opt_recover_session), + fsparam_enum ("recover_session", Opt_recover_session, ceph_param_recover), fsparam_flag_no ("require_active_mds", Opt_require_active_mds), fsparam_u32 ("rsize", Opt_rsize), fsparam_string ("snapdirname", Opt_snapdirname), @@ -201,7 +201,6 @@ static const struct fs_parameter_spec ceph_mount_param_specs[] = { static const struct fs_parameter_description ceph_mount_parameters = { .name = "ceph", .specs = ceph_mount_param_specs, - .enums = ceph_mount_param_enums, }; struct ceph_parse_opts_ctx { diff --git a/fs/fs_parser.c b/fs/fs_parser.c index 07ae041b83a8..34275191697f 100644 --- a/fs/fs_parser.c +++ b/fs/fs_parser.c @@ -189,9 +189,8 @@ int fs_parse(struct fs_context *fc, goto maybe_okay; case fs_param_is_enum: - for (e = desc->enums; e->name[0]; e++) { - if (e->opt == p->opt && - strcmp(e->name, param->string) == 0) { + for (e = p->data; e->name; e++) { + if (strcmp(e->name, param->string) == 0) { result->uint_32 = e->value; goto okay; } @@ -359,10 +358,8 @@ bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size, bool fs_validate_description(const struct fs_parameter_description *desc) { const struct fs_parameter_spec *param, *p2; - const struct fs_parameter_enum *e; const char *name = desc->name; - unsigned int nr_params = 0; - bool good = true, enums = false; + bool good = true; pr_notice("*** VALIDATE %s ***\n", name); @@ -383,7 +380,12 @@ bool fs_validate_description(const struct fs_parameter_description *desc) name, param->name, t); good = false; } else if (t == fs_param_is_enum) { - enums = true; + const struct fs_parameter_enum *e = param->data; + if (!e || !e->name) { + pr_err("VALIDATE %s: PARAM[%s] enum with no values\n", + name, param->name); + good = false; + } } /* Check for duplicate parameter names */ @@ -395,63 +397,7 @@ bool fs_validate_description(const struct fs_parameter_description *desc) } } } - - nr_params = param - desc->specs; - } - - if (desc->enums) { - if (!nr_params) { - pr_err("VALIDATE %s: Enum table but no parameters\n", - name); - good = false; - goto no_enums; - } - if (!enums) { - pr_err("VALIDATE %s: Enum table but no enum-type values\n", - name); - good = false; - goto no_enums; - } - - for (e = desc->enums; e->name[0]; e++) { - /* Check that all entries in the enum table have at - * least one parameter that uses them. - */ - for (param = desc->specs; param->name; param++) { - if (param->opt == e->opt && - param->type != fs_param_is_enum) { - pr_err("VALIDATE %s: e[%tu] enum val for %s\n", - name, e - desc->enums, param->name); - good = false; - } - } - } - - /* Check that all enum-type parameters have at least one enum - * value in the enum table. - */ - for (param = desc->specs; param->name; param++) { - if (param->type != fs_param_is_enum) - continue; - for (e = desc->enums; e->name[0]; e++) - if (e->opt == param->opt) - break; - if (!e->name[0]) { - pr_err("VALIDATE %s: PARAM[%s] enum with no values\n", - name, param->name); - good = false; - } - } - } else { - if (enums) { - pr_err("VALIDATE %s: enum-type values, but no enum table\n", - name); - good = false; - goto no_enums; - } } - -no_enums: return good; } #endif /* CONFIG_VALIDATE_FS_PARSER */ diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e8b7b0ce8404..0df8f2df9491 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1271,6 +1271,13 @@ enum opt_quota { Opt_quota_on, }; +static const struct fs_parameter_enum gfs2_param_quota[] = { + {"off", Opt_quota_off }, + {"account", Opt_quota_account }, + {"on", Opt_quota_on }, + {} +}; + static const unsigned int opt_quota_values[] = { [Opt_quota_off] = GFS2_QUOTA_OFF, [Opt_quota_account] = GFS2_QUOTA_ACCOUNT, @@ -1282,11 +1289,23 @@ enum opt_data { Opt_data_ordered = GFS2_DATA_ORDERED, }; +static const struct fs_parameter_enum gfs2_param_data[] = { + {"writeback", Opt_data_writeback }, + {"ordered", Opt_data_ordered }, + {} +}; + enum opt_errors { Opt_errors_withdraw = GFS2_ERRORS_WITHDRAW, Opt_errors_panic = GFS2_ERRORS_PANIC, }; +static const struct fs_parameter_enum gfs2_param_errors[] = { + {"withdraw", Opt_errors_withdraw }, + {"panic", Opt_errors_panic }, + {} +}; + static const struct fs_parameter_spec gfs2_param_specs[] = { fsparam_string ("lockproto", Opt_lockproto), fsparam_string ("locktable", Opt_locktable), @@ -1300,11 +1319,11 @@ static const struct fs_parameter_spec gfs2_param_specs[] = { fsparam_flag ("upgrade", Opt_upgrade), fsparam_flag_no("acl", Opt_acl), fsparam_flag_no("suiddir", Opt_suiddir), - fsparam_enum ("data", Opt_data), + fsparam_enum ("data", Opt_data, gfs2_param_data), fsparam_flag ("meta", Opt_meta), fsparam_flag_no("discard", Opt_discard), fsparam_s32 ("commit", Opt_commit), - fsparam_enum ("errors", Opt_errors), + fsparam_enum ("errors", Opt_errors, gfs2_param_errors), fsparam_s32 ("statfs_quantum", Opt_statfs_quantum), fsparam_s32 ("statfs_percent", Opt_statfs_percent), fsparam_s32 ("quota_quantum", Opt_quota_quantum), @@ -1312,25 +1331,14 @@ static const struct fs_parameter_spec gfs2_param_specs[] = { fsparam_flag_no("rgrplvb", Opt_rgrplvb), fsparam_flag_no("loccookie", Opt_loccookie), /* quota can be a flag or an enum so it gets special treatment */ - __fsparam(fs_param_is_enum, "quota", Opt_quota, fs_param_neg_with_no|fs_param_v_optional), - {} -}; - -static const struct fs_parameter_enum gfs2_param_enums[] = { - { Opt_quota, "off", Opt_quota_off }, - { Opt_quota, "account", Opt_quota_account }, - { Opt_quota, "on", Opt_quota_on }, - { Opt_data, "writeback", Opt_data_writeback }, - { Opt_data, "ordered", Opt_data_ordered }, - { Opt_errors, "withdraw", Opt_errors_withdraw }, - { Opt_errors, "panic", Opt_errors_panic }, + __fsparam(fs_param_is_enum, "quota", Opt_quota, + fs_param_neg_with_no|fs_param_v_optional, gfs2_param_quota), {} }; static const struct fs_parameter_description gfs2_fs_parameters = { .name = "gfs2", .specs = gfs2_param_specs, - .enums = gfs2_param_enums, }; /* Parse a single mount parameter */ diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c index 0e6406c4f362..ecd1a13a35d8 100644 --- a/fs/jffs2/super.c +++ b/fs/jffs2/super.c @@ -167,27 +167,26 @@ enum { Opt_rp_size, }; -static const struct fs_parameter_spec jffs2_param_specs[] = { - fsparam_enum ("compr", Opt_override_compr), - fsparam_u32 ("rp_size", Opt_rp_size), - {} -}; - -static const struct fs_parameter_enum jffs2_param_enums[] = { - { Opt_override_compr, "none", JFFS2_COMPR_MODE_NONE }, +static const struct fs_parameter_enum jffs2_param_compr[] = { + {"none", JFFS2_COMPR_MODE_NONE }, #ifdef CONFIG_JFFS2_LZO - { Opt_override_compr, "lzo", JFFS2_COMPR_MODE_FORCELZO }, + {"lzo", JFFS2_COMPR_MODE_FORCELZO }, #endif #ifdef CONFIG_JFFS2_ZLIB - { Opt_override_compr, "zlib", JFFS2_COMPR_MODE_FORCEZLIB }, + {"zlib", JFFS2_COMPR_MODE_FORCEZLIB }, #endif {} }; +static const struct fs_parameter_spec jffs2_param_specs[] = { + fsparam_enum ("compr", Opt_override_compr, jffs2_param_compr), + fsparam_u32 ("rp_size", Opt_rp_size), + {} +}; + const struct fs_parameter_description jffs2_fs_parameters = { .name = "jffs2", .specs = jffs2_param_specs, - .enums = jffs2_param_enums, }; static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param) diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c index 2c6dc1b6cc92..01c76885f54e 100644 --- a/fs/nfs/fs_context.c +++ b/fs/nfs/fs_context.c @@ -83,6 +83,34 @@ enum nfs_param { Opt_wsize, }; +enum { + Opt_local_lock_all, + Opt_local_lock_flock, + Opt_local_lock_none, + Opt_local_lock_posix, +}; + +static const struct fs_parameter_enum nfs_param_enums_local_lock[] = { + { "all", Opt_local_lock_all }, + { "flock", Opt_local_lock_flock }, + { "none", Opt_local_lock_none }, + {} +}; + +enum { + Opt_lookupcache_all, + Opt_lookupcache_none, + Opt_lookupcache_positive, +}; + +static const struct fs_parameter_enum nfs_param_enums_lookupcache[] = { + { "all", Opt_lookupcache_all }, + { "none", Opt_lookupcache_none }, + { "pos", Opt_lookupcache_positive }, + { "positive", Opt_lookupcache_positive }, + {} +}; + static const struct fs_parameter_spec nfs_param_specs[] = { fsparam_flag_no("ac", Opt_ac), fsparam_u32 ("acdirmax", Opt_acdirmax), @@ -98,13 +126,13 @@ static const struct fs_parameter_spec nfs_param_specs[] = { fsparam_flag_no("cto", Opt_cto), fsparam_flag ("fg", Opt_fg), __fsparam(fs_param_is_string, "fsc", Opt_fscache, - fs_param_neg_with_no|fs_param_v_optional), + fs_param_neg_with_no|fs_param_v_optional, NULL), fsparam_flag ("hard", Opt_hard), __fsparam(fs_param_is_flag, "intr", Opt_intr, - fs_param_neg_with_no|fs_param_deprecated), - fsparam_enum ("local_lock", Opt_local_lock), + fs_param_neg_with_no|fs_param_deprecated, NULL), + fsparam_enum ("local_lock", Opt_local_lock, nfs_param_enums_local_lock), fsparam_flag_no("lock", Opt_lock), - fsparam_enum ("lookupcache", Opt_lookupcache), + fsparam_enum ("lookupcache", Opt_lookupcache, nfs_param_enums_lookupcache), fsparam_flag_no("migration", Opt_migration), fsparam_u32 ("minorversion", Opt_minorversion), fsparam_string("mountaddr", Opt_mountaddr), @@ -145,35 +173,9 @@ static const struct fs_parameter_spec nfs_param_specs[] = { {} }; -enum { - Opt_local_lock_all, - Opt_local_lock_flock, - Opt_local_lock_none, - Opt_local_lock_posix, -}; - -enum { - Opt_lookupcache_all, - Opt_lookupcache_none, - Opt_lookupcache_positive, -}; - -static const struct fs_parameter_enum nfs_param_enums[] = { - { Opt_local_lock, "all", Opt_local_lock_all }, - { Opt_local_lock, "flock", Opt_local_lock_flock }, - { Opt_local_lock, "none", Opt_local_lock_none }, - { Opt_local_lock, "posix", Opt_local_lock_posix }, - { Opt_lookupcache, "all", Opt_lookupcache_all }, - { Opt_lookupcache, "none", Opt_lookupcache_none }, - { Opt_lookupcache, "pos", Opt_lookupcache_positive }, - { Opt_lookupcache, "positive", Opt_lookupcache_positive }, - {} -}; - static const struct fs_parameter_description nfs_fs_parameters = { .name = "nfs", .specs = nfs_param_specs, - .enums = nfs_param_enums, }; enum { -- cgit v1.2.3