Linux Audio

Check our new training course

Loading...
v5.9
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 *  linux/fs/nfs/super.c
   4 *
   5 *  Copyright (C) 1992  Rick Sladkey
   6 *
   7 *  nfs superblock handling functions
   8 *
   9 *  Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
  10 *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
  11 *
  12 *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  13 *  J.S.Peatfield@damtp.cam.ac.uk
  14 *
  15 *  Split from inode.c by David Howells <dhowells@redhat.com>
  16 *
  17 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
  18 *   particular server are held in the same superblock
  19 * - NFS superblocks can have several effective roots to the dentry tree
  20 * - directory type roots are spliced into the tree when a path from one root reaches the root
  21 *   of another (see nfs_lookup())
  22 */
  23
  24#include <linux/module.h>
  25#include <linux/init.h>
  26
  27#include <linux/time.h>
  28#include <linux/kernel.h>
  29#include <linux/mm.h>
  30#include <linux/string.h>
  31#include <linux/stat.h>
  32#include <linux/errno.h>
  33#include <linux/unistd.h>
  34#include <linux/sunrpc/clnt.h>
  35#include <linux/sunrpc/addr.h>
  36#include <linux/sunrpc/stats.h>
  37#include <linux/sunrpc/metrics.h>
  38#include <linux/sunrpc/xprtsock.h>
  39#include <linux/sunrpc/xprtrdma.h>
  40#include <linux/nfs_fs.h>
  41#include <linux/nfs_mount.h>
  42#include <linux/nfs4_mount.h>
  43#include <linux/lockd/bind.h>
  44#include <linux/seq_file.h>
  45#include <linux/mount.h>
  46#include <linux/namei.h>
 
  47#include <linux/vfs.h>
  48#include <linux/inet.h>
  49#include <linux/in6.h>
  50#include <linux/slab.h>
  51#include <net/ipv6.h>
  52#include <linux/netdevice.h>
  53#include <linux/nfs_xdr.h>
  54#include <linux/magic.h>
  55#include <linux/parser.h>
  56#include <linux/nsproxy.h>
  57#include <linux/rcupdate.h>
  58
  59#include <linux/uaccess.h>
  60
  61#include "nfs4_fs.h"
  62#include "callback.h"
  63#include "delegation.h"
  64#include "iostat.h"
  65#include "internal.h"
  66#include "fscache.h"
  67#include "nfs4session.h"
  68#include "pnfs.h"
  69#include "nfs.h"
  70
  71#define NFSDBG_FACILITY		NFSDBG_VFS
 
  72
  73const struct super_operations nfs_sops = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  74	.alloc_inode	= nfs_alloc_inode,
  75	.free_inode	= nfs_free_inode,
  76	.write_inode	= nfs_write_inode,
  77	.drop_inode	= nfs_drop_inode,
  78	.statfs		= nfs_statfs,
  79	.evict_inode	= nfs_evict_inode,
  80	.umount_begin	= nfs_umount_begin,
  81	.show_options	= nfs_show_options,
  82	.show_devname	= nfs_show_devname,
  83	.show_path	= nfs_show_path,
  84	.show_stats	= nfs_show_stats,
 
  85};
  86EXPORT_SYMBOL_GPL(nfs_sops);
  87
  88#if IS_ENABLED(CONFIG_NFS_V4)
  89static int __init register_nfs4_fs(void)
  90{
  91	return register_filesystem(&nfs4_fs_type);
  92}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  93
  94static void unregister_nfs4_fs(void)
  95{
  96	unregister_filesystem(&nfs4_fs_type);
  97}
  98#else
  99static int __init register_nfs4_fs(void)
 100{
 101	return 0;
 102}
 103
 104static void unregister_nfs4_fs(void)
 105{
 106}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 107#endif
 108
 109static struct shrinker acl_shrinker = {
 110	.count_objects	= nfs_access_cache_count,
 111	.scan_objects	= nfs_access_cache_scan,
 112	.seeks		= DEFAULT_SEEKS,
 113};
 114
 115/*
 116 * Register the NFS filesystems
 117 */
 118int __init register_nfs_fs(void)
 119{
 120	int ret;
 121
 122        ret = register_filesystem(&nfs_fs_type);
 123	if (ret < 0)
 124		goto error_0;
 125
 126	ret = register_nfs4_fs();
 127	if (ret < 0)
 128		goto error_1;
 129
 130	ret = nfs_register_sysctl();
 131	if (ret < 0)
 132		goto error_2;
 133	ret = register_shrinker(&acl_shrinker);
 134	if (ret < 0)
 135		goto error_3;
 136	return 0;
 137error_3:
 138	nfs_unregister_sysctl();
 139error_2:
 140	unregister_nfs4_fs();
 
 141error_1:
 142	unregister_filesystem(&nfs_fs_type);
 143error_0:
 144	return ret;
 145}
 146
 147/*
 148 * Unregister the NFS filesystems
 149 */
 150void __exit unregister_nfs_fs(void)
 151{
 152	unregister_shrinker(&acl_shrinker);
 
 
 
 153	nfs_unregister_sysctl();
 154	unregister_nfs4_fs();
 155	unregister_filesystem(&nfs_fs_type);
 156}
 157
 158bool nfs_sb_active(struct super_block *sb)
 159{
 160	struct nfs_server *server = NFS_SB(sb);
 161
 162	if (!atomic_inc_not_zero(&sb->s_active))
 163		return false;
 164	if (atomic_inc_return(&server->active) != 1)
 165		atomic_dec(&sb->s_active);
 166	return true;
 167}
 168EXPORT_SYMBOL_GPL(nfs_sb_active);
 169
 170void nfs_sb_deactive(struct super_block *sb)
 171{
 172	struct nfs_server *server = NFS_SB(sb);
 173
 174	if (atomic_dec_and_test(&server->active))
 175		deactivate_super(sb);
 176}
 177EXPORT_SYMBOL_GPL(nfs_sb_deactive);
 178
 179static int __nfs_list_for_each_server(struct list_head *head,
 180		int (*fn)(struct nfs_server *, void *),
 181		void *data)
 182{
 183	struct nfs_server *server, *last = NULL;
 184	int ret = 0;
 185
 186	rcu_read_lock();
 187	list_for_each_entry_rcu(server, head, client_link) {
 188		if (!(server->super && nfs_sb_active(server->super)))
 189			continue;
 190		rcu_read_unlock();
 191		if (last)
 192			nfs_sb_deactive(last->super);
 193		last = server;
 194		ret = fn(server, data);
 195		if (ret)
 196			goto out;
 197		rcu_read_lock();
 198	}
 199	rcu_read_unlock();
 200out:
 201	if (last)
 202		nfs_sb_deactive(last->super);
 203	return ret;
 204}
 205
 206int nfs_client_for_each_server(struct nfs_client *clp,
 207		int (*fn)(struct nfs_server *, void *),
 208		void *data)
 209{
 210	return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data);
 211}
 212EXPORT_SYMBOL_GPL(nfs_client_for_each_server);
 213
 214/*
 215 * Deliver file system statistics to userspace
 216 */
 217int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 218{
 219	struct nfs_server *server = NFS_SB(dentry->d_sb);
 220	unsigned char blockbits;
 221	unsigned long blockres;
 222	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
 223	struct nfs_fsstat res;
 224	int error = -ENOMEM;
 225
 226	res.fattr = nfs_alloc_fattr();
 227	if (res.fattr == NULL)
 228		goto out_err;
 229
 230	error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
 231	if (unlikely(error == -ESTALE)) {
 232		struct dentry *pd_dentry;
 233
 234		pd_dentry = dget_parent(dentry);
 235		nfs_zap_caches(d_inode(pd_dentry));
 236		dput(pd_dentry);
 
 
 237	}
 238	nfs_free_fattr(res.fattr);
 239	if (error < 0)
 240		goto out_err;
 241
 242	buf->f_type = NFS_SUPER_MAGIC;
 243
 244	/*
 245	 * Current versions of glibc do not correctly handle the
 246	 * case where f_frsize != f_bsize.  Eventually we want to
 247	 * report the value of wtmult in this field.
 248	 */
 249	buf->f_frsize = dentry->d_sb->s_blocksize;
 250
 251	/*
 252	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
 253	 * are reported in units of f_frsize.  Linux hasn't had
 254	 * an f_frsize field in its statfs struct until recently,
 255	 * thus historically Linux's sys_statfs reports these
 256	 * fields in units of f_bsize.
 257	 */
 258	buf->f_bsize = dentry->d_sb->s_blocksize;
 259	blockbits = dentry->d_sb->s_blocksize_bits;
 260	blockres = (1 << blockbits) - 1;
 261	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
 262	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
 263	buf->f_bavail = (res.abytes + blockres) >> blockbits;
 264
 265	buf->f_files = res.tfiles;
 266	buf->f_ffree = res.afiles;
 267
 268	buf->f_namelen = server->namelen;
 269
 270	return 0;
 271
 272 out_err:
 273	dprintk("%s: statfs error = %d\n", __func__, -error);
 274	return error;
 275}
 276EXPORT_SYMBOL_GPL(nfs_statfs);
 277
 278/*
 279 * Map the security flavour number to a name
 280 */
 281static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
 282{
 283	static const struct {
 284		rpc_authflavor_t flavour;
 285		const char *str;
 286	} sec_flavours[NFS_AUTH_INFO_MAX_FLAVORS] = {
 287		/* update NFS_AUTH_INFO_MAX_FLAVORS when this list changes! */
 288		{ RPC_AUTH_NULL, "null" },
 289		{ RPC_AUTH_UNIX, "sys" },
 290		{ RPC_AUTH_GSS_KRB5, "krb5" },
 291		{ RPC_AUTH_GSS_KRB5I, "krb5i" },
 292		{ RPC_AUTH_GSS_KRB5P, "krb5p" },
 293		{ RPC_AUTH_GSS_LKEY, "lkey" },
 294		{ RPC_AUTH_GSS_LKEYI, "lkeyi" },
 295		{ RPC_AUTH_GSS_LKEYP, "lkeyp" },
 296		{ RPC_AUTH_GSS_SPKM, "spkm" },
 297		{ RPC_AUTH_GSS_SPKMI, "spkmi" },
 298		{ RPC_AUTH_GSS_SPKMP, "spkmp" },
 299		{ UINT_MAX, "unknown" }
 300	};
 301	int i;
 302
 303	for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
 304		if (sec_flavours[i].flavour == flavour)
 305			break;
 306	}
 307	return sec_flavours[i].str;
 308}
 309
 310static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
 311				  int showdefaults)
 312{
 313	struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
 314	char *proto = NULL;
 315
 
 316	switch (sap->sa_family) {
 317	case AF_INET:
 318		switch (nfss->mountd_protocol) {
 319		case IPPROTO_UDP:
 320			proto = RPCBIND_NETID_UDP;
 321			break;
 322		case IPPROTO_TCP:
 323			proto = RPCBIND_NETID_TCP;
 324			break;
 
 
 
 325		}
 326		break;
 327	case AF_INET6:
 328		switch (nfss->mountd_protocol) {
 329		case IPPROTO_UDP:
 330			proto = RPCBIND_NETID_UDP6;
 331			break;
 332		case IPPROTO_TCP:
 333			proto = RPCBIND_NETID_TCP6;
 334			break;
 
 
 
 335		}
 336		break;
 
 
 
 337	}
 338	if (proto || showdefaults)
 339		seq_printf(m, ",mountproto=%s", proto ?: "auto");
 340}
 341
 342static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
 343				    int showdefaults)
 344{
 345	struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
 346
 347	if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
 348		return;
 349
 350	switch (sap->sa_family) {
 351	case AF_INET: {
 352		struct sockaddr_in *sin = (struct sockaddr_in *)sap;
 353		seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
 354		break;
 355	}
 356	case AF_INET6: {
 357		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 358		seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
 359		break;
 360	}
 361	default:
 362		if (showdefaults)
 363			seq_puts(m, ",mountaddr=unspecified");
 364	}
 365
 366	if (nfss->mountd_version || showdefaults)
 367		seq_printf(m, ",mountvers=%u", nfss->mountd_version);
 368	if ((nfss->mountd_port &&
 369		nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
 370		showdefaults)
 371		seq_printf(m, ",mountport=%u", nfss->mountd_port);
 372
 373	nfs_show_mountd_netid(m, nfss, showdefaults);
 374}
 375
 376#if IS_ENABLED(CONFIG_NFS_V4)
 377static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
 378				    int showdefaults)
 379{
 380	struct nfs_client *clp = nfss->nfs_client;
 381
 382	seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
 383}
 384#else
 385static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
 386				    int showdefaults)
 387{
 388}
 389#endif
 390
 391static void nfs_show_nfs_version(struct seq_file *m,
 392		unsigned int version,
 393		unsigned int minorversion)
 394{
 395	seq_printf(m, ",vers=%u", version);
 396	if (version == 4)
 397		seq_printf(m, ".%u", minorversion);
 398}
 399
 400/*
 401 * Describe the mount options in force on this server representation
 402 */
 403static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
 404				   int showdefaults)
 405{
 406	static const struct proc_nfs_info {
 407		int flag;
 408		const char *str;
 409		const char *nostr;
 410	} nfs_info[] = {
 411		{ NFS_MOUNT_SOFT, ",soft", "" },
 412		{ NFS_MOUNT_SOFTERR, ",softerr", "" },
 413		{ NFS_MOUNT_SOFTREVAL, ",softreval", "" },
 414		{ NFS_MOUNT_POSIX, ",posix", "" },
 415		{ NFS_MOUNT_NOCTO, ",nocto", "" },
 416		{ NFS_MOUNT_NOAC, ",noac", "" },
 417		{ NFS_MOUNT_NONLM, ",nolock", "" },
 418		{ NFS_MOUNT_NOACL, ",noacl", "" },
 419		{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
 420		{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
 421		{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
 422		{ 0, NULL, NULL }
 423	};
 424	const struct proc_nfs_info *nfs_infop;
 425	struct nfs_client *clp = nfss->nfs_client;
 426	u32 version = clp->rpc_ops->version;
 427	int local_flock, local_fcntl;
 428
 429	nfs_show_nfs_version(m, version, clp->cl_minorversion);
 430	seq_printf(m, ",rsize=%u", nfss->rsize);
 431	seq_printf(m, ",wsize=%u", nfss->wsize);
 432	if (nfss->bsize != 0)
 433		seq_printf(m, ",bsize=%u", nfss->bsize);
 434	seq_printf(m, ",namlen=%u", nfss->namelen);
 435	if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
 436		seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
 437	if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
 438		seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
 439	if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
 440		seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
 441	if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
 442		seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
 443	if (!(nfss->flags & (NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR)))
 444			seq_puts(m, ",hard");
 445	for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
 446		if (nfss->flags & nfs_infop->flag)
 447			seq_puts(m, nfs_infop->str);
 448		else
 449			seq_puts(m, nfs_infop->nostr);
 450	}
 451	rcu_read_lock();
 452	seq_printf(m, ",proto=%s",
 453		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
 454	rcu_read_unlock();
 455	if (clp->cl_nconnect > 0)
 456		seq_printf(m, ",nconnect=%u", clp->cl_nconnect);
 457	if (version == 4) {
 458		if (nfss->port != NFS_PORT)
 459			seq_printf(m, ",port=%u", nfss->port);
 460	} else
 461		if (nfss->port)
 462			seq_printf(m, ",port=%u", nfss->port);
 463
 464	seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
 465	seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
 466	seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
 467
 468	if (version != 4)
 469		nfs_show_mountd_options(m, nfss, showdefaults);
 470	else
 471		nfs_show_nfsv4_options(m, nfss, showdefaults);
 472
 473	if (nfss->options & NFS_OPTION_FSCACHE)
 474		seq_puts(m, ",fsc");
 475
 476	if (nfss->options & NFS_OPTION_MIGRATION)
 477		seq_puts(m, ",migration");
 478
 479	if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
 480		if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
 481			seq_puts(m, ",lookupcache=none");
 482		else
 483			seq_puts(m, ",lookupcache=pos");
 484	}
 485
 486	local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
 487	local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
 488
 489	if (!local_flock && !local_fcntl)
 490		seq_puts(m, ",local_lock=none");
 491	else if (local_flock && local_fcntl)
 492		seq_puts(m, ",local_lock=all");
 493	else if (local_flock)
 494		seq_puts(m, ",local_lock=flock");
 495	else
 496		seq_puts(m, ",local_lock=posix");
 497}
 498
 499/*
 500 * Describe the mount options on this VFS mountpoint
 501 */
 502int nfs_show_options(struct seq_file *m, struct dentry *root)
 503{
 504	struct nfs_server *nfss = NFS_SB(root->d_sb);
 505
 506	nfs_show_mount_options(m, nfss, 0);
 507
 508	rcu_read_lock();
 509	seq_printf(m, ",addr=%s",
 510			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
 511							RPC_DISPLAY_ADDR));
 512	rcu_read_unlock();
 513
 514	return 0;
 515}
 516EXPORT_SYMBOL_GPL(nfs_show_options);
 517
 518#if IS_ENABLED(CONFIG_NFS_V4)
 519static void show_lease(struct seq_file *m, struct nfs_server *server)
 520{
 521	struct nfs_client *clp = server->nfs_client;
 522	unsigned long expire;
 523
 524	seq_printf(m, ",lease_time=%ld", clp->cl_lease_time / HZ);
 525	expire = clp->cl_last_renewal + clp->cl_lease_time;
 526	seq_printf(m, ",lease_expired=%ld",
 527		   time_after(expire, jiffies) ?  0 : (jiffies - expire) / HZ);
 528}
 529#ifdef CONFIG_NFS_V4_1
 530static void show_sessions(struct seq_file *m, struct nfs_server *server)
 531{
 532	if (nfs4_has_session(server->nfs_client))
 533		seq_puts(m, ",sessions");
 534}
 535#else
 536static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
 537#endif
 538#endif
 539
 540#ifdef CONFIG_NFS_V4_1
 541static void show_pnfs(struct seq_file *m, struct nfs_server *server)
 542{
 543	seq_printf(m, ",pnfs=");
 544	if (server->pnfs_curr_ld)
 545		seq_printf(m, "%s", server->pnfs_curr_ld->name);
 546	else
 547		seq_printf(m, "not configured");
 548}
 549
 550static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
 551{
 552	if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
 553		struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
 554		seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
 555			   "date='%llu,%u'",
 556			   impl_id->name, impl_id->domain,
 557			   impl_id->date.seconds, impl_id->date.nseconds);
 558	}
 559}
 560#else
 561#if IS_ENABLED(CONFIG_NFS_V4)
 562static void show_pnfs(struct seq_file *m, struct nfs_server *server)
 563{
 564}
 565#endif
 566static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
 567{
 568}
 569#endif
 570
 571int nfs_show_devname(struct seq_file *m, struct dentry *root)
 572{
 573	char *page = (char *) __get_free_page(GFP_KERNEL);
 574	char *devname, *dummy;
 575	int err = 0;
 576	if (!page)
 577		return -ENOMEM;
 578	devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
 579	if (IS_ERR(devname))
 580		err = PTR_ERR(devname);
 581	else
 582		seq_escape(m, devname, " \t\n\\");
 583	free_page((unsigned long)page);
 584	return err;
 585}
 586EXPORT_SYMBOL_GPL(nfs_show_devname);
 587
 588int nfs_show_path(struct seq_file *m, struct dentry *dentry)
 589{
 590	seq_puts(m, "/");
 591	return 0;
 592}
 593EXPORT_SYMBOL_GPL(nfs_show_path);
 594
 595/*
 596 * Present statistical information for this VFS mountpoint
 597 */
 598int nfs_show_stats(struct seq_file *m, struct dentry *root)
 599{
 600	int i, cpu;
 601	struct nfs_server *nfss = NFS_SB(root->d_sb);
 602	struct rpc_auth *auth = nfss->client->cl_auth;
 603	struct nfs_iostats totals = { };
 604
 605	seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
 606
 607	/*
 608	 * Display all mount option settings
 609	 */
 610	seq_puts(m, "\n\topts:\t");
 611	seq_puts(m, sb_rdonly(root->d_sb) ? "ro" : "rw");
 612	seq_puts(m, root->d_sb->s_flags & SB_SYNCHRONOUS ? ",sync" : "");
 613	seq_puts(m, root->d_sb->s_flags & SB_NOATIME ? ",noatime" : "");
 614	seq_puts(m, root->d_sb->s_flags & SB_NODIRATIME ? ",nodiratime" : "");
 615	nfs_show_mount_options(m, nfss, 1);
 616
 617	seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
 618
 619	show_implementation_id(m, nfss);
 620
 621	seq_puts(m, "\n\tcaps:\t");
 622	seq_printf(m, "caps=0x%x", nfss->caps);
 623	seq_printf(m, ",wtmult=%u", nfss->wtmult);
 624	seq_printf(m, ",dtsize=%u", nfss->dtsize);
 625	seq_printf(m, ",bsize=%u", nfss->bsize);
 626	seq_printf(m, ",namlen=%u", nfss->namelen);
 627
 628#if IS_ENABLED(CONFIG_NFS_V4)
 629	if (nfss->nfs_client->rpc_ops->version == 4) {
 630		seq_puts(m, "\n\tnfsv4:\t");
 631		seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
 632		seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
 633		seq_printf(m, ",bm2=0x%x", nfss->attr_bitmask[2]);
 634		seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
 635		show_sessions(m, nfss);
 636		show_pnfs(m, nfss);
 637		show_lease(m, nfss);
 638	}
 639#endif
 640
 641	/*
 642	 * Display security flavor in effect for this mount
 643	 */
 644	seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
 645	if (auth->au_flavor)
 646		seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
 647
 648	/*
 649	 * Display superblock I/O counters
 650	 */
 651	for_each_possible_cpu(cpu) {
 652		struct nfs_iostats *stats;
 653
 654		preempt_disable();
 655		stats = per_cpu_ptr(nfss->io_stats, cpu);
 656
 657		for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
 658			totals.events[i] += stats->events[i];
 659		for (i = 0; i < __NFSIOS_BYTESMAX; i++)
 660			totals.bytes[i] += stats->bytes[i];
 661#ifdef CONFIG_NFS_FSCACHE
 662		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
 663			totals.fscache[i] += stats->fscache[i];
 664#endif
 665
 666		preempt_enable();
 667	}
 668
 669	seq_puts(m, "\n\tevents:\t");
 670	for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
 671		seq_printf(m, "%lu ", totals.events[i]);
 672	seq_puts(m, "\n\tbytes:\t");
 673	for (i = 0; i < __NFSIOS_BYTESMAX; i++)
 674		seq_printf(m, "%Lu ", totals.bytes[i]);
 675#ifdef CONFIG_NFS_FSCACHE
 676	if (nfss->options & NFS_OPTION_FSCACHE) {
 677		seq_puts(m, "\n\tfsc:\t");
 678		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
 679			seq_printf(m, "%Lu ", totals.fscache[i]);
 680	}
 681#endif
 682	seq_putc(m, '\n');
 683
 684	rpc_clnt_show_stats(m, nfss->client);
 685
 686	return 0;
 687}
 688EXPORT_SYMBOL_GPL(nfs_show_stats);
 689
 690/*
 691 * Begin unmount by attempting to remove all automounted mountpoints we added
 692 * in response to xdev traversals and referrals
 693 */
 694void nfs_umount_begin(struct super_block *sb)
 695{
 696	struct nfs_server *server;
 697	struct rpc_clnt *rpc;
 698
 699	server = NFS_SB(sb);
 700	/* -EIO all pending I/O */
 701	rpc = server->client_acl;
 702	if (!IS_ERR(rpc))
 703		rpc_killall_tasks(rpc);
 704	rpc = server->client;
 705	if (!IS_ERR(rpc))
 706		rpc_killall_tasks(rpc);
 707}
 708EXPORT_SYMBOL_GPL(nfs_umount_begin);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 709
 710/*
 711 * Return true if 'match' is in auth_info or auth_info is empty.
 712 * Return false otherwise.
 
 
 713 */
 714bool nfs_auth_info_match(const struct nfs_auth_info *auth_info,
 715			 rpc_authflavor_t match)
 716{
 717	int i;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 718
 719	if (!auth_info->flavor_len)
 720		return true;
 721
 722	for (i = 0; i < auth_info->flavor_len; i++) {
 723		if (auth_info->flavors[i] == match)
 724			return true;
 
 
 
 
 
 
 
 
 
 
 725	}
 726	return false;
 727}
 728EXPORT_SYMBOL_GPL(nfs_auth_info_match);
 729
 730/*
 731 * Ensure that a specified authtype in ctx->auth_info is supported by
 732 * the server. Returns 0 and sets ctx->selected_flavor if it's ok, and
 733 * -EACCES if not.
 734 */
 735static int nfs_verify_authflavors(struct nfs_fs_context *ctx,
 736				  rpc_authflavor_t *server_authlist,
 737				  unsigned int count)
 738{
 739	rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
 740	bool found_auth_null = false;
 741	unsigned int i;
 742
 743	/*
 744	 * If the sec= mount option is used, the specified flavor or AUTH_NULL
 745	 * must be in the list returned by the server.
 746	 *
 747	 * AUTH_NULL has a special meaning when it's in the server list - it
 748	 * means that the server will ignore the rpc creds, so any flavor
 749	 * can be used but still use the sec= that was specified.
 750	 *
 751	 * Note also that the MNT procedure in MNTv1 does not return a list
 752	 * of supported security flavors. In this case, nfs_mount() fabricates
 753	 * a security flavor list containing just AUTH_NULL.
 754	 */
 755	for (i = 0; i < count; i++) {
 756		flavor = server_authlist[i];
 757
 758		if (nfs_auth_info_match(&ctx->auth_info, flavor))
 759			goto out;
 
 
 
 
 
 760
 761		if (flavor == RPC_AUTH_NULL)
 762			found_auth_null = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 763	}
 764
 765	if (found_auth_null) {
 766		flavor = ctx->auth_info.flavors[0];
 767		goto out;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 768	}
 
 
 769
 770	dfprintk(MOUNT,
 771		 "NFS: specified auth flavors not supported by server\n");
 772	return -EACCES;
 
 
 
 773
 774out:
 775	ctx->selected_flavor = flavor;
 776	dfprintk(MOUNT, "NFS: using auth flavor %u\n", ctx->selected_flavor);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 777	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 778}
 779
 780/*
 781 * Use the remote server's MOUNT service to request the NFS file handle
 782 * corresponding to the provided path.
 783 */
 784static int nfs_request_mount(struct fs_context *fc,
 785			     struct nfs_fh *root_fh,
 786			     rpc_authflavor_t *server_authlist,
 787			     unsigned int *server_authlist_len)
 788{
 789	struct nfs_fs_context *ctx = nfs_fc2context(fc);
 
 790	struct nfs_mount_request request = {
 791		.sap		= (struct sockaddr *)
 792						&ctx->mount_server.address,
 793		.dirpath	= ctx->nfs_server.export_path,
 794		.protocol	= ctx->mount_server.protocol,
 795		.fh		= root_fh,
 796		.noresvport	= ctx->flags & NFS_MOUNT_NORESVPORT,
 797		.auth_flav_len	= server_authlist_len,
 798		.auth_flavs	= server_authlist,
 799		.net		= fc->net_ns,
 800	};
 801	int status;
 802
 803	if (ctx->mount_server.version == 0) {
 804		switch (ctx->version) {
 805			default:
 806				ctx->mount_server.version = NFS_MNT3_VERSION;
 807				break;
 808			case 2:
 809				ctx->mount_server.version = NFS_MNT_VERSION;
 810		}
 811	}
 812	request.version = ctx->mount_server.version;
 813
 814	if (ctx->mount_server.hostname)
 815		request.hostname = ctx->mount_server.hostname;
 816	else
 817		request.hostname = ctx->nfs_server.hostname;
 818
 819	/*
 820	 * Construct the mount server's address.
 821	 */
 822	if (ctx->mount_server.address.sa_family == AF_UNSPEC) {
 823		memcpy(request.sap, &ctx->nfs_server.address,
 824		       ctx->nfs_server.addrlen);
 825		ctx->mount_server.addrlen = ctx->nfs_server.addrlen;
 826	}
 827	request.salen = ctx->mount_server.addrlen;
 828	nfs_set_port(request.sap, &ctx->mount_server.port, 0);
 829
 830	/*
 831	 * Now ask the mount server to map our export path
 832	 * to a file handle.
 833	 */
 834	status = nfs_mount(&request);
 835	if (status != 0) {
 836		dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
 837				request.hostname, status);
 838		return status;
 839	}
 840
 841	return 0;
 
 
 
 
 
 842}
 843
 844static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 
 845{
 846	struct nfs_fs_context *ctx = nfs_fc2context(fc);
 847	int status;
 848	unsigned int i;
 849	bool tried_auth_unix = false;
 850	bool auth_null_in_list = false;
 851	struct nfs_server *server = ERR_PTR(-EACCES);
 852	rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
 853	unsigned int authlist_len = ARRAY_SIZE(authlist);
 854
 855	status = nfs_request_mount(fc, ctx->mntfh, authlist, &authlist_len);
 856	if (status)
 857		return ERR_PTR(status);
 858
 859	/*
 860	 * Was a sec= authflavor specified in the options? First, verify
 861	 * whether the server supports it, and then just try to use it if so.
 862	 */
 863	if (ctx->auth_info.flavor_len > 0) {
 864		status = nfs_verify_authflavors(ctx, authlist, authlist_len);
 865		dfprintk(MOUNT, "NFS: using auth flavor %u\n",
 866			 ctx->selected_flavor);
 867		if (status)
 868			return ERR_PTR(status);
 869		return ctx->nfs_mod->rpc_ops->create_server(fc);
 870	}
 871
 872	/*
 873	 * No sec= option was provided. RFC 2623, section 2.7 suggests we
 874	 * SHOULD prefer the flavor listed first. However, some servers list
 875	 * AUTH_NULL first. Avoid ever choosing AUTH_NULL.
 876	 */
 877	for (i = 0; i < authlist_len; ++i) {
 878		rpc_authflavor_t flavor;
 879		struct rpcsec_gss_info info;
 880
 881		flavor = authlist[i];
 882		switch (flavor) {
 883		case RPC_AUTH_UNIX:
 884			tried_auth_unix = true;
 885			break;
 886		case RPC_AUTH_NULL:
 887			auth_null_in_list = true;
 888			continue;
 889		default:
 890			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 891				continue;
 892			/* Fallthrough */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 893		}
 894		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 895		ctx->selected_flavor = flavor;
 896		server = ctx->nfs_mod->rpc_ops->create_server(fc);
 897		if (!IS_ERR(server))
 898			return server;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 899	}
 900
 901	/*
 902	 * Nothing we tried so far worked. At this point, give up if we've
 903	 * already tried AUTH_UNIX or if the server's list doesn't contain
 904	 * AUTH_NULL
 905	 */
 906	if (tried_auth_unix || !auth_null_in_list)
 907		return server;
 908
 909	/* Last chance! Try AUTH_UNIX */
 910	dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", RPC_AUTH_UNIX);
 911	ctx->selected_flavor = RPC_AUTH_UNIX;
 912	return ctx->nfs_mod->rpc_ops->create_server(fc);
 913}
 914
 915int nfs_try_get_tree(struct fs_context *fc)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 916{
 917	struct nfs_fs_context *ctx = nfs_fc2context(fc);
 
 
 918
 919	if (ctx->need_mount)
 920		ctx->server = nfs_try_mount_request(fc);
 921	else
 922		ctx->server = ctx->nfs_mod->rpc_ops->create_server(fc);
 
 
 
 
 923
 924	return nfs_get_tree_common(fc);
 925}
 926EXPORT_SYMBOL_GPL(nfs_try_get_tree);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 927
 
 928
 929#define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \
 930		| NFS_MOUNT_SECURE \
 931		| NFS_MOUNT_TCP \
 932		| NFS_MOUNT_VER3 \
 933		| NFS_MOUNT_KERBEROS \
 934		| NFS_MOUNT_NONLM \
 935		| NFS_MOUNT_BROKEN_SUID \
 936		| NFS_MOUNT_STRICTLOCK \
 937		| NFS_MOUNT_LEGACY_INTERFACE)
 938
 939#define NFS_MOUNT_CMP_FLAGMASK (NFS_REMOUNT_CMP_FLAGMASK & \
 940		~(NFS_MOUNT_UNSHARED | NFS_MOUNT_NORESVPORT))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 941
 942static int
 943nfs_compare_remount_data(struct nfs_server *nfss,
 944			 struct nfs_fs_context *ctx)
 945{
 946	if ((ctx->flags ^ nfss->flags) & NFS_REMOUNT_CMP_FLAGMASK ||
 947	    ctx->rsize != nfss->rsize ||
 948	    ctx->wsize != nfss->wsize ||
 949	    ctx->version != nfss->nfs_client->rpc_ops->version ||
 950	    ctx->minorversion != nfss->nfs_client->cl_minorversion ||
 951	    ctx->retrans != nfss->client->cl_timeout->to_retries ||
 952	    !nfs_auth_info_match(&ctx->auth_info, nfss->client->cl_auth->au_flavor) ||
 953	    ctx->acregmin != nfss->acregmin / HZ ||
 954	    ctx->acregmax != nfss->acregmax / HZ ||
 955	    ctx->acdirmin != nfss->acdirmin / HZ ||
 956	    ctx->acdirmax != nfss->acdirmax / HZ ||
 957	    ctx->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
 958	    (ctx->options & NFS_OPTION_FSCACHE) != (nfss->options & NFS_OPTION_FSCACHE) ||
 959	    ctx->nfs_server.port != nfss->port ||
 960	    ctx->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
 961	    !rpc_cmp_addr((struct sockaddr *)&ctx->nfs_server.address,
 962			  (struct sockaddr *)&nfss->nfs_client->cl_addr))
 963		return -EINVAL;
 964
 965	return 0;
 966}
 967
 968int nfs_reconfigure(struct fs_context *fc)
 
 969{
 970	struct nfs_fs_context *ctx = nfs_fc2context(fc);
 971	struct super_block *sb = fc->root->d_sb;
 972	struct nfs_server *nfss = sb->s_fs_info;
 973
 974	sync_filesystem(sb);
 
 
 975
 976	/*
 977	 * Userspace mount programs that send binary options generally send
 978	 * them populated with default values. We have no way to know which
 979	 * ones were explicitly specified. Fall back to legacy behavior and
 980	 * just return success.
 981	 */
 982	if (ctx->skip_reconfig_option_check)
 
 
 983		return 0;
 984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 985	/*
 986	 * noac is a special case. It implies -o sync, but that's not
 987	 * necessarily reflected in the mtab options. reconfigure_super
 988	 * will clear SB_SYNCHRONOUS if -o sync wasn't specified in the
 989	 * remount options, so we have to explicitly reset it.
 990	 */
 991	if (ctx->flags & NFS_MOUNT_NOAC) {
 992		fc->sb_flags |= SB_SYNCHRONOUS;
 993		fc->sb_flags_mask |= SB_SYNCHRONOUS;
 994	}
 995
 996	/* compare new mount options with old ones */
 997	return nfs_compare_remount_data(nfss, ctx);
 
 
 
 998}
 999EXPORT_SYMBOL_GPL(nfs_reconfigure);
1000
1001/*
1002 * Finish setting up an NFS superblock
1003 */
1004static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
1005{
1006	struct nfs_server *server = NFS_SB(sb);
1007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1008	sb->s_blocksize_bits = 0;
1009	sb->s_blocksize = 0;
1010	sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
1011	sb->s_op = server->nfs_client->cl_nfs_mod->sops;
1012	if (ctx && ctx->bsize)
1013		sb->s_blocksize = nfs_block_size(ctx->bsize, &sb->s_blocksize_bits);
1014
1015	if (server->nfs_client->rpc_ops->version != 2) {
1016		/* The VFS shouldn't apply the umask to mode bits. We will do
1017		 * so ourselves when necessary.
1018		 */
1019		sb->s_flags |= SB_POSIXACL;
1020		sb->s_time_gran = 1;
1021		sb->s_export_op = &nfs_export_ops;
1022	} else
1023		sb->s_time_gran = 1000;
1024
1025	if (server->nfs_client->rpc_ops->version != 4) {
1026		sb->s_time_min = 0;
1027		sb->s_time_max = U32_MAX;
1028	} else {
1029		sb->s_time_min = S64_MIN;
1030		sb->s_time_max = S64_MAX;
1031	}
1032
1033	sb->s_magic = NFS_SUPER_MAGIC;
 
 
1034
1035	/* We probably want something more informative here */
1036	snprintf(sb->s_id, sizeof(sb->s_id),
1037		 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
 
 
 
 
 
1038
1039	if (sb->s_blocksize == 0)
1040		sb->s_blocksize = nfs_block_bits(server->wsize,
1041						 &sb->s_blocksize_bits);
1042
1043	nfs_super_set_maxbytes(sb, server->maxfilesize);
 
 
 
 
 
 
 
 
 
1044}
1045
1046static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b,
1047				     const struct fs_context *fc)
1048{
1049	const struct nfs_server *a = s->s_fs_info;
1050	const struct rpc_clnt *clnt_a = a->client;
1051	const struct rpc_clnt *clnt_b = b->client;
1052
1053	if ((s->s_flags & NFS_SB_MASK) != (fc->sb_flags & NFS_SB_MASK))
1054		goto Ebusy;
1055	if (a->nfs_client != b->nfs_client)
1056		goto Ebusy;
1057	if ((a->flags ^ b->flags) & NFS_MOUNT_CMP_FLAGMASK)
1058		goto Ebusy;
1059	if (a->wsize != b->wsize)
1060		goto Ebusy;
1061	if (a->rsize != b->rsize)
1062		goto Ebusy;
1063	if (a->acregmin != b->acregmin)
1064		goto Ebusy;
1065	if (a->acregmax != b->acregmax)
1066		goto Ebusy;
1067	if (a->acdirmin != b->acdirmin)
1068		goto Ebusy;
1069	if (a->acdirmax != b->acdirmax)
1070		goto Ebusy;
1071	if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1072		goto Ebusy;
1073	return 1;
1074Ebusy:
1075	return 0;
1076}
1077
1078static int nfs_set_super(struct super_block *s, struct fs_context *fc)
 
 
 
 
 
1079{
1080	struct nfs_server *server = fc->s_fs_info;
 
1081	int ret;
1082
 
 
1083	s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
1084	ret = set_anon_super(s, server);
1085	if (ret == 0)
1086		server->s_dev = s->s_dev;
1087	return ret;
1088}
1089
1090static int nfs_compare_super_address(struct nfs_server *server1,
1091				     struct nfs_server *server2)
1092{
1093	struct sockaddr *sap1, *sap2;
1094	struct rpc_xprt *xprt1 = server1->client->cl_xprt;
1095	struct rpc_xprt *xprt2 = server2->client->cl_xprt;
1096
1097	if (!net_eq(xprt1->xprt_net, xprt2->xprt_net))
1098		return 0;
1099
1100	sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1101	sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1102
1103	if (sap1->sa_family != sap2->sa_family)
1104		return 0;
1105
1106	switch (sap1->sa_family) {
1107	case AF_INET: {
1108		struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1109		struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1110		if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1111			return 0;
1112		if (sin1->sin_port != sin2->sin_port)
1113			return 0;
1114		break;
1115	}
1116	case AF_INET6: {
1117		struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1118		struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1119		if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1120			return 0;
1121		if (sin1->sin6_port != sin2->sin6_port)
1122			return 0;
1123		break;
1124	}
1125	default:
1126		return 0;
1127	}
1128
1129	return 1;
1130}
1131
1132static int nfs_compare_userns(const struct nfs_server *old,
1133		const struct nfs_server *new)
1134{
1135	const struct user_namespace *oldns = &init_user_ns;
1136	const struct user_namespace *newns = &init_user_ns;
1137
1138	if (old->client && old->client->cl_cred)
1139		oldns = old->client->cl_cred->user_ns;
1140	if (new->client && new->client->cl_cred)
1141		newns = new->client->cl_cred->user_ns;
1142	if (oldns != newns)
1143		return 0;
1144	return 1;
1145}
1146
1147static int nfs_compare_super(struct super_block *sb, struct fs_context *fc)
1148{
1149	struct nfs_server *server = fc->s_fs_info, *old = NFS_SB(sb);
1150
1151	if (!nfs_compare_super_address(old, server))
1152		return 0;
1153	/* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1154	if (old->flags & NFS_MOUNT_UNSHARED)
1155		return 0;
1156	if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1157		return 0;
1158	if (!nfs_compare_userns(old, server))
1159		return 0;
1160	return nfs_compare_mount_options(sb, server, fc);
1161}
1162
1163#ifdef CONFIG_NFS_FSCACHE
1164static void nfs_get_cache_cookie(struct super_block *sb,
1165				 struct nfs_fs_context *ctx)
 
1166{
1167	struct nfs_server *nfss = NFS_SB(sb);
1168	char *uniq = NULL;
1169	int ulen = 0;
1170
1171	nfss->fscache_key = NULL;
1172	nfss->fscache = NULL;
1173
1174	if (!ctx)
1175		return;
1176
1177	if (ctx->clone_data.sb) {
1178		struct nfs_server *mnt_s = NFS_SB(ctx->clone_data.sb);
1179		if (!(mnt_s->options & NFS_OPTION_FSCACHE))
1180			return;
1181		if (mnt_s->fscache_key) {
1182			uniq = mnt_s->fscache_key->key.uniquifier;
1183			ulen = mnt_s->fscache_key->key.uniq_len;
1184		}
1185	} else {
1186		if (!(ctx->options & NFS_OPTION_FSCACHE))
1187			return;
1188		if (ctx->fscache_uniq) {
1189			uniq = ctx->fscache_uniq;
1190			ulen = strlen(ctx->fscache_uniq);
1191		}
1192	}
1193
1194	nfs_fscache_get_super_cookie(sb, uniq, ulen);
1195}
1196#else
1197static void nfs_get_cache_cookie(struct super_block *sb,
1198				 struct nfs_fs_context *ctx)
 
1199{
1200}
1201#endif
1202
1203static void nfs_set_readahead(struct backing_dev_info *bdi,
1204			      unsigned long iomax_pages)
1205{
1206	bdi->ra_pages = VM_READAHEAD_PAGES;
1207	bdi->io_pages = iomax_pages;
1208}
1209
1210int nfs_get_tree_common(struct fs_context *fc)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211{
1212	struct nfs_fs_context *ctx = nfs_fc2context(fc);
1213	struct super_block *s;
1214	int (*compare_super)(struct super_block *, struct fs_context *) = nfs_compare_super;
1215	struct nfs_server *server = ctx->server;
 
 
 
 
1216	int error;
1217
1218	ctx->server = NULL;
1219	if (IS_ERR(server))
1220		return PTR_ERR(server);
1221
1222	if (server->flags & NFS_MOUNT_UNSHARED)
1223		compare_super = NULL;
1224
1225	/* -o noac implies -o sync */
1226	if (server->flags & NFS_MOUNT_NOAC)
1227		fc->sb_flags |= SB_SYNCHRONOUS;
1228
1229	if (ctx->clone_data.sb)
1230		if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS)
1231			fc->sb_flags |= SB_SYNCHRONOUS;
1232
1233	if (server->caps & NFS_CAP_SECURITY_LABEL)
1234		fc->lsm_flags |= SECURITY_LSM_NATIVE_LABELS;
1235
1236	/* Get a superblock - note that we may end up sharing one that already exists */
1237	fc->s_fs_info = server;
1238	s = sget_fc(fc, compare_super, nfs_set_super);
1239	fc->s_fs_info = NULL;
1240	if (IS_ERR(s)) {
1241		error = PTR_ERR(s);
1242		nfs_errorf(fc, "NFS: Couldn't get superblock");
1243		goto out_err_nosb;
1244	}
1245
1246	if (s->s_fs_info != server) {
1247		nfs_free_server(server);
1248		server = NULL;
1249	} else {
1250		error = super_setup_bdi_name(s, "%u:%u", MAJOR(server->s_dev),
1251					     MINOR(server->s_dev));
1252		if (error)
1253			goto error_splat_super;
1254		nfs_set_readahead(s->s_bdi, server->rpages);
1255		server->super = s;
1256	}
1257
1258	if (!s->s_root) {
1259		unsigned bsize = ctx->clone_data.inherited_bsize;
1260		/* initial superblock/root creation */
1261		nfs_fill_super(s, ctx);
1262		if (bsize) {
1263			s->s_blocksize_bits = bsize;
1264			s->s_blocksize = 1U << bsize;
1265		}
1266		nfs_get_cache_cookie(s, ctx);
1267	}
1268
1269	error = nfs_get_root(s, fc);
1270	if (error < 0) {
1271		nfs_errorf(fc, "NFS: Couldn't get root dentry");
1272		goto error_splat_super;
1273	}
1274
1275	s->s_flags |= SB_ACTIVE;
1276	error = 0;
 
 
 
1277
1278out:
1279	return error;
1280
1281out_err_nosb:
1282	nfs_free_server(server);
1283	goto out;
 
 
 
 
1284error_splat_super:
 
 
 
1285	deactivate_locked_super(s);
1286	goto out;
1287}
1288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1289/*
1290 * Destroy an NFS2/3 superblock
 
1291 */
1292void nfs_kill_super(struct super_block *s)
1293{
1294	struct nfs_server *server = NFS_SB(s);
1295	dev_t dev = s->s_dev;
1296
1297	generic_shutdown_super(s);
 
1298
1299	nfs_fscache_release_super_cookie(s);
 
 
 
 
 
1300
 
 
1301	nfs_free_server(server);
1302	free_anon_bdev(dev);
1303}
1304EXPORT_SYMBOL_GPL(nfs_kill_super);
1305
1306#if IS_ENABLED(CONFIG_NFS_V4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1307
1308/*
1309 * NFS v4 module parameters need to stay in the
1310 * NFS client for backwards compatibility
1311 */
1312unsigned int nfs_callback_set_tcpport;
1313unsigned short nfs_callback_nr_threads;
1314/* Default cache timeout is 10 minutes */
1315unsigned int nfs_idmap_cache_timeout = 600;
1316/* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
1317bool nfs4_disable_idmapping = true;
1318unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
1319unsigned short max_session_cb_slots = NFS4_DEF_CB_SLOT_TABLE_SIZE;
1320unsigned short send_implementation_id = 1;
1321char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
1322bool recover_lost_locks = false;
1323
1324EXPORT_SYMBOL_GPL(nfs_callback_nr_threads);
1325EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
1326EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
1327EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
1328EXPORT_SYMBOL_GPL(max_session_slots);
1329EXPORT_SYMBOL_GPL(max_session_cb_slots);
1330EXPORT_SYMBOL_GPL(send_implementation_id);
1331EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
1332EXPORT_SYMBOL_GPL(recover_lost_locks);
1333
1334#define NFS_CALLBACK_MAXPORTNR (65535U)
1335
1336static int param_set_portnr(const char *val, const struct kernel_param *kp)
 
 
 
 
1337{
1338	unsigned long num;
1339	int ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1340
1341	if (!val)
1342		return -EINVAL;
1343	ret = kstrtoul(val, 0, &num);
1344	if (ret || num > NFS_CALLBACK_MAXPORTNR)
1345		return -EINVAL;
1346	*((unsigned int *)kp->arg) = num;
1347	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1348}
1349static const struct kernel_param_ops param_ops_portnr = {
1350	.set = param_set_portnr,
1351	.get = param_get_uint,
1352};
1353#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
1354
1355module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
1356module_param_named(callback_nr_threads, nfs_callback_nr_threads, ushort, 0644);
1357MODULE_PARM_DESC(callback_nr_threads, "Number of threads that will be "
1358		"assigned to the NFSv4 callback channels.");
1359module_param(nfs_idmap_cache_timeout, int, 0644);
1360module_param(nfs4_disable_idmapping, bool, 0644);
1361module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
1362			NFS4_CLIENT_ID_UNIQ_LEN, 0600);
1363MODULE_PARM_DESC(nfs4_disable_idmapping,
1364		"Turn off NFSv4 idmapping when using 'sec=sys'");
1365module_param(max_session_slots, ushort, 0644);
1366MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
1367		"requests the client will negotiate");
1368module_param(max_session_cb_slots, ushort, 0644);
1369MODULE_PARM_DESC(max_session_cb_slots, "Maximum number of parallel NFSv4.1 "
1370		"callbacks the client will process for a given server");
1371module_param(send_implementation_id, ushort, 0644);
1372MODULE_PARM_DESC(send_implementation_id,
1373		"Send implementation ID with NFSv4.1 exchange_id");
1374MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
1375
1376module_param(recover_lost_locks, bool, 0644);
1377MODULE_PARM_DESC(recover_lost_locks,
1378		 "If the server reports that a lock might be lost, "
1379		 "try to recover it risking data corruption.");
1380
 
1381
1382#endif /* CONFIG_NFS_V4 */
v3.5.6
 
   1/*
   2 *  linux/fs/nfs/super.c
   3 *
   4 *  Copyright (C) 1992  Rick Sladkey
   5 *
   6 *  nfs superblock handling functions
   7 *
   8 *  Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
   9 *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
  10 *
  11 *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  12 *  J.S.Peatfield@damtp.cam.ac.uk
  13 *
  14 *  Split from inode.c by David Howells <dhowells@redhat.com>
  15 *
  16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
  17 *   particular server are held in the same superblock
  18 * - NFS superblocks can have several effective roots to the dentry tree
  19 * - directory type roots are spliced into the tree when a path from one root reaches the root
  20 *   of another (see nfs_lookup())
  21 */
  22
  23#include <linux/module.h>
  24#include <linux/init.h>
  25
  26#include <linux/time.h>
  27#include <linux/kernel.h>
  28#include <linux/mm.h>
  29#include <linux/string.h>
  30#include <linux/stat.h>
  31#include <linux/errno.h>
  32#include <linux/unistd.h>
  33#include <linux/sunrpc/clnt.h>
 
  34#include <linux/sunrpc/stats.h>
  35#include <linux/sunrpc/metrics.h>
  36#include <linux/sunrpc/xprtsock.h>
  37#include <linux/sunrpc/xprtrdma.h>
  38#include <linux/nfs_fs.h>
  39#include <linux/nfs_mount.h>
  40#include <linux/nfs4_mount.h>
  41#include <linux/lockd/bind.h>
  42#include <linux/seq_file.h>
  43#include <linux/mount.h>
  44#include <linux/namei.h>
  45#include <linux/nfs_idmap.h>
  46#include <linux/vfs.h>
  47#include <linux/inet.h>
  48#include <linux/in6.h>
  49#include <linux/slab.h>
  50#include <net/ipv6.h>
  51#include <linux/netdevice.h>
  52#include <linux/nfs_xdr.h>
  53#include <linux/magic.h>
  54#include <linux/parser.h>
  55#include <linux/nsproxy.h>
  56#include <linux/rcupdate.h>
  57
  58#include <asm/uaccess.h>
  59
  60#include "nfs4_fs.h"
  61#include "callback.h"
  62#include "delegation.h"
  63#include "iostat.h"
  64#include "internal.h"
  65#include "fscache.h"
 
  66#include "pnfs.h"
 
  67
  68#define NFSDBG_FACILITY		NFSDBG_VFS
  69#define NFS_TEXT_DATA		1
  70
  71#ifdef CONFIG_NFS_V3
  72#define NFS_DEFAULT_VERSION 3
  73#else
  74#define NFS_DEFAULT_VERSION 2
  75#endif
  76
  77enum {
  78	/* Mount options that take no arguments */
  79	Opt_soft, Opt_hard,
  80	Opt_posix, Opt_noposix,
  81	Opt_cto, Opt_nocto,
  82	Opt_ac, Opt_noac,
  83	Opt_lock, Opt_nolock,
  84	Opt_udp, Opt_tcp, Opt_rdma,
  85	Opt_acl, Opt_noacl,
  86	Opt_rdirplus, Opt_nordirplus,
  87	Opt_sharecache, Opt_nosharecache,
  88	Opt_resvport, Opt_noresvport,
  89	Opt_fscache, Opt_nofscache,
  90
  91	/* Mount options that take integer arguments */
  92	Opt_port,
  93	Opt_rsize, Opt_wsize, Opt_bsize,
  94	Opt_timeo, Opt_retrans,
  95	Opt_acregmin, Opt_acregmax,
  96	Opt_acdirmin, Opt_acdirmax,
  97	Opt_actimeo,
  98	Opt_namelen,
  99	Opt_mountport,
 100	Opt_mountvers,
 101	Opt_minorversion,
 102
 103	/* Mount options that take string arguments */
 104	Opt_nfsvers,
 105	Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
 106	Opt_addr, Opt_mountaddr, Opt_clientaddr,
 107	Opt_lookupcache,
 108	Opt_fscache_uniq,
 109	Opt_local_lock,
 110
 111	/* Special mount options */
 112	Opt_userspace, Opt_deprecated, Opt_sloppy,
 113
 114	Opt_err
 115};
 116
 117static const match_table_t nfs_mount_option_tokens = {
 118	{ Opt_userspace, "bg" },
 119	{ Opt_userspace, "fg" },
 120	{ Opt_userspace, "retry=%s" },
 121
 122	{ Opt_sloppy, "sloppy" },
 123
 124	{ Opt_soft, "soft" },
 125	{ Opt_hard, "hard" },
 126	{ Opt_deprecated, "intr" },
 127	{ Opt_deprecated, "nointr" },
 128	{ Opt_posix, "posix" },
 129	{ Opt_noposix, "noposix" },
 130	{ Opt_cto, "cto" },
 131	{ Opt_nocto, "nocto" },
 132	{ Opt_ac, "ac" },
 133	{ Opt_noac, "noac" },
 134	{ Opt_lock, "lock" },
 135	{ Opt_nolock, "nolock" },
 136	{ Opt_udp, "udp" },
 137	{ Opt_tcp, "tcp" },
 138	{ Opt_rdma, "rdma" },
 139	{ Opt_acl, "acl" },
 140	{ Opt_noacl, "noacl" },
 141	{ Opt_rdirplus, "rdirplus" },
 142	{ Opt_nordirplus, "nordirplus" },
 143	{ Opt_sharecache, "sharecache" },
 144	{ Opt_nosharecache, "nosharecache" },
 145	{ Opt_resvport, "resvport" },
 146	{ Opt_noresvport, "noresvport" },
 147	{ Opt_fscache, "fsc" },
 148	{ Opt_nofscache, "nofsc" },
 149
 150	{ Opt_port, "port=%s" },
 151	{ Opt_rsize, "rsize=%s" },
 152	{ Opt_wsize, "wsize=%s" },
 153	{ Opt_bsize, "bsize=%s" },
 154	{ Opt_timeo, "timeo=%s" },
 155	{ Opt_retrans, "retrans=%s" },
 156	{ Opt_acregmin, "acregmin=%s" },
 157	{ Opt_acregmax, "acregmax=%s" },
 158	{ Opt_acdirmin, "acdirmin=%s" },
 159	{ Opt_acdirmax, "acdirmax=%s" },
 160	{ Opt_actimeo, "actimeo=%s" },
 161	{ Opt_namelen, "namlen=%s" },
 162	{ Opt_mountport, "mountport=%s" },
 163	{ Opt_mountvers, "mountvers=%s" },
 164	{ Opt_minorversion, "minorversion=%s" },
 165
 166	{ Opt_nfsvers, "nfsvers=%s" },
 167	{ Opt_nfsvers, "vers=%s" },
 168
 169	{ Opt_sec, "sec=%s" },
 170	{ Opt_proto, "proto=%s" },
 171	{ Opt_mountproto, "mountproto=%s" },
 172	{ Opt_addr, "addr=%s" },
 173	{ Opt_clientaddr, "clientaddr=%s" },
 174	{ Opt_mounthost, "mounthost=%s" },
 175	{ Opt_mountaddr, "mountaddr=%s" },
 176
 177	{ Opt_lookupcache, "lookupcache=%s" },
 178	{ Opt_fscache_uniq, "fsc=%s" },
 179	{ Opt_local_lock, "local_lock=%s" },
 180
 181	/* The following needs to be listed after all other options */
 182	{ Opt_nfsvers, "v%s" },
 183
 184	{ Opt_err, NULL }
 185};
 186
 187enum {
 188	Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
 189
 190	Opt_xprt_err
 191};
 192
 193static const match_table_t nfs_xprt_protocol_tokens = {
 194	{ Opt_xprt_udp, "udp" },
 195	{ Opt_xprt_udp6, "udp6" },
 196	{ Opt_xprt_tcp, "tcp" },
 197	{ Opt_xprt_tcp6, "tcp6" },
 198	{ Opt_xprt_rdma, "rdma" },
 199
 200	{ Opt_xprt_err, NULL }
 201};
 202
 203enum {
 204	Opt_sec_none, Opt_sec_sys,
 205	Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
 206	Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
 207	Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
 208
 209	Opt_sec_err
 210};
 211
 212static const match_table_t nfs_secflavor_tokens = {
 213	{ Opt_sec_none, "none" },
 214	{ Opt_sec_none, "null" },
 215	{ Opt_sec_sys, "sys" },
 216
 217	{ Opt_sec_krb5, "krb5" },
 218	{ Opt_sec_krb5i, "krb5i" },
 219	{ Opt_sec_krb5p, "krb5p" },
 220
 221	{ Opt_sec_lkey, "lkey" },
 222	{ Opt_sec_lkeyi, "lkeyi" },
 223	{ Opt_sec_lkeyp, "lkeyp" },
 224
 225	{ Opt_sec_spkm, "spkm3" },
 226	{ Opt_sec_spkmi, "spkm3i" },
 227	{ Opt_sec_spkmp, "spkm3p" },
 228
 229	{ Opt_sec_err, NULL }
 230};
 231
 232enum {
 233	Opt_lookupcache_all, Opt_lookupcache_positive,
 234	Opt_lookupcache_none,
 235
 236	Opt_lookupcache_err
 237};
 238
 239static match_table_t nfs_lookupcache_tokens = {
 240	{ Opt_lookupcache_all, "all" },
 241	{ Opt_lookupcache_positive, "pos" },
 242	{ Opt_lookupcache_positive, "positive" },
 243	{ Opt_lookupcache_none, "none" },
 244
 245	{ Opt_lookupcache_err, NULL }
 246};
 247
 248enum {
 249	Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
 250	Opt_local_lock_none,
 251
 252	Opt_local_lock_err
 253};
 254
 255static match_table_t nfs_local_lock_tokens = {
 256	{ Opt_local_lock_all, "all" },
 257	{ Opt_local_lock_flock, "flock" },
 258	{ Opt_local_lock_posix, "posix" },
 259	{ Opt_local_lock_none, "none" },
 260
 261	{ Opt_local_lock_err, NULL }
 262};
 263
 264enum {
 265	Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
 266	Opt_vers_4_1,
 267
 268	Opt_vers_err
 269};
 270
 271static match_table_t nfs_vers_tokens = {
 272	{ Opt_vers_2, "2" },
 273	{ Opt_vers_3, "3" },
 274	{ Opt_vers_4, "4" },
 275	{ Opt_vers_4_0, "4.0" },
 276	{ Opt_vers_4_1, "4.1" },
 277
 278	{ Opt_vers_err, NULL }
 279};
 280
 281struct nfs_mount_info {
 282	void (*fill_super)(struct super_block *, struct nfs_mount_info *);
 283	int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
 284	struct nfs_parsed_mount_data *parsed;
 285	struct nfs_clone_mount *cloned;
 286	struct nfs_fh *mntfh;
 287};
 288
 289static void nfs_umount_begin(struct super_block *);
 290static int  nfs_statfs(struct dentry *, struct kstatfs *);
 291static int  nfs_show_options(struct seq_file *, struct dentry *);
 292static int  nfs_show_devname(struct seq_file *, struct dentry *);
 293static int  nfs_show_path(struct seq_file *, struct dentry *);
 294static int  nfs_show_stats(struct seq_file *, struct dentry *);
 295static struct dentry *nfs_fs_mount_common(struct file_system_type *,
 296		struct nfs_server *, int, const char *, struct nfs_mount_info *);
 297static struct dentry *nfs_fs_mount(struct file_system_type *,
 298		int, const char *, void *);
 299static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
 300		int flags, const char *dev_name, void *raw_data);
 301static void nfs_put_super(struct super_block *);
 302static void nfs_kill_super(struct super_block *);
 303static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
 304
 305static struct file_system_type nfs_fs_type = {
 306	.owner		= THIS_MODULE,
 307	.name		= "nfs",
 308	.mount		= nfs_fs_mount,
 309	.kill_sb	= nfs_kill_super,
 310	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 311};
 312
 313struct file_system_type nfs_xdev_fs_type = {
 314	.owner		= THIS_MODULE,
 315	.name		= "nfs",
 316	.mount		= nfs_xdev_mount,
 317	.kill_sb	= nfs_kill_super,
 318	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 319};
 320
 321static const struct super_operations nfs_sops = {
 322	.alloc_inode	= nfs_alloc_inode,
 323	.destroy_inode	= nfs_destroy_inode,
 324	.write_inode	= nfs_write_inode,
 325	.put_super	= nfs_put_super,
 326	.statfs		= nfs_statfs,
 327	.evict_inode	= nfs_evict_inode,
 328	.umount_begin	= nfs_umount_begin,
 329	.show_options	= nfs_show_options,
 330	.show_devname	= nfs_show_devname,
 331	.show_path	= nfs_show_path,
 332	.show_stats	= nfs_show_stats,
 333	.remount_fs	= nfs_remount,
 334};
 
 335
 336#ifdef CONFIG_NFS_V4
 337static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *);
 338static int nfs4_validate_mount_data(void *options,
 339	struct nfs_parsed_mount_data *args, const char *dev_name);
 340static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
 341	struct nfs_mount_info *mount_info);
 342static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
 343	int flags, const char *dev_name, void *raw_data);
 344static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
 345	int flags, const char *dev_name, void *raw_data);
 346static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
 347	int flags, const char *dev_name, void *raw_data);
 348static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
 349	int flags, const char *dev_name, void *raw_data);
 350static void nfs4_kill_super(struct super_block *sb);
 351
 352static struct file_system_type nfs4_fs_type = {
 353	.owner		= THIS_MODULE,
 354	.name		= "nfs4",
 355	.mount		= nfs_fs_mount,
 356	.kill_sb	= nfs4_kill_super,
 357	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 358};
 359
 360static struct file_system_type nfs4_remote_fs_type = {
 361	.owner		= THIS_MODULE,
 362	.name		= "nfs4",
 363	.mount		= nfs4_remote_mount,
 364	.kill_sb	= nfs4_kill_super,
 365	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 366};
 
 
 367
 368struct file_system_type nfs4_xdev_fs_type = {
 369	.owner		= THIS_MODULE,
 370	.name		= "nfs4",
 371	.mount		= nfs4_xdev_mount,
 372	.kill_sb	= nfs4_kill_super,
 373	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 374};
 375
 376static struct file_system_type nfs4_remote_referral_fs_type = {
 377	.owner		= THIS_MODULE,
 378	.name		= "nfs4",
 379	.mount		= nfs4_remote_referral_mount,
 380	.kill_sb	= nfs4_kill_super,
 381	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 382};
 383
 384struct file_system_type nfs4_referral_fs_type = {
 385	.owner		= THIS_MODULE,
 386	.name		= "nfs4",
 387	.mount		= nfs4_referral_mount,
 388	.kill_sb	= nfs4_kill_super,
 389	.fs_flags	= FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 390};
 391
 392static const struct super_operations nfs4_sops = {
 393	.alloc_inode	= nfs_alloc_inode,
 394	.destroy_inode	= nfs_destroy_inode,
 395	.write_inode	= nfs_write_inode,
 396	.put_super	= nfs_put_super,
 397	.statfs		= nfs_statfs,
 398	.evict_inode	= nfs4_evict_inode,
 399	.umount_begin	= nfs_umount_begin,
 400	.show_options	= nfs_show_options,
 401	.show_devname	= nfs_show_devname,
 402	.show_path	= nfs_show_path,
 403	.show_stats	= nfs_show_stats,
 404	.remount_fs	= nfs_remount,
 405};
 406#endif
 407
 408static struct shrinker acl_shrinker = {
 409	.shrink		= nfs_access_cache_shrinker,
 
 410	.seeks		= DEFAULT_SEEKS,
 411};
 412
 413/*
 414 * Register the NFS filesystems
 415 */
 416int __init register_nfs_fs(void)
 417{
 418	int ret;
 419
 420        ret = register_filesystem(&nfs_fs_type);
 421	if (ret < 0)
 422		goto error_0;
 423
 424	ret = nfs_register_sysctl();
 425	if (ret < 0)
 426		goto error_1;
 427#ifdef CONFIG_NFS_V4
 428	ret = register_filesystem(&nfs4_fs_type);
 429	if (ret < 0)
 430		goto error_2;
 431#endif
 432	register_shrinker(&acl_shrinker);
 
 433	return 0;
 434
 435#ifdef CONFIG_NFS_V4
 436error_2:
 437	nfs_unregister_sysctl();
 438#endif
 439error_1:
 440	unregister_filesystem(&nfs_fs_type);
 441error_0:
 442	return ret;
 443}
 444
 445/*
 446 * Unregister the NFS filesystems
 447 */
 448void __exit unregister_nfs_fs(void)
 449{
 450	unregister_shrinker(&acl_shrinker);
 451#ifdef CONFIG_NFS_V4
 452	unregister_filesystem(&nfs4_fs_type);
 453#endif
 454	nfs_unregister_sysctl();
 
 455	unregister_filesystem(&nfs_fs_type);
 456}
 457
 458void nfs_sb_active(struct super_block *sb)
 459{
 460	struct nfs_server *server = NFS_SB(sb);
 461
 462	if (atomic_inc_return(&server->active) == 1)
 463		atomic_inc(&sb->s_active);
 
 
 
 464}
 
 465
 466void nfs_sb_deactive(struct super_block *sb)
 467{
 468	struct nfs_server *server = NFS_SB(sb);
 469
 470	if (atomic_dec_and_test(&server->active))
 471		deactivate_super(sb);
 472}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 473
 474/*
 475 * Deliver file system statistics to userspace
 476 */
 477static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 478{
 479	struct nfs_server *server = NFS_SB(dentry->d_sb);
 480	unsigned char blockbits;
 481	unsigned long blockres;
 482	struct nfs_fh *fh = NFS_FH(dentry->d_inode);
 483	struct nfs_fsstat res;
 484	int error = -ENOMEM;
 485
 486	res.fattr = nfs_alloc_fattr();
 487	if (res.fattr == NULL)
 488		goto out_err;
 489
 490	error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
 491	if (unlikely(error == -ESTALE)) {
 492		struct dentry *pd_dentry;
 493
 494		pd_dentry = dget_parent(dentry);
 495		if (pd_dentry != NULL) {
 496			nfs_zap_caches(pd_dentry->d_inode);
 497			dput(pd_dentry);
 498		}
 499	}
 500	nfs_free_fattr(res.fattr);
 501	if (error < 0)
 502		goto out_err;
 503
 504	buf->f_type = NFS_SUPER_MAGIC;
 505
 506	/*
 507	 * Current versions of glibc do not correctly handle the
 508	 * case where f_frsize != f_bsize.  Eventually we want to
 509	 * report the value of wtmult in this field.
 510	 */
 511	buf->f_frsize = dentry->d_sb->s_blocksize;
 512
 513	/*
 514	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
 515	 * are reported in units of f_frsize.  Linux hasn't had
 516	 * an f_frsize field in its statfs struct until recently,
 517	 * thus historically Linux's sys_statfs reports these
 518	 * fields in units of f_bsize.
 519	 */
 520	buf->f_bsize = dentry->d_sb->s_blocksize;
 521	blockbits = dentry->d_sb->s_blocksize_bits;
 522	blockres = (1 << blockbits) - 1;
 523	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
 524	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
 525	buf->f_bavail = (res.abytes + blockres) >> blockbits;
 526
 527	buf->f_files = res.tfiles;
 528	buf->f_ffree = res.afiles;
 529
 530	buf->f_namelen = server->namelen;
 531
 532	return 0;
 533
 534 out_err:
 535	dprintk("%s: statfs error = %d\n", __func__, -error);
 536	return error;
 537}
 
 538
 539/*
 540 * Map the security flavour number to a name
 541 */
 542static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
 543{
 544	static const struct {
 545		rpc_authflavor_t flavour;
 546		const char *str;
 547	} sec_flavours[] = {
 
 548		{ RPC_AUTH_NULL, "null" },
 549		{ RPC_AUTH_UNIX, "sys" },
 550		{ RPC_AUTH_GSS_KRB5, "krb5" },
 551		{ RPC_AUTH_GSS_KRB5I, "krb5i" },
 552		{ RPC_AUTH_GSS_KRB5P, "krb5p" },
 553		{ RPC_AUTH_GSS_LKEY, "lkey" },
 554		{ RPC_AUTH_GSS_LKEYI, "lkeyi" },
 555		{ RPC_AUTH_GSS_LKEYP, "lkeyp" },
 556		{ RPC_AUTH_GSS_SPKM, "spkm" },
 557		{ RPC_AUTH_GSS_SPKMI, "spkmi" },
 558		{ RPC_AUTH_GSS_SPKMP, "spkmp" },
 559		{ UINT_MAX, "unknown" }
 560	};
 561	int i;
 562
 563	for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
 564		if (sec_flavours[i].flavour == flavour)
 565			break;
 566	}
 567	return sec_flavours[i].str;
 568}
 569
 570static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
 571				  int showdefaults)
 572{
 573	struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
 
 574
 575	seq_printf(m, ",mountproto=");
 576	switch (sap->sa_family) {
 577	case AF_INET:
 578		switch (nfss->mountd_protocol) {
 579		case IPPROTO_UDP:
 580			seq_printf(m, RPCBIND_NETID_UDP);
 581			break;
 582		case IPPROTO_TCP:
 583			seq_printf(m, RPCBIND_NETID_TCP);
 584			break;
 585		default:
 586			if (showdefaults)
 587				seq_printf(m, "auto");
 588		}
 589		break;
 590	case AF_INET6:
 591		switch (nfss->mountd_protocol) {
 592		case IPPROTO_UDP:
 593			seq_printf(m, RPCBIND_NETID_UDP6);
 594			break;
 595		case IPPROTO_TCP:
 596			seq_printf(m, RPCBIND_NETID_TCP6);
 597			break;
 598		default:
 599			if (showdefaults)
 600				seq_printf(m, "auto");
 601		}
 602		break;
 603	default:
 604		if (showdefaults)
 605			seq_printf(m, "auto");
 606	}
 
 
 607}
 608
 609static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
 610				    int showdefaults)
 611{
 612	struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
 613
 614	if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
 615		return;
 616
 617	switch (sap->sa_family) {
 618	case AF_INET: {
 619		struct sockaddr_in *sin = (struct sockaddr_in *)sap;
 620		seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
 621		break;
 622	}
 623	case AF_INET6: {
 624		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
 625		seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
 626		break;
 627	}
 628	default:
 629		if (showdefaults)
 630			seq_printf(m, ",mountaddr=unspecified");
 631	}
 632
 633	if (nfss->mountd_version || showdefaults)
 634		seq_printf(m, ",mountvers=%u", nfss->mountd_version);
 635	if ((nfss->mountd_port &&
 636		nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
 637		showdefaults)
 638		seq_printf(m, ",mountport=%u", nfss->mountd_port);
 639
 640	nfs_show_mountd_netid(m, nfss, showdefaults);
 641}
 642
 643#ifdef CONFIG_NFS_V4
 644static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
 645				    int showdefaults)
 646{
 647	struct nfs_client *clp = nfss->nfs_client;
 648
 649	seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
 650}
 651#else
 652static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
 653				    int showdefaults)
 654{
 655}
 656#endif
 657
 658static void nfs_show_nfs_version(struct seq_file *m,
 659		unsigned int version,
 660		unsigned int minorversion)
 661{
 662	seq_printf(m, ",vers=%u", version);
 663	if (version == 4)
 664		seq_printf(m, ".%u", minorversion);
 665}
 666
 667/*
 668 * Describe the mount options in force on this server representation
 669 */
 670static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
 671				   int showdefaults)
 672{
 673	static const struct proc_nfs_info {
 674		int flag;
 675		const char *str;
 676		const char *nostr;
 677	} nfs_info[] = {
 678		{ NFS_MOUNT_SOFT, ",soft", ",hard" },
 
 
 679		{ NFS_MOUNT_POSIX, ",posix", "" },
 680		{ NFS_MOUNT_NOCTO, ",nocto", "" },
 681		{ NFS_MOUNT_NOAC, ",noac", "" },
 682		{ NFS_MOUNT_NONLM, ",nolock", "" },
 683		{ NFS_MOUNT_NOACL, ",noacl", "" },
 684		{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
 685		{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
 686		{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
 687		{ 0, NULL, NULL }
 688	};
 689	const struct proc_nfs_info *nfs_infop;
 690	struct nfs_client *clp = nfss->nfs_client;
 691	u32 version = clp->rpc_ops->version;
 692	int local_flock, local_fcntl;
 693
 694	nfs_show_nfs_version(m, version, clp->cl_minorversion);
 695	seq_printf(m, ",rsize=%u", nfss->rsize);
 696	seq_printf(m, ",wsize=%u", nfss->wsize);
 697	if (nfss->bsize != 0)
 698		seq_printf(m, ",bsize=%u", nfss->bsize);
 699	seq_printf(m, ",namlen=%u", nfss->namelen);
 700	if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
 701		seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
 702	if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
 703		seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
 704	if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
 705		seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
 706	if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
 707		seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
 
 
 708	for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
 709		if (nfss->flags & nfs_infop->flag)
 710			seq_puts(m, nfs_infop->str);
 711		else
 712			seq_puts(m, nfs_infop->nostr);
 713	}
 714	rcu_read_lock();
 715	seq_printf(m, ",proto=%s",
 716		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
 717	rcu_read_unlock();
 
 
 718	if (version == 4) {
 719		if (nfss->port != NFS_PORT)
 720			seq_printf(m, ",port=%u", nfss->port);
 721	} else
 722		if (nfss->port)
 723			seq_printf(m, ",port=%u", nfss->port);
 724
 725	seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
 726	seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
 727	seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
 728
 729	if (version != 4)
 730		nfs_show_mountd_options(m, nfss, showdefaults);
 731	else
 732		nfs_show_nfsv4_options(m, nfss, showdefaults);
 733
 734	if (nfss->options & NFS_OPTION_FSCACHE)
 735		seq_printf(m, ",fsc");
 
 
 
 736
 737	if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
 738		if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
 739			seq_printf(m, ",lookupcache=none");
 740		else
 741			seq_printf(m, ",lookupcache=pos");
 742	}
 743
 744	local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
 745	local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
 746
 747	if (!local_flock && !local_fcntl)
 748		seq_printf(m, ",local_lock=none");
 749	else if (local_flock && local_fcntl)
 750		seq_printf(m, ",local_lock=all");
 751	else if (local_flock)
 752		seq_printf(m, ",local_lock=flock");
 753	else
 754		seq_printf(m, ",local_lock=posix");
 755}
 756
 757/*
 758 * Describe the mount options on this VFS mountpoint
 759 */
 760static int nfs_show_options(struct seq_file *m, struct dentry *root)
 761{
 762	struct nfs_server *nfss = NFS_SB(root->d_sb);
 763
 764	nfs_show_mount_options(m, nfss, 0);
 765
 766	rcu_read_lock();
 767	seq_printf(m, ",addr=%s",
 768			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
 769							RPC_DISPLAY_ADDR));
 770	rcu_read_unlock();
 771
 772	return 0;
 773}
 
 774
 775#ifdef CONFIG_NFS_V4
 
 
 
 
 
 
 
 
 
 
 776#ifdef CONFIG_NFS_V4_1
 777static void show_sessions(struct seq_file *m, struct nfs_server *server)
 778{
 779	if (nfs4_has_session(server->nfs_client))
 780		seq_printf(m, ",sessions");
 781}
 782#else
 783static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
 784#endif
 785#endif
 786
 787#ifdef CONFIG_NFS_V4_1
 788static void show_pnfs(struct seq_file *m, struct nfs_server *server)
 789{
 790	seq_printf(m, ",pnfs=");
 791	if (server->pnfs_curr_ld)
 792		seq_printf(m, "%s", server->pnfs_curr_ld->name);
 793	else
 794		seq_printf(m, "not configured");
 795}
 796
 797static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
 798{
 799	if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
 800		struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
 801		seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
 802			   "date='%llu,%u'",
 803			   impl_id->name, impl_id->domain,
 804			   impl_id->date.seconds, impl_id->date.nseconds);
 805	}
 806}
 807#else
 808#ifdef CONFIG_NFS_V4
 809static void show_pnfs(struct seq_file *m, struct nfs_server *server)
 810{
 811}
 812#endif
 813static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
 814{
 815}
 816#endif
 817
 818static int nfs_show_devname(struct seq_file *m, struct dentry *root)
 819{
 820	char *page = (char *) __get_free_page(GFP_KERNEL);
 821	char *devname, *dummy;
 822	int err = 0;
 823	if (!page)
 824		return -ENOMEM;
 825	devname = nfs_path(&dummy, root, page, PAGE_SIZE);
 826	if (IS_ERR(devname))
 827		err = PTR_ERR(devname);
 828	else
 829		seq_escape(m, devname, " \t\n\\");
 830	free_page((unsigned long)page);
 831	return err;
 832}
 
 833
 834static int nfs_show_path(struct seq_file *m, struct dentry *dentry)
 835{
 836	seq_puts(m, "/");
 837	return 0;
 838}
 
 839
 840/*
 841 * Present statistical information for this VFS mountpoint
 842 */
 843static int nfs_show_stats(struct seq_file *m, struct dentry *root)
 844{
 845	int i, cpu;
 846	struct nfs_server *nfss = NFS_SB(root->d_sb);
 847	struct rpc_auth *auth = nfss->client->cl_auth;
 848	struct nfs_iostats totals = { };
 849
 850	seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
 851
 852	/*
 853	 * Display all mount option settings
 854	 */
 855	seq_printf(m, "\n\topts:\t");
 856	seq_puts(m, root->d_sb->s_flags & MS_RDONLY ? "ro" : "rw");
 857	seq_puts(m, root->d_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
 858	seq_puts(m, root->d_sb->s_flags & MS_NOATIME ? ",noatime" : "");
 859	seq_puts(m, root->d_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
 860	nfs_show_mount_options(m, nfss, 1);
 861
 862	seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
 863
 864	show_implementation_id(m, nfss);
 865
 866	seq_printf(m, "\n\tcaps:\t");
 867	seq_printf(m, "caps=0x%x", nfss->caps);
 868	seq_printf(m, ",wtmult=%u", nfss->wtmult);
 869	seq_printf(m, ",dtsize=%u", nfss->dtsize);
 870	seq_printf(m, ",bsize=%u", nfss->bsize);
 871	seq_printf(m, ",namlen=%u", nfss->namelen);
 872
 873#ifdef CONFIG_NFS_V4
 874	if (nfss->nfs_client->rpc_ops->version == 4) {
 875		seq_printf(m, "\n\tnfsv4:\t");
 876		seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
 877		seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
 
 878		seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
 879		show_sessions(m, nfss);
 880		show_pnfs(m, nfss);
 
 881	}
 882#endif
 883
 884	/*
 885	 * Display security flavor in effect for this mount
 886	 */
 887	seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
 888	if (auth->au_flavor)
 889		seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
 890
 891	/*
 892	 * Display superblock I/O counters
 893	 */
 894	for_each_possible_cpu(cpu) {
 895		struct nfs_iostats *stats;
 896
 897		preempt_disable();
 898		stats = per_cpu_ptr(nfss->io_stats, cpu);
 899
 900		for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
 901			totals.events[i] += stats->events[i];
 902		for (i = 0; i < __NFSIOS_BYTESMAX; i++)
 903			totals.bytes[i] += stats->bytes[i];
 904#ifdef CONFIG_NFS_FSCACHE
 905		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
 906			totals.fscache[i] += stats->fscache[i];
 907#endif
 908
 909		preempt_enable();
 910	}
 911
 912	seq_printf(m, "\n\tevents:\t");
 913	for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
 914		seq_printf(m, "%lu ", totals.events[i]);
 915	seq_printf(m, "\n\tbytes:\t");
 916	for (i = 0; i < __NFSIOS_BYTESMAX; i++)
 917		seq_printf(m, "%Lu ", totals.bytes[i]);
 918#ifdef CONFIG_NFS_FSCACHE
 919	if (nfss->options & NFS_OPTION_FSCACHE) {
 920		seq_printf(m, "\n\tfsc:\t");
 921		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
 922			seq_printf(m, "%Lu ", totals.bytes[i]);
 923	}
 924#endif
 925	seq_printf(m, "\n");
 926
 927	rpc_print_iostats(m, nfss->client);
 928
 929	return 0;
 930}
 
 931
 932/*
 933 * Begin unmount by attempting to remove all automounted mountpoints we added
 934 * in response to xdev traversals and referrals
 935 */
 936static void nfs_umount_begin(struct super_block *sb)
 937{
 938	struct nfs_server *server;
 939	struct rpc_clnt *rpc;
 940
 941	server = NFS_SB(sb);
 942	/* -EIO all pending I/O */
 943	rpc = server->client_acl;
 944	if (!IS_ERR(rpc))
 945		rpc_killall_tasks(rpc);
 946	rpc = server->client;
 947	if (!IS_ERR(rpc))
 948		rpc_killall_tasks(rpc);
 949}
 950
 951static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)
 952{
 953	struct nfs_parsed_mount_data *data;
 954
 955	data = kzalloc(sizeof(*data), GFP_KERNEL);
 956	if (data) {
 957		data->acregmin		= NFS_DEF_ACREGMIN;
 958		data->acregmax		= NFS_DEF_ACREGMAX;
 959		data->acdirmin		= NFS_DEF_ACDIRMIN;
 960		data->acdirmax		= NFS_DEF_ACDIRMAX;
 961		data->mount_server.port	= NFS_UNSPEC_PORT;
 962		data->nfs_server.port	= NFS_UNSPEC_PORT;
 963		data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
 964		data->auth_flavors[0]	= RPC_AUTH_UNIX;
 965		data->auth_flavor_len	= 1;
 966		data->minorversion	= 0;
 967		data->need_mount	= true;
 968		data->net		= current->nsproxy->net_ns;
 969		security_init_mnt_opts(&data->lsm_opts);
 970	}
 971	return data;
 972}
 973
 974static void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data *data)
 975{
 976	if (data) {
 977		kfree(data->client_address);
 978		kfree(data->mount_server.hostname);
 979		kfree(data->nfs_server.export_path);
 980		kfree(data->nfs_server.hostname);
 981		kfree(data->fscache_uniq);
 982		security_free_mnt_opts(&data->lsm_opts);
 983		kfree(data);
 984	}
 985}
 986
 987/*
 988 * Sanity-check a server address provided by the mount command.
 989 *
 990 * Address family must be initialized, and address must not be
 991 * the ANY address for that family.
 992 */
 993static int nfs_verify_server_address(struct sockaddr *addr)
 
 994{
 995	switch (addr->sa_family) {
 996	case AF_INET: {
 997		struct sockaddr_in *sa = (struct sockaddr_in *)addr;
 998		return sa->sin_addr.s_addr != htonl(INADDR_ANY);
 999	}
1000	case AF_INET6: {
1001		struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
1002		return !ipv6_addr_any(sa);
1003	}
1004	}
1005
1006	dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
1007	return 0;
1008}
1009
1010/*
1011 * Select between a default port value and a user-specified port value.
1012 * If a zero value is set, then autobind will be used.
1013 */
1014static void nfs_set_port(struct sockaddr *sap, int *port,
1015				 const unsigned short default_port)
1016{
1017	if (*port == NFS_UNSPEC_PORT)
1018		*port = default_port;
1019
1020	rpc_set_port(sap, *port);
1021}
1022
1023/*
1024 * Sanity check the NFS transport protocol.
1025 *
1026 */
1027static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
1028{
1029	switch (mnt->nfs_server.protocol) {
1030	case XPRT_TRANSPORT_UDP:
1031	case XPRT_TRANSPORT_TCP:
1032	case XPRT_TRANSPORT_RDMA:
1033		break;
1034	default:
1035		mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1036	}
 
1037}
 
1038
1039/*
1040 * For text based NFSv2/v3 mounts, the mount protocol transport default
1041 * settings should depend upon the specified NFS transport.
 
1042 */
1043static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
 
 
1044{
1045	nfs_validate_transport_protocol(mnt);
 
 
1046
1047	if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
1048	    mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
1049			return;
1050	switch (mnt->nfs_server.protocol) {
1051	case XPRT_TRANSPORT_UDP:
1052		mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1053		break;
1054	case XPRT_TRANSPORT_TCP:
1055	case XPRT_TRANSPORT_RDMA:
1056		mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1057	}
1058}
 
 
1059
1060/*
1061 * Parse the value of the 'sec=' option.
1062 */
1063static int nfs_parse_security_flavors(char *value,
1064				      struct nfs_parsed_mount_data *mnt)
1065{
1066	substring_t args[MAX_OPT_ARGS];
1067
1068	dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
1069
1070	switch (match_token(value, nfs_secflavor_tokens, args)) {
1071	case Opt_sec_none:
1072		mnt->auth_flavors[0] = RPC_AUTH_NULL;
1073		break;
1074	case Opt_sec_sys:
1075		mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1076		break;
1077	case Opt_sec_krb5:
1078		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1079		break;
1080	case Opt_sec_krb5i:
1081		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1082		break;
1083	case Opt_sec_krb5p:
1084		mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1085		break;
1086	case Opt_sec_lkey:
1087		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1088		break;
1089	case Opt_sec_lkeyi:
1090		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1091		break;
1092	case Opt_sec_lkeyp:
1093		mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1094		break;
1095	case Opt_sec_spkm:
1096		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1097		break;
1098	case Opt_sec_spkmi:
1099		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1100		break;
1101	case Opt_sec_spkmp:
1102		mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1103		break;
1104	default:
1105		return 0;
1106	}
1107
1108	mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1109	mnt->auth_flavor_len = 1;
1110	return 1;
1111}
1112
1113static int nfs_parse_version_string(char *string,
1114		struct nfs_parsed_mount_data *mnt,
1115		substring_t *args)
1116{
1117	mnt->flags &= ~NFS_MOUNT_VER3;
1118	switch (match_token(string, nfs_vers_tokens, args)) {
1119	case Opt_vers_2:
1120		mnt->version = 2;
1121		break;
1122	case Opt_vers_3:
1123		mnt->flags |= NFS_MOUNT_VER3;
1124		mnt->version = 3;
1125		break;
1126	case Opt_vers_4:
1127		/* Backward compatibility option. In future,
1128		 * the mount program should always supply
1129		 * a NFSv4 minor version number.
1130		 */
1131		mnt->version = 4;
1132		break;
1133	case Opt_vers_4_0:
1134		mnt->version = 4;
1135		mnt->minorversion = 0;
1136		break;
1137	case Opt_vers_4_1:
1138		mnt->version = 4;
1139		mnt->minorversion = 1;
1140		break;
1141	default:
1142		return 0;
1143	}
1144	return 1;
1145}
1146
1147static int nfs_get_option_str(substring_t args[], char **option)
1148{
1149	kfree(*option);
1150	*option = match_strdup(args);
1151	return !option;
1152}
1153
1154static int nfs_get_option_ul(substring_t args[], unsigned long *option)
1155{
1156	int rc;
1157	char *string;
1158
1159	string = match_strdup(args);
1160	if (string == NULL)
1161		return -ENOMEM;
1162	rc = strict_strtoul(string, 10, option);
1163	kfree(string);
1164
1165	return rc;
1166}
1167
1168/*
1169 * Error-check and convert a string of mount options from user space into
1170 * a data structure.  The whole mount string is processed; bad options are
1171 * skipped as they are encountered.  If there were no errors, return 1;
1172 * otherwise return 0 (zero).
1173 */
1174static int nfs_parse_mount_options(char *raw,
1175				   struct nfs_parsed_mount_data *mnt)
1176{
1177	char *p, *string, *secdata;
1178	int rc, sloppy = 0, invalid_option = 0;
1179	unsigned short protofamily = AF_UNSPEC;
1180	unsigned short mountfamily = AF_UNSPEC;
1181
1182	if (!raw) {
1183		dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1184		return 1;
1185	}
1186	dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1187
1188	secdata = alloc_secdata();
1189	if (!secdata)
1190		goto out_nomem;
1191
1192	rc = security_sb_copy_data(raw, secdata);
1193	if (rc)
1194		goto out_security_failure;
1195
1196	rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1197	if (rc)
1198		goto out_security_failure;
1199
1200	free_secdata(secdata);
1201
1202	while ((p = strsep(&raw, ",")) != NULL) {
1203		substring_t args[MAX_OPT_ARGS];
1204		unsigned long option;
1205		int token;
1206
1207		if (!*p)
1208			continue;
1209
1210		dfprintk(MOUNT, "NFS:   parsing nfs mount option '%s'\n", p);
1211
1212		token = match_token(p, nfs_mount_option_tokens, args);
1213		switch (token) {
1214
1215		/*
1216		 * boolean options:  foo/nofoo
1217		 */
1218		case Opt_soft:
1219			mnt->flags |= NFS_MOUNT_SOFT;
1220			break;
1221		case Opt_hard:
1222			mnt->flags &= ~NFS_MOUNT_SOFT;
1223			break;
1224		case Opt_posix:
1225			mnt->flags |= NFS_MOUNT_POSIX;
1226			break;
1227		case Opt_noposix:
1228			mnt->flags &= ~NFS_MOUNT_POSIX;
1229			break;
1230		case Opt_cto:
1231			mnt->flags &= ~NFS_MOUNT_NOCTO;
1232			break;
1233		case Opt_nocto:
1234			mnt->flags |= NFS_MOUNT_NOCTO;
1235			break;
1236		case Opt_ac:
1237			mnt->flags &= ~NFS_MOUNT_NOAC;
1238			break;
1239		case Opt_noac:
1240			mnt->flags |= NFS_MOUNT_NOAC;
1241			break;
1242		case Opt_lock:
1243			mnt->flags &= ~NFS_MOUNT_NONLM;
1244			mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1245					NFS_MOUNT_LOCAL_FCNTL);
1246			break;
1247		case Opt_nolock:
1248			mnt->flags |= NFS_MOUNT_NONLM;
1249			mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1250				       NFS_MOUNT_LOCAL_FCNTL);
1251			break;
1252		case Opt_udp:
1253			mnt->flags &= ~NFS_MOUNT_TCP;
1254			mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1255			break;
1256		case Opt_tcp:
1257			mnt->flags |= NFS_MOUNT_TCP;
1258			mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1259			break;
1260		case Opt_rdma:
1261			mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1262			mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1263			xprt_load_transport(p);
1264			break;
1265		case Opt_acl:
1266			mnt->flags &= ~NFS_MOUNT_NOACL;
1267			break;
1268		case Opt_noacl:
1269			mnt->flags |= NFS_MOUNT_NOACL;
1270			break;
1271		case Opt_rdirplus:
1272			mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1273			break;
1274		case Opt_nordirplus:
1275			mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1276			break;
1277		case Opt_sharecache:
1278			mnt->flags &= ~NFS_MOUNT_UNSHARED;
1279			break;
1280		case Opt_nosharecache:
1281			mnt->flags |= NFS_MOUNT_UNSHARED;
1282			break;
1283		case Opt_resvport:
1284			mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1285			break;
1286		case Opt_noresvport:
1287			mnt->flags |= NFS_MOUNT_NORESVPORT;
1288			break;
1289		case Opt_fscache:
1290			mnt->options |= NFS_OPTION_FSCACHE;
1291			kfree(mnt->fscache_uniq);
1292			mnt->fscache_uniq = NULL;
1293			break;
1294		case Opt_nofscache:
1295			mnt->options &= ~NFS_OPTION_FSCACHE;
1296			kfree(mnt->fscache_uniq);
1297			mnt->fscache_uniq = NULL;
1298			break;
1299
1300		/*
1301		 * options that take numeric values
1302		 */
1303		case Opt_port:
1304			if (nfs_get_option_ul(args, &option) ||
1305			    option > USHRT_MAX)
1306				goto out_invalid_value;
1307			mnt->nfs_server.port = option;
1308			break;
1309		case Opt_rsize:
1310			if (nfs_get_option_ul(args, &option))
1311				goto out_invalid_value;
1312			mnt->rsize = option;
1313			break;
1314		case Opt_wsize:
1315			if (nfs_get_option_ul(args, &option))
1316				goto out_invalid_value;
1317			mnt->wsize = option;
1318			break;
1319		case Opt_bsize:
1320			if (nfs_get_option_ul(args, &option))
1321				goto out_invalid_value;
1322			mnt->bsize = option;
1323			break;
1324		case Opt_timeo:
1325			if (nfs_get_option_ul(args, &option) || option == 0)
1326				goto out_invalid_value;
1327			mnt->timeo = option;
1328			break;
1329		case Opt_retrans:
1330			if (nfs_get_option_ul(args, &option) || option == 0)
1331				goto out_invalid_value;
1332			mnt->retrans = option;
1333			break;
1334		case Opt_acregmin:
1335			if (nfs_get_option_ul(args, &option))
1336				goto out_invalid_value;
1337			mnt->acregmin = option;
1338			break;
1339		case Opt_acregmax:
1340			if (nfs_get_option_ul(args, &option))
1341				goto out_invalid_value;
1342			mnt->acregmax = option;
1343			break;
1344		case Opt_acdirmin:
1345			if (nfs_get_option_ul(args, &option))
1346				goto out_invalid_value;
1347			mnt->acdirmin = option;
1348			break;
1349		case Opt_acdirmax:
1350			if (nfs_get_option_ul(args, &option))
1351				goto out_invalid_value;
1352			mnt->acdirmax = option;
1353			break;
1354		case Opt_actimeo:
1355			if (nfs_get_option_ul(args, &option))
1356				goto out_invalid_value;
1357			mnt->acregmin = mnt->acregmax =
1358			mnt->acdirmin = mnt->acdirmax = option;
1359			break;
1360		case Opt_namelen:
1361			if (nfs_get_option_ul(args, &option))
1362				goto out_invalid_value;
1363			mnt->namlen = option;
1364			break;
1365		case Opt_mountport:
1366			if (nfs_get_option_ul(args, &option) ||
1367			    option > USHRT_MAX)
1368				goto out_invalid_value;
1369			mnt->mount_server.port = option;
1370			break;
1371		case Opt_mountvers:
1372			if (nfs_get_option_ul(args, &option) ||
1373			    option < NFS_MNT_VERSION ||
1374			    option > NFS_MNT3_VERSION)
1375				goto out_invalid_value;
1376			mnt->mount_server.version = option;
1377			break;
1378		case Opt_minorversion:
1379			if (nfs_get_option_ul(args, &option))
1380				goto out_invalid_value;
1381			if (option > NFS4_MAX_MINOR_VERSION)
1382				goto out_invalid_value;
1383			mnt->minorversion = option;
1384			break;
1385
1386		/*
1387		 * options that take text values
1388		 */
1389		case Opt_nfsvers:
1390			string = match_strdup(args);
1391			if (string == NULL)
1392				goto out_nomem;
1393			rc = nfs_parse_version_string(string, mnt, args);
1394			kfree(string);
1395			if (!rc)
1396				goto out_invalid_value;
1397			break;
1398		case Opt_sec:
1399			string = match_strdup(args);
1400			if (string == NULL)
1401				goto out_nomem;
1402			rc = nfs_parse_security_flavors(string, mnt);
1403			kfree(string);
1404			if (!rc) {
1405				dfprintk(MOUNT, "NFS:   unrecognized "
1406						"security flavor\n");
1407				return 0;
1408			}
1409			break;
1410		case Opt_proto:
1411			string = match_strdup(args);
1412			if (string == NULL)
1413				goto out_nomem;
1414			token = match_token(string,
1415					    nfs_xprt_protocol_tokens, args);
1416
1417			protofamily = AF_INET;
1418			switch (token) {
1419			case Opt_xprt_udp6:
1420				protofamily = AF_INET6;
1421			case Opt_xprt_udp:
1422				mnt->flags &= ~NFS_MOUNT_TCP;
1423				mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1424				break;
1425			case Opt_xprt_tcp6:
1426				protofamily = AF_INET6;
1427			case Opt_xprt_tcp:
1428				mnt->flags |= NFS_MOUNT_TCP;
1429				mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1430				break;
1431			case Opt_xprt_rdma:
1432				/* vector side protocols to TCP */
1433				mnt->flags |= NFS_MOUNT_TCP;
1434				mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1435				xprt_load_transport(string);
1436				break;
1437			default:
1438				dfprintk(MOUNT, "NFS:   unrecognized "
1439						"transport protocol\n");
1440				kfree(string);
1441				return 0;
1442			}
1443			kfree(string);
1444			break;
1445		case Opt_mountproto:
1446			string = match_strdup(args);
1447			if (string == NULL)
1448				goto out_nomem;
1449			token = match_token(string,
1450					    nfs_xprt_protocol_tokens, args);
1451			kfree(string);
1452
1453			mountfamily = AF_INET;
1454			switch (token) {
1455			case Opt_xprt_udp6:
1456				mountfamily = AF_INET6;
1457			case Opt_xprt_udp:
1458				mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1459				break;
1460			case Opt_xprt_tcp6:
1461				mountfamily = AF_INET6;
1462			case Opt_xprt_tcp:
1463				mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1464				break;
1465			case Opt_xprt_rdma: /* not used for side protocols */
1466			default:
1467				dfprintk(MOUNT, "NFS:   unrecognized "
1468						"transport protocol\n");
1469				return 0;
1470			}
1471			break;
1472		case Opt_addr:
1473			string = match_strdup(args);
1474			if (string == NULL)
1475				goto out_nomem;
1476			mnt->nfs_server.addrlen =
1477				rpc_pton(mnt->net, string, strlen(string),
1478					(struct sockaddr *)
1479					&mnt->nfs_server.address,
1480					sizeof(mnt->nfs_server.address));
1481			kfree(string);
1482			if (mnt->nfs_server.addrlen == 0)
1483				goto out_invalid_address;
1484			break;
1485		case Opt_clientaddr:
1486			if (nfs_get_option_str(args, &mnt->client_address))
1487				goto out_nomem;
1488			break;
1489		case Opt_mounthost:
1490			if (nfs_get_option_str(args,
1491					       &mnt->mount_server.hostname))
1492				goto out_nomem;
1493			break;
1494		case Opt_mountaddr:
1495			string = match_strdup(args);
1496			if (string == NULL)
1497				goto out_nomem;
1498			mnt->mount_server.addrlen =
1499				rpc_pton(mnt->net, string, strlen(string),
1500					(struct sockaddr *)
1501					&mnt->mount_server.address,
1502					sizeof(mnt->mount_server.address));
1503			kfree(string);
1504			if (mnt->mount_server.addrlen == 0)
1505				goto out_invalid_address;
1506			break;
1507		case Opt_lookupcache:
1508			string = match_strdup(args);
1509			if (string == NULL)
1510				goto out_nomem;
1511			token = match_token(string,
1512					nfs_lookupcache_tokens, args);
1513			kfree(string);
1514			switch (token) {
1515				case Opt_lookupcache_all:
1516					mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1517					break;
1518				case Opt_lookupcache_positive:
1519					mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1520					mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1521					break;
1522				case Opt_lookupcache_none:
1523					mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1524					break;
1525				default:
1526					dfprintk(MOUNT, "NFS:   invalid "
1527							"lookupcache argument\n");
1528					return 0;
1529			};
1530			break;
1531		case Opt_fscache_uniq:
1532			if (nfs_get_option_str(args, &mnt->fscache_uniq))
1533				goto out_nomem;
1534			mnt->options |= NFS_OPTION_FSCACHE;
1535			break;
1536		case Opt_local_lock:
1537			string = match_strdup(args);
1538			if (string == NULL)
1539				goto out_nomem;
1540			token = match_token(string, nfs_local_lock_tokens,
1541					args);
1542			kfree(string);
1543			switch (token) {
1544			case Opt_local_lock_all:
1545				mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1546					       NFS_MOUNT_LOCAL_FCNTL);
1547				break;
1548			case Opt_local_lock_flock:
1549				mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1550				break;
1551			case Opt_local_lock_posix:
1552				mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1553				break;
1554			case Opt_local_lock_none:
1555				mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1556						NFS_MOUNT_LOCAL_FCNTL);
1557				break;
1558			default:
1559				dfprintk(MOUNT, "NFS:	invalid	"
1560						"local_lock argument\n");
1561				return 0;
1562			};
1563			break;
1564
1565		/*
1566		 * Special options
1567		 */
1568		case Opt_sloppy:
1569			sloppy = 1;
1570			dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
1571			break;
1572		case Opt_userspace:
1573		case Opt_deprecated:
1574			dfprintk(MOUNT, "NFS:   ignoring mount option "
1575					"'%s'\n", p);
1576			break;
1577
1578		default:
1579			invalid_option = 1;
1580			dfprintk(MOUNT, "NFS:   unrecognized mount option "
1581					"'%s'\n", p);
1582		}
1583	}
1584
1585	if (!sloppy && invalid_option)
1586		return 0;
1587
1588	if (mnt->minorversion && mnt->version != 4)
1589		goto out_minorversion_mismatch;
1590
1591	/*
1592	 * verify that any proto=/mountproto= options match the address
1593	 * familiies in the addr=/mountaddr= options.
1594	 */
1595	if (protofamily != AF_UNSPEC &&
1596	    protofamily != mnt->nfs_server.address.ss_family)
1597		goto out_proto_mismatch;
1598
1599	if (mountfamily != AF_UNSPEC) {
1600		if (mnt->mount_server.addrlen) {
1601			if (mountfamily != mnt->mount_server.address.ss_family)
1602				goto out_mountproto_mismatch;
1603		} else {
1604			if (mountfamily != mnt->nfs_server.address.ss_family)
1605				goto out_mountproto_mismatch;
1606		}
1607	}
1608
1609	return 1;
1610
1611out_mountproto_mismatch:
1612	printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1613			 "option\n");
1614	return 0;
1615out_proto_mismatch:
1616	printk(KERN_INFO "NFS: server address does not match proto= option\n");
1617	return 0;
1618out_invalid_address:
1619	printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1620	return 0;
1621out_invalid_value:
1622	printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1623	return 0;
1624out_minorversion_mismatch:
1625	printk(KERN_INFO "NFS: mount option vers=%u does not support "
1626			 "minorversion=%u\n", mnt->version, mnt->minorversion);
1627	return 0;
1628out_nomem:
1629	printk(KERN_INFO "NFS: not enough memory to parse option\n");
1630	return 0;
1631out_security_failure:
1632	free_secdata(secdata);
1633	printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1634	return 0;
1635}
1636
1637/*
1638 * Match the requested auth flavors with the list returned by
1639 * the server.  Returns zero and sets the mount's authentication
1640 * flavor on success; returns -EACCES if server does not support
1641 * the requested flavor.
1642 */
1643static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1644			     struct nfs_mount_request *request)
1645{
1646	unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1647
1648	/*
1649	 * Certain releases of Linux's mountd return an empty
1650	 * flavor list.  To prevent behavioral regression with
1651	 * these servers (ie. rejecting mounts that used to
1652	 * succeed), revert to pre-2.6.32 behavior (no checking)
1653	 * if the returned flavor list is empty.
1654	 */
1655	if (server_authlist_len == 0)
1656		return 0;
1657
1658	/*
1659	 * We avoid sophisticated negotiating here, as there are
1660	 * plenty of cases where we can get it wrong, providing
1661	 * either too little or too much security.
1662	 *
1663	 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1664	 * flavor listed first.  However, some servers list
1665	 * AUTH_NULL first.  Our caller plants AUTH_SYS, the
1666	 * preferred default, in args->auth_flavors[0] if user
1667	 * didn't specify sec= mount option.
1668	 */
1669	for (i = 0; i < args->auth_flavor_len; i++)
1670		for (j = 0; j < server_authlist_len; j++)
1671			if (args->auth_flavors[i] == request->auth_flavs[j]) {
1672				dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1673					request->auth_flavs[j]);
1674				args->auth_flavors[0] = request->auth_flavs[j];
1675				return 0;
1676			}
1677
1678	dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1679	nfs_umount(request);
1680	return -EACCES;
1681}
1682
1683/*
1684 * Use the remote server's MOUNT service to request the NFS file handle
1685 * corresponding to the provided path.
1686 */
1687static int nfs_request_mount(struct nfs_parsed_mount_data *args,
1688			     struct nfs_fh *root_fh)
 
 
1689{
1690	rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1691	unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1692	struct nfs_mount_request request = {
1693		.sap		= (struct sockaddr *)
1694						&args->mount_server.address,
1695		.dirpath	= args->nfs_server.export_path,
1696		.protocol	= args->mount_server.protocol,
1697		.fh		= root_fh,
1698		.noresvport	= args->flags & NFS_MOUNT_NORESVPORT,
1699		.auth_flav_len	= &server_authlist_len,
1700		.auth_flavs	= server_authlist,
1701		.net		= args->net,
1702	};
1703	int status;
1704
1705	if (args->mount_server.version == 0) {
1706		switch (args->version) {
1707			default:
1708				args->mount_server.version = NFS_MNT3_VERSION;
1709				break;
1710			case 2:
1711				args->mount_server.version = NFS_MNT_VERSION;
1712		}
1713	}
1714	request.version = args->mount_server.version;
1715
1716	if (args->mount_server.hostname)
1717		request.hostname = args->mount_server.hostname;
1718	else
1719		request.hostname = args->nfs_server.hostname;
1720
1721	/*
1722	 * Construct the mount server's address.
1723	 */
1724	if (args->mount_server.address.ss_family == AF_UNSPEC) {
1725		memcpy(request.sap, &args->nfs_server.address,
1726		       args->nfs_server.addrlen);
1727		args->mount_server.addrlen = args->nfs_server.addrlen;
1728	}
1729	request.salen = args->mount_server.addrlen;
1730	nfs_set_port(request.sap, &args->mount_server.port, 0);
1731
1732	/*
1733	 * Now ask the mount server to map our export path
1734	 * to a file handle.
1735	 */
1736	status = nfs_mount(&request);
1737	if (status != 0) {
1738		dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1739				request.hostname, status);
1740		return status;
1741	}
1742
1743	/*
1744	 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1745	 */
1746	if (args->mount_server.version != NFS_MNT3_VERSION)
1747		return 0;
1748	return nfs_walk_authlist(args, &request);
1749}
1750
1751static struct dentry *nfs_try_mount(int flags, const char *dev_name,
1752				    struct nfs_mount_info *mount_info)
1753{
 
1754	int status;
1755	struct nfs_server *server;
 
 
 
 
 
 
 
 
 
1756
1757	if (mount_info->parsed->need_mount) {
1758		status = nfs_request_mount(mount_info->parsed, mount_info->mntfh);
 
 
 
 
 
 
1759		if (status)
1760			return ERR_PTR(status);
 
1761	}
1762
1763	/* Get a volume representation */
1764	server = nfs_create_server(mount_info->parsed, mount_info->mntfh);
1765	if (IS_ERR(server))
1766		return ERR_CAST(server);
1767
1768	return nfs_fs_mount_common(&nfs_fs_type, server, flags, dev_name, mount_info);
1769}
1770
1771/*
1772 * Split "dev_name" into "hostname:export_path".
1773 *
1774 * The leftmost colon demarks the split between the server's hostname
1775 * and the export path.  If the hostname starts with a left square
1776 * bracket, then it may contain colons.
1777 *
1778 * Note: caller frees hostname and export path, even on error.
1779 */
1780static int nfs_parse_devname(const char *dev_name,
1781			     char **hostname, size_t maxnamlen,
1782			     char **export_path, size_t maxpathlen)
1783{
1784	size_t len;
1785	char *end;
1786
1787	/* Is the host name protected with square brakcets? */
1788	if (*dev_name == '[') {
1789		end = strchr(++dev_name, ']');
1790		if (end == NULL || end[1] != ':')
1791			goto out_bad_devname;
1792
1793		len = end - dev_name;
1794		end++;
1795	} else {
1796		char *comma;
1797
1798		end = strchr(dev_name, ':');
1799		if (end == NULL)
1800			goto out_bad_devname;
1801		len = end - dev_name;
1802
1803		/* kill possible hostname list: not supported */
1804		comma = strchr(dev_name, ',');
1805		if (comma != NULL && comma < end)
1806			*comma = 0;
1807	}
1808
1809	if (len > maxnamlen)
1810		goto out_hostname;
1811
1812	/* N.B. caller will free nfs_server.hostname in all cases */
1813	*hostname = kstrndup(dev_name, len, GFP_KERNEL);
1814	if (*hostname == NULL)
1815		goto out_nomem;
1816	len = strlen(++end);
1817	if (len > maxpathlen)
1818		goto out_path;
1819	*export_path = kstrndup(end, len, GFP_KERNEL);
1820	if (!*export_path)
1821		goto out_nomem;
1822
1823	dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1824	return 0;
1825
1826out_bad_devname:
1827	dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1828	return -EINVAL;
1829
1830out_nomem:
1831	dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1832	return -ENOMEM;
1833
1834out_hostname:
1835	dfprintk(MOUNT, "NFS: server hostname too long\n");
1836	return -ENAMETOOLONG;
1837
1838out_path:
1839	dfprintk(MOUNT, "NFS: export pathname too long\n");
1840	return -ENAMETOOLONG;
1841}
1842
1843/*
1844 * Validate the NFS2/NFS3 mount data
1845 * - fills in the mount root filehandle
1846 *
1847 * For option strings, user space handles the following behaviors:
1848 *
1849 * + DNS: mapping server host name to IP address ("addr=" option)
1850 *
1851 * + failure mode: how to behave if a mount request can't be handled
1852 *   immediately ("fg/bg" option)
1853 *
1854 * + retry: how often to retry a mount request ("retry=" option)
1855 *
1856 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1857 *   mountproto=tcp after mountproto=udp, and so on
1858 */
1859static int nfs23_validate_mount_data(void *options,
1860				     struct nfs_parsed_mount_data *args,
1861				     struct nfs_fh *mntfh,
1862				     const char *dev_name)
1863{
1864	struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1865	struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1866
1867	if (data == NULL)
1868		goto out_no_data;
1869
1870	args->version = NFS_DEFAULT_VERSION;
1871	switch (data->version) {
1872	case 1:
1873		data->namlen = 0;
1874	case 2:
1875		data->bsize = 0;
1876	case 3:
1877		if (data->flags & NFS_MOUNT_VER3)
1878			goto out_no_v3;
1879		data->root.size = NFS2_FHSIZE;
1880		memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1881	case 4:
1882		if (data->flags & NFS_MOUNT_SECFLAVOUR)
1883			goto out_no_sec;
1884	case 5:
1885		memset(data->context, 0, sizeof(data->context));
1886	case 6:
1887		if (data->flags & NFS_MOUNT_VER3) {
1888			if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1889				goto out_invalid_fh;
1890			mntfh->size = data->root.size;
1891			args->version = 3;
1892		} else {
1893			mntfh->size = NFS2_FHSIZE;
1894			args->version = 2;
1895		}
1896
1897
1898		memcpy(mntfh->data, data->root.data, mntfh->size);
1899		if (mntfh->size < sizeof(mntfh->data))
1900			memset(mntfh->data + mntfh->size, 0,
1901			       sizeof(mntfh->data) - mntfh->size);
1902
1903		/*
1904		 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1905		 * can deal with.
1906		 */
1907		args->flags		= data->flags & NFS_MOUNT_FLAGMASK;
1908		args->flags		|= NFS_MOUNT_LEGACY_INTERFACE;
1909		args->rsize		= data->rsize;
1910		args->wsize		= data->wsize;
1911		args->timeo		= data->timeo;
1912		args->retrans		= data->retrans;
1913		args->acregmin		= data->acregmin;
1914		args->acregmax		= data->acregmax;
1915		args->acdirmin		= data->acdirmin;
1916		args->acdirmax		= data->acdirmax;
1917		args->need_mount	= false;
1918
1919		memcpy(sap, &data->addr, sizeof(data->addr));
1920		args->nfs_server.addrlen = sizeof(data->addr);
1921		args->nfs_server.port = ntohs(data->addr.sin_port);
1922		if (!nfs_verify_server_address(sap))
1923			goto out_no_address;
1924
1925		if (!(data->flags & NFS_MOUNT_TCP))
1926			args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1927		/* N.B. caller will free nfs_server.hostname in all cases */
1928		args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1929		args->namlen		= data->namlen;
1930		args->bsize		= data->bsize;
1931
1932		if (data->flags & NFS_MOUNT_SECFLAVOUR)
1933			args->auth_flavors[0] = data->pseudoflavor;
1934		if (!args->nfs_server.hostname)
1935			goto out_nomem;
1936
1937		if (!(data->flags & NFS_MOUNT_NONLM))
1938			args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1939					 NFS_MOUNT_LOCAL_FCNTL);
1940		else
1941			args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1942					NFS_MOUNT_LOCAL_FCNTL);
1943		/*
1944		 * The legacy version 6 binary mount data from userspace has a
1945		 * field used only to transport selinux information into the
1946		 * the kernel.  To continue to support that functionality we
1947		 * have a touch of selinux knowledge here in the NFS code. The
1948		 * userspace code converted context=blah to just blah so we are
1949		 * converting back to the full string selinux understands.
1950		 */
1951		if (data->context[0]){
1952#ifdef CONFIG_SECURITY_SELINUX
1953			int rc;
1954			char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1955			if (!opts_str)
1956				return -ENOMEM;
1957			strcpy(opts_str, "context=");
1958			data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1959			strcat(opts_str, &data->context[0]);
1960			rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1961			kfree(opts_str);
1962			if (rc)
1963				return rc;
1964#else
1965			return -EINVAL;
1966#endif
1967		}
1968
1969		break;
1970	default:
1971		return NFS_TEXT_DATA;
1972	}
1973
1974#ifndef CONFIG_NFS_V3
1975	if (args->version == 3)
1976		goto out_v3_not_compiled;
1977#endif /* !CONFIG_NFS_V3 */
 
 
 
