From 48ce73b1bef20331007b35de7ade8fe26cd55e84 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 17 Dec 2019 20:03:59 -0500 Subject: fs_parse: handle optional arguments sanely Don't bother with "mixed" options that would allow both the form with and without argument (i.e. both -o foo and -o foo=bar). Rather than trying to shove both into a single fs_parameter_spec, allow having with-argument and no-argument specs with the same name and teach fs_parse to handle that. There are very few options of that sort, and they are actually easier to handle that way - callers end up with less postprocessing. Signed-off-by: Al Viro --- fs/nfs/fs_context.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'fs/nfs') diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c index 39f980a0ee48..c87cdedbdd0c 100644 --- a/fs/nfs/fs_context.c +++ b/fs/nfs/fs_context.c @@ -45,6 +45,7 @@ enum nfs_param { Opt_cto, Opt_fg, Opt_fscache, + Opt_fscache_flag, Opt_hard, Opt_intr, Opt_local_lock, @@ -125,8 +126,8 @@ static const struct fs_parameter_spec nfs_fs_parameters[] = { fsparam_string("clientaddr", Opt_clientaddr), 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, NULL), + fsparam_flag_no("fsc", Opt_fscache_flag), + fsparam_string("fsc", Opt_fscache), fsparam_flag ("hard", Opt_hard), __fsparam(fs_param_is_flag, "intr", Opt_intr, fs_param_neg_with_no|fs_param_deprecated, NULL), @@ -537,14 +538,19 @@ static int nfs_fs_context_parse_param(struct fs_context *fc, else ctx->flags &= ~NFS_MOUNT_NORESVPORT; break; - case Opt_fscache: - kfree(ctx->fscache_uniq); - ctx->fscache_uniq = param->string; - param->string = NULL; + case Opt_fscache_flag: if (result.negated) ctx->options &= ~NFS_OPTION_FSCACHE; else ctx->options |= NFS_OPTION_FSCACHE; + kfree(ctx->fscache_uniq); + ctx->fscache_uniq = NULL; + break; + case Opt_fscache: + ctx->options |= NFS_OPTION_FSCACHE; + kfree(ctx->fscache_uniq); + ctx->fscache_uniq = param->string; + param->string = NULL; break; case Opt_migration: if (result.negated) -- cgit v1.2.3-59-g8ed1b