* Add 'flavor' to 'auth_info' if not already present.
* Returns true if 'flavor' ends up in the list, false otherwise
*/
-static bool nfs_auth_info_add(struct nfs_auth_info *auth_info,
- rpc_authflavor_t flavor)
+static int nfs_auth_info_add(struct nfs_fs_context *ctx,
+ struct nfs_auth_info *auth_info,
+ rpc_authflavor_t flavor)
{
unsigned int i;
unsigned int max_flavor_len = ARRAY_SIZE(auth_info->flavors);
/* make sure this flavor isn't already in the list */
for (i = 0; i < auth_info->flavor_len; i++) {
if (flavor == auth_info->flavors[i])
- return true;
+ return 0;
}
if (auth_info->flavor_len + 1 >= max_flavor_len) {
dfprintk(MOUNT, "NFS: too many sec= flavors\n");
- return false;
+ return -EINVAL;
}
auth_info->flavors[auth_info->flavor_len++] = flavor;
- return true;
+ return 0;
}
/*
* Parse the value of the 'sec=' option.
*/
-static int nfs_parse_security_flavors(char *value, struct nfs_fs_context *ctx)
+static int nfs_parse_security_flavors(struct nfs_fs_context *ctx, char *value)
{
substring_t args[MAX_OPT_ARGS];
rpc_authflavor_t pseudoflavor;
char *p;
+ int ret;
dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
default:
dfprintk(MOUNT,
"NFS: sec= option '%s' not recognized\n", p);
- return 0;
+ return -EINVAL;
}
- if (!nfs_auth_info_add(&ctx->auth_info, pseudoflavor))
- return 0;
+ ret = nfs_auth_info_add(ctx, &ctx->auth_info, pseudoflavor);
+ if (ret < 0)
+ return ret;
}
- return 1;
+ return 0;
}
-static int nfs_parse_version_string(char *string,
- struct nfs_fs_context *ctx,
- substring_t *args)
+static int nfs_parse_version_string(struct nfs_fs_context *ctx,
+ char *string,
+ substring_t *args)
{
ctx->flags &= ~NFS_MOUNT_VER3;
switch (match_token(string, nfs_vers_tokens, args)) {
ctx->minorversion = 2;
break;
default:
- return 0;
+ dfprintk(MOUNT, "NFS: Unsupported NFS version\n");
+ return -EINVAL;
}
- return 1;
+ return 0;
}
static int nfs_get_option_str(substring_t args[], char **option)
{
substring_t args[MAX_OPT_ARGS];
char *string;
- int token, rc;
+ int token, ret;
dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
break;
case Opt_lock:
ctx->flags &= ~NFS_MOUNT_NONLM;
- ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
+ ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
break;
case Opt_nolock:
ctx->flags |= NFS_MOUNT_NONLM;
- ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
+ ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
break;
case Opt_udp:
ctx->flags &= ~NFS_MOUNT_TCP;
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = nfs_parse_version_string(string, ctx, args);
+ ret = nfs_parse_version_string(ctx, string, args);
kfree(string);
- if (!rc)
- goto out_invalid_value;
+ if (ret < 0)
+ return ret;
break;
case Opt_sec:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = nfs_parse_security_flavors(string, ctx);
+ ret = nfs_parse_security_flavors(ctx, string);
kfree(string);
- if (!rc) {
- dfprintk(MOUNT, "NFS: unrecognized "
- "security flavor\n");
- return -EINVAL;
- }
+ if (ret < 0)
+ return ret;
break;
case Opt_proto:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- token = match_token(string,
- nfs_xprt_protocol_tokens, args);
+ token = match_token(string, nfs_xprt_protocol_tokens, args);
ctx->protofamily = AF_INET;
switch (token) {
xprt_load_transport(string);
break;
default:
- dfprintk(MOUNT, "NFS: unrecognized "
- "transport protocol\n");
kfree(string);
+ dfprintk(MOUNT, "NFS: unrecognized transport protocol\n");
return -EINVAL;
}
kfree(string);
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- token = match_token(string,
- nfs_xprt_protocol_tokens, args);
+ token = match_token(string, nfs_xprt_protocol_tokens, args);
kfree(string);
ctx->mountfamily = AF_INET;
break;
case Opt_xprt_rdma: /* not used for side protocols */
default:
- dfprintk(MOUNT, "NFS: unrecognized "
- "transport protocol\n");
+ dfprintk(MOUNT, "NFS: unrecognized transport protocol\n");
return -EINVAL;
}
break;
goto out_nomem;
ctx->nfs_server.addrlen =
rpc_pton(ctx->net, string, strlen(string),
- (struct sockaddr *)
&ctx->nfs_server.address,
- sizeof(ctx->nfs_server.address));
+ sizeof(ctx->nfs_server._address));
kfree(string);
if (ctx->nfs_server.addrlen == 0)
goto out_invalid_address;
goto out_nomem;
break;
case Opt_mounthost:
- if (nfs_get_option_str(args,
- &ctx->mount_server.hostname))
+ if (nfs_get_option_str(args, &ctx->mount_server.hostname))
goto out_nomem;
break;
case Opt_mountaddr:
goto out_nomem;
ctx->mount_server.addrlen =
rpc_pton(ctx->net, string, strlen(string),
- (struct sockaddr *)
&ctx->mount_server.address,
- sizeof(ctx->mount_server.address));
+ sizeof(ctx->mount_server._address));
kfree(string);
if (ctx->mount_server.addrlen == 0)
goto out_invalid_address;
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- token = match_token(string,
- nfs_lookupcache_tokens, args);
+ token = match_token(string, nfs_lookupcache_tokens, args);
kfree(string);
switch (token) {
case Opt_lookupcache_all:
ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
break;
default:
- dfprintk(MOUNT, "NFS: invalid "
- "lookupcache argument\n");
+ dfprintk(MOUNT, "NFS: invalid lookupcache argument\n");
return -EINVAL;
}
break;
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- token = match_token(string, nfs_local_lock_tokens,
- args);
+ token = match_token(string, nfs_local_lock_tokens, args);
kfree(string);
switch (token) {
case Opt_local_lock_all:
NFS_MOUNT_LOCAL_FCNTL);
break;
default:
- dfprintk(MOUNT, "NFS: invalid "
- "local_lock argument\n");
+ dfprintk(MOUNT, "NFS: invalid local_lock argument\n");
return -EINVAL;
}
break;
break;
case Opt_userspace:
case Opt_deprecated:
- dfprintk(MOUNT, "NFS: ignoring mount option "
- "'%s'\n", p);
+ dfprintk(MOUNT, "NFS: ignoring mount option '%s'\n", p);
break;
default:
- dfprintk(MOUNT, "NFS: unrecognized mount option "
- "'%s'\n", p);
+ dfprintk(MOUNT, "NFS: unrecognized mount option '%s'\n", p);
return -EINVAL;
}
* families in the addr=/mountaddr= options.
*/
if (ctx->protofamily != AF_UNSPEC &&
- ctx->protofamily != ctx->nfs_server.address.ss_family)
+ ctx->protofamily != ctx->nfs_server.address.sa_family)
goto out_proto_mismatch;
if (ctx->mountfamily != AF_UNSPEC) {
if (ctx->mount_server.addrlen) {
- if (ctx->mountfamily != ctx->mount_server.address.ss_family)
+ if (ctx->mountfamily != ctx->mount_server.address.sa_family)
goto out_mountproto_mismatch;
} else {
- if (ctx->mountfamily != ctx->nfs_server.address.ss_family)
+ if (ctx->mountfamily != ctx->nfs_server.address.sa_family)
goto out_mountproto_mismatch;
}
}
*
* Note: caller frees hostname and export path, even on error.
*/
-static int nfs_parse_devname(const char *dev_name,
- char **hostname, size_t maxnamlen,
- char **export_path, size_t maxpathlen)
+static int nfs_parse_devname(struct nfs_fs_context *ctx,
+ const char *dev_name,
+ size_t maxnamlen, size_t maxpathlen)
{
size_t len;
char *end;
goto out_hostname;
/* N.B. caller will free nfs_server.hostname in all cases */
- *hostname = kstrndup(dev_name, len, GFP_KERNEL);
- if (*hostname == NULL)
+ ctx->nfs_server.hostname = kmemdup_nul(dev_name, len, GFP_KERNEL);
+ if (!ctx->nfs_server.hostname)
goto out_nomem;
len = strlen(++end);
if (len > maxpathlen)
goto out_path;
- *export_path = kstrndup(end, len, GFP_KERNEL);
- if (!*export_path)
+ ctx->nfs_server.export_path = kmemdup_nul(end, len, GFP_KERNEL);
+ if (!ctx->nfs_server.export_path)
goto out_nomem;
- dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
+ dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", ctx->nfs_server.export_path);
return 0;
out_bad_devname:
}
/*
- * Validate the NFS2/NFS3 mount data
+ * Parse monolithic NFS2/NFS3 mount data
* - fills in the mount root filehandle
*
* For option strings, user space handles the following behaviors:
nfs_set_port(sap, &ctx->nfs_server.port, port);
- return nfs_parse_devname(dev_name,
- &ctx->nfs_server.hostname,
- max_namelen,
- &ctx->nfs_server.export_path,
- max_pathlen);
+ return nfs_parse_devname(ctx, dev_name, max_namelen, max_pathlen);
#if !IS_ENABLED(CONFIG_NFS_V4)
out_v4_not_compiled: