17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
545916cd2Sjpk * Common Development and Distribution License (the "License").
645916cd2Sjpk * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22a19609f8Sjv * Copyright (c) 1986, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
277c478bd9Sstevel@tonic-gate * All rights reserved.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <sys/param.h>
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/cred.h>
347c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
35aa59c4cbSrsb #include <sys/vfs_opreg.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
407c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
417c478bd9Sstevel@tonic-gate #include <sys/mount.h>
427c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
437c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
447c478bd9Sstevel@tonic-gate #include <sys/errno.h>
457c478bd9Sstevel@tonic-gate #include <sys/debug.h>
467c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
477c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
487c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
497c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
507c478bd9Sstevel@tonic-gate #include <sys/acl.h>
517c478bd9Sstevel@tonic-gate #include <sys/flock.h>
527c478bd9Sstevel@tonic-gate #include <sys/policy.h>
537c478bd9Sstevel@tonic-gate #include <sys/zone.h>
547c478bd9Sstevel@tonic-gate #include <sys/class.h>
557c478bd9Sstevel@tonic-gate #include <sys/socket.h>
567c478bd9Sstevel@tonic-gate #include <sys/netconfig.h>
5745916cd2Sjpk #include <sys/tsol/tnet.h>
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #include <rpc/types.h>
607c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
617c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
647c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
657c478bd9Sstevel@tonic-gate #include <nfs/rnode.h>
667c478bd9Sstevel@tonic-gate #include <nfs/mount.h>
677c478bd9Sstevel@tonic-gate #include <nfs/nfs_acl.h>
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate * From rpcsec module (common/rpcsec).
737c478bd9Sstevel@tonic-gate */
747c478bd9Sstevel@tonic-gate extern int sec_clnt_loadinfo(struct sec_data *, struct sec_data **, model_t);
757c478bd9Sstevel@tonic-gate extern void sec_clnt_freeinfo(struct sec_data *);
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * The order and contents of this structure must be kept in sync with that of
797c478bd9Sstevel@tonic-gate * rfsreqcnt_v3_tmpl in nfs_stats.c
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate static char *rfsnames_v3[] = {
827c478bd9Sstevel@tonic-gate "null", "getattr", "setattr", "lookup", "access", "readlink", "read",
837c478bd9Sstevel@tonic-gate "write", "create", "mkdir", "symlink", "mknod", "remove", "rmdir",
847c478bd9Sstevel@tonic-gate "rename", "link", "readdir", "readdirplus", "fsstat", "fsinfo",
857c478bd9Sstevel@tonic-gate "pathconf", "commit"
867c478bd9Sstevel@tonic-gate };
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate * This table maps from NFS protocol number into call type.
907c478bd9Sstevel@tonic-gate * Zero means a "Lookup" type call
917c478bd9Sstevel@tonic-gate * One means a "Read" type call
927c478bd9Sstevel@tonic-gate * Two means a "Write" type call
937c478bd9Sstevel@tonic-gate * This is used to select a default time-out.
947c478bd9Sstevel@tonic-gate */
957c478bd9Sstevel@tonic-gate static uchar_t call_type_v3[] = {
967c478bd9Sstevel@tonic-gate 0, 0, 1, 0, 0, 0, 1,
977c478bd9Sstevel@tonic-gate 2, 2, 2, 2, 2, 2, 2,
987c478bd9Sstevel@tonic-gate 2, 2, 1, 2, 0, 0, 0,
997c478bd9Sstevel@tonic-gate 2 };
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * Similar table, but to determine which timer to use
1037c478bd9Sstevel@tonic-gate * (only real reads and writes!)
1047c478bd9Sstevel@tonic-gate */
1057c478bd9Sstevel@tonic-gate static uchar_t timer_type_v3[] = {
1067c478bd9Sstevel@tonic-gate 0, 0, 0, 0, 0, 0, 1,
1077c478bd9Sstevel@tonic-gate 2, 0, 0, 0, 0, 0, 0,
1087c478bd9Sstevel@tonic-gate 0, 0, 1, 1, 0, 0, 0,
1097c478bd9Sstevel@tonic-gate 0 };
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate * This table maps from NFS protocol number into a call type
1137c478bd9Sstevel@tonic-gate * for the semisoft mount option.
1147c478bd9Sstevel@tonic-gate * Zero means do not repeat operation.
1157c478bd9Sstevel@tonic-gate * One means repeat.
1167c478bd9Sstevel@tonic-gate */
1177c478bd9Sstevel@tonic-gate static uchar_t ss_call_type_v3[] = {
1187c478bd9Sstevel@tonic-gate 0, 0, 1, 0, 0, 0, 0,
1197c478bd9Sstevel@tonic-gate 1, 1, 1, 1, 1, 1, 1,
1207c478bd9Sstevel@tonic-gate 1, 1, 0, 0, 0, 0, 0,
1217c478bd9Sstevel@tonic-gate 1 };
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * nfs3 vfs operations.
1257c478bd9Sstevel@tonic-gate */
1267c478bd9Sstevel@tonic-gate static int nfs3_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
1277c478bd9Sstevel@tonic-gate static int nfs3_unmount(vfs_t *, int, cred_t *);
1287c478bd9Sstevel@tonic-gate static int nfs3_root(vfs_t *, vnode_t **);
1297c478bd9Sstevel@tonic-gate static int nfs3_statvfs(vfs_t *, struct statvfs64 *);
1307c478bd9Sstevel@tonic-gate static int nfs3_sync(vfs_t *, short, cred_t *);
1317c478bd9Sstevel@tonic-gate static int nfs3_vget(vfs_t *, vnode_t **, fid_t *);
1327c478bd9Sstevel@tonic-gate static int nfs3_mountroot(vfs_t *, whymountroot_t);
1337c478bd9Sstevel@tonic-gate static void nfs3_freevfs(vfs_t *);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate static int nfs3rootvp(vnode_t **, vfs_t *, struct servinfo *,
1367c478bd9Sstevel@tonic-gate int, cred_t *, zone_t *);
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * Initialize the vfs structure
1407c478bd9Sstevel@tonic-gate */
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate static int nfs3fstyp;
1437c478bd9Sstevel@tonic-gate vfsops_t *nfs3_vfsops;
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate * Debug variable to check for rdma based
1477c478bd9Sstevel@tonic-gate * transport startup and cleanup. Controlled
1487c478bd9Sstevel@tonic-gate * through /etc/system. Off by default.
1497c478bd9Sstevel@tonic-gate */
1507c478bd9Sstevel@tonic-gate extern int rdma_debug;
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate int
nfs3init(int fstyp,char * name)1537c478bd9Sstevel@tonic-gate nfs3init(int fstyp, char *name)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate static const fs_operation_def_t nfs3_vfsops_template[] = {
156aa59c4cbSrsb VFSNAME_MOUNT, { .vfs_mount = nfs3_mount },
157aa59c4cbSrsb VFSNAME_UNMOUNT, { .vfs_unmount = nfs3_unmount },
158aa59c4cbSrsb VFSNAME_ROOT, { .vfs_root = nfs3_root },
159aa59c4cbSrsb VFSNAME_STATVFS, { .vfs_statvfs = nfs3_statvfs },
160aa59c4cbSrsb VFSNAME_SYNC, { .vfs_sync = nfs3_sync },
161aa59c4cbSrsb VFSNAME_VGET, { .vfs_vget = nfs3_vget },
162aa59c4cbSrsb VFSNAME_MOUNTROOT, { .vfs_mountroot = nfs3_mountroot },
163aa59c4cbSrsb VFSNAME_FREEVFS, { .vfs_freevfs = nfs3_freevfs },
164aa59c4cbSrsb NULL, NULL
1657c478bd9Sstevel@tonic-gate };
1667c478bd9Sstevel@tonic-gate int error;
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate error = vfs_setfsops(fstyp, nfs3_vfsops_template, &nfs3_vfsops);
1697c478bd9Sstevel@tonic-gate if (error != 0) {
1707c478bd9Sstevel@tonic-gate zcmn_err(GLOBAL_ZONEID, CE_WARN,
1717c478bd9Sstevel@tonic-gate "nfs3init: bad vfs ops template");
1727c478bd9Sstevel@tonic-gate return (error);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate error = vn_make_ops(name, nfs3_vnodeops_template, &nfs3_vnodeops);
1767c478bd9Sstevel@tonic-gate if (error != 0) {
1777c478bd9Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstyp);
1787c478bd9Sstevel@tonic-gate zcmn_err(GLOBAL_ZONEID, CE_WARN,
1797c478bd9Sstevel@tonic-gate "nfs3init: bad vnode ops template");
1807c478bd9Sstevel@tonic-gate return (error);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate nfs3fstyp = fstyp;
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate return (0);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate void
nfs3fini(void)1897c478bd9Sstevel@tonic-gate nfs3fini(void)
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
19339d3e169Sevanl static void
nfs3_free_args(struct nfs_args * nargs,nfs_fhandle * fh)19439d3e169Sevanl nfs3_free_args(struct nfs_args *nargs, nfs_fhandle *fh)
19539d3e169Sevanl {
19639d3e169Sevanl
19739d3e169Sevanl if (fh)
19839d3e169Sevanl kmem_free(fh, sizeof (*fh));
19939d3e169Sevanl
20039d3e169Sevanl if (nargs->knconf) {
20139d3e169Sevanl if (nargs->knconf->knc_protofmly)
202dcedb507SMarcel Telka kmem_free(nargs->knconf->knc_protofmly, KNC_STRSIZE);
203dcedb507SMarcel Telka if (nargs->knconf->knc_proto)
204dcedb507SMarcel Telka kmem_free(nargs->knconf->knc_proto, KNC_STRSIZE);
20539d3e169Sevanl kmem_free(nargs->knconf, sizeof (*nargs->knconf));
20639d3e169Sevanl nargs->knconf = NULL;
20739d3e169Sevanl }
20839d3e169Sevanl
20939d3e169Sevanl if (nargs->fh) {
21039d3e169Sevanl kmem_free(nargs->fh, strlen(nargs->fh) + 1);
21139d3e169Sevanl nargs->fh = NULL;
21239d3e169Sevanl }
21339d3e169Sevanl
21439d3e169Sevanl if (nargs->hostname) {
21539d3e169Sevanl kmem_free(nargs->hostname, strlen(nargs->hostname) + 1);
21639d3e169Sevanl nargs->hostname = NULL;
21739d3e169Sevanl }
21839d3e169Sevanl
21939d3e169Sevanl if (nargs->addr) {
22039d3e169Sevanl if (nargs->addr->buf) {
22139d3e169Sevanl ASSERT(nargs->addr->len);
22239d3e169Sevanl kmem_free(nargs->addr->buf, nargs->addr->len);
22339d3e169Sevanl }
22439d3e169Sevanl kmem_free(nargs->addr, sizeof (struct netbuf));
22539d3e169Sevanl nargs->addr = NULL;
22639d3e169Sevanl }
22739d3e169Sevanl
22839d3e169Sevanl if (nargs->syncaddr) {
22939d3e169Sevanl ASSERT(nargs->syncaddr->len);
23039d3e169Sevanl if (nargs->syncaddr->buf) {
23139d3e169Sevanl ASSERT(nargs->syncaddr->len);
23239d3e169Sevanl kmem_free(nargs->syncaddr->buf, nargs->syncaddr->len);
23339d3e169Sevanl }
23439d3e169Sevanl kmem_free(nargs->syncaddr, sizeof (struct netbuf));
23539d3e169Sevanl nargs->syncaddr = NULL;
23639d3e169Sevanl }
23739d3e169Sevanl
23839d3e169Sevanl if (nargs->netname) {
23939d3e169Sevanl kmem_free(nargs->netname, strlen(nargs->netname) + 1);
24039d3e169Sevanl nargs->netname = NULL;
24139d3e169Sevanl }
24239d3e169Sevanl
24339d3e169Sevanl if (nargs->nfs_ext_u.nfs_extA.secdata) {
24439d3e169Sevanl sec_clnt_freeinfo(nargs->nfs_ext_u.nfs_extA.secdata);
24539d3e169Sevanl nargs->nfs_ext_u.nfs_extA.secdata = NULL;
24639d3e169Sevanl }
24739d3e169Sevanl }
24839d3e169Sevanl
24939d3e169Sevanl static int
nfs3_copyin(char * data,int datalen,struct nfs_args * nargs,nfs_fhandle * fh)25039d3e169Sevanl nfs3_copyin(char *data, int datalen, struct nfs_args *nargs, nfs_fhandle *fh)
25139d3e169Sevanl {
25239d3e169Sevanl
25339d3e169Sevanl int error;
25439d3e169Sevanl size_t nlen; /* length of netname */
25539d3e169Sevanl size_t hlen; /* length of hostname */
25639d3e169Sevanl char netname[MAXNETNAMELEN+1]; /* server's netname */
25739d3e169Sevanl struct netbuf addr; /* server's address */
25839d3e169Sevanl struct netbuf syncaddr; /* AUTH_DES time sync addr */
25939d3e169Sevanl struct knetconfig *knconf; /* transport knetconfig structure */
26039d3e169Sevanl struct sec_data *secdata = NULL; /* security data */
26139d3e169Sevanl STRUCT_DECL(nfs_args, args); /* nfs mount arguments */
26239d3e169Sevanl STRUCT_DECL(knetconfig, knconf_tmp);
26339d3e169Sevanl STRUCT_DECL(netbuf, addr_tmp);
26439d3e169Sevanl int flags;
26539d3e169Sevanl char *p, *pf;
26639d3e169Sevanl char *userbufptr;
26739d3e169Sevanl
26839d3e169Sevanl
26939d3e169Sevanl bzero(nargs, sizeof (*nargs));
27039d3e169Sevanl
27139d3e169Sevanl STRUCT_INIT(args, get_udatamodel());
27239d3e169Sevanl bzero(STRUCT_BUF(args), SIZEOF_STRUCT(nfs_args, DATAMODEL_NATIVE));
27339d3e169Sevanl if (copyin(data, STRUCT_BUF(args), MIN(datalen, STRUCT_SIZE(args))))
27439d3e169Sevanl return (EFAULT);
27539d3e169Sevanl
27639d3e169Sevanl nargs->wsize = STRUCT_FGET(args, wsize);
27739d3e169Sevanl nargs->rsize = STRUCT_FGET(args, rsize);
27839d3e169Sevanl nargs->timeo = STRUCT_FGET(args, timeo);
27939d3e169Sevanl nargs->retrans = STRUCT_FGET(args, retrans);
28039d3e169Sevanl nargs->acregmin = STRUCT_FGET(args, acregmin);
28139d3e169Sevanl nargs->acregmax = STRUCT_FGET(args, acregmax);
28239d3e169Sevanl nargs->acdirmin = STRUCT_FGET(args, acdirmin);
28339d3e169Sevanl nargs->acdirmax = STRUCT_FGET(args, acdirmax);
28439d3e169Sevanl
28539d3e169Sevanl flags = STRUCT_FGET(args, flags);
28639d3e169Sevanl nargs->flags = flags;
28739d3e169Sevanl
28839d3e169Sevanl addr.buf = NULL;
28939d3e169Sevanl syncaddr.buf = NULL;
29039d3e169Sevanl
29139d3e169Sevanl /*
29239d3e169Sevanl * Allocate space for a knetconfig structure and
29339d3e169Sevanl * its strings and copy in from user-land.
29439d3e169Sevanl */
29539d3e169Sevanl knconf = kmem_zalloc(sizeof (*knconf), KM_SLEEP);
29639d3e169Sevanl STRUCT_INIT(knconf_tmp, get_udatamodel());
29739d3e169Sevanl if (copyin(STRUCT_FGETP(args, knconf), STRUCT_BUF(knconf_tmp),
298dcedb507SMarcel Telka STRUCT_SIZE(knconf_tmp))) {
29939d3e169Sevanl kmem_free(knconf, sizeof (*knconf));
30039d3e169Sevanl return (EFAULT);
30139d3e169Sevanl }
30239d3e169Sevanl
30339d3e169Sevanl knconf->knc_semantics = STRUCT_FGET(knconf_tmp, knc_semantics);
30439d3e169Sevanl knconf->knc_protofmly = STRUCT_FGETP(knconf_tmp, knc_protofmly);
30539d3e169Sevanl knconf->knc_proto = STRUCT_FGETP(knconf_tmp, knc_proto);
30639d3e169Sevanl if (get_udatamodel() != DATAMODEL_LP64) {
30739d3e169Sevanl knconf->knc_rdev = expldev(STRUCT_FGET(knconf_tmp, knc_rdev));
30839d3e169Sevanl } else {
30939d3e169Sevanl knconf->knc_rdev = STRUCT_FGET(knconf_tmp, knc_rdev);
31039d3e169Sevanl }
31139d3e169Sevanl
31239d3e169Sevanl pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
31339d3e169Sevanl p = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
31439d3e169Sevanl error = copyinstr(knconf->knc_protofmly, pf, KNC_STRSIZE, NULL);
31539d3e169Sevanl if (error) {
31639d3e169Sevanl kmem_free(pf, KNC_STRSIZE);
31739d3e169Sevanl kmem_free(p, KNC_STRSIZE);
31839d3e169Sevanl kmem_free(knconf, sizeof (*knconf));
31939d3e169Sevanl return (error);
32039d3e169Sevanl }
32139d3e169Sevanl
32239d3e169Sevanl error = copyinstr(knconf->knc_proto, p, KNC_STRSIZE, NULL);
32339d3e169Sevanl if (error) {
32439d3e169Sevanl kmem_free(pf, KNC_STRSIZE);
32539d3e169Sevanl kmem_free(p, KNC_STRSIZE);
32639d3e169Sevanl kmem_free(knconf, sizeof (*knconf));
32739d3e169Sevanl return (error);
32839d3e169Sevanl }
32939d3e169Sevanl
33039d3e169Sevanl
33139d3e169Sevanl knconf->knc_protofmly = pf;
33239d3e169Sevanl knconf->knc_proto = p;
33339d3e169Sevanl
33439d3e169Sevanl nargs->knconf = knconf;
33539d3e169Sevanl /*
33639d3e169Sevanl * Get server address
33739d3e169Sevanl */
33839d3e169Sevanl STRUCT_INIT(addr_tmp, get_udatamodel());
33939d3e169Sevanl if (copyin(STRUCT_FGETP(args, addr), STRUCT_BUF(addr_tmp),
340dcedb507SMarcel Telka STRUCT_SIZE(addr_tmp))) {
341dcedb507SMarcel Telka error = EFAULT;
342dcedb507SMarcel Telka goto errout;
34339d3e169Sevanl }
34439d3e169Sevanl
34539d3e169Sevanl nargs->addr = kmem_alloc(sizeof (struct netbuf), KM_SLEEP);
34639d3e169Sevanl userbufptr = STRUCT_FGETP(addr_tmp, buf);
34739d3e169Sevanl addr.len = STRUCT_FGET(addr_tmp, len);
34839d3e169Sevanl addr.buf = kmem_alloc(addr.len, KM_SLEEP);
34939d3e169Sevanl addr.maxlen = addr.len;
35039d3e169Sevanl if (copyin(userbufptr, addr.buf, addr.len)) {
35139d3e169Sevanl kmem_free(addr.buf, addr.len);
35239d3e169Sevanl error = EFAULT;
35339d3e169Sevanl goto errout;
35439d3e169Sevanl }
35539d3e169Sevanl bcopy(&addr, nargs->addr, sizeof (struct netbuf));
35639d3e169Sevanl
35739d3e169Sevanl /*
35839d3e169Sevanl * Get the root fhandle
35939d3e169Sevanl */
36039d3e169Sevanl
36139d3e169Sevanl if (copyin(STRUCT_FGETP(args, fh), fh, sizeof (nfs_fhandle))) {
36239d3e169Sevanl error = EFAULT;
36339d3e169Sevanl goto errout;
36439d3e169Sevanl }
36539d3e169Sevanl
36639d3e169Sevanl
36739d3e169Sevanl /*
36839d3e169Sevanl * Get server's hostname
36939d3e169Sevanl */
37039d3e169Sevanl if (flags & NFSMNT_HOSTNAME) {
371dcedb507SMarcel Telka error = copyinstr(STRUCT_FGETP(args, hostname), netname,
372dcedb507SMarcel Telka sizeof (netname), &hlen);
37339d3e169Sevanl if (error)
37439d3e169Sevanl goto errout;
37539d3e169Sevanl nargs->hostname = kmem_zalloc(hlen, KM_SLEEP);
37639d3e169Sevanl (void) strcpy(nargs->hostname, netname);
37739d3e169Sevanl } else {
37839d3e169Sevanl nargs->hostname = NULL;
37939d3e169Sevanl }
38039d3e169Sevanl
38139d3e169Sevanl
38239d3e169Sevanl /*
38339d3e169Sevanl * If there are syncaddr and netname data, load them in. This is
38439d3e169Sevanl * to support data needed for NFSV4 when AUTH_DH is the negotiated
38539d3e169Sevanl * flavor via SECINFO. (instead of using MOUNT protocol in V3).
38639d3e169Sevanl */
38739d3e169Sevanl netname[0] = '\0';
38839d3e169Sevanl if (flags & NFSMNT_SECURE) {
38939d3e169Sevanl if (STRUCT_FGETP(args, syncaddr) == NULL) {
39039d3e169Sevanl error = EINVAL;
39139d3e169Sevanl goto errout;
39239d3e169Sevanl }
39339d3e169Sevanl /* get syncaddr */
39439d3e169Sevanl STRUCT_INIT(addr_tmp, get_udatamodel());
39539d3e169Sevanl if (copyin(STRUCT_FGETP(args, syncaddr), STRUCT_BUF(addr_tmp),
396dcedb507SMarcel Telka STRUCT_SIZE(addr_tmp))) {
39739d3e169Sevanl error = EINVAL;
39839d3e169Sevanl goto errout;
39939d3e169Sevanl }
40039d3e169Sevanl userbufptr = STRUCT_FGETP(addr_tmp, buf);
40139d3e169Sevanl syncaddr.len = STRUCT_FGET(addr_tmp, len);
40239d3e169Sevanl syncaddr.buf = kmem_alloc(syncaddr.len, KM_SLEEP);
40339d3e169Sevanl syncaddr.maxlen = syncaddr.len;
40439d3e169Sevanl if (copyin(userbufptr, syncaddr.buf, syncaddr.len)) {
40539d3e169Sevanl kmem_free(syncaddr.buf, syncaddr.len);
40639d3e169Sevanl error = EFAULT;
40739d3e169Sevanl goto errout;
40839d3e169Sevanl }
40939d3e169Sevanl
41039d3e169Sevanl nargs->syncaddr = kmem_alloc(sizeof (struct netbuf), KM_SLEEP);
41139d3e169Sevanl bcopy(&syncaddr, nargs->syncaddr, sizeof (struct netbuf));
41239d3e169Sevanl
41339d3e169Sevanl ASSERT(STRUCT_FGETP(args, netname));
41439d3e169Sevanl
41539d3e169Sevanl if (copyinstr(STRUCT_FGETP(args, netname), netname,
416dcedb507SMarcel Telka sizeof (netname), &nlen)) {
41739d3e169Sevanl error = EFAULT;
41839d3e169Sevanl goto errout;
41939d3e169Sevanl }
42039d3e169Sevanl
42139d3e169Sevanl netname[nlen] = '\0';
42239d3e169Sevanl nargs->netname = kmem_zalloc(nlen, KM_SLEEP);
42339d3e169Sevanl (void) strcpy(nargs->netname, netname);
42439d3e169Sevanl }
42539d3e169Sevanl
42639d3e169Sevanl /*
42739d3e169Sevanl * Get the extention data which has the security data structure.
42839d3e169Sevanl * This includes data for AUTH_SYS as well.
42939d3e169Sevanl */
43039d3e169Sevanl if (flags & NFSMNT_NEWARGS) {
43139d3e169Sevanl nargs->nfs_args_ext = STRUCT_FGET(args, nfs_args_ext);
43239d3e169Sevanl if (nargs->nfs_args_ext == NFS_ARGS_EXTA ||
433dcedb507SMarcel Telka nargs->nfs_args_ext == NFS_ARGS_EXTB) {
43439d3e169Sevanl /*
43539d3e169Sevanl * Indicating the application is using the new
43639d3e169Sevanl * sec_data structure to pass in the security
43739d3e169Sevanl * data.
43839d3e169Sevanl */
43939d3e169Sevanl if (STRUCT_FGETP(args,
440dcedb507SMarcel Telka nfs_ext_u.nfs_extA.secdata) != NULL) {
44139d3e169Sevanl error = sec_clnt_loadinfo(
442dcedb507SMarcel Telka (struct sec_data *)STRUCT_FGETP(args,
443dcedb507SMarcel Telka nfs_ext_u.nfs_extA.secdata), &secdata,
444dcedb507SMarcel Telka get_udatamodel());
44539d3e169Sevanl }
44639d3e169Sevanl nargs->nfs_ext_u.nfs_extA.secdata = secdata;
44739d3e169Sevanl }
44839d3e169Sevanl }
44939d3e169Sevanl
45039d3e169Sevanl if (error)
45139d3e169Sevanl goto errout;
45239d3e169Sevanl
45339d3e169Sevanl /*
45439d3e169Sevanl * Failover support:
45539d3e169Sevanl *
45639d3e169Sevanl * We may have a linked list of nfs_args structures,
45739d3e169Sevanl * which means the user is looking for failover. If
45839d3e169Sevanl * the mount is either not "read-only" or "soft",
45939d3e169Sevanl * we want to bail out with EINVAL.
46039d3e169Sevanl */
46139d3e169Sevanl if (nargs->nfs_args_ext == NFS_ARGS_EXTB)
46239d3e169Sevanl nargs->nfs_ext_u.nfs_extB.next =
463dcedb507SMarcel Telka STRUCT_FGETP(args, nfs_ext_u.nfs_extB.next);
46439d3e169Sevanl
46539d3e169Sevanl errout:
46639d3e169Sevanl if (error)
46739d3e169Sevanl nfs3_free_args(nargs, fh);
46839d3e169Sevanl
46939d3e169Sevanl return (error);
47039d3e169Sevanl }
47139d3e169Sevanl
47239d3e169Sevanl
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate * nfs mount vfsop
4757c478bd9Sstevel@tonic-gate * Set up mount info record and attach it to vfs struct.
4767c478bd9Sstevel@tonic-gate */
4777c478bd9Sstevel@tonic-gate static int
nfs3_mount(vfs_t * vfsp,vnode_t * mvp,struct mounta * uap,cred_t * cr)4787c478bd9Sstevel@tonic-gate nfs3_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
4797c478bd9Sstevel@tonic-gate {
48039d3e169Sevanl struct nfs_args *args = NULL;
48139d3e169Sevanl nfs_fhandle *fhandle = NULL;
4827c478bd9Sstevel@tonic-gate char *data = uap->dataptr;
4837c478bd9Sstevel@tonic-gate int error;
4847c478bd9Sstevel@tonic-gate vnode_t *rtvp; /* the server's root */
4857c478bd9Sstevel@tonic-gate mntinfo_t *mi; /* mount info, pointed at by vfs */
4867c478bd9Sstevel@tonic-gate size_t nlen; /* length of netname */
4877c478bd9Sstevel@tonic-gate struct knetconfig *knconf; /* transport knetconfig structure */
4887c478bd9Sstevel@tonic-gate struct knetconfig *rdma_knconf; /* rdma transport structure */
4897c478bd9Sstevel@tonic-gate rnode_t *rp;
4907c478bd9Sstevel@tonic-gate struct servinfo *svp; /* nfs server info */
4917c478bd9Sstevel@tonic-gate struct servinfo *svp_tail = NULL; /* previous nfs server info */
4927c478bd9Sstevel@tonic-gate struct servinfo *svp_head; /* first nfs server info */
4937c478bd9Sstevel@tonic-gate struct servinfo *svp_2ndlast; /* 2nd last in server info list */
4947c478bd9Sstevel@tonic-gate struct sec_data *secdata; /* security data */
4957c478bd9Sstevel@tonic-gate int flags, addr_type;
496108322fbScarlsonj zone_t *zone = nfs_zone();
49745916cd2Sjpk zone_t *mntzone = NULL;
4987c478bd9Sstevel@tonic-gate
49939d3e169Sevanl
5007c478bd9Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
5017c478bd9Sstevel@tonic-gate return (EPERM);
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate if (mvp->v_type != VDIR)
5047c478bd9Sstevel@tonic-gate return (ENOTDIR);
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate * get arguments
5087c478bd9Sstevel@tonic-gate *
5097c478bd9Sstevel@tonic-gate * nfs_args is now versioned and is extensible, so
5107c478bd9Sstevel@tonic-gate * uap->datalen might be different from sizeof (args)
5117c478bd9Sstevel@tonic-gate * in a compatible situation.
5127c478bd9Sstevel@tonic-gate */
51339d3e169Sevanl
5147c478bd9Sstevel@tonic-gate more:
5157c478bd9Sstevel@tonic-gate
51639d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) {
51739d3e169Sevanl if (args == NULL)
51839d3e169Sevanl args = kmem_alloc(sizeof (struct nfs_args), KM_SLEEP);
51939d3e169Sevanl else {
52039d3e169Sevanl nfs3_free_args(args, fhandle);
52139d3e169Sevanl fhandle = NULL;
52239d3e169Sevanl }
52339d3e169Sevanl if (fhandle == NULL)
52439d3e169Sevanl fhandle = kmem_alloc(sizeof (nfs_fhandle), KM_SLEEP);
52539d3e169Sevanl error = nfs3_copyin(data, uap->datalen, args, fhandle);
52639d3e169Sevanl if (error) {
52739d3e169Sevanl if (args)
52839d3e169Sevanl kmem_free(args, sizeof (*args));
52939d3e169Sevanl return (error);
53039d3e169Sevanl }
53139d3e169Sevanl } else {
53239d3e169Sevanl args = (struct nfs_args *)data;
53339d3e169Sevanl fhandle = (nfs_fhandle *)args->fh;
53439d3e169Sevanl }
53539d3e169Sevanl
53639d3e169Sevanl
53739d3e169Sevanl flags = args->flags;
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate if (uap->flags & MS_REMOUNT) {
54039d3e169Sevanl size_t n;
54139d3e169Sevanl char name[FSTYPSZ];
5427c478bd9Sstevel@tonic-gate
54339d3e169Sevanl if (uap->flags & MS_SYSSPACE) {
5447c478bd9Sstevel@tonic-gate error = copystr(uap->fstype, name, FSTYPSZ, &n);
54539d3e169Sevanl } else {
54639d3e169Sevanl nfs3_free_args(args, fhandle);
54739d3e169Sevanl kmem_free(args, sizeof (*args));
5487c478bd9Sstevel@tonic-gate error = copyinstr(uap->fstype, name, FSTYPSZ, &n);
54939d3e169Sevanl }
5507c478bd9Sstevel@tonic-gate if (error) {
5517c478bd9Sstevel@tonic-gate if (error == ENAMETOOLONG)
5527c478bd9Sstevel@tonic-gate return (EINVAL);
5537c478bd9Sstevel@tonic-gate return (error);
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate /*
5577c478bd9Sstevel@tonic-gate * This check is to ensure that the request is a
5587c478bd9Sstevel@tonic-gate * genuine nfs remount request.
5597c478bd9Sstevel@tonic-gate */
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate if (strncmp(name, "nfs", 3) != 0)
5627c478bd9Sstevel@tonic-gate return (EINVAL);
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate /*
5657c478bd9Sstevel@tonic-gate * If the request changes the locking type, disallow the
5667c478bd9Sstevel@tonic-gate * remount,
5677c478bd9Sstevel@tonic-gate * because it's questionable whether we can transfer the
5687c478bd9Sstevel@tonic-gate * locking state correctly.
5697c478bd9Sstevel@tonic-gate */
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate if ((mi = VFTOMI(vfsp)) != NULL) {
5727c478bd9Sstevel@tonic-gate uint_t new_mi_llock;
5737c478bd9Sstevel@tonic-gate uint_t old_mi_llock;
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate new_mi_llock = (flags & NFSMNT_LLOCK) ? 1 : 0;
5767c478bd9Sstevel@tonic-gate old_mi_llock = (mi->mi_flags & MI_LLOCK) ? 1 : 0;
5777c478bd9Sstevel@tonic-gate if (old_mi_llock != new_mi_llock)
5787c478bd9Sstevel@tonic-gate return (EBUSY);
5797c478bd9Sstevel@tonic-gate }
5807c478bd9Sstevel@tonic-gate return (0);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate mutex_enter(&mvp->v_lock);
5847c478bd9Sstevel@tonic-gate if (!(uap->flags & MS_OVERLAY) &&
5857c478bd9Sstevel@tonic-gate (mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
5867c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock);
58739d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) {
58839d3e169Sevanl nfs3_free_args(args, fhandle);
58939d3e169Sevanl kmem_free(args, sizeof (*args));
59039d3e169Sevanl }
5917c478bd9Sstevel@tonic-gate return (EBUSY);
5927c478bd9Sstevel@tonic-gate }
5937c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock);
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate /* make sure things are zeroed for errout: */
5967c478bd9Sstevel@tonic-gate rtvp = NULL;
5977c478bd9Sstevel@tonic-gate mi = NULL;
5987c478bd9Sstevel@tonic-gate secdata = NULL;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate * A valid knetconfig structure is required.
6027c478bd9Sstevel@tonic-gate */
60339d3e169Sevanl if (!(flags & NFSMNT_KNCONF)) {
60439d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) {
60539d3e169Sevanl nfs3_free_args(args, fhandle);
60639d3e169Sevanl kmem_free(args, sizeof (*args));
60739d3e169Sevanl }
6087c478bd9Sstevel@tonic-gate return (EINVAL);
60939d3e169Sevanl }
61039d3e169Sevanl
61139d3e169Sevanl if ((strlen(args->knconf->knc_protofmly) >= KNC_STRSIZE) ||
612dcedb507SMarcel Telka (strlen(args->knconf->knc_proto) >= KNC_STRSIZE)) {
61339d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) {
61439d3e169Sevanl nfs3_free_args(args, fhandle);
61539d3e169Sevanl kmem_free(args, sizeof (*args));
61639d3e169Sevanl }
61739d3e169Sevanl return (EINVAL);
61839d3e169Sevanl }
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate * Allocate a servinfo struct.
6227c478bd9Sstevel@tonic-gate */
6237c478bd9Sstevel@tonic-gate svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
6247c478bd9Sstevel@tonic-gate mutex_init(&svp->sv_lock, NULL, MUTEX_DEFAULT, NULL);
6257c478bd9Sstevel@tonic-gate if (svp_tail) {
6267c478bd9Sstevel@tonic-gate svp_2ndlast = svp_tail;
6277c478bd9Sstevel@tonic-gate svp_tail->sv_next = svp;
6287c478bd9Sstevel@tonic-gate } else {
6297c478bd9Sstevel@tonic-gate svp_head = svp;
6307c478bd9Sstevel@tonic-gate svp_2ndlast = svp;
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate svp_tail = svp;
6347c478bd9Sstevel@tonic-gate
63539d3e169Sevanl svp->sv_knconf = args->knconf;
63639d3e169Sevanl args->knconf = NULL;
6377c478bd9Sstevel@tonic-gate
63839d3e169Sevanl if (args->addr == NULL || args->addr->buf == NULL) {
63939d3e169Sevanl error = EINVAL;
6407c478bd9Sstevel@tonic-gate goto errout;
6417c478bd9Sstevel@tonic-gate }
6427c478bd9Sstevel@tonic-gate
64339d3e169Sevanl svp->sv_addr.maxlen = args->addr->maxlen;
64439d3e169Sevanl svp->sv_addr.len = args->addr->len;
64539d3e169Sevanl svp->sv_addr.buf = args->addr->buf;
64639d3e169Sevanl args->addr->buf = NULL;
64739d3e169Sevanl
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate * Check the root fhandle length
6507c478bd9Sstevel@tonic-gate */
65139d3e169Sevanl ASSERT(fhandle);
65239d3e169Sevanl if (fhandle->fh_len > NFS3_FHSIZE || fhandle->fh_len == 0) {
6537c478bd9Sstevel@tonic-gate error = EINVAL;
6547c478bd9Sstevel@tonic-gate #ifdef DEBUG
6557c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
6567c478bd9Sstevel@tonic-gate "nfs3_mount: got an invalid fhandle. fh_len = %d",
65739d3e169Sevanl fhandle->fh_len);
65839d3e169Sevanl fhandle->fh_len = NFS_FHANDLE_LEN;
65939d3e169Sevanl nfs_printfhandle(fhandle);
6607c478bd9Sstevel@tonic-gate #endif
6617c478bd9Sstevel@tonic-gate goto errout;
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate
66439d3e169Sevanl bcopy(&fhandle->fh_buf, &svp->sv_fhandle.fh_buf, fhandle->fh_len);
66539d3e169Sevanl svp->sv_fhandle.fh_len = fhandle->fh_len;
66639d3e169Sevanl
6677c478bd9Sstevel@tonic-gate /*
6687c478bd9Sstevel@tonic-gate * Get server's hostname
6697c478bd9Sstevel@tonic-gate */
6707c478bd9Sstevel@tonic-gate if (flags & NFSMNT_HOSTNAME) {
67139d3e169Sevanl if (args->hostname == NULL) {
67239d3e169Sevanl error = EINVAL;
6737c478bd9Sstevel@tonic-gate goto errout;
67439d3e169Sevanl }
67539d3e169Sevanl svp->sv_hostnamelen = strlen(args->hostname) + 1;
67639d3e169Sevanl svp->sv_hostname = args->hostname;
67739d3e169Sevanl args->hostname = NULL;
6787c478bd9Sstevel@tonic-gate } else {
6797c478bd9Sstevel@tonic-gate char *p = "unknown-host";
68039d3e169Sevanl svp->sv_hostnamelen = strlen(p) + 1;
68139d3e169Sevanl svp->sv_hostname = kmem_zalloc(svp->sv_hostnamelen, KM_SLEEP);
68239d3e169Sevanl (void) strcpy(svp->sv_hostname, p);
6837c478bd9Sstevel@tonic-gate }
68439d3e169Sevanl
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate /*
6877c478bd9Sstevel@tonic-gate * RDMA MOUNT SUPPORT FOR NFS v3:
6887c478bd9Sstevel@tonic-gate * Establish, is it possible to use RDMA, if so overload the
6897c478bd9Sstevel@tonic-gate * knconf with rdma specific knconf and free the orignal.
6907c478bd9Sstevel@tonic-gate */
6917c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_TRYRDMA) || (flags & NFSMNT_DORDMA)) {
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate * Determine the addr type for RDMA, IPv4 or v6.
6947c478bd9Sstevel@tonic-gate */
6957c478bd9Sstevel@tonic-gate if (strcmp(svp->sv_knconf->knc_protofmly, NC_INET) == 0)
6967c478bd9Sstevel@tonic-gate addr_type = AF_INET;
6977c478bd9Sstevel@tonic-gate else if (strcmp(svp->sv_knconf->knc_protofmly, NC_INET6) == 0)
6987c478bd9Sstevel@tonic-gate addr_type = AF_INET6;
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate if (rdma_reachable(addr_type, &svp->sv_addr,
701dcedb507SMarcel Telka &rdma_knconf) == 0) {
7027c478bd9Sstevel@tonic-gate /*
7037c478bd9Sstevel@tonic-gate * If successful, hijack the orignal knconf and
7047c478bd9Sstevel@tonic-gate * replace with a new one, depending on the flags.
7057c478bd9Sstevel@tonic-gate */
7067c478bd9Sstevel@tonic-gate svp->sv_origknconf = svp->sv_knconf;
7077c478bd9Sstevel@tonic-gate svp->sv_knconf = rdma_knconf;
7087c478bd9Sstevel@tonic-gate knconf = rdma_knconf;
7097c478bd9Sstevel@tonic-gate } else {
7107c478bd9Sstevel@tonic-gate if (flags & NFSMNT_TRYRDMA) {
7117c478bd9Sstevel@tonic-gate #ifdef DEBUG
7127c478bd9Sstevel@tonic-gate if (rdma_debug)
7137c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
7147c478bd9Sstevel@tonic-gate "no RDMA onboard, revert\n");
7157c478bd9Sstevel@tonic-gate #endif
7167c478bd9Sstevel@tonic-gate }
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate if (flags & NFSMNT_DORDMA) {
7197c478bd9Sstevel@tonic-gate /*
7207c478bd9Sstevel@tonic-gate * If proto=rdma is specified and no RDMA
7217c478bd9Sstevel@tonic-gate * path to this server is avialable then
7227c478bd9Sstevel@tonic-gate * ditch this server.
7237c478bd9Sstevel@tonic-gate * This is not included in the mountable
7247c478bd9Sstevel@tonic-gate * server list or the replica list.
7257c478bd9Sstevel@tonic-gate * Check if more servers are specified;
7267c478bd9Sstevel@tonic-gate * Failover case, otherwise bail out of mount.
7277c478bd9Sstevel@tonic-gate */
728dcedb507SMarcel Telka if (args->nfs_args_ext == NFS_ARGS_EXTB &&
729dcedb507SMarcel Telka args->nfs_ext_u.nfs_extB.next != NULL) {
73039d3e169Sevanl data = (char *)
731dcedb507SMarcel Telka args->nfs_ext_u.nfs_extB.next;
7327c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY &&
7337c478bd9Sstevel@tonic-gate !(flags & NFSMNT_SOFT)) {
7347c478bd9Sstevel@tonic-gate if (svp_head->sv_next == NULL) {
7357c478bd9Sstevel@tonic-gate svp_tail = NULL;
7367c478bd9Sstevel@tonic-gate svp_2ndlast = NULL;
7377c478bd9Sstevel@tonic-gate sv_free(svp_head);
7387c478bd9Sstevel@tonic-gate goto more;
7397c478bd9Sstevel@tonic-gate } else {
7407c478bd9Sstevel@tonic-gate svp_tail = svp_2ndlast;
7417c478bd9Sstevel@tonic-gate svp_2ndlast->sv_next =
7427c478bd9Sstevel@tonic-gate NULL;
7437c478bd9Sstevel@tonic-gate sv_free(svp);
7447c478bd9Sstevel@tonic-gate goto more;
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate } else {
7487c478bd9Sstevel@tonic-gate /*
7497c478bd9Sstevel@tonic-gate * This is the last server specified
7507c478bd9Sstevel@tonic-gate * in the nfs_args list passed down
7517c478bd9Sstevel@tonic-gate * and its not rdma capable.
7527c478bd9Sstevel@tonic-gate */
7537c478bd9Sstevel@tonic-gate if (svp_head->sv_next == NULL) {
7547c478bd9Sstevel@tonic-gate /*
7557c478bd9Sstevel@tonic-gate * Is this the only one
7567c478bd9Sstevel@tonic-gate */
7577c478bd9Sstevel@tonic-gate error = EINVAL;
7587c478bd9Sstevel@tonic-gate #ifdef DEBUG
7597c478bd9Sstevel@tonic-gate if (rdma_debug)
7607c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(),
7617c478bd9Sstevel@tonic-gate CE_WARN,
7627c478bd9Sstevel@tonic-gate "No RDMA srv");
7637c478bd9Sstevel@tonic-gate #endif
7647c478bd9Sstevel@tonic-gate goto errout;
7657c478bd9Sstevel@tonic-gate } else {
7667c478bd9Sstevel@tonic-gate /*
7677c478bd9Sstevel@tonic-gate * There is list, since some
7687c478bd9Sstevel@tonic-gate * servers specified before
7697c478bd9Sstevel@tonic-gate * this passed all requirements
7707c478bd9Sstevel@tonic-gate */
7717c478bd9Sstevel@tonic-gate svp_tail = svp_2ndlast;
7727c478bd9Sstevel@tonic-gate svp_2ndlast->sv_next = NULL;
7737c478bd9Sstevel@tonic-gate sv_free(svp);
7747c478bd9Sstevel@tonic-gate goto proceed;
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate /*
7827c478bd9Sstevel@tonic-gate * Get the extention data which has the new security data structure.
7837c478bd9Sstevel@tonic-gate */
7847c478bd9Sstevel@tonic-gate if (flags & NFSMNT_NEWARGS) {
78539d3e169Sevanl switch (args->nfs_args_ext) {
7867c478bd9Sstevel@tonic-gate case NFS_ARGS_EXTA:
7877c478bd9Sstevel@tonic-gate case NFS_ARGS_EXTB:
7887c478bd9Sstevel@tonic-gate /*
7897c478bd9Sstevel@tonic-gate * Indicating the application is using the new
7907c478bd9Sstevel@tonic-gate * sec_data structure to pass in the security
7917c478bd9Sstevel@tonic-gate * data.
7927c478bd9Sstevel@tonic-gate */
79339d3e169Sevanl secdata = args->nfs_ext_u.nfs_extA.secdata;
79439d3e169Sevanl if (args->nfs_ext_u.nfs_extA.secdata == NULL) {
7957c478bd9Sstevel@tonic-gate error = EINVAL;
7967c478bd9Sstevel@tonic-gate } else {
79739d3e169Sevanl /*
79839d3e169Sevanl * Need to validate the flavor here if
79939d3e169Sevanl * sysspace, userspace was already
80039d3e169Sevanl * validate from the nfs_copyin function.
80139d3e169Sevanl */
80239d3e169Sevanl switch (secdata->rpcflavor) {
80339d3e169Sevanl case AUTH_NONE:
80439d3e169Sevanl case AUTH_UNIX:
80539d3e169Sevanl case AUTH_LOOPBACK:
80639d3e169Sevanl case AUTH_DES:
80739d3e169Sevanl case RPCSEC_GSS:
808dcedb507SMarcel Telka args->nfs_ext_u.nfs_extA.secdata = NULL;
80939d3e169Sevanl break;
81039d3e169Sevanl default:
81139d3e169Sevanl error = EINVAL;
81239d3e169Sevanl goto errout;
81339d3e169Sevanl }
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate break;
8167c478bd9Sstevel@tonic-gate
8177c478bd9Sstevel@tonic-gate default:
8187c478bd9Sstevel@tonic-gate error = EINVAL;
8197c478bd9Sstevel@tonic-gate break;
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate } else if (flags & NFSMNT_SECURE) {
8227c478bd9Sstevel@tonic-gate /*
8237c478bd9Sstevel@tonic-gate * Keep this for backward compatibility to support
8247c478bd9Sstevel@tonic-gate * NFSMNT_SECURE/NFSMNT_RPCTIMESYNC flags.
8257c478bd9Sstevel@tonic-gate */
82639d3e169Sevanl if (args->syncaddr == NULL || args->syncaddr->buf == NULL) {
8277c478bd9Sstevel@tonic-gate error = EINVAL;
82839d3e169Sevanl goto errout;
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate /*
8317c478bd9Sstevel@tonic-gate * Move security related data to the sec_data structure.
8327c478bd9Sstevel@tonic-gate */
83339d3e169Sevanl {
8347c478bd9Sstevel@tonic-gate dh_k4_clntdata_t *data;
8357c478bd9Sstevel@tonic-gate char *pf, *p;
8367c478bd9Sstevel@tonic-gate secdata = kmem_alloc(sizeof (*secdata), KM_SLEEP);
8377c478bd9Sstevel@tonic-gate if (flags & NFSMNT_RPCTIMESYNC)
8387c478bd9Sstevel@tonic-gate secdata->flags |= AUTH_F_RPCTIMESYNC;
8397c478bd9Sstevel@tonic-gate data = kmem_alloc(sizeof (*data), KM_SLEEP);
84039d3e169Sevanl bcopy(args->syncaddr, &data->syncaddr,
841dcedb507SMarcel Telka sizeof (*args->syncaddr));
8427c478bd9Sstevel@tonic-gate
8437c478bd9Sstevel@tonic-gate /*
8447c478bd9Sstevel@tonic-gate * duplicate the knconf information for the
8457c478bd9Sstevel@tonic-gate * new opaque data.
8467c478bd9Sstevel@tonic-gate */
8477c478bd9Sstevel@tonic-gate data->knconf = kmem_alloc(sizeof (*knconf), KM_SLEEP);
8487c478bd9Sstevel@tonic-gate *data->knconf = *knconf;
8497c478bd9Sstevel@tonic-gate pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
8507c478bd9Sstevel@tonic-gate p = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
8517c478bd9Sstevel@tonic-gate bcopy(knconf->knc_protofmly, pf, KNC_STRSIZE);
8527c478bd9Sstevel@tonic-gate bcopy(knconf->knc_proto, pf, KNC_STRSIZE);
8537c478bd9Sstevel@tonic-gate data->knconf->knc_protofmly = pf;
8547c478bd9Sstevel@tonic-gate data->knconf->knc_proto = p;
8557c478bd9Sstevel@tonic-gate
85639d3e169Sevanl nlen = strlen(args->hostname) + 1;
8577c478bd9Sstevel@tonic-gate /* move server netname to the sec_data structure */
8587c478bd9Sstevel@tonic-gate if (nlen != 0) {
8597c478bd9Sstevel@tonic-gate data->netname = kmem_alloc(nlen, KM_SLEEP);
86039d3e169Sevanl bcopy(args->hostname, data->netname, nlen);
86139d3e169Sevanl data->netnamelen = nlen;
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate secdata->secmod = secdata->rpcflavor = AUTH_DES;
8647c478bd9Sstevel@tonic-gate secdata->data = (caddr_t)data;
8657c478bd9Sstevel@tonic-gate }
86639d3e169Sevanl } else {
8677c478bd9Sstevel@tonic-gate secdata = kmem_alloc(sizeof (*secdata), KM_SLEEP);
8687c478bd9Sstevel@tonic-gate secdata->secmod = secdata->rpcflavor = AUTH_UNIX;
8697c478bd9Sstevel@tonic-gate secdata->data = NULL;
8707c478bd9Sstevel@tonic-gate }
87139d3e169Sevanl
8727c478bd9Sstevel@tonic-gate svp->sv_secdata = secdata;
8737c478bd9Sstevel@tonic-gate if (error)
8747c478bd9Sstevel@tonic-gate goto errout;
8757c478bd9Sstevel@tonic-gate
8767c478bd9Sstevel@tonic-gate /*
8777c478bd9Sstevel@tonic-gate * See bug 1180236.
8787c478bd9Sstevel@tonic-gate * If mount secure failed, we will fall back to AUTH_NONE
8797c478bd9Sstevel@tonic-gate * and try again. nfs3rootvp() will turn this back off.
8807c478bd9Sstevel@tonic-gate *
8817c478bd9Sstevel@tonic-gate * The NFS Version 3 mount uses the FSINFO and GETATTR
8827c478bd9Sstevel@tonic-gate * procedures. The server should not care if these procedures
8837c478bd9Sstevel@tonic-gate * have the proper security flavor, so if mount retries using
8847c478bd9Sstevel@tonic-gate * AUTH_NONE that does not require a credential setup for root
8857c478bd9Sstevel@tonic-gate * then the automounter would work without requiring root to be
8867c478bd9Sstevel@tonic-gate * keylogged into AUTH_DES.
8877c478bd9Sstevel@tonic-gate */
8887c478bd9Sstevel@tonic-gate if (secdata->rpcflavor != AUTH_UNIX &&
8897c478bd9Sstevel@tonic-gate secdata->rpcflavor != AUTH_LOOPBACK)
8907c478bd9Sstevel@tonic-gate secdata->flags |= AUTH_F_TRYNONE;
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate /*
8937c478bd9Sstevel@tonic-gate * Failover support:
8947c478bd9Sstevel@tonic-gate *
8957c478bd9Sstevel@tonic-gate * We may have a linked list of nfs_args structures,
8967c478bd9Sstevel@tonic-gate * which means the user is looking for failover. If
8977c478bd9Sstevel@tonic-gate * the mount is either not "read-only" or "soft",
8987c478bd9Sstevel@tonic-gate * we want to bail out with EINVAL.
8997c478bd9Sstevel@tonic-gate */
90039d3e169Sevanl if (args->nfs_args_ext == NFS_ARGS_EXTB &&
90139d3e169Sevanl args->nfs_ext_u.nfs_extB.next != NULL) {
9027c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY && !(flags & NFSMNT_SOFT)) {
90339d3e169Sevanl data = (char *)args->nfs_ext_u.nfs_extB.next;
9047c478bd9Sstevel@tonic-gate goto more;
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate error = EINVAL;
9077c478bd9Sstevel@tonic-gate goto errout;
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate
9107c478bd9Sstevel@tonic-gate /*
9117c478bd9Sstevel@tonic-gate * Determine the zone we're being mounted into.
9127c478bd9Sstevel@tonic-gate */
91345916cd2Sjpk zone_hold(mntzone = zone); /* start with this assumption */
9147c478bd9Sstevel@tonic-gate if (getzoneid() == GLOBAL_ZONEID) {
91545916cd2Sjpk zone_rele(mntzone);
9167c478bd9Sstevel@tonic-gate mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt));
9177c478bd9Sstevel@tonic-gate ASSERT(mntzone != NULL);
9187c478bd9Sstevel@tonic-gate if (mntzone != zone) {
9197c478bd9Sstevel@tonic-gate error = EBUSY;
9207c478bd9Sstevel@tonic-gate goto errout;
9217c478bd9Sstevel@tonic-gate }
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate
92445916cd2Sjpk if (is_system_labeled()) {
92545916cd2Sjpk error = nfs_mount_label_policy(vfsp, &svp->sv_addr,
92645916cd2Sjpk svp->sv_knconf, cr);
92745916cd2Sjpk
92845916cd2Sjpk if (error > 0)
92945916cd2Sjpk goto errout;
93045916cd2Sjpk
93145916cd2Sjpk if (error == -1) {
93245916cd2Sjpk /* change mount to read-only to prevent write-down */
93345916cd2Sjpk vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
93445916cd2Sjpk }
93545916cd2Sjpk }
93645916cd2Sjpk
9377c478bd9Sstevel@tonic-gate /*
9387c478bd9Sstevel@tonic-gate * Stop the mount from going any further if the zone is going away.
9397c478bd9Sstevel@tonic-gate */
94045916cd2Sjpk if (zone_status_get(mntzone) >= ZONE_IS_SHUTTING_DOWN) {
9417c478bd9Sstevel@tonic-gate error = EBUSY;
9427c478bd9Sstevel@tonic-gate goto errout;
9437c478bd9Sstevel@tonic-gate }
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate /*
9467c478bd9Sstevel@tonic-gate * Get root vnode.
9477c478bd9Sstevel@tonic-gate */
9487c478bd9Sstevel@tonic-gate proceed:
94945916cd2Sjpk error = nfs3rootvp(&rtvp, vfsp, svp_head, flags, cr, mntzone);
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate if (error)
9527c478bd9Sstevel@tonic-gate goto errout;
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate /*
9557c478bd9Sstevel@tonic-gate * Set option fields in the mount info record
9567c478bd9Sstevel@tonic-gate */
9577c478bd9Sstevel@tonic-gate mi = VTOMI(rtvp);
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gate if (svp_head->sv_next)
9607c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_LLOCK;
9617c478bd9Sstevel@tonic-gate
96239d3e169Sevanl error = nfs_setopts(rtvp, DATAMODEL_NATIVE, args);
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate errout:
965dcedb507SMarcel Telka if (rtvp != NULL) {
966dcedb507SMarcel Telka if (error) {
9677c478bd9Sstevel@tonic-gate rp = VTOR(rtvp);
9687c478bd9Sstevel@tonic-gate if (rp->r_flags & RHASHED)
9697c478bd9Sstevel@tonic-gate rp_rmhash(rp);
9707c478bd9Sstevel@tonic-gate }
971dcedb507SMarcel Telka VN_RELE(rtvp);
972dcedb507SMarcel Telka }
973dcedb507SMarcel Telka
974dcedb507SMarcel Telka if (error) {
9757c478bd9Sstevel@tonic-gate sv_free(svp_head);
9767c478bd9Sstevel@tonic-gate if (mi != NULL) {
9777c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp);
9787c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp);
9797c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) {
9807c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats);
9817c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL;
9827c478bd9Sstevel@tonic-gate }
9837c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) {
9847c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats);
9857c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL;
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate nfs_free_mi(mi);
9887c478bd9Sstevel@tonic-gate }
9897c478bd9Sstevel@tonic-gate }
9907c478bd9Sstevel@tonic-gate
99139d3e169Sevanl
99239d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) {
99339d3e169Sevanl nfs3_free_args(args, fhandle);
99439d3e169Sevanl kmem_free(args, sizeof (*args));
99539d3e169Sevanl }
99639d3e169Sevanl
99745916cd2Sjpk if (mntzone != NULL)
99845916cd2Sjpk zone_rele(mntzone);
99945916cd2Sjpk
10007c478bd9Sstevel@tonic-gate return (error);
1001dcedb507SMarcel Telka }
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate static int nfs3_dynamic = 0; /* global variable to enable dynamic retrans. */
10047c478bd9Sstevel@tonic-gate static ushort_t nfs3_max_threads = 8; /* max number of active async threads */
1005c242f9a0Schunli zhang - Sun Microsystems - Irvine United States uint_t nfs3_bsize = 32 * 1024; /* client `block' size */
10067c478bd9Sstevel@tonic-gate static uint_t nfs3_async_clusters = 1; /* # of reqs from each async queue */
10077c478bd9Sstevel@tonic-gate static uint_t nfs3_cots_timeo = NFS_COTS_TIMEO;
10087c478bd9Sstevel@tonic-gate
10097c478bd9Sstevel@tonic-gate static int
nfs3rootvp(vnode_t ** rtvpp,vfs_t * vfsp,struct servinfo * svp,int flags,cred_t * cr,zone_t * zone)10107c478bd9Sstevel@tonic-gate nfs3rootvp(vnode_t **rtvpp, vfs_t *vfsp, struct servinfo *svp,
1011*e010bda9SMarcel Telka int flags, cred_t *cr, zone_t *zone)
10127c478bd9Sstevel@tonic-gate {
10137c478bd9Sstevel@tonic-gate vnode_t *rtvp;
10147c478bd9Sstevel@tonic-gate mntinfo_t *mi;
10157c478bd9Sstevel@tonic-gate dev_t nfs_dev;
10167c478bd9Sstevel@tonic-gate struct vattr va;
10177c478bd9Sstevel@tonic-gate struct FSINFO3args args;
10187c478bd9Sstevel@tonic-gate struct FSINFO3res res;
10197c478bd9Sstevel@tonic-gate int error;
10207c478bd9Sstevel@tonic-gate int douprintf;
10217c478bd9Sstevel@tonic-gate rnode_t *rp;
10227c478bd9Sstevel@tonic-gate int i;
10237c478bd9Sstevel@tonic-gate uint_t max_transfer_size;
10247c478bd9Sstevel@tonic-gate struct nfs_stats *nfsstatsp;
10257c478bd9Sstevel@tonic-gate cred_t *lcr = NULL, *tcr = cr;
10267c478bd9Sstevel@tonic-gate
1027108322fbScarlsonj nfsstatsp = zone_getspecific(nfsstat_zone_key, nfs_zone());
10287c478bd9Sstevel@tonic-gate ASSERT(nfsstatsp != NULL);
10297c478bd9Sstevel@tonic-gate
1030108322fbScarlsonj ASSERT(nfs_zone() == zone);
10317c478bd9Sstevel@tonic-gate /*
10327c478bd9Sstevel@tonic-gate * Create a mount record and link it to the vfs struct.
10337c478bd9Sstevel@tonic-gate */
10347c478bd9Sstevel@tonic-gate mi = kmem_zalloc(sizeof (*mi), KM_SLEEP);
10357c478bd9Sstevel@tonic-gate mutex_init(&mi->mi_lock, NULL, MUTEX_DEFAULT, NULL);
1036e8dc3b7dSvv mutex_init(&mi->mi_remap_lock, NULL, MUTEX_DEFAULT, NULL);
10377c478bd9Sstevel@tonic-gate mi->mi_flags = MI_ACL | MI_EXTATTR;
10387c478bd9Sstevel@tonic-gate if (!(flags & NFSMNT_SOFT))
10397c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_HARD;
10407c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_SEMISOFT))
10417c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_SEMISOFT;
10427c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_NOPRINT))
10437c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_NOPRINT;
10447c478bd9Sstevel@tonic-gate if (flags & NFSMNT_INT)
10457c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_INT;
10467c478bd9Sstevel@tonic-gate mi->mi_retrans = NFS_RETRIES;
10477c478bd9Sstevel@tonic-gate if (svp->sv_knconf->knc_semantics == NC_TPI_COTS_ORD ||
10487c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_semantics == NC_TPI_COTS)
10497c478bd9Sstevel@tonic-gate mi->mi_timeo = nfs3_cots_timeo;
10507c478bd9Sstevel@tonic-gate else
10517c478bd9Sstevel@tonic-gate mi->mi_timeo = NFS_TIMEO;
10527c478bd9Sstevel@tonic-gate mi->mi_prog = NFS_PROGRAM;
10537c478bd9Sstevel@tonic-gate mi->mi_vers = NFS_V3;
10547c478bd9Sstevel@tonic-gate mi->mi_rfsnames = rfsnames_v3;
10557c478bd9Sstevel@tonic-gate mi->mi_reqs = nfsstatsp->nfs_stats_v3.rfsreqcnt_ptr;
10567c478bd9Sstevel@tonic-gate mi->mi_call_type = call_type_v3;
10577c478bd9Sstevel@tonic-gate mi->mi_ss_call_type = ss_call_type_v3;
10587c478bd9Sstevel@tonic-gate mi->mi_timer_type = timer_type_v3;
10597c478bd9Sstevel@tonic-gate mi->mi_aclnames = aclnames_v3;
10607c478bd9Sstevel@tonic-gate mi->mi_aclreqs = nfsstatsp->nfs_stats_v3.aclreqcnt_ptr;
10617c478bd9Sstevel@tonic-gate mi->mi_acl_call_type = acl_call_type_v3;
10627c478bd9Sstevel@tonic-gate mi->mi_acl_ss_call_type = acl_ss_call_type_v3;
10637c478bd9Sstevel@tonic-gate mi->mi_acl_timer_type = acl_timer_type_v3;
10647c478bd9Sstevel@tonic-gate cv_init(&mi->mi_failover_cv, NULL, CV_DEFAULT, NULL);
10657c478bd9Sstevel@tonic-gate mi->mi_servers = svp;
10667c478bd9Sstevel@tonic-gate mi->mi_curr_serv = svp;
10677c478bd9Sstevel@tonic-gate mi->mi_acregmin = SEC2HR(ACREGMIN);
10687c478bd9Sstevel@tonic-gate mi->mi_acregmax = SEC2HR(ACREGMAX);
10697c478bd9Sstevel@tonic-gate mi->mi_acdirmin = SEC2HR(ACDIRMIN);
10707c478bd9Sstevel@tonic-gate mi->mi_acdirmax = SEC2HR(ACDIRMAX);
10717c478bd9Sstevel@tonic-gate
10727c478bd9Sstevel@tonic-gate if (nfs3_dynamic)
10737c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_DYNAMIC;
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate if (flags & NFSMNT_DIRECTIO)
10767c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_DIRECTIO;
10777c478bd9Sstevel@tonic-gate
1078*e010bda9SMarcel Telka mutex_init(&mi->mi_rnodes_lock, NULL, MUTEX_DEFAULT, NULL);
1079*e010bda9SMarcel Telka list_create(&mi->mi_rnodes, sizeof (rnode_t),
1080*e010bda9SMarcel Telka offsetof(rnode_t, r_mi_link));
1081*e010bda9SMarcel Telka
10827c478bd9Sstevel@tonic-gate /*
10837c478bd9Sstevel@tonic-gate * Make a vfs struct for nfs. We do this here instead of below
10847c478bd9Sstevel@tonic-gate * because rtvp needs a vfs before we can do a getattr on it.
10857c478bd9Sstevel@tonic-gate *
10867c478bd9Sstevel@tonic-gate * Assign a unique device id to the mount
10877c478bd9Sstevel@tonic-gate */
10887c478bd9Sstevel@tonic-gate mutex_enter(&nfs_minor_lock);
10897c478bd9Sstevel@tonic-gate do {
10907c478bd9Sstevel@tonic-gate nfs_minor = (nfs_minor + 1) & MAXMIN32;
10917c478bd9Sstevel@tonic-gate nfs_dev = makedevice(nfs_major, nfs_minor);
10927c478bd9Sstevel@tonic-gate } while (vfs_devismounted(nfs_dev));
10937c478bd9Sstevel@tonic-gate mutex_exit(&nfs_minor_lock);
10947c478bd9Sstevel@tonic-gate
10957c478bd9Sstevel@tonic-gate vfsp->vfs_dev = nfs_dev;
10967c478bd9Sstevel@tonic-gate vfs_make_fsid(&vfsp->vfs_fsid, nfs_dev, nfs3fstyp);
10977c478bd9Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)mi;
10987c478bd9Sstevel@tonic-gate vfsp->vfs_fstype = nfsfstyp;
10997c478bd9Sstevel@tonic-gate
11007c478bd9Sstevel@tonic-gate /*
11017c478bd9Sstevel@tonic-gate * Verify that nfs3_bsize tuneable is set to an
11027c478bd9Sstevel@tonic-gate * acceptable value. It be a multiple of PAGESIZE or
11037c478bd9Sstevel@tonic-gate * file corruption can occur.
11047c478bd9Sstevel@tonic-gate */
11057c478bd9Sstevel@tonic-gate if (nfs3_bsize & PAGEOFFSET)
11067c478bd9Sstevel@tonic-gate nfs3_bsize &= PAGEMASK;
11077c478bd9Sstevel@tonic-gate if (nfs3_bsize < PAGESIZE)
11087c478bd9Sstevel@tonic-gate nfs3_bsize = PAGESIZE;
11097c478bd9Sstevel@tonic-gate vfsp->vfs_bsize = nfs3_bsize;
11107c478bd9Sstevel@tonic-gate
11117c478bd9Sstevel@tonic-gate /*
11127c478bd9Sstevel@tonic-gate * Initialize fields used to support async putpage operations.
11137c478bd9Sstevel@tonic-gate */
11147c478bd9Sstevel@tonic-gate for (i = 0; i < NFS_ASYNC_TYPES; i++)
11157c478bd9Sstevel@tonic-gate mi->mi_async_clusters[i] = nfs3_async_clusters;
11167c478bd9Sstevel@tonic-gate mi->mi_async_init_clusters = nfs3_async_clusters;
11170776f5e6SVallish Vaidyeshwara mi->mi_async_curr[NFS_ASYNC_QUEUE] =
11180776f5e6SVallish Vaidyeshwara mi->mi_async_curr[NFS_ASYNC_PGOPS_QUEUE] = &mi->mi_async_reqs[0];
11197c478bd9Sstevel@tonic-gate mi->mi_max_threads = nfs3_max_threads;
11207c478bd9Sstevel@tonic-gate mutex_init(&mi->mi_async_lock, NULL, MUTEX_DEFAULT, NULL);
11217c478bd9Sstevel@tonic-gate cv_init(&mi->mi_async_reqs_cv, NULL, CV_DEFAULT, NULL);
11220776f5e6SVallish Vaidyeshwara cv_init(&mi->mi_async_work_cv[NFS_ASYNC_QUEUE], NULL, CV_DEFAULT, NULL);
11230776f5e6SVallish Vaidyeshwara cv_init(&mi->mi_async_work_cv[NFS_ASYNC_PGOPS_QUEUE], NULL,
11240776f5e6SVallish Vaidyeshwara CV_DEFAULT, NULL);
11257c478bd9Sstevel@tonic-gate cv_init(&mi->mi_async_cv, NULL, CV_DEFAULT, NULL);
11267c478bd9Sstevel@tonic-gate
11277c478bd9Sstevel@tonic-gate mi->mi_vfsp = vfsp;
1128a19609f8Sjv mi->mi_zone = zone;
1129a19609f8Sjv zone_init_ref(&mi->mi_zone_ref);
1130a19609f8Sjv zone_hold_ref(zone, &mi->mi_zone_ref, ZONE_REF_NFS);
11317c478bd9Sstevel@tonic-gate nfs_mi_zonelist_add(mi);
11327c478bd9Sstevel@tonic-gate
11337c478bd9Sstevel@tonic-gate /*
11347c478bd9Sstevel@tonic-gate * Make the root vnode, use it to get attributes,
11357c478bd9Sstevel@tonic-gate * then remake it with the attributes.
11367c478bd9Sstevel@tonic-gate */
11377c478bd9Sstevel@tonic-gate rtvp = makenfs3node((nfs_fh3 *)&svp->sv_fhandle,
11387c478bd9Sstevel@tonic-gate NULL, vfsp, gethrtime(), cr, NULL, NULL);
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate /*
11417c478bd9Sstevel@tonic-gate * Make the FSINFO calls, primarily at this point to
11427c478bd9Sstevel@tonic-gate * determine the transfer size. For client failover,
11437c478bd9Sstevel@tonic-gate * we'll want this to be the minimum bid from any
11447c478bd9Sstevel@tonic-gate * server, so that we don't overrun stated limits.
11457c478bd9Sstevel@tonic-gate *
11467c478bd9Sstevel@tonic-gate * While we're looping, we'll turn off AUTH_F_TRYNONE,
11477c478bd9Sstevel@tonic-gate * which is only for the mount operation.
11487c478bd9Sstevel@tonic-gate */
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate mi->mi_tsize = nfs3_tsize(svp->sv_knconf);
11517c478bd9Sstevel@tonic-gate mi->mi_stsize = mi->mi_tsize;
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate mi->mi_curread = nfs3_bsize;
11547c478bd9Sstevel@tonic-gate mi->mi_curwrite = mi->mi_curread;
11557c478bd9Sstevel@tonic-gate
11567c478bd9Sstevel@tonic-gate /*
11577c478bd9Sstevel@tonic-gate * If the uid is set then set the creds for secure mounts
11587c478bd9Sstevel@tonic-gate * by proxy processes such as automountd.
11597c478bd9Sstevel@tonic-gate */
11607c478bd9Sstevel@tonic-gate if (svp->sv_secdata->uid != 0 &&
11617c478bd9Sstevel@tonic-gate svp->sv_secdata->rpcflavor == RPCSEC_GSS) {
11627c478bd9Sstevel@tonic-gate lcr = crdup(cr);
11637c478bd9Sstevel@tonic-gate (void) crsetugid(lcr, svp->sv_secdata->uid, crgetgid(cr));
11647c478bd9Sstevel@tonic-gate tcr = lcr;
11657c478bd9Sstevel@tonic-gate }
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate for (svp = mi->mi_servers; svp != NULL; svp = svp->sv_next) {
11687c478bd9Sstevel@tonic-gate douprintf = 1;
11697c478bd9Sstevel@tonic-gate mi->mi_curr_serv = svp;
11707c478bd9Sstevel@tonic-gate max_transfer_size = nfs3_tsize(svp->sv_knconf);
11717c478bd9Sstevel@tonic-gate mi->mi_tsize = MIN(max_transfer_size, mi->mi_tsize);
11727c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(max_transfer_size, mi->mi_stsize);
11737c478bd9Sstevel@tonic-gate mi->mi_curread = MIN(max_transfer_size, mi->mi_curread);
11747c478bd9Sstevel@tonic-gate mi->mi_curwrite = MIN(max_transfer_size, mi->mi_curwrite);
11757c478bd9Sstevel@tonic-gate args.fsroot = *(nfs_fh3 *)&svp->sv_fhandle;
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate error = rfs3call(mi, NFSPROC3_FSINFO,
11787c478bd9Sstevel@tonic-gate xdr_nfs_fh3, (caddr_t)&args,
11797c478bd9Sstevel@tonic-gate xdr_FSINFO3res, (caddr_t)&res, tcr,
11807c478bd9Sstevel@tonic-gate &douprintf, &res.status, 0, NULL);
11817c478bd9Sstevel@tonic-gate if (error)
11827c478bd9Sstevel@tonic-gate goto bad;
11837c478bd9Sstevel@tonic-gate error = geterrno3(res.status);
11847c478bd9Sstevel@tonic-gate if (error)
11857c478bd9Sstevel@tonic-gate goto bad;
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate /* get type of root node */
11887c478bd9Sstevel@tonic-gate if (res.resok.obj_attributes.attributes) {
11897c478bd9Sstevel@tonic-gate if (res.resok.obj_attributes.attr.type < NF3REG ||
11907c478bd9Sstevel@tonic-gate res.resok.obj_attributes.attr.type > NF3FIFO) {
11917c478bd9Sstevel@tonic-gate #ifdef DEBUG
11927c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
11937c478bd9Sstevel@tonic-gate "NFS3 server %s returned a bad file type for root",
11947c478bd9Sstevel@tonic-gate svp->sv_hostname);
11957c478bd9Sstevel@tonic-gate #else
11967c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
11977c478bd9Sstevel@tonic-gate "NFS server %s returned a bad file type for root",
11987c478bd9Sstevel@tonic-gate svp->sv_hostname);
11997c478bd9Sstevel@tonic-gate #endif
12007c478bd9Sstevel@tonic-gate error = EINVAL;
12017c478bd9Sstevel@tonic-gate goto bad;
12027c478bd9Sstevel@tonic-gate } else {
1203dcedb507SMarcel Telka if (rtvp->v_type != VNON && rtvp->v_type !=
1204dcedb507SMarcel Telka nf3_to_vt[res.resok.obj_attributes.attr.
1205dcedb507SMarcel Telka type]) {
12067c478bd9Sstevel@tonic-gate #ifdef DEBUG
12077c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12087c478bd9Sstevel@tonic-gate "NFS3 server %s returned a different file type for root",
12097c478bd9Sstevel@tonic-gate svp->sv_hostname);
12107c478bd9Sstevel@tonic-gate #else
12117c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12127c478bd9Sstevel@tonic-gate "NFS server %s returned a different file type for root",
12137c478bd9Sstevel@tonic-gate svp->sv_hostname);
12147c478bd9Sstevel@tonic-gate #endif
12157c478bd9Sstevel@tonic-gate error = EINVAL;
12167c478bd9Sstevel@tonic-gate goto bad;
12177c478bd9Sstevel@tonic-gate }
12187c478bd9Sstevel@tonic-gate rtvp->v_type =
1219dcedb507SMarcel Telka nf3_to_vt[res.resok.obj_attributes.attr.
1220dcedb507SMarcel Telka type];
12217c478bd9Sstevel@tonic-gate }
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate
12247c478bd9Sstevel@tonic-gate if (res.resok.rtmax != 0) {
12257c478bd9Sstevel@tonic-gate mi->mi_tsize = MIN(res.resok.rtmax, mi->mi_tsize);
12267c478bd9Sstevel@tonic-gate if (res.resok.rtpref != 0) {
12277c478bd9Sstevel@tonic-gate mi->mi_curread = MIN(res.resok.rtpref,
1228dcedb507SMarcel Telka mi->mi_curread);
12297c478bd9Sstevel@tonic-gate } else {
12307c478bd9Sstevel@tonic-gate mi->mi_curread = MIN(res.resok.rtmax,
1231dcedb507SMarcel Telka mi->mi_curread);
12327c478bd9Sstevel@tonic-gate }
12337c478bd9Sstevel@tonic-gate } else if (res.resok.rtpref != 0) {
12347c478bd9Sstevel@tonic-gate mi->mi_tsize = MIN(res.resok.rtpref, mi->mi_tsize);
12357c478bd9Sstevel@tonic-gate mi->mi_curread = MIN(res.resok.rtpref, mi->mi_curread);
12367c478bd9Sstevel@tonic-gate } else {
12377c478bd9Sstevel@tonic-gate #ifdef DEBUG
12387c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12397c478bd9Sstevel@tonic-gate "NFS3 server %s returned 0 for read transfer sizes",
12407c478bd9Sstevel@tonic-gate svp->sv_hostname);
12417c478bd9Sstevel@tonic-gate #else
12427c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12437c478bd9Sstevel@tonic-gate "NFS server %s returned 0 for read transfer sizes",
12447c478bd9Sstevel@tonic-gate svp->sv_hostname);
12457c478bd9Sstevel@tonic-gate #endif
12467c478bd9Sstevel@tonic-gate error = EIO;
12477c478bd9Sstevel@tonic-gate goto bad;
12487c478bd9Sstevel@tonic-gate }
12497c478bd9Sstevel@tonic-gate if (res.resok.wtmax != 0) {
12507c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(res.resok.wtmax, mi->mi_stsize);
12517c478bd9Sstevel@tonic-gate if (res.resok.wtpref != 0) {
12527c478bd9Sstevel@tonic-gate mi->mi_curwrite = MIN(res.resok.wtpref,
1253dcedb507SMarcel Telka mi->mi_curwrite);
12547c478bd9Sstevel@tonic-gate } else {
12557c478bd9Sstevel@tonic-gate mi->mi_curwrite = MIN(res.resok.wtmax,
1256dcedb507SMarcel Telka mi->mi_curwrite);
12577c478bd9Sstevel@tonic-gate }
12587c478bd9Sstevel@tonic-gate } else if (res.resok.wtpref != 0) {
12597c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(res.resok.wtpref, mi->mi_stsize);
12607c478bd9Sstevel@tonic-gate mi->mi_curwrite = MIN(res.resok.wtpref,
1261dcedb507SMarcel Telka mi->mi_curwrite);
12627c478bd9Sstevel@tonic-gate } else {
12637c478bd9Sstevel@tonic-gate #ifdef DEBUG
12647c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12657c478bd9Sstevel@tonic-gate "NFS3 server %s returned 0 for write transfer sizes",
12667c478bd9Sstevel@tonic-gate svp->sv_hostname);
12677c478bd9Sstevel@tonic-gate #else
12687c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN,
12697c478bd9Sstevel@tonic-gate "NFS server %s returned 0 for write transfer sizes",
12707c478bd9Sstevel@tonic-gate svp->sv_hostname);
12717c478bd9Sstevel@tonic-gate #endif
12727c478bd9Sstevel@tonic-gate error = EIO;
12737c478bd9Sstevel@tonic-gate goto bad;
12747c478bd9Sstevel@tonic-gate }
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gate /*
12777c478bd9Sstevel@tonic-gate * These signal the ability of the server to create
12787c478bd9Sstevel@tonic-gate * hard links and symbolic links, so they really
12797c478bd9Sstevel@tonic-gate * aren't relevant if there is more than one server.
12807c478bd9Sstevel@tonic-gate * We'll set them here, though it probably looks odd.
12817c478bd9Sstevel@tonic-gate */
12827c478bd9Sstevel@tonic-gate if (res.resok.properties & FSF3_LINK)
12837c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_LINK;
12847c478bd9Sstevel@tonic-gate if (res.resok.properties & FSF3_SYMLINK)
12857c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_SYMLINK;
12867c478bd9Sstevel@tonic-gate
12877c478bd9Sstevel@tonic-gate /* Pick up smallest non-zero maxfilesize value */
12887c478bd9Sstevel@tonic-gate if (res.resok.maxfilesize) {
12897c478bd9Sstevel@tonic-gate if (mi->mi_maxfilesize) {
12907c478bd9Sstevel@tonic-gate mi->mi_maxfilesize = MIN(mi->mi_maxfilesize,
1291dcedb507SMarcel Telka res.resok.maxfilesize);
12927c478bd9Sstevel@tonic-gate } else
12937c478bd9Sstevel@tonic-gate mi->mi_maxfilesize = res.resok.maxfilesize;
12947c478bd9Sstevel@tonic-gate }
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gate /*
12977c478bd9Sstevel@tonic-gate * AUTH_F_TRYNONE is only for the mount operation,
12987c478bd9Sstevel@tonic-gate * so turn it back off.
12997c478bd9Sstevel@tonic-gate */
13007c478bd9Sstevel@tonic-gate svp->sv_secdata->flags &= ~AUTH_F_TRYNONE;
13017c478bd9Sstevel@tonic-gate }
13027c478bd9Sstevel@tonic-gate mi->mi_curr_serv = mi->mi_servers;
13037c478bd9Sstevel@tonic-gate
13047c478bd9Sstevel@tonic-gate /*
13057c478bd9Sstevel@tonic-gate * Start the thread responsible for handling async worker threads.
13067c478bd9Sstevel@tonic-gate */
13077c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); /* add reference for thread */
13087c478bd9Sstevel@tonic-gate mi->mi_manager_thread = zthread_create(NULL, 0, nfs_async_manager,
1309dcedb507SMarcel Telka vfsp, 0, minclsyspri);
13107c478bd9Sstevel@tonic-gate ASSERT(mi->mi_manager_thread != NULL);
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate /*
13137c478bd9Sstevel@tonic-gate * Initialize kstats
13147c478bd9Sstevel@tonic-gate */
13157c478bd9Sstevel@tonic-gate nfs_mnt_kstat_init(vfsp);
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate /* If we didn't get a type, get one now */
13187c478bd9Sstevel@tonic-gate if (rtvp->v_type == VNON) {
13197c478bd9Sstevel@tonic-gate va.va_mask = AT_ALL;
13207c478bd9Sstevel@tonic-gate
13217c478bd9Sstevel@tonic-gate error = nfs3getattr(rtvp, &va, tcr);
13227c478bd9Sstevel@tonic-gate if (error)
13237c478bd9Sstevel@tonic-gate goto bad;
13247c478bd9Sstevel@tonic-gate rtvp->v_type = va.va_type;
13257c478bd9Sstevel@tonic-gate }
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate mi->mi_type = rtvp->v_type;
13287c478bd9Sstevel@tonic-gate
13297c478bd9Sstevel@tonic-gate *rtvpp = rtvp;
13307c478bd9Sstevel@tonic-gate if (lcr != NULL)
13317c478bd9Sstevel@tonic-gate crfree(lcr);
13327c478bd9Sstevel@tonic-gate
13337c478bd9Sstevel@tonic-gate return (0);
13347c478bd9Sstevel@tonic-gate bad:
13357c478bd9Sstevel@tonic-gate /*
13367c478bd9Sstevel@tonic-gate * An error occurred somewhere, need to clean up...
13377c478bd9Sstevel@tonic-gate * We need to release our reference to the root vnode and
13387c478bd9Sstevel@tonic-gate * destroy the mntinfo struct that we just created.
13397c478bd9Sstevel@tonic-gate */
13407c478bd9Sstevel@tonic-gate if (lcr != NULL)
13417c478bd9Sstevel@tonic-gate crfree(lcr);
13427c478bd9Sstevel@tonic-gate rp = VTOR(rtvp);
13437c478bd9Sstevel@tonic-gate if (rp->r_flags & RHASHED)
13447c478bd9Sstevel@tonic-gate rp_rmhash(rp);
13457c478bd9Sstevel@tonic-gate VN_RELE(rtvp);
13467c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp);
13477c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp);
13487c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) {
13497c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats);
13507c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL;
13517c478bd9Sstevel@tonic-gate }
13527c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) {
13537c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats);
13547c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL;
13557c478bd9Sstevel@tonic-gate }
13567c478bd9Sstevel@tonic-gate nfs_free_mi(mi);
13577c478bd9Sstevel@tonic-gate *rtvpp = NULL;
13587c478bd9Sstevel@tonic-gate return (error);
13597c478bd9Sstevel@tonic-gate }
13607c478bd9Sstevel@tonic-gate
13617c478bd9Sstevel@tonic-gate /*
13627c478bd9Sstevel@tonic-gate * vfs operations
13637c478bd9Sstevel@tonic-gate */
13647c478bd9Sstevel@tonic-gate static int
nfs3_unmount(vfs_t * vfsp,int flag,cred_t * cr)13657c478bd9Sstevel@tonic-gate nfs3_unmount(vfs_t *vfsp, int flag, cred_t *cr)
13667c478bd9Sstevel@tonic-gate {
13677c478bd9Sstevel@tonic-gate mntinfo_t *mi;
13687c478bd9Sstevel@tonic-gate ushort_t omax;
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0)
13717c478bd9Sstevel@tonic-gate return (EPERM);
13727c478bd9Sstevel@tonic-gate
13737c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp);
13747c478bd9Sstevel@tonic-gate if (flag & MS_FORCE) {
1375423be36cSmaheshvs
13767c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_UNMOUNTED;
1377423be36cSmaheshvs
1378423be36cSmaheshvs /*
1379423be36cSmaheshvs * We are about to stop the async manager.
1380423be36cSmaheshvs * Let every one know not to schedule any
1381423be36cSmaheshvs * more async requests
1382423be36cSmaheshvs */
1383423be36cSmaheshvs mutex_enter(&mi->mi_async_lock);
1384423be36cSmaheshvs mi->mi_max_threads = 0;
13850776f5e6SVallish Vaidyeshwara NFS_WAKEALL_ASYNC_WORKERS(mi->mi_async_work_cv);
1386423be36cSmaheshvs mutex_exit(&mi->mi_async_lock);
1387423be36cSmaheshvs
13887c478bd9Sstevel@tonic-gate /*
13897c478bd9Sstevel@tonic-gate * We need to stop the manager thread explicitly; the worker
13907c478bd9Sstevel@tonic-gate * threads can time out and exit on their own.
13917c478bd9Sstevel@tonic-gate */
13927c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp);
13937c478bd9Sstevel@tonic-gate destroy_rtable(vfsp, cr);
13947c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) {
13957c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats);
13967c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL;
13977c478bd9Sstevel@tonic-gate }
13987c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) {
13997c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats);
14007c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL;
14017c478bd9Sstevel@tonic-gate }
14027c478bd9Sstevel@tonic-gate return (0);
14037c478bd9Sstevel@tonic-gate }
14047c478bd9Sstevel@tonic-gate /*
14057c478bd9Sstevel@tonic-gate * Wait until all asynchronous putpage operations on
14067c478bd9Sstevel@tonic-gate * this file system are complete before flushing rnodes
14077c478bd9Sstevel@tonic-gate * from the cache.
14087c478bd9Sstevel@tonic-gate */
14097c478bd9Sstevel@tonic-gate omax = mi->mi_max_threads;
14107c478bd9Sstevel@tonic-gate if (nfs_async_stop_sig(vfsp)) {
14117c478bd9Sstevel@tonic-gate return (EINTR);
14127c478bd9Sstevel@tonic-gate }
14137c478bd9Sstevel@tonic-gate rflush(vfsp, cr);
14147c478bd9Sstevel@tonic-gate /*
14157c478bd9Sstevel@tonic-gate * If there are any active vnodes on this file system,
14167c478bd9Sstevel@tonic-gate * then the file system is busy and can't be umounted.
14177c478bd9Sstevel@tonic-gate */
14187c478bd9Sstevel@tonic-gate if (check_rtable(vfsp)) {
14197c478bd9Sstevel@tonic-gate mutex_enter(&mi->mi_async_lock);
14207c478bd9Sstevel@tonic-gate mi->mi_max_threads = omax;
14217c478bd9Sstevel@tonic-gate mutex_exit(&mi->mi_async_lock);
14227c478bd9Sstevel@tonic-gate return (EBUSY);
14237c478bd9Sstevel@tonic-gate }
14247c478bd9Sstevel@tonic-gate /*
14257c478bd9Sstevel@tonic-gate * The unmount can't fail from now on; stop the worker thread manager.
14267c478bd9Sstevel@tonic-gate */
14277c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp);
14287c478bd9Sstevel@tonic-gate /*
14297c478bd9Sstevel@tonic-gate * Destroy all rnodes belonging to this file system from the
14307c478bd9Sstevel@tonic-gate * rnode hash queues and purge any resources allocated to
14317c478bd9Sstevel@tonic-gate * them.
14327c478bd9Sstevel@tonic-gate */
14337c478bd9Sstevel@tonic-gate destroy_rtable(vfsp, cr);
14347c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) {
14357c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats);
14367c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL;
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) {
14397c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats);
14407c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL;
14417c478bd9Sstevel@tonic-gate }
14427c478bd9Sstevel@tonic-gate return (0);
14437c478bd9Sstevel@tonic-gate }
14447c478bd9Sstevel@tonic-gate
14457c478bd9Sstevel@tonic-gate /*
14467c478bd9Sstevel@tonic-gate * find root of nfs
14477c478bd9Sstevel@tonic-gate */
14487c478bd9Sstevel@tonic-gate static int
nfs3_root(vfs_t * vfsp,vnode_t ** vpp)14497c478bd9Sstevel@tonic-gate nfs3_root(vfs_t *vfsp, vnode_t **vpp)
14507c478bd9Sstevel@tonic-gate {
14517c478bd9Sstevel@tonic-gate mntinfo_t *mi;
14527c478bd9Sstevel@tonic-gate vnode_t *vp;
14537c478bd9Sstevel@tonic-gate servinfo_t *svp;
1454210225b5Sgt rnode_t *rp;
1455210225b5Sgt int error = 0;
14567c478bd9Sstevel@tonic-gate
14577c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp);
14587c478bd9Sstevel@tonic-gate
1459108322fbScarlsonj if (nfs_zone() != mi->mi_zone)
14607c478bd9Sstevel@tonic-gate return (EPERM);
14617c478bd9Sstevel@tonic-gate
14627c478bd9Sstevel@tonic-gate svp = mi->mi_curr_serv;
14637c478bd9Sstevel@tonic-gate if (svp && (svp->sv_flags & SV_ROOT_STALE)) {
14647c478bd9Sstevel@tonic-gate mutex_enter(&svp->sv_lock);
14657c478bd9Sstevel@tonic-gate svp->sv_flags &= ~SV_ROOT_STALE;
14667c478bd9Sstevel@tonic-gate mutex_exit(&svp->sv_lock);
1467210225b5Sgt error = ENOENT;
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate vp = makenfs3node((nfs_fh3 *)&mi->mi_curr_serv->sv_fhandle,
14717c478bd9Sstevel@tonic-gate NULL, vfsp, gethrtime(), CRED(), NULL, NULL);
14727c478bd9Sstevel@tonic-gate
1473210225b5Sgt /*
1474210225b5Sgt * if the SV_ROOT_STALE flag was reset above, reset the
1475210225b5Sgt * RSTALE flag if needed and return an error
1476210225b5Sgt */
1477210225b5Sgt if (error == ENOENT) {
1478210225b5Sgt rp = VTOR(vp);
1479210225b5Sgt if (svp && rp->r_flags & RSTALE) {
1480210225b5Sgt mutex_enter(&rp->r_statelock);
1481210225b5Sgt rp->r_flags &= ~RSTALE;
1482210225b5Sgt mutex_exit(&rp->r_statelock);
1483210225b5Sgt }
14847c478bd9Sstevel@tonic-gate VN_RELE(vp);
1485210225b5Sgt return (error);
14867c478bd9Sstevel@tonic-gate }
14877c478bd9Sstevel@tonic-gate
14887c478bd9Sstevel@tonic-gate ASSERT(vp->v_type == VNON || vp->v_type == mi->mi_type);
14897c478bd9Sstevel@tonic-gate
14907c478bd9Sstevel@tonic-gate vp->v_type = mi->mi_type;
14917c478bd9Sstevel@tonic-gate
14927c478bd9Sstevel@tonic-gate *vpp = vp;
14937c478bd9Sstevel@tonic-gate
14947c478bd9Sstevel@tonic-gate return (0);
14957c478bd9Sstevel@tonic-gate }
14967c478bd9Sstevel@tonic-gate
14977c478bd9Sstevel@tonic-gate /*
14987c478bd9Sstevel@tonic-gate * Get file system statistics.
14997c478bd9Sstevel@tonic-gate */
15007c478bd9Sstevel@tonic-gate static int
nfs3_statvfs(vfs_t * vfsp,struct statvfs64 * sbp)15017c478bd9Sstevel@tonic-gate nfs3_statvfs(vfs_t *vfsp, struct statvfs64 *sbp)
15027c478bd9Sstevel@tonic-gate {
15037c478bd9Sstevel@tonic-gate int error;
15047c478bd9Sstevel@tonic-gate struct mntinfo *mi;
15057c478bd9Sstevel@tonic-gate struct FSSTAT3args args;
15067c478bd9Sstevel@tonic-gate struct FSSTAT3res res;
15077c478bd9Sstevel@tonic-gate int douprintf;
15087c478bd9Sstevel@tonic-gate failinfo_t fi;
15097c478bd9Sstevel@tonic-gate vnode_t *vp;
15107c478bd9Sstevel@tonic-gate cred_t *cr;
15117c478bd9Sstevel@tonic-gate hrtime_t t;
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp);
1514108322fbScarlsonj if (nfs_zone() != mi->mi_zone)
15157c478bd9Sstevel@tonic-gate return (EPERM);
15167c478bd9Sstevel@tonic-gate error = nfs3_root(vfsp, &vp);
15177c478bd9Sstevel@tonic-gate if (error)
15187c478bd9Sstevel@tonic-gate return (error);
15197c478bd9Sstevel@tonic-gate
15207c478bd9Sstevel@tonic-gate cr = CRED();
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gate args.fsroot = *VTOFH3(vp);
15237c478bd9Sstevel@tonic-gate fi.vp = vp;
15247c478bd9Sstevel@tonic-gate fi.fhp = (caddr_t)&args.fsroot;
15257c478bd9Sstevel@tonic-gate fi.copyproc = nfs3copyfh;
15267c478bd9Sstevel@tonic-gate fi.lookupproc = nfs3lookup;
15277c478bd9Sstevel@tonic-gate fi.xattrdirproc = acl_getxattrdir3;
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate douprintf = 1;
15307c478bd9Sstevel@tonic-gate
15317c478bd9Sstevel@tonic-gate t = gethrtime();
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gate error = rfs3call(mi, NFSPROC3_FSSTAT,
15347c478bd9Sstevel@tonic-gate xdr_nfs_fh3, (caddr_t)&args,
15357c478bd9Sstevel@tonic-gate xdr_FSSTAT3res, (caddr_t)&res, cr,
15367c478bd9Sstevel@tonic-gate &douprintf, &res.status, 0, &fi);
15377c478bd9Sstevel@tonic-gate
15387c478bd9Sstevel@tonic-gate if (error) {
15397c478bd9Sstevel@tonic-gate VN_RELE(vp);
15407c478bd9Sstevel@tonic-gate return (error);
15417c478bd9Sstevel@tonic-gate }
15427c478bd9Sstevel@tonic-gate
15437c478bd9Sstevel@tonic-gate error = geterrno3(res.status);
15447c478bd9Sstevel@tonic-gate if (!error) {
15457c478bd9Sstevel@tonic-gate nfs3_cache_post_op_attr(vp, &res.resok.obj_attributes, t, cr);
15467c478bd9Sstevel@tonic-gate sbp->f_bsize = MAXBSIZE;
15477c478bd9Sstevel@tonic-gate sbp->f_frsize = DEV_BSIZE;
15487c478bd9Sstevel@tonic-gate /*
15497c478bd9Sstevel@tonic-gate * Allow -1 fields to pass through unconverted. These
15507c478bd9Sstevel@tonic-gate * indicate "don't know" fields.
15517c478bd9Sstevel@tonic-gate */
15527c478bd9Sstevel@tonic-gate if (res.resok.tbytes == (size3)-1)
15537c478bd9Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)res.resok.tbytes;
15547c478bd9Sstevel@tonic-gate else {
15557c478bd9Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)
15567c478bd9Sstevel@tonic-gate (res.resok.tbytes / DEV_BSIZE);
15577c478bd9Sstevel@tonic-gate }
15587c478bd9Sstevel@tonic-gate if (res.resok.fbytes == (size3)-1)
15597c478bd9Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)res.resok.fbytes;
15607c478bd9Sstevel@tonic-gate else {
15617c478bd9Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)
15627c478bd9Sstevel@tonic-gate (res.resok.fbytes / DEV_BSIZE);
15637c478bd9Sstevel@tonic-gate }
15647c478bd9Sstevel@tonic-gate if (res.resok.abytes == (size3)-1)
15657c478bd9Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)res.resok.abytes;
15667c478bd9Sstevel@tonic-gate else {
15677c478bd9Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)
15687c478bd9Sstevel@tonic-gate (res.resok.abytes / DEV_BSIZE);
15697c478bd9Sstevel@tonic-gate }
15707c478bd9Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)res.resok.tfiles;
15717c478bd9Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)res.resok.ffiles;
15727c478bd9Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)res.resok.afiles;
15737c478bd9Sstevel@tonic-gate sbp->f_fsid = (unsigned long)vfsp->vfs_fsid.val[0];
15747c478bd9Sstevel@tonic-gate (void) strncpy(sbp->f_basetype,
15757c478bd9Sstevel@tonic-gate vfssw[vfsp->vfs_fstype].vsw_name, FSTYPSZ);
15767c478bd9Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
15777c478bd9Sstevel@tonic-gate sbp->f_namemax = (ulong_t)-1;
15787c478bd9Sstevel@tonic-gate } else {
15797c478bd9Sstevel@tonic-gate nfs3_cache_post_op_attr(vp, &res.resfail.obj_attributes, t, cr);
15807c478bd9Sstevel@tonic-gate PURGE_STALE_FH(error, vp, cr);
15817c478bd9Sstevel@tonic-gate }
15827c478bd9Sstevel@tonic-gate
15837c478bd9Sstevel@tonic-gate VN_RELE(vp);
15847c478bd9Sstevel@tonic-gate
15857c478bd9Sstevel@tonic-gate return (error);
15867c478bd9Sstevel@tonic-gate }
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate static kmutex_t nfs3_syncbusy;
15897c478bd9Sstevel@tonic-gate
15907c478bd9Sstevel@tonic-gate /*
15917c478bd9Sstevel@tonic-gate * Flush dirty nfs files for file system vfsp.
15927c478bd9Sstevel@tonic-gate * If vfsp == NULL, all nfs files are flushed.
15937c478bd9Sstevel@tonic-gate */
15947c478bd9Sstevel@tonic-gate /* ARGSUSED */
15957c478bd9Sstevel@tonic-gate static int
nfs3_sync(vfs_t * vfsp,short flag,cred_t * cr)15967c478bd9Sstevel@tonic-gate nfs3_sync(vfs_t *vfsp, short flag, cred_t *cr)
15977c478bd9Sstevel@tonic-gate {
15987c478bd9Sstevel@tonic-gate /*
15997c478bd9Sstevel@tonic-gate * Cross-zone calls are OK here, since this translates to a
16007c478bd9Sstevel@tonic-gate * VOP_PUTPAGE(B_ASYNC), which gets picked up by the right zone.
16017c478bd9Sstevel@tonic-gate */
16027c478bd9Sstevel@tonic-gate if (!(flag & SYNC_ATTR) && mutex_tryenter(&nfs3_syncbusy) != 0) {
16037c478bd9Sstevel@tonic-gate rflush(vfsp, cr);
16047c478bd9Sstevel@tonic-gate mutex_exit(&nfs3_syncbusy);
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate return (0);
16077c478bd9Sstevel@tonic-gate }
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate /* ARGSUSED */
16107c478bd9Sstevel@tonic-gate static int
nfs3_vget(vfs_t * vfsp,vnode_t ** vpp,fid_t * fidp)16117c478bd9Sstevel@tonic-gate nfs3_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp)
16127c478bd9Sstevel@tonic-gate {
16137c478bd9Sstevel@tonic-gate int error;
16147c478bd9Sstevel@tonic-gate nfs_fh3 fh;
16157c478bd9Sstevel@tonic-gate vnode_t *vp;
16167c478bd9Sstevel@tonic-gate struct vattr va;
16177c478bd9Sstevel@tonic-gate
16187c478bd9Sstevel@tonic-gate if (fidp->fid_len > NFS3_FHSIZE) {
16197c478bd9Sstevel@tonic-gate *vpp = NULL;
16207c478bd9Sstevel@tonic-gate return (ESTALE);
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate
1623108322fbScarlsonj if (nfs_zone() != VFTOMI(vfsp)->mi_zone)
16247c478bd9Sstevel@tonic-gate return (EPERM);
16257c478bd9Sstevel@tonic-gate fh.fh3_length = fidp->fid_len;
16267c478bd9Sstevel@tonic-gate bcopy(fidp->fid_data, fh.fh3_u.data, fh.fh3_length);
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate vp = makenfs3node(&fh, NULL, vfsp, gethrtime(), CRED(), NULL, NULL);
16297c478bd9Sstevel@tonic-gate
16307c478bd9Sstevel@tonic-gate if (VTOR(vp)->r_flags & RSTALE) {
16317c478bd9Sstevel@tonic-gate VN_RELE(vp);
16327c478bd9Sstevel@tonic-gate *vpp = NULL;
16337c478bd9Sstevel@tonic-gate return (ENOENT);
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate if (vp->v_type == VNON) {
16377c478bd9Sstevel@tonic-gate va.va_mask = AT_ALL;
16387c478bd9Sstevel@tonic-gate error = nfs3getattr(vp, &va, CRED());
16397c478bd9Sstevel@tonic-gate if (error) {
16407c478bd9Sstevel@tonic-gate VN_RELE(vp);
16417c478bd9Sstevel@tonic-gate *vpp = NULL;
16427c478bd9Sstevel@tonic-gate return (error);
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate vp->v_type = va.va_type;
16457c478bd9Sstevel@tonic-gate }
16467c478bd9Sstevel@tonic-gate
16477c478bd9Sstevel@tonic-gate *vpp = vp;
16487c478bd9Sstevel@tonic-gate
16497c478bd9Sstevel@tonic-gate return (0);
16507c478bd9Sstevel@tonic-gate }
16517c478bd9Sstevel@tonic-gate
16527c478bd9Sstevel@tonic-gate /* ARGSUSED */
16537c478bd9Sstevel@tonic-gate static int
nfs3_mountroot(vfs_t * vfsp,whymountroot_t why)16547c478bd9Sstevel@tonic-gate nfs3_mountroot(vfs_t *vfsp, whymountroot_t why)
16557c478bd9Sstevel@tonic-gate {
16567c478bd9Sstevel@tonic-gate vnode_t *rtvp;
16577c478bd9Sstevel@tonic-gate char root_hostname[SYS_NMLN+1];
16587c478bd9Sstevel@tonic-gate struct servinfo *svp;
16597c478bd9Sstevel@tonic-gate int error;
16607c478bd9Sstevel@tonic-gate int vfsflags;
16617c478bd9Sstevel@tonic-gate size_t size;
16627c478bd9Sstevel@tonic-gate char *root_path;
16637c478bd9Sstevel@tonic-gate struct pathname pn;
16647c478bd9Sstevel@tonic-gate char *name;
16657c478bd9Sstevel@tonic-gate cred_t *cr;
16667c478bd9Sstevel@tonic-gate struct nfs_args args; /* nfs mount arguments */
16677c478bd9Sstevel@tonic-gate static char token[10];
16687c478bd9Sstevel@tonic-gate
16697c478bd9Sstevel@tonic-gate bzero(&args, sizeof (args));
16707c478bd9Sstevel@tonic-gate
16717c478bd9Sstevel@tonic-gate /* do this BEFORE getfile which causes xid stamps to be initialized */
16727c478bd9Sstevel@tonic-gate clkset(-1L); /* hack for now - until we get time svc? */
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate if (why == ROOT_REMOUNT) {
16757c478bd9Sstevel@tonic-gate /*
16767c478bd9Sstevel@tonic-gate * Shouldn't happen.
16777c478bd9Sstevel@tonic-gate */
16787c478bd9Sstevel@tonic-gate panic("nfs3_mountroot: why == ROOT_REMOUNT");
16797c478bd9Sstevel@tonic-gate }
16807c478bd9Sstevel@tonic-gate
16817c478bd9Sstevel@tonic-gate if (why == ROOT_UNMOUNT) {
16827c478bd9Sstevel@tonic-gate /*
16837c478bd9Sstevel@tonic-gate * Nothing to do for NFS.
16847c478bd9Sstevel@tonic-gate */
16857c478bd9Sstevel@tonic-gate return (0);
16867c478bd9Sstevel@tonic-gate }
16877c478bd9Sstevel@tonic-gate
16887c478bd9Sstevel@tonic-gate /*
16897c478bd9Sstevel@tonic-gate * why == ROOT_INIT
16907c478bd9Sstevel@tonic-gate */
16917c478bd9Sstevel@tonic-gate
16927c478bd9Sstevel@tonic-gate name = token;
16937c478bd9Sstevel@tonic-gate *name = 0;
16947c478bd9Sstevel@tonic-gate getfsname("root", name, sizeof (token));
16957c478bd9Sstevel@tonic-gate
16967c478bd9Sstevel@tonic-gate pn_alloc(&pn);
16977c478bd9Sstevel@tonic-gate root_path = pn.pn_path;
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gate svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
17007c478bd9Sstevel@tonic-gate svp->sv_knconf = kmem_zalloc(sizeof (*svp->sv_knconf), KM_SLEEP);
17017c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_protofmly = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
17027c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_proto = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
17037c478bd9Sstevel@tonic-gate
17047c478bd9Sstevel@tonic-gate /*
17057c478bd9Sstevel@tonic-gate * Get server address
17067c478bd9Sstevel@tonic-gate * Get the root fhandle
17077c478bd9Sstevel@tonic-gate * Get server's transport
17087c478bd9Sstevel@tonic-gate * Get server's hostname
17097c478bd9Sstevel@tonic-gate * Get options
17107c478bd9Sstevel@tonic-gate */
17117c478bd9Sstevel@tonic-gate args.addr = &svp->sv_addr;
17127c478bd9Sstevel@tonic-gate args.fh = (char *)&svp->sv_fhandle;
17137c478bd9Sstevel@tonic-gate args.knconf = svp->sv_knconf;
17147c478bd9Sstevel@tonic-gate args.hostname = root_hostname;
17157c478bd9Sstevel@tonic-gate vfsflags = 0;
17167c478bd9Sstevel@tonic-gate if (error = mount_root(*name ? name : "root", root_path, NFS_V3,
17177c478bd9Sstevel@tonic-gate &args, &vfsflags)) {
17187c478bd9Sstevel@tonic-gate if (error == EPROTONOSUPPORT)
17197c478bd9Sstevel@tonic-gate nfs_cmn_err(error, CE_WARN, "nfs3_mountroot: "
17207c478bd9Sstevel@tonic-gate "mount_root failed: server doesn't support NFS V3");
17217c478bd9Sstevel@tonic-gate else
17227c478bd9Sstevel@tonic-gate nfs_cmn_err(error, CE_WARN,
17237c478bd9Sstevel@tonic-gate "nfs3_mountroot: mount_root failed: %m");
17247c478bd9Sstevel@tonic-gate sv_free(svp);
17257c478bd9Sstevel@tonic-gate pn_free(&pn);
17267c478bd9Sstevel@tonic-gate return (error);
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate svp->sv_hostnamelen = (int)(strlen(root_hostname) + 1);
17297c478bd9Sstevel@tonic-gate svp->sv_hostname = kmem_alloc(svp->sv_hostnamelen, KM_SLEEP);
17307c478bd9Sstevel@tonic-gate (void) strcpy(svp->sv_hostname, root_hostname);
17317c478bd9Sstevel@tonic-gate
17327c478bd9Sstevel@tonic-gate /*
17337c478bd9Sstevel@tonic-gate * Force root partition to always be mounted with AUTH_UNIX for now
17347c478bd9Sstevel@tonic-gate */
17357c478bd9Sstevel@tonic-gate svp->sv_secdata = kmem_alloc(sizeof (*svp->sv_secdata), KM_SLEEP);
17367c478bd9Sstevel@tonic-gate svp->sv_secdata->secmod = AUTH_UNIX;
17377c478bd9Sstevel@tonic-gate svp->sv_secdata->rpcflavor = AUTH_UNIX;
17387c478bd9Sstevel@tonic-gate svp->sv_secdata->data = NULL;
17397c478bd9Sstevel@tonic-gate
17407c478bd9Sstevel@tonic-gate cr = crgetcred();
17417c478bd9Sstevel@tonic-gate rtvp = NULL;
17427c478bd9Sstevel@tonic-gate
17437c478bd9Sstevel@tonic-gate error = nfs3rootvp(&rtvp, vfsp, svp, args.flags, cr, global_zone);
17447c478bd9Sstevel@tonic-gate
17457c478bd9Sstevel@tonic-gate crfree(cr);
17467c478bd9Sstevel@tonic-gate
17477c478bd9Sstevel@tonic-gate if (error) {
17487c478bd9Sstevel@tonic-gate pn_free(&pn);
1749ab7762b6Smaheshvs sv_free(svp);
1750ab7762b6Smaheshvs return (error);
17517c478bd9Sstevel@tonic-gate }
17527c478bd9Sstevel@tonic-gate
17537c478bd9Sstevel@tonic-gate error = nfs_setopts(rtvp, DATAMODEL_NATIVE, &args);
17547c478bd9Sstevel@tonic-gate if (error) {
17557c478bd9Sstevel@tonic-gate nfs_cmn_err(error, CE_WARN,
17567c478bd9Sstevel@tonic-gate "nfs3_mountroot: invalid root mount options");
17577c478bd9Sstevel@tonic-gate pn_free(&pn);
17587c478bd9Sstevel@tonic-gate goto errout;
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate
17617c478bd9Sstevel@tonic-gate (void) vfs_lock_wait(vfsp);
17627c478bd9Sstevel@tonic-gate vfs_add(NULL, vfsp, vfsflags);
17637c478bd9Sstevel@tonic-gate vfs_unlock(vfsp);
17647c478bd9Sstevel@tonic-gate
17657c478bd9Sstevel@tonic-gate size = strlen(svp->sv_hostname);
17667c478bd9Sstevel@tonic-gate (void) strcpy(rootfs.bo_name, svp->sv_hostname);
17677c478bd9Sstevel@tonic-gate rootfs.bo_name[size] = ':';
17687c478bd9Sstevel@tonic-gate (void) strcpy(&rootfs.bo_name[size + 1], root_path);
17697c478bd9Sstevel@tonic-gate
17707c478bd9Sstevel@tonic-gate pn_free(&pn);
17717c478bd9Sstevel@tonic-gate
17727c478bd9Sstevel@tonic-gate errout:
17737c478bd9Sstevel@tonic-gate if (error) {
17747c478bd9Sstevel@tonic-gate sv_free(svp);
17757c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp);
17767c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp);
17777c478bd9Sstevel@tonic-gate }
17787c478bd9Sstevel@tonic-gate
17797c478bd9Sstevel@tonic-gate if (rtvp != NULL)
17807c478bd9Sstevel@tonic-gate VN_RELE(rtvp);
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gate return (error);
17837c478bd9Sstevel@tonic-gate }
17847c478bd9Sstevel@tonic-gate
17857c478bd9Sstevel@tonic-gate /*
17867c478bd9Sstevel@tonic-gate * Initialization routine for VFS routines. Should only be called once
17877c478bd9Sstevel@tonic-gate */
17887c478bd9Sstevel@tonic-gate int
nfs3_vfsinit(void)17897c478bd9Sstevel@tonic-gate nfs3_vfsinit(void)
17907c478bd9Sstevel@tonic-gate {
17917c478bd9Sstevel@tonic-gate mutex_init(&nfs3_syncbusy, NULL, MUTEX_DEFAULT, NULL);
17927c478bd9Sstevel@tonic-gate return (0);
17937c478bd9Sstevel@tonic-gate }
17947c478bd9Sstevel@tonic-gate
17957c478bd9Sstevel@tonic-gate void
nfs3_vfsfini(void)17967c478bd9Sstevel@tonic-gate nfs3_vfsfini(void)
17977c478bd9Sstevel@tonic-gate {
17987c478bd9Sstevel@tonic-gate mutex_destroy(&nfs3_syncbusy);
17997c478bd9Sstevel@tonic-gate }
18007c478bd9Sstevel@tonic-gate
18017c478bd9Sstevel@tonic-gate void
nfs3_freevfs(vfs_t * vfsp)18027c478bd9Sstevel@tonic-gate nfs3_freevfs(vfs_t *vfsp)
18037c478bd9Sstevel@tonic-gate {
18047c478bd9Sstevel@tonic-gate mntinfo_t *mi;
18057c478bd9Sstevel@tonic-gate servinfo_t *svp;
18067c478bd9Sstevel@tonic-gate
18077c478bd9Sstevel@tonic-gate /* free up the resources */
18087c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp);
18097c478bd9Sstevel@tonic-gate svp = mi->mi_servers;
18107c478bd9Sstevel@tonic-gate mi->mi_servers = mi->mi_curr_serv = NULL;
18117c478bd9Sstevel@tonic-gate sv_free(svp);
18127c478bd9Sstevel@tonic-gate
18137c478bd9Sstevel@tonic-gate /*
18147c478bd9Sstevel@tonic-gate * By this time we should have already deleted the
18157c478bd9Sstevel@tonic-gate * mi kstats in the unmount code. If they are still around
18167c478bd9Sstevel@tonic-gate * somethings wrong
18177c478bd9Sstevel@tonic-gate */
18187c478bd9Sstevel@tonic-gate ASSERT(mi->mi_io_kstats == NULL);
18197c478bd9Sstevel@tonic-gate nfs_free_mi(mi);
18207c478bd9Sstevel@tonic-gate }
1821