Commit f2aedb71 authored by David Howells's avatar David Howells Committed by Anna Schumaker
Browse files

NFS: Add fs_context support.



Add filesystem context support to NFS, parsing the options in advance and
attaching the information to struct nfs_fs_context.  The highlights are:

 (*) Merge nfs_mount_info and nfs_clone_mount into nfs_fs_context.  This
     structure represents NFS's superblock config.

 (*) Make use of the VFS's parsing support to split comma-separated lists

 (*) Pin the NFS protocol module in the nfs_fs_context.

 (*) Attach supplementary error information to fs_context.  This has the
     downside that these strings must be static and can't be formatted.

 (*) Remove the auxiliary file_system_type structs since the information
     necessary can be conveyed in the nfs_fs_context struct instead.

 (*) Root mounts are made by duplicating the config for the requested mount
     so as to have the same parameters.  Submounts pick up their parameters
     from the parent superblock.

[AV -- retrans is u32, not string]
[SM -- Renamed cfg to ctx in a few functions in an earlier patch]
[SM -- Moved fs_context mount option parsing to an earlier patch]
[SM -- Moved fs_context error logging to a later patch]
[SM -- Fixed printks in nfs4_try_get_tree() and nfs4_get_referral_tree()]
[SM -- Added is_remount_fc() helper]
[SM -- Deferred some refactoring to a later patch]
[SM -- Fixed referral mounts, which were broken in the original patch]
[SM -- Fixed leak of nfs_fattr when fs_context is freed]

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarScott Mayhew <smayhew@redhat.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent e38bb238
Loading
Loading
Loading
Loading
+316 −154
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@
 * linux/fs/nfs/fs_context.c
 * linux/fs/nfs/fs_context.c
 *
 *
 * Copyright (C) 1992 Rick Sladkey
 * Copyright (C) 1992 Rick Sladkey
 * Conversion to new mount api Copyright (C) David Howells
 *
 *
 * NFS mount handling.
 * NFS mount handling.
 *
 *
@@ -467,21 +468,31 @@ static int nfs_parse_version_string(struct nfs_fs_context *ctx,
/*
/*
 * Parse a single mount parameter.
 * Parse a single mount parameter.
 */
 */
static int nfs_fs_context_parse_param(struct nfs_fs_context *ctx,
static int nfs_fs_context_parse_param(struct fs_context *fc,
				      struct fs_parameter *param)
				      struct fs_parameter *param)
{
{
	struct fs_parse_result result;
	struct fs_parse_result result;
	struct nfs_fs_context *ctx = nfs_fc2context(fc);
	unsigned short protofamily, mountfamily;
	unsigned short protofamily, mountfamily;
	unsigned int len;
	unsigned int len;
	int ret, opt;
	int ret, opt;


	dfprintk(MOUNT, "NFS:   parsing nfs mount option '%s'\n", param->key);
	dfprintk(MOUNT, "NFS:   parsing nfs mount option '%s'\n", param->key);


	opt = fs_parse(NULL, &nfs_fs_parameters, param, &result);
	opt = fs_parse(fc, &nfs_fs_parameters, param, &result);
	if (opt < 0)
	if (opt < 0)
		return ctx->sloppy ? 1 : opt;
		return ctx->sloppy ? 1 : opt;


	switch (opt) {
	switch (opt) {
	case Opt_source:
		if (fc->source) {
			dfprintk(MOUNT, "NFS: Multiple sources not supported\n");
			return -EINVAL;
		}
		fc->source = param->string;
		param->string = NULL;
		break;

		/*
		/*
		 * boolean options:  foo/nofoo
		 * boolean options:  foo/nofoo
		 */
		 */
@@ -807,112 +818,6 @@ out_of_bounds:
	return -ERANGE;
	return -ERANGE;
}
}


/* cribbed from generic_parse_monolithic and vfs_parse_fs_string */
static int nfs_fs_context_parse_option(struct nfs_fs_context *ctx, char *p)
{
	int ret;
	char *key = p, *value;
	size_t v_size = 0;
	struct fs_parameter param;

	memset(&param, 0, sizeof(param));
	value = strchr(key, '=');
	if (value && value != key) {
		*value++ = 0;
		v_size = strlen(value);
	}
	param.key = key;
	param.type = fs_value_is_flag;
	param.size = v_size;
	if (v_size > 0) {
		param.type = fs_value_is_string;
		param.string = kmemdup_nul(value, v_size, GFP_KERNEL);
		if (!param.string)
			return -ENOMEM;
	}
	ret = nfs_fs_context_parse_param(ctx, &param);
	kfree(param.string);
	return ret;
}

/*
 * Error-check and convert a string of mount options from user space into
 * a data structure.  The whole mount string is processed; bad options are
 * skipped as they are encountered.  If there were no errors, return 1;
 * otherwise return 0 (zero).
 */
int nfs_parse_mount_options(char *raw, struct nfs_fs_context *ctx)
{
	char *p;
	int rc, sloppy = 0, invalid_option = 0;

	if (!raw) {
		dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
		return 1;
	}
	dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);

	rc = security_sb_eat_lsm_opts(raw, &ctx->lsm_opts);
	if (rc)
		goto out_security_failure;

	while ((p = strsep(&raw, ",")) != NULL) {
		if (!*p)
			continue;
		if (nfs_fs_context_parse_option(ctx, p) < 0)
			invalid_option = true;
	}

	if (!sloppy && invalid_option)
		return 0;

	if (ctx->minorversion && ctx->version != 4)
		goto out_minorversion_mismatch;

	if (ctx->options & NFS_OPTION_MIGRATION &&
	    (ctx->version != 4 || ctx->minorversion != 0))
		goto out_migration_misuse;

	/*
	 * verify that any proto=/mountproto= options match the address
	 * families in the addr=/mountaddr= options.
	 */
	if (ctx->protofamily != AF_UNSPEC &&
	    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.sa_family)
				goto out_mountproto_mismatch;
		} else {
			if (ctx->mountfamily != ctx->nfs_server.address.sa_family)
				goto out_mountproto_mismatch;
		}
	}

	return 1;

out_minorversion_mismatch:
	printk(KERN_INFO "NFS: mount option vers=%u does not support "
			 "minorversion=%u\n", ctx->version, ctx->minorversion);
	return 0;
out_mountproto_mismatch:
	printk(KERN_INFO "NFS: mount server address does not match mountproto= "
			 "option\n");
	return 0;
out_proto_mismatch:
	printk(KERN_INFO "NFS: server address does not match proto= option\n");
	return 0;
out_migration_misuse:
	printk(KERN_INFO
		"NFS: 'migration' not supported for this NFS version\n");
	return -EINVAL;
out_security_failure:
	printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
	return 0;
}

/*
/*
 * Split "dev_name" into "hostname:export_path".
 * Split "dev_name" into "hostname:export_path".
 *
 *
@@ -990,6 +895,11 @@ out_path:
	return -ENAMETOOLONG;
	return -ENAMETOOLONG;
}
}


static inline bool is_remount_fc(struct fs_context *fc)
{
	return fc->root != NULL;
}

/*
/*
 * Parse monolithic NFS2/NFS3 mount data
 * Parse monolithic NFS2/NFS3 mount data
 * - fills in the mount root filehandle
 * - fills in the mount root filehandle
@@ -1006,12 +916,11 @@ out_path:
 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
 *   mountproto=tcp after mountproto=udp, and so on
 *   mountproto=tcp after mountproto=udp, and so on
 */
 */
static int nfs23_validate_mount_data(void *options,
static int nfs23_parse_monolithic(struct fs_context *fc,
				     struct nfs_fs_context *ctx,
				  struct nfs_mount_data *data)
				     struct nfs_fh *mntfh,
				     const char *dev_name)
{
{
	struct nfs_mount_data *data = (struct nfs_mount_data *)options;
	struct nfs_fs_context *ctx = nfs_fc2context(fc);
	struct nfs_fh *mntfh = ctx->mount_info.mntfh;
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	int extra_flags = NFS_MOUNT_LEGACY_INTERFACE;
	int extra_flags = NFS_MOUNT_LEGACY_INTERFACE;


@@ -1083,6 +992,9 @@ static int nfs23_validate_mount_data(void *options,
			ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
			ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
		/* N.B. caller will free nfs_server.hostname in all cases */
		/* N.B. caller will free nfs_server.hostname in all cases */
		ctx->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
		ctx->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
		if (!ctx->nfs_server.hostname)
			goto out_nomem;

		ctx->namlen		= data->namlen;
		ctx->namlen		= data->namlen;
		ctx->bsize		= data->bsize;
		ctx->bsize		= data->bsize;


@@ -1090,8 +1002,6 @@ static int nfs23_validate_mount_data(void *options,
			ctx->selected_flavor = data->pseudoflavor;
			ctx->selected_flavor = data->pseudoflavor;
		else
		else
			ctx->selected_flavor = RPC_AUTH_UNIX;
			ctx->selected_flavor = RPC_AUTH_UNIX;
		if (!ctx->nfs_server.hostname)
			goto out_nomem;


		if (!(data->flags & NFS_MOUNT_NONLM))
		if (!(data->flags & NFS_MOUNT_NONLM))
			ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
			ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
@@ -1109,12 +1019,13 @@ static int nfs23_validate_mount_data(void *options,
		 */
		 */
		if (data->context[0]){
		if (data->context[0]){
#ifdef CONFIG_SECURITY_SELINUX
#ifdef CONFIG_SECURITY_SELINUX
			int rc;
			int ret;

			data->context[NFS_MAX_CONTEXT_LEN] = '\0';
			data->context[NFS_MAX_CONTEXT_LEN] = '\0';
			rc = security_add_mnt_opt("context", data->context,
			ret = vfs_parse_fs_string(fc, "context",
					strlen(data->context), ctx->lsm_opts);
						  data->context, strlen(data->context));
			if (rc)
			if (ret < 0)
				return rc;
				return ret;
#else
#else
			return -EINVAL;
			return -EINVAL;
#endif
#endif
@@ -1122,12 +1033,20 @@ static int nfs23_validate_mount_data(void *options,


		break;
		break;
	default:
	default:
		return NFS_TEXT_DATA;
		goto generic;
	}
	}


	ctx->skip_reconfig_option_check = true;
	return 0;
	return 0;


generic:
	return generic_parse_monolithic(fc, data);

out_no_data:
out_no_data:
	if (is_remount_fc(fc)) {
		ctx->skip_reconfig_option_check = true;
		return 0;
	}
	dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
	dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
	return -EINVAL;
	return -EINVAL;


@@ -1163,12 +1082,11 @@ static void nfs4_validate_mount_flags(struct nfs_fs_context *ctx)
/*
/*
 * Validate NFSv4 mount options
 * Validate NFSv4 mount options
 */
 */
static int nfs4_validate_mount_data(void *options,
static int nfs4_parse_monolithic(struct fs_context *fc,
				    struct nfs_fs_context *ctx,
				 struct nfs4_mount_data *data)
				    const char *dev_name)
{
{
	struct nfs_fs_context *ctx = nfs_fc2context(fc);
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
	char *c;
	char *c;


	if (data == NULL)
	if (data == NULL)
@@ -1218,7 +1136,7 @@ static int nfs4_validate_mount_data(void *options,
		ctx->client_address = c;
		ctx->client_address = c;


		/*
		/*
		 * Translate to nfs_fs_context, which nfs4_fill_super
		 * Translate to nfs_fs_context, which nfs_fill_super
		 * can deal with.
		 * can deal with.
		 */
		 */


@@ -1238,12 +1156,20 @@ static int nfs4_validate_mount_data(void *options,


		break;
		break;
	default:
	default:
		return NFS_TEXT_DATA;
		goto generic;
	}
	}


	ctx->skip_reconfig_option_check = true;
	return 0;
	return 0;


generic:
	return generic_parse_monolithic(fc, data);

out_no_data:
out_no_data:
	if (is_remount_fc(fc)) {
		ctx->skip_reconfig_option_check = true;
		return 0;
	}
	dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
	dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
	return -EINVAL;
	return -EINVAL;


@@ -1260,39 +1186,66 @@ out_invalid_transport_udp:
	dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
	dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
	return -EINVAL;
	return -EINVAL;
}
}
#endif


int nfs_validate_mount_data(struct file_system_type *fs_type,
/*
			    void *options,
 * Parse a monolithic block of data from sys_mount().
			    struct nfs_fs_context *ctx,
 */
			    struct nfs_fh *mntfh,
static int nfs_fs_context_parse_monolithic(struct fs_context *fc,
			    const char *dev_name)
					   void *data)
{
	if (fs_type == &nfs_fs_type)
		return nfs23_validate_mount_data(options, ctx, mntfh, dev_name);
	return nfs4_validate_mount_data(options, ctx, dev_name);
}
#else
int nfs_validate_mount_data(struct file_system_type *fs_type,
			    void *options,
			    struct nfs_fs_context *ctx,
			    struct nfs_fh *mntfh,
			    const char *dev_name)
{
{
	return nfs23_validate_mount_data(options, ctx, mntfh, dev_name);
	if (fc->fs_type == &nfs_fs_type)
}
		return nfs23_parse_monolithic(fc, data);

#if IS_ENABLED(CONFIG_NFS_V4)
	if (fc->fs_type == &nfs4_fs_type)
		return nfs4_parse_monolithic(fc, data);
#endif
#endif


int nfs_validate_text_mount_data(void *options,
	dfprintk(MOUNT, "NFS: Unsupported monolithic data version\n");
				 struct nfs_fs_context *ctx,
	return -EINVAL;
				 const char *dev_name)
}

/*
 * Validate the preparsed information in the config.
 */
static int nfs_fs_context_validate(struct fs_context *fc)
{
{
	int port = 0;
	struct nfs_fs_context *ctx = nfs_fc2context(fc);
	struct nfs_subversion *nfs_mod;
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	int max_namelen = PAGE_SIZE;
	int max_namelen = PAGE_SIZE;
	int max_pathlen = NFS_MAXPATHLEN;
	int max_pathlen = NFS_MAXPATHLEN;
	struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
	int port = 0;
	int ret;


	if (nfs_parse_mount_options((char *)options, ctx) == 0)
	if (!fc->source)
		return -EINVAL;
		goto out_no_device_name;

	/* Check for sanity first. */
	if (ctx->minorversion && ctx->version != 4)
		goto out_minorversion_mismatch;

	if (ctx->options & NFS_OPTION_MIGRATION &&
	    (ctx->version != 4 || ctx->minorversion != 0))
		goto out_migration_misuse;

	/* Verify that any proto=/mountproto= options match the address
	 * families in the addr=/mountaddr= options.
	 */
	if (ctx->protofamily != AF_UNSPEC &&
	    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.sa_family)
				goto out_mountproto_mismatch;
		} else {
			if (ctx->mountfamily != ctx->nfs_server.address.sa_family)
				goto out_mountproto_mismatch;
		}
	}


	if (!nfs_verify_server_address(sap))
	if (!nfs_verify_server_address(sap))
		goto out_no_address;
		goto out_no_address;
@@ -1320,8 +1273,24 @@ int nfs_validate_text_mount_data(void *options,


	nfs_set_port(sap, &ctx->nfs_server.port, port);
	nfs_set_port(sap, &ctx->nfs_server.port, port);


	return nfs_parse_devname(ctx, dev_name, max_namelen, max_pathlen);
	ret = nfs_parse_devname(ctx, fc->source, max_namelen, max_pathlen);
	if (ret < 0)
		return ret;


	/* Load the NFS protocol module if we haven't done so yet */
	if (!ctx->mount_info.nfs_mod) {
		nfs_mod = get_nfs_version(ctx->version);
		if (IS_ERR(nfs_mod)) {
			ret = PTR_ERR(nfs_mod);
			goto out_version_unavailable;
		}
		ctx->mount_info.nfs_mod = nfs_mod;
	}
	return 0;

out_no_device_name:
	dfprintk(MOUNT, "NFS: Device name not specified\n");
	return -EINVAL;
#if !IS_ENABLED(CONFIG_NFS_V4)
#if !IS_ENABLED(CONFIG_NFS_V4)
out_v4_not_compiled:
out_v4_not_compiled:
	dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
	dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
@@ -1331,8 +1300,201 @@ out_invalid_transport_udp:
	dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
	dfprintk(MOUNT, "NFSv4: Unsupported transport protocol udp\n");
	return -EINVAL;
	return -EINVAL;
#endif /* !CONFIG_NFS_V4 */
#endif /* !CONFIG_NFS_V4 */

out_no_address:
out_no_address:
	dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
	dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
	return -EINVAL;
	return -EINVAL;
out_mountproto_mismatch:
	dfprintk(MOUNT, "NFS: Mount server address does not match mountproto= option\n");
	return -EINVAL;
out_proto_mismatch:
	dfprintk(MOUNT, "NFS: Server address does not match proto= option\n");
	return -EINVAL;
out_minorversion_mismatch:
	dfprintk(MOUNT, "NFS: Mount option vers=%u does not support minorversion=%u\n",
			  ctx->version, ctx->minorversion);
	return -EINVAL;
out_migration_misuse:
	dfprintk(MOUNT, "NFS: 'Migration' not supported for this NFS version\n");
	return -EINVAL;
out_version_unavailable:
	dfprintk(MOUNT, "NFS: Version unavailable\n");
	return ret;
}

/*
 * Create an NFS superblock by the appropriate method.
 */
static int nfs_get_tree(struct fs_context *fc)
{
	struct nfs_fs_context *ctx = nfs_fc2context(fc);
	int err = nfs_fs_context_validate(fc);

	if (err)
		return err;
	if (!ctx->internal)
		return ctx->mount_info.nfs_mod->rpc_ops->try_get_tree(fc);
	else
		return nfs_get_tree_common(fc);
}

/*
 * Handle duplication of a configuration.  The caller copied *src into *sc, but
 * it can't deal with resource pointers in the filesystem context, so we have
 * to do that.  We need to clear pointers, copy data or get extra refs as
 * appropriate.
 */
static int nfs_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc)
{
	struct nfs_fs_context *src = nfs_fc2context(src_fc), *ctx;

	ctx = kmemdup(src, sizeof(struct nfs_fs_context), GFP_KERNEL);
	if (!ctx)
		return -ENOMEM;

	ctx->mount_info.mntfh = nfs_alloc_fhandle();
	if (!ctx->mount_info.mntfh) {
		kfree(ctx);
		return -ENOMEM;
	}
	nfs_copy_fh(ctx->mount_info.mntfh, src->mount_info.mntfh);

	__module_get(ctx->mount_info.nfs_mod->owner);
	ctx->client_address		= NULL;
	ctx->mount_server.hostname	= NULL;
	ctx->nfs_server.export_path	= NULL;
	ctx->nfs_server.hostname	= NULL;
	ctx->fscache_uniq		= NULL;
	ctx->clone_data.addr		= NULL;
	ctx->clone_data.fattr		= NULL;
	fc->fs_private = ctx;
	return 0;
}

static void nfs_fs_context_free(struct fs_context *fc)
{
	struct nfs_fs_context *ctx = nfs_fc2context(fc);

	if (ctx) {
		if (ctx->mount_info.server)
			nfs_free_server(ctx->mount_info.server);
		if (ctx->mount_info.nfs_mod)
			put_nfs_version(ctx->mount_info.nfs_mod);
		kfree(ctx->client_address);
		kfree(ctx->mount_server.hostname);
		kfree(ctx->nfs_server.export_path);
		kfree(ctx->nfs_server.hostname);
		kfree(ctx->fscache_uniq);
		nfs_free_fhandle(ctx->mount_info.mntfh);
		kfree(ctx->clone_data.addr);
		nfs_free_fattr(ctx->clone_data.fattr);
		kfree(ctx);
	}
}
}

static const struct fs_context_operations nfs_fs_context_ops = {
	.free			= nfs_fs_context_free,
	.dup			= nfs_fs_context_dup,
	.parse_param		= nfs_fs_context_parse_param,
	.parse_monolithic	= nfs_fs_context_parse_monolithic,
	.get_tree		= nfs_get_tree,
	.reconfigure		= nfs_reconfigure,
};

/*
 * Prepare superblock configuration.  We use the namespaces attached to the
 * context.  This may be the current process's namespaces, or it may be a
 * container's namespaces.
 */
static int nfs_init_fs_context(struct fs_context *fc)
{
	struct nfs_fs_context *ctx;

	ctx = kzalloc(sizeof(struct nfs_fs_context), GFP_KERNEL);
	if (unlikely(!ctx))
		return -ENOMEM;

	ctx->mount_info.ctx = ctx;
	ctx->mount_info.mntfh = nfs_alloc_fhandle();
	if (unlikely(!ctx->mount_info.mntfh)) {
		kfree(ctx);
		return -ENOMEM;
	}

	ctx->protofamily	= AF_UNSPEC;
	ctx->mountfamily	= AF_UNSPEC;
	ctx->mount_server.port	= NFS_UNSPEC_PORT;

	if (fc->root) {
		/* reconfigure, start with the current config */
		struct nfs_server *nfss = fc->root->d_sb->s_fs_info;
		struct net *net = nfss->nfs_client->cl_net;

		ctx->flags		= nfss->flags;
		ctx->rsize		= nfss->rsize;
		ctx->wsize		= nfss->wsize;
		ctx->retrans		= nfss->client->cl_timeout->to_retries;
		ctx->selected_flavor	= nfss->client->cl_auth->au_flavor;
		ctx->acregmin		= nfss->acregmin / HZ;
		ctx->acregmax		= nfss->acregmax / HZ;
		ctx->acdirmin		= nfss->acdirmin / HZ;
		ctx->acdirmax		= nfss->acdirmax / HZ;
		ctx->timeo		= 10U * nfss->client->cl_timeout->to_initval / HZ;
		ctx->nfs_server.port	= nfss->port;
		ctx->nfs_server.addrlen	= nfss->nfs_client->cl_addrlen;
		ctx->version		= nfss->nfs_client->rpc_ops->version;
		ctx->minorversion	= nfss->nfs_client->cl_minorversion;

		memcpy(&ctx->nfs_server.address, &nfss->nfs_client->cl_addr,
			ctx->nfs_server.addrlen);

		if (fc->net_ns != net) {
			put_net(fc->net_ns);
			fc->net_ns = get_net(net);
		}

		ctx->mount_info.nfs_mod = nfss->nfs_client->cl_nfs_mod;
		__module_get(ctx->mount_info.nfs_mod->owner);
	} else {
		/* defaults */
		ctx->timeo		= NFS_UNSPEC_TIMEO;
		ctx->retrans		= NFS_UNSPEC_RETRANS;
		ctx->acregmin		= NFS_DEF_ACREGMIN;
		ctx->acregmax		= NFS_DEF_ACREGMAX;
		ctx->acdirmin		= NFS_DEF_ACDIRMIN;
		ctx->acdirmax		= NFS_DEF_ACDIRMAX;
		ctx->nfs_server.port	= NFS_UNSPEC_PORT;
		ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP;
		ctx->selected_flavor	= RPC_AUTH_MAXFLAVOR;
		ctx->minorversion	= 0;
		ctx->need_mount		= true;
	}
	ctx->net = fc->net_ns;
	fc->fs_private = ctx;
	fc->ops = &nfs_fs_context_ops;
	return 0;
}

struct file_system_type nfs_fs_type = {
	.owner			= THIS_MODULE,
	.name			= "nfs",
	.init_fs_context	= nfs_init_fs_context,
	.parameters		= &nfs_fs_parameters,
	.kill_sb		= nfs_kill_super,
	.fs_flags		= FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
};
MODULE_ALIAS_FS("nfs");
EXPORT_SYMBOL_GPL(nfs_fs_type);

#if IS_ENABLED(CONFIG_NFS_V4)
struct file_system_type nfs4_fs_type = {
	.owner			= THIS_MODULE,
	.name			= "nfs4",
	.init_fs_context	= nfs_init_fs_context,
	.parameters		= &nfs_fs_parameters,
	.kill_sb		= nfs_kill_super,
	.fs_flags		= FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA,
};
MODULE_ALIAS_FS("nfs4");
MODULE_ALIAS("nfs4");
EXPORT_SYMBOL_GPL(nfs4_fs_type);
#endif /* CONFIG_NFS_V4 */
+33 −41
Original line number Original line Diff line number Diff line
@@ -4,7 +4,7 @@
 */
 */


#include "nfs4_fs.h"
#include "nfs4_fs.h"
#include <linux/mount.h>
#include <linux/fs_context.h>
#include <linux/security.h>
#include <linux/security.h>
#include <linux/crc32.h>
#include <linux/crc32.h>
#include <linux/sunrpc/addr.h>
#include <linux/sunrpc/addr.h>
@@ -16,6 +16,7 @@
extern const struct export_operations nfs_export_ops;
extern const struct export_operations nfs_export_ops;


struct nfs_string;
struct nfs_string;
struct nfs_pageio_descriptor;


static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
{
{
@@ -34,12 +35,13 @@ static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)


struct nfs_clone_mount {
struct nfs_clone_mount {
	const struct super_block *sb;
	const struct super_block *sb;
	const struct dentry *dentry;
	struct dentry *dentry;
	char *hostname;
	char *hostname;
	char *mnt_path;
	char *mnt_path;
	struct sockaddr *addr;
	struct sockaddr *addr;
	size_t addrlen;
	size_t addrlen;
	rpc_authflavor_t authflavor;
	rpc_authflavor_t authflavor;
	struct nfs_fattr *fattr;
};
};


/*
/*
@@ -78,10 +80,23 @@ struct nfs_client_initdata {
	const struct cred *cred;
	const struct cred *cred;
};
};


struct nfs_mount_info {
	unsigned int inherited_bsize;
	struct nfs_fs_context *ctx;
	struct nfs_clone_mount *cloned;
	struct nfs_server *server;
	struct nfs_fh *mntfh;
	struct nfs_subversion *nfs_mod;
};

/*
/*
 * In-kernel mount arguments
 * In-kernel mount arguments
 */
 */
struct nfs_fs_context {
struct nfs_fs_context {
	bool			internal;
	bool			skip_reconfig_option_check;
	bool			need_mount;
	bool			sloppy;
	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
	unsigned int		rsize, wsize;
	unsigned int		rsize, wsize;
	unsigned int		timeo, retrans;
	unsigned int		timeo, retrans;
@@ -98,8 +113,6 @@ struct nfs_fs_context {
	char			*fscache_uniq;
	char			*fscache_uniq;
	unsigned short		protofamily;
	unsigned short		protofamily;
	unsigned short		mountfamily;
	unsigned short		mountfamily;
	bool			need_mount;
	bool			sloppy;


	struct {
	struct {
		union {
		union {
@@ -124,14 +137,23 @@ struct nfs_fs_context {
		int			port;
		int			port;
		unsigned short		protocol;
		unsigned short		protocol;
		unsigned short		nconnect;
		unsigned short		nconnect;
		unsigned short		export_path_len;
	} nfs_server;
	} nfs_server;


	void			*lsm_opts;
	void			*lsm_opts;
	struct net		*net;
	struct net		*net;


	char			buf[32];	/* Parse buffer */
	char			buf[32];	/* Parse buffer */

	struct nfs_mount_info	mount_info;
	struct nfs_clone_mount	clone_data;
};
};


static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
{
	return fc->fs_private;
}

/* mount_clnt.c */
/* mount_clnt.c */
struct nfs_mount_request {
struct nfs_mount_request {
	struct sockaddr		*sap;
	struct sockaddr		*sap;
@@ -147,15 +169,6 @@ struct nfs_mount_request {
	struct net		*net;
	struct net		*net;
};
};


struct nfs_mount_info {
	unsigned int inherited_bsize;
	struct nfs_fs_context *ctx;
	struct nfs_clone_mount *cloned;
	struct nfs_server *server;
	struct nfs_fh *mntfh;
	struct nfs_subversion *nfs_mod;
};

extern int nfs_mount(struct nfs_mount_request *info);
extern int nfs_mount(struct nfs_mount_request *info);
extern void nfs_umount(const struct nfs_mount_request *info);
extern void nfs_umount(const struct nfs_mount_request *info);


@@ -235,22 +248,8 @@ static inline void nfs_fs_proc_exit(void)
extern const struct svc_version nfs4_callback_version1;
extern const struct svc_version nfs4_callback_version1;
extern const struct svc_version nfs4_callback_version4;
extern const struct svc_version nfs4_callback_version4;


struct nfs_pageio_descriptor;
/* fs_context.c */

extern struct file_system_type nfs_fs_type;
/* mount.c */
#define NFS_TEXT_DATA		1

extern struct nfs_fs_context *nfs_alloc_parsed_mount_data(void);
extern void nfs_free_parsed_mount_data(struct nfs_fs_context *ctx);
extern int nfs_parse_mount_options(char *raw, struct nfs_fs_context *ctx);
extern int nfs_validate_mount_data(struct file_system_type *fs_type,
				   void *options,
				   struct nfs_fs_context *ctx,
				   struct nfs_fh *mntfh,
				   const char *dev_name);
extern int nfs_validate_text_mount_data(void *options,
					struct nfs_fs_context *ctx,
					const char *dev_name);


/* pagelist.c */
/* pagelist.c */
extern int __init nfs_init_nfspagecache(void);
extern int __init nfs_init_nfspagecache(void);
@@ -411,14 +410,9 @@ extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);


/* super.c */
/* super.c */
extern const struct super_operations nfs_sops;
extern const struct super_operations nfs_sops;
extern struct file_system_type nfs_fs_type;
extern struct file_system_type nfs_prepared_fs_type;
#if IS_ENABLED(CONFIG_NFS_V4)
extern struct file_system_type nfs4_referral_fs_type;
#endif
bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *);
int nfs_try_get_tree(struct fs_context *);
struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
int nfs_get_tree_common(struct fs_context *);
void nfs_kill_super(struct super_block *);
void nfs_kill_super(struct super_block *);


extern struct rpc_stat nfs_rpcstat;
extern struct rpc_stat nfs_rpcstat;
@@ -446,10 +440,8 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
extern char *nfs_path(char **p, struct dentry *dentry,
extern char *nfs_path(char **p, struct dentry *dentry,
		      char *buffer, ssize_t buflen, unsigned flags);
		      char *buffer, ssize_t buflen, unsigned flags);
extern struct vfsmount *nfs_d_automount(struct path *path);
extern struct vfsmount *nfs_d_automount(struct path *path);
struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
int nfs_submount(struct fs_context *, struct nfs_server *);
			      struct nfs_fh *, struct nfs_fattr *);
int nfs_do_submount(struct fs_context *);
struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
				 struct nfs_fattr *, rpc_authflavor_t);


/* getroot.c */
/* getroot.c */
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
@@ -476,7 +468,7 @@ int nfs_show_options(struct seq_file *, struct dentry *);
int  nfs_show_devname(struct seq_file *, struct dentry *);
int  nfs_show_devname(struct seq_file *, struct dentry *);
int  nfs_show_path(struct seq_file *, struct dentry *);
int  nfs_show_path(struct seq_file *, struct dentry *);
int  nfs_show_stats(struct seq_file *, struct dentry *);
int  nfs_show_stats(struct seq_file *, struct dentry *);
int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
int  nfs_reconfigure(struct fs_context *);


/* write.c */
/* write.c */
extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
+84 −52

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Original line Diff line number Diff line
@@ -990,7 +990,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
	.nlmclnt_ops	= &nlmclnt_fl_close_lock_ops,
	.nlmclnt_ops	= &nlmclnt_fl_close_lock_ops,
	.getroot	= nfs3_proc_get_root,
	.getroot	= nfs3_proc_get_root,
	.submount	= nfs_submount,
	.submount	= nfs_submount,
	.try_mount	= nfs_try_mount,
	.try_get_tree	= nfs_try_get_tree,
	.getattr	= nfs3_proc_getattr,
	.getattr	= nfs3_proc_getattr,
	.setattr	= nfs3_proc_setattr,
	.setattr	= nfs3_proc_setattr,
	.lookup		= nfs3_proc_lookup,
	.lookup		= nfs3_proc_lookup,
+5 −4
Original line number Original line Diff line number Diff line
@@ -268,14 +268,13 @@ extern const struct dentry_operations nfs4_dentry_operations;
int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
		    unsigned, umode_t);
		    unsigned, umode_t);


/* super.c */
/* fs_context.c */
extern struct file_system_type nfs4_fs_type;
extern struct file_system_type nfs4_fs_type;


/* nfs4namespace.c */
/* nfs4namespace.c */
struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
					 const struct qstr *);
					 const struct qstr *);
struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
int nfs4_submount(struct fs_context *, struct nfs_server *);
			       struct nfs_fh *, struct nfs_fattr *);
int nfs4_replace_transport(struct nfs_server *server,
int nfs4_replace_transport(struct nfs_server *server,
				const struct nfs4_fs_locations *locations);
				const struct nfs4_fs_locations *locations);


@@ -526,7 +525,6 @@ extern const nfs4_stateid invalid_stateid;
/* nfs4super.c */
/* nfs4super.c */
struct nfs_mount_info;
struct nfs_mount_info;
extern struct nfs_subversion nfs_v4;
extern struct nfs_subversion nfs_v4;
struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *);
extern bool nfs4_disable_idmapping;
extern bool nfs4_disable_idmapping;
extern unsigned short max_session_slots;
extern unsigned short max_session_slots;
extern unsigned short max_session_cb_slots;
extern unsigned short max_session_cb_slots;
@@ -536,6 +534,9 @@ extern bool recover_lost_locks;
#define NFS4_CLIENT_ID_UNIQ_LEN		(64)
#define NFS4_CLIENT_ID_UNIQ_LEN		(64)
extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];


extern int nfs4_try_get_tree(struct fs_context *);
extern int nfs4_get_referral_tree(struct fs_context *);

/* nfs4sysctl.c */
/* nfs4sysctl.c */
#ifdef CONFIG_SYSCTL
#ifdef CONFIG_SYSCTL
int nfs4_register_sysctl(void);
int nfs4_register_sysctl(void);
Loading