1978
1979	return 0;
 
 
 
 
1980
1981out_no_data:
1982	dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1983	return -EINVAL;
1984
1985out_no_v3:
1986	dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1987		 data->version);
1988	return -EINVAL;
1989
1990out_no_sec:
1991	dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1992	return -EINVAL;
1993
1994#ifndef CONFIG_NFS_V3
1995out_v3_not_compiled:
1996	dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1997	return -EPROTONOSUPPORT;
1998#endif /* !CONFIG_NFS_V3 */
1999
2000out_nomem:
2001	dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
2002	return -ENOMEM;
2003
2004out_no_address:
2005	dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2006	return -EINVAL;
2007
2008out_invalid_fh:
2009	dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2010	return -EINVAL;
2011}
2012
2013#ifdef CONFIG_NFS_V4
2014static int nfs_validate_mount_data(struct file_system_type *fs_type,
2015				   void *options,
2016				   struct nfs_parsed_mount_data *args,
2017				   struct nfs_fh *mntfh,
2018				   const char *dev_name)
2019{
2020	if (fs_type == &nfs_fs_type)
2021		return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2022	return nfs4_validate_mount_data(options, args, dev_name);
2023}
2024#else
2025static int nfs_validate_mount_data(struct file_system_type *fs_type,
2026				   void *options,
2027				   struct nfs_parsed_mount_data *args,
2028				   struct nfs_fh *mntfh,
2029				   const char *dev_name)
2030{
2031	return nfs23_validate_mount_data(options, args, mntfh, dev_name);
2032}
2033#endif
2034
2035static int nfs_validate_text_mount_data(void *options,
2036					struct nfs_parsed_mount_data *args,
2037					const char *dev_name)
2038{
2039	int port = 0;
2040	int max_namelen = PAGE_SIZE;
2041	int max_pathlen = NFS_MAXPATHLEN;
2042	struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2043
2044	if (nfs_parse_mount_options((char *)options, args) == 0)
2045		return -EINVAL;
2046
2047	if (!nfs_verify_server_address(sap))
2048		goto out_no_address;
2049
2050	if (args->version == 4) {
2051#ifdef CONFIG_NFS_V4
2052		port = NFS_PORT;
2053		max_namelen = NFS4_MAXNAMLEN;
2054		max_pathlen = NFS4_MAXPATHLEN;
2055		nfs_validate_transport_protocol(args);
2056		nfs4_validate_mount_flags(args);
2057#else
2058		goto out_v4_not_compiled;
2059#endif /* CONFIG_NFS_V4 */
2060	} else
2061		nfs_set_mount_transport_protocol(args);
2062
2063	nfs_set_port(sap, &args->nfs_server.port, port);
2064
2065	if (args->auth_flavor_len > 1)
2066		goto out_bad_auth;
 
 
 
 
 
 
 
2067
2068	return nfs_parse_devname(dev_name,
2069				   &args->nfs_server.hostname,
2070				   max_namelen,
2071				   &args->nfs_server.export_path,
2072				   max_pathlen);
2073
2074#ifndef CONFIG_NFS_V4
2075out_v4_not_compiled:
2076	dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
2077	return -EPROTONOSUPPORT;
2078#endif /* !CONFIG_NFS_V4 */
2079
2080out_no_address:
2081	dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2082	return -EINVAL;
2083
2084out_bad_auth:
2085	dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n");
2086	return -EINVAL;
2087}
2088
2089static int
2090nfs_compare_remount_data(struct nfs_server *nfss,
2091			 struct nfs_parsed_mount_data *data)
2092{
2093	if (data->flags != nfss->flags ||
2094	    data->rsize != nfss->rsize ||
2095	    data->wsize != nfss->wsize ||
2096	    data->retrans != nfss->client->cl_timeout->to_retries ||
2097	    data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2098	    data->acregmin != nfss->acregmin / HZ ||
2099	    data->acregmax != nfss->acregmax / HZ ||
2100	    data->acdirmin != nfss->acdirmin / HZ ||
2101	    data->acdirmax != nfss->acdirmax / HZ ||
2102	    data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
2103	    data->nfs_server.port != nfss->port ||
2104	    data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
2105	    !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
 
 
 
2106			  (struct sockaddr *)&nfss->nfs_client->cl_addr))
2107		return -EINVAL;
2108
2109	return 0;
2110}
2111
2112static int
2113nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2114{
2115	int error;
 
2116	struct nfs_server *nfss = sb->s_fs_info;
2117	struct nfs_parsed_mount_data *data;
2118	struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2119	struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
2120	u32 nfsvers = nfss->nfs_client->rpc_ops->version;
2121
2122	/*
2123	 * Userspace mount programs that send binary options generally send
2124	 * them populated with default values. We have no way to know which
2125	 * ones were explicitly specified. Fall back to legacy behavior and
2126	 * just return success.
2127	 */
2128	if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2129	    (nfsvers <= 3 && (!options || (options->version >= 1 &&
2130					   options->version <= 6))))
2131		return 0;
2132
2133	data = kzalloc(sizeof(*data), GFP_KERNEL);
2134	if (data == NULL)
2135		return -ENOMEM;
2136
2137	/* fill out struct with values from existing mount */
2138	data->flags = nfss->flags;
2139	data->rsize = nfss->rsize;
2140	data->wsize = nfss->wsize;
2141	data->retrans = nfss->client->cl_timeout->to_retries;
2142	data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2143	data->acregmin = nfss->acregmin / HZ;
2144	data->acregmax = nfss->acregmax / HZ;
2145	data->acdirmin = nfss->acdirmin / HZ;
2146	data->acdirmax = nfss->acdirmax / HZ;
2147	data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
2148	data->nfs_server.port = nfss->port;
2149	data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2150	memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2151		data->nfs_server.addrlen);
2152
2153	/* overwrite those values with any that were specified */
2154	error = nfs_parse_mount_options((char *)options, data);
2155	if (error < 0)
2156		goto out;
2157
2158	/*
2159	 * noac is a special case. It implies -o sync, but that's not
2160	 * necessarily reflected in the mtab options. do_remount_sb
2161	 * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the
2162	 * remount options, so we have to explicitly reset it.
2163	 */
2164	if (data->flags & NFS_MOUNT_NOAC)
2165		*flags |= MS_SYNCHRONOUS;
 
 
2166
2167	/* compare new mount options with old ones */
2168	error = nfs_compare_remount_data(nfss, data);
2169out:
2170	kfree(data);
2171	return error;
2172}
 
2173
2174/*
2175 * Initialise the common bits of the superblock
2176 */
2177static inline void nfs_initialise_sb(struct super_block *sb)
2178{
2179	struct nfs_server *server = NFS_SB(sb);
2180
2181	sb->s_magic = NFS_SUPER_MAGIC;
2182
2183	/* We probably want something more informative here */
2184	snprintf(sb->s_id, sizeof(sb->s_id),
2185		 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2186
2187	if (sb->s_blocksize == 0)
2188		sb->s_blocksize = nfs_block_bits(server->wsize,
2189						 &sb->s_blocksize_bits);
2190
2191	sb->s_bdi = &server->backing_dev_info;
2192
2193	nfs_super_set_maxbytes(sb, server->maxfilesize);
2194}
2195
2196/*
2197 * Finish setting up an NFS2/3 superblock
2198 */
2199static void nfs_fill_super(struct super_block *sb,
2200			   struct nfs_mount_info *mount_info)
2201{
2202	struct nfs_parsed_mount_data *data = mount_info->parsed;
2203	struct nfs_server *server = NFS_SB(sb);
2204
2205	sb->s_blocksize_bits = 0;
2206	sb->s_blocksize = 0;
2207	if (data->bsize)
2208		sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
 
 
2209
2210	if (server->nfs_client->rpc_ops->version == 3) {
2211		/* The VFS shouldn't apply the umask to mode bits. We will do
2212		 * so ourselves when necessary.
2213		 */
2214		sb->s_flags |= MS_POSIXACL;
2215		sb->s_time_gran = 1;
 
 
 
 
 
 
 
 
 
 
2216	}
2217
2218	sb->s_op = &nfs_sops;
2219 	nfs_initialise_sb(sb);
2220}
2221
2222/*
2223 * Finish setting up a cloned NFS2/3 superblock
2224 */
2225static void nfs_clone_super(struct super_block *sb,
2226			    struct nfs_mount_info *mount_info)
2227{
2228	const struct super_block *old_sb = mount_info->cloned->sb;
2229	struct nfs_server *server = NFS_SB(sb);
2230
2231	sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2232	sb->s_blocksize = old_sb->s_blocksize;
2233	sb->s_maxbytes = old_sb->s_maxbytes;
2234
2235	if (server->nfs_client->rpc_ops->version == 3) {
2236		/* The VFS shouldn't apply the umask to mode bits. We will do
2237		 * so ourselves when necessary.
2238		 */
2239		sb->s_flags |= MS_POSIXACL;
2240		sb->s_time_gran = 1;
2241	}
2242
2243	sb->s_op = old_sb->s_op;
2244 	nfs_initialise_sb(sb);
2245}
2246
2247static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
 
2248{
2249	const struct nfs_server *a = s->s_fs_info;
2250	const struct rpc_clnt *clnt_a = a->client;
2251	const struct rpc_clnt *clnt_b = b->client;
2252
2253	if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2254		goto Ebusy;
2255	if (a->nfs_client != b->nfs_client)
2256		goto Ebusy;
2257	if (a->flags != b->flags)
2258		goto Ebusy;
2259	if (a->wsize != b->wsize)
2260		goto Ebusy;
2261	if (a->rsize != b->rsize)
2262		goto Ebusy;
2263	if (a->acregmin != b->acregmin)
2264		goto Ebusy;
2265	if (a->acregmax != b->acregmax)
2266		goto Ebusy;
2267	if (a->acdirmin != b->acdirmin)
2268		goto Ebusy;
2269	if (a->acdirmax != b->acdirmax)
2270		goto Ebusy;
2271	if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2272		goto Ebusy;
2273	return 1;
2274Ebusy:
2275	return 0;
2276}
2277
2278struct nfs_sb_mountdata {
2279	struct nfs_server *server;
2280	int mntflags;
2281};
2282
2283static int nfs_set_super(struct super_block *s, void *data)
2284{
2285	struct nfs_sb_mountdata *sb_mntdata = data;
2286	struct nfs_server *server = sb_mntdata->server;
2287	int ret;
2288
2289	s->s_flags = sb_mntdata->mntflags;
2290	s->s_fs_info = server;
2291	s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
2292	ret = set_anon_super(s, server);
2293	if (ret == 0)
2294		server->s_dev = s->s_dev;
2295	return ret;
2296}
2297
2298static int nfs_compare_super_address(struct nfs_server *server1,
2299				     struct nfs_server *server2)
2300{
2301	struct sockaddr *sap1, *sap2;
 
 
 
 
 
2302
2303	sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2304	sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2305
2306	if (sap1->sa_family != sap2->sa_family)
2307		return 0;
2308
2309	switch (sap1->sa_family) {
2310	case AF_INET: {
2311		struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2312		struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2313		if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2314			return 0;
2315		if (sin1->sin_port != sin2->sin_port)
2316			return 0;
2317		break;
2318	}
2319	case AF_INET6: {
2320		struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2321		struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2322		if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2323			return 0;
2324		if (sin1->sin6_port != sin2->sin6_port)
2325			return 0;
2326		break;
2327	}
2328	default:
2329		return 0;
2330	}
2331
2332	return 1;
2333}
2334
2335static int nfs_compare_super(struct super_block *sb, void *data)
 
2336{
2337	struct nfs_sb_mountdata *sb_mntdata = data;
2338	struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2339	int mntflags = sb_mntdata->mntflags;
 
 
 
 
 
 
 
 
 
 
 
 
2340
2341	if (!nfs_compare_super_address(old, server))
2342		return 0;
2343	/* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2344	if (old->flags & NFS_MOUNT_UNSHARED)
2345		return 0;
2346	if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2347		return 0;
2348	return nfs_compare_mount_options(sb, server, mntflags);
 
 
2349}
2350
2351#ifdef CONFIG_NFS_FSCACHE
2352static void nfs_get_cache_cookie(struct super_block *sb,
2353				 struct nfs_parsed_mount_data *parsed,
2354				 struct nfs_clone_mount *cloned)
2355{
 
2356	char *uniq = NULL;
2357	int ulen = 0;
2358
2359	if (parsed && parsed->fscache_uniq) {
2360		uniq = parsed->fscache_uniq;
2361		ulen = strlen(parsed->fscache_uniq);
2362	} else if (cloned) {
2363		struct nfs_server *mnt_s = NFS_SB(cloned->sb);
 
 
 
 
 
2364		if (mnt_s->fscache_key) {
2365			uniq = mnt_s->fscache_key->key.uniquifier;
2366			ulen = mnt_s->fscache_key->key.uniq_len;
2367		};
 
 
 
 
 
 
 
2368	}
2369
2370	nfs_fscache_get_super_cookie(sb, uniq, ulen);
2371}
2372#else
2373static void nfs_get_cache_cookie(struct super_block *sb,
2374				 struct nfs_parsed_mount_data *parsed,
2375				 struct nfs_clone_mount *cloned)
2376{
2377}
2378#endif
2379
2380static int nfs_bdi_register(struct nfs_server *server)
 
2381{
2382	return bdi_register_dev(&server->backing_dev_info, server->s_dev);
 
2383}
2384
2385static int nfs_set_sb_security(struct super_block *s, struct dentry *mntroot,
2386			       struct nfs_mount_info *mount_info)
2387{
2388	return security_sb_set_mnt_opts(s, &mount_info->parsed->lsm_opts);
2389}
2390
2391static int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
2392				 struct nfs_mount_info *mount_info)
2393{
2394	/* clone any lsm security options from the parent to the new sb */
2395	security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
2396	if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
2397		return -ESTALE;
2398	return 0;
2399}
2400
2401static struct dentry *nfs_fs_mount_common(struct file_system_type *fs_type,
2402					  struct nfs_server *server,
2403					  int flags, const char *dev_name,
2404					  struct nfs_mount_info *mount_info)
2405{
 
2406	struct super_block *s;
2407	struct dentry *mntroot = ERR_PTR(-ENOMEM);
2408	int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2409	struct nfs_sb_mountdata sb_mntdata = {
2410		.mntflags = flags,
2411		.server = server,
2412	};
2413	int error;
2414
 
 
 
 
2415	if (server->flags & NFS_MOUNT_UNSHARED)
2416		compare_super = NULL;
2417
2418	/* -o noac implies -o sync */
2419	if (server->flags & NFS_MOUNT_NOAC)
2420		sb_mntdata.mntflags |= MS_SYNCHRONOUS;
 
 
 
 
 
 
 
2421
2422	/* Get a superblock - note that we may end up sharing one that already exists */
2423	s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
 
 
2424	if (IS_ERR(s)) {
2425		mntroot = ERR_CAST(s);
 
2426		goto out_err_nosb;
2427	}
2428
2429	if (s->s_fs_info != server) {
2430		nfs_free_server(server);
2431		server = NULL;
2432	} else {
2433		error = nfs_bdi_register(server);
2434		if (error) {
2435			mntroot = ERR_PTR(error);
2436			goto error_splat_bdi;
2437		}
 
2438	}
2439
2440	if (!s->s_root) {
 
2441		/* initial superblock/root creation */
2442		mount_info->fill_super(s, mount_info);
2443		nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned);
 
 
 
 
2444	}
2445
2446	mntroot = nfs_get_root(s, mount_info->mntfh, dev_name);
2447	if (IS_ERR(mntroot))
 
2448		goto error_splat_super;
 
2449
2450	error = mount_info->set_security(s, mntroot, mount_info);
2451	if (error)
2452		goto error_splat_root;
2453
2454	s->s_flags |= MS_ACTIVE;
2455
2456out:
2457	return mntroot;
2458
2459out_err_nosb:
2460	nfs_free_server(server);
2461	goto out;
2462
2463error_splat_root:
2464	dput(mntroot);
2465	mntroot = ERR_PTR(error);
2466error_splat_super:
2467	if (server && !s->s_root)
2468		bdi_unregister(&server->backing_dev_info);
2469error_splat_bdi:
2470	deactivate_locked_super(s);
2471	goto out;
2472}
2473
2474static struct dentry *nfs_fs_mount(struct file_system_type *fs_type,
2475	int flags, const char *dev_name, void *raw_data)
2476{
2477	struct nfs_mount_info mount_info = {
2478		.fill_super = nfs_fill_super,
2479		.set_security = nfs_set_sb_security,
2480	};
2481	struct dentry *mntroot = ERR_PTR(-ENOMEM);
2482	int error;
2483
2484	mount_info.parsed = nfs_alloc_parsed_mount_data();
2485	mount_info.mntfh = nfs_alloc_fhandle();
2486	if (mount_info.parsed == NULL || mount_info.mntfh == NULL)
2487		goto out;
2488
2489	/* Validate the mount data */
2490	error = nfs_validate_mount_data(fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);
2491	if (error == NFS_TEXT_DATA)
2492		error = nfs_validate_text_mount_data(raw_data, mount_info.parsed, dev_name);
2493	if (error < 0) {
2494		mntroot = ERR_PTR(error);
2495		goto out;
2496	}
2497
2498#ifdef CONFIG_NFS_V4
2499	if (mount_info.parsed->version == 4)
2500		mntroot = nfs4_try_mount(flags, dev_name, &mount_info);
2501	else
2502#endif	/* CONFIG_NFS_V4 */
2503		mntroot = nfs_try_mount(flags, dev_name, &mount_info);
2504
2505out:
2506	nfs_free_parsed_mount_data(mount_info.parsed);
2507	nfs_free_fhandle(mount_info.mntfh);
2508	return mntroot;
2509}
2510
2511/*
2512 * Ensure that we unregister the bdi before kill_anon_super
2513 * releases the device name
2514 */
2515static void nfs_put_super(struct super_block *s)
2516{
2517	struct nfs_server *server = NFS_SB(s);
 
2518
2519	bdi_unregister(&server->backing_dev_info);
2520}
2521
2522/*
2523 * Destroy an NFS2/3 superblock
2524 */
2525static void nfs_kill_super(struct super_block *s)
2526{
2527	struct nfs_server *server = NFS_SB(s);
2528
2529	kill_anon_super(s);
2530	nfs_fscache_release_super_cookie(s);
2531	nfs_free_server(server);
 
2532}
 
2533
2534/*
2535 * Clone an NFS2/3/4 server record on xdev traversal (FSID-change)
2536 */
2537static struct dentry *
2538nfs_xdev_mount_common(struct file_system_type *fs_type, int flags,
2539		const char *dev_name, struct nfs_mount_info *mount_info)
2540{
2541	struct nfs_clone_mount *data = mount_info->cloned;
2542	struct nfs_server *server;
2543	struct dentry *mntroot = ERR_PTR(-ENOMEM);
2544	int error;
2545
2546	dprintk("--> nfs_xdev_mount_common()\n");
2547
2548	mount_info->mntfh = data->fh;
2549
2550	/* create a new volume representation */
2551	server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr, data->authflavor);
2552	if (IS_ERR(server)) {
2553		error = PTR_ERR(server);
2554		goto out_err;
2555	}
2556
2557	mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mount_info);
2558	dprintk("<-- nfs_xdev_mount_common() = 0\n");
2559out:
2560	return mntroot;
2561
2562out_err:
2563	dprintk("<-- nfs_xdev_mount_common() = %d [error]\n", error);
2564	goto out;
2565}
2566
2567/*
2568 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2569 */
2570static struct dentry *
2571nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2572		const char *dev_name, void *raw_data)
2573{
2574	struct nfs_mount_info mount_info = {
2575		.fill_super = nfs_clone_super,
2576		.set_security = nfs_clone_sb_security,
2577		.cloned   = raw_data,
2578	};
2579	return nfs_xdev_mount_common(&nfs_fs_type, flags, dev_name, &mount_info);
2580}
 
 
 
 
 
 
 
 
 
 
 
2581
2582#ifdef CONFIG_NFS_V4
2583
2584/*
2585 * Finish setting up a cloned NFS4 superblock
2586 */
2587static void nfs4_clone_super(struct super_block *sb,
2588			     struct nfs_mount_info *mount_info)
2589{
2590	const struct super_block *old_sb = mount_info->cloned->sb;
2591	sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2592	sb->s_blocksize = old_sb->s_blocksize;
2593	sb->s_maxbytes = old_sb->s_maxbytes;
2594	sb->s_time_gran = 1;
2595	sb->s_op = old_sb->s_op;
2596	/*
2597	 * The VFS shouldn't apply the umask to mode bits. We will do
2598	 * so ourselves when necessary.
2599	 */
2600	sb->s_flags  |= MS_POSIXACL;
2601	sb->s_xattr  = old_sb->s_xattr;
2602	nfs_initialise_sb(sb);
2603}
2604
2605/*
2606 * Set up an NFS4 superblock
2607 */
2608static void nfs4_fill_super(struct super_block *sb,
2609			    struct nfs_mount_info *mount_info)
2610{
2611	sb->s_time_gran = 1;
2612	sb->s_op = &nfs4_sops;
2613	/*
2614	 * The VFS shouldn't apply the umask to mode bits. We will do
2615	 * so ourselves when necessary.
2616	 */
2617	sb->s_flags  |= MS_POSIXACL;
2618	sb->s_xattr = nfs4_xattr_handlers;
2619	nfs_initialise_sb(sb);
2620}
2621
2622static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2623{
2624	args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2625			 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
2626}
2627
2628/*
2629 * Validate NFSv4 mount options
2630 */
2631static int nfs4_validate_mount_data(void *options,
2632				    struct nfs_parsed_mount_data *args,
2633				    const char *dev_name)
2634{
2635	struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2636	struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2637	char *c;
2638
2639	if (data == NULL)
2640		goto out_no_data;
2641
2642	args->version = 4;
2643
2644	switch (data->version) {
2645	case 1:
2646		if (data->host_addrlen > sizeof(args->nfs_server.address))
2647			goto out_no_address;
2648		if (data->host_addrlen == 0)
2649			goto out_no_address;
2650		args->nfs_server.addrlen = data->host_addrlen;
2651		if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2652			return -EFAULT;
2653		if (!nfs_verify_server_address(sap))
2654			goto out_no_address;
2655		args->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
2656
2657		if (data->auth_flavourlen) {
2658			if (data->auth_flavourlen > 1)
2659				goto out_inval_auth;
2660			if (copy_from_user(&args->auth_flavors[0],
2661					   data->auth_flavours,
2662					   sizeof(args->auth_flavors[0])))
2663				return -EFAULT;
2664		}
2665
2666		c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2667		if (IS_ERR(c))
2668			return PTR_ERR(c);
2669		args->nfs_server.hostname = c;
2670
2671		c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2672		if (IS_ERR(c))
2673			return PTR_ERR(c);
2674		args->nfs_server.export_path = c;
2675		dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2676
2677		c = strndup_user(data->client_addr.data, 16);
2678		if (IS_ERR(c))
2679			return PTR_ERR(c);
2680		args->client_address = c;
2681
2682		/*
2683		 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2684		 * can deal with.
2685		 */
2686
2687		args->flags	= data->flags & NFS4_MOUNT_FLAGMASK;
2688		args->rsize	= data->rsize;
2689		args->wsize	= data->wsize;
2690		args->timeo	= data->timeo;
2691		args->retrans	= data->retrans;
2692		args->acregmin	= data->acregmin;
2693		args->acregmax	= data->acregmax;
2694		args->acdirmin	= data->acdirmin;
2695		args->acdirmax	= data->acdirmax;
2696		args->nfs_server.protocol = data->proto;
2697		nfs_validate_transport_protocol(args);
2698
2699		break;
2700	default:
2701		return NFS_TEXT_DATA;
2702	}
2703
 
 
 
 
 
 
2704	return 0;
2705
2706out_no_data:
2707	dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2708	return -EINVAL;
2709
2710out_inval_auth:
2711	dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2712		 data->auth_flavourlen);
2713	return -EINVAL;
2714
2715out_no_address:
2716	dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2717	return -EINVAL;
2718}
2719
2720/*
2721 * Get the superblock for the NFS4 root partition
2722 */
2723static struct dentry *
2724nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2725		  const char *dev_name, void *info)
2726{
2727	struct nfs_mount_info *mount_info = info;
2728	struct nfs_server *server;
2729	struct dentry *mntroot = ERR_PTR(-ENOMEM);
2730
2731	mount_info->fill_super = nfs4_fill_super;
2732	mount_info->set_security = nfs_set_sb_security;
2733
2734	/* Get a volume representation */
2735	server = nfs4_create_server(mount_info->parsed, mount_info->mntfh);
2736	if (IS_ERR(server)) {
2737		mntroot = ERR_CAST(server);
2738		goto out;
2739	}
2740
2741	mntroot = nfs_fs_mount_common(fs_type, server, flags, dev_name, mount_info);
2742
2743out:
2744	return mntroot;
2745}
2746
2747static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2748		int flags, void *data, const char *hostname)
2749{
2750	struct vfsmount *root_mnt;
2751	char *root_devname;
2752	size_t len;
2753
2754	len = strlen(hostname) + 5;
2755	root_devname = kmalloc(len, GFP_KERNEL);
2756	if (root_devname == NULL)
2757		return ERR_PTR(-ENOMEM);
2758	/* Does hostname needs to be enclosed in brackets? */
2759	if (strchr(hostname, ':'))
2760		snprintf(root_devname, len, "[%s]:/", hostname);
2761	else
2762		snprintf(root_devname, len, "%s:/", hostname);
2763	root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2764	kfree(root_devname);
2765	return root_mnt;
2766}
2767
2768struct nfs_referral_count {
2769	struct list_head list;
2770	const struct task_struct *task;
2771	unsigned int referral_count;
2772};
2773
2774static LIST_HEAD(nfs_referral_count_list);
2775static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2776
2777static struct nfs_referral_count *nfs_find_referral_count(void)
2778{
2779	struct nfs_referral_count *p;
2780
2781	list_for_each_entry(p, &nfs_referral_count_list, list) {
2782		if (p->task == current)
2783			return p;
2784	}
2785	return NULL;
2786}
2787
2788#define NFS_MAX_NESTED_REFERRALS 2
2789
2790static int nfs_referral_loop_protect(void)
2791{
2792	struct nfs_referral_count *p, *new;
2793	int ret = -ENOMEM;
2794
2795	new = kmalloc(sizeof(*new), GFP_KERNEL);
2796	if (!new)
2797		goto out;
2798	new->task = current;
2799	new->referral_count = 1;
2800
2801	ret = 0;
2802	spin_lock(&nfs_referral_count_list_lock);
2803	p = nfs_find_referral_count();
2804	if (p != NULL) {
2805		if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2806			ret = -ELOOP;
2807		else
2808			p->referral_count++;
2809	} else {
2810		list_add(&new->list, &nfs_referral_count_list);
2811		new = NULL;
2812	}
2813	spin_unlock(&nfs_referral_count_list_lock);
2814	kfree(new);
2815out:
2816	return ret;
2817}
2818
2819static void nfs_referral_loop_unprotect(void)
2820{
2821	struct nfs_referral_count *p;
2822
2823	spin_lock(&nfs_referral_count_list_lock);
2824	p = nfs_find_referral_count();
2825	p->referral_count--;
2826	if (p->referral_count == 0)
2827		list_del(&p->list);
2828	else
2829		p = NULL;
2830	spin_unlock(&nfs_referral_count_list_lock);
2831	kfree(p);
2832}
2833
2834static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
2835		const char *export_path)
2836{
2837	struct dentry *dentry;
2838	int err;
2839
2840	if (IS_ERR(root_mnt))
2841		return ERR_CAST(root_mnt);
2842
2843	err = nfs_referral_loop_protect();
2844	if (err) {
2845		mntput(root_mnt);
2846		return ERR_PTR(err);
2847	}
2848
2849	dentry = mount_subtree(root_mnt, export_path);
2850	nfs_referral_loop_unprotect();
2851
2852	return dentry;
2853}
2854
2855static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
2856			 struct nfs_mount_info *mount_info)
2857{
2858	char *export_path;
2859	struct vfsmount *root_mnt;
2860	struct dentry *res;
2861	struct nfs_parsed_mount_data *data = mount_info->parsed;
2862
2863	dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2864
2865	mount_info->fill_super = nfs4_fill_super;
2866
2867	export_path = data->nfs_server.export_path;
2868	data->nfs_server.export_path = "/";
2869	root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, mount_info,
2870			data->nfs_server.hostname);
2871	data->nfs_server.export_path = export_path;
2872
2873	res = nfs_follow_remote_path(root_mnt, export_path);
2874
2875	dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
2876			IS_ERR(res) ? PTR_ERR(res) : 0,
2877			IS_ERR(res) ? " [error]" : "");
2878	return res;
2879}
2880
2881static void nfs4_kill_super(struct super_block *sb)
2882{
2883	struct nfs_server *server = NFS_SB(sb);
2884
2885	dprintk("--> %s\n", __func__);
2886	nfs_super_return_all_delegations(sb);
2887	kill_anon_super(sb);
2888	nfs_fscache_release_super_cookie(sb);
2889	nfs_free_server(server);
2890	dprintk("<-- %s\n", __func__);
2891}
2892
2893/*
2894 * Clone an NFS4 server record on xdev traversal (FSID-change)
2895 */
2896static struct dentry *
2897nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2898		 const char *dev_name, void *raw_data)
2899{
2900	struct nfs_mount_info mount_info = {
2901		.fill_super = nfs4_clone_super,
2902		.set_security = nfs_clone_sb_security,
2903		.cloned = raw_data,
2904	};
2905	return nfs_xdev_mount_common(&nfs4_fs_type, flags, dev_name, &mount_info);
2906}
2907
2908static struct dentry *
2909nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2910			   const char *dev_name, void *raw_data)
2911{
2912	struct nfs_mount_info mount_info = {
2913		.fill_super = nfs4_fill_super,
2914		.set_security = nfs_clone_sb_security,
2915		.cloned = raw_data,
2916	};
2917	struct nfs_server *server;
2918	struct dentry *mntroot = ERR_PTR(-ENOMEM);
2919
2920	dprintk("--> nfs4_referral_get_sb()\n");
2921
2922	mount_info.mntfh = nfs_alloc_fhandle();
2923	if (mount_info.cloned == NULL || mount_info.mntfh == NULL)
2924		goto out;
2925
2926	/* create a new volume representation */
2927	server = nfs4_create_referral_server(mount_info.cloned, mount_info.mntfh);
2928	if (IS_ERR(server)) {
2929		mntroot = ERR_CAST(server);
2930		goto out;
2931	}
2932
2933	mntroot = nfs_fs_mount_common(&nfs4_fs_type, server, flags, dev_name, &mount_info);
2934out:
2935	nfs_free_fhandle(mount_info.mntfh);
2936	return mntroot;
2937}
2938
2939/*
2940 * Create an NFS4 server record on referral traversal
2941 */
2942static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
2943		int flags, const char *dev_name, void *raw_data)
2944{
2945	struct nfs_clone_mount *data = raw_data;
2946	char *export_path;
2947	struct vfsmount *root_mnt;
2948	struct dentry *res;
2949
2950	dprintk("--> nfs4_referral_mount()\n");
2951
2952	export_path = data->mnt_path;
2953	data->mnt_path = "/";
2954
2955	root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2956			flags, data, data->hostname);
2957	data->mnt_path = export_path;
2958
2959	res = nfs_follow_remote_path(root_mnt, export_path);
2960	dprintk("<-- nfs4_referral_mount() = %ld%s\n",
2961			IS_ERR(res) ? PTR_ERR(res) : 0,
2962			IS_ERR(res) ? " [error]" : "");
2963	return res;
2964}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2965
2966MODULE_ALIAS("nfs4");
2967
2968#endif /* CONFIG_NFS_V4 */