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 /* 22*dcedb507SMarcel Telka * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate * 257c478bd9Sstevel@tonic-gate * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T. 267c478bd9Sstevel@tonic-gate * All rights reserved. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/systm.h> 327c478bd9Sstevel@tonic-gate #include <sys/cred.h> 337c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 34aa59c4cbSrsb #include <sys/vfs_opreg.h> 357c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 367c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 387c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 397c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 407c478bd9Sstevel@tonic-gate #include <sys/mount.h> 417c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 427c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 437c478bd9Sstevel@tonic-gate #include <sys/errno.h> 447c478bd9Sstevel@tonic-gate #include <sys/debug.h> 457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 467c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 477c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 487c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 497c478bd9Sstevel@tonic-gate #include <sys/acl.h> 507c478bd9Sstevel@tonic-gate #include <sys/flock.h> 517c478bd9Sstevel@tonic-gate #include <sys/policy.h> 527c478bd9Sstevel@tonic-gate #include <sys/zone.h> 537c478bd9Sstevel@tonic-gate #include <sys/class.h> 547c478bd9Sstevel@tonic-gate #include <sys/socket.h> 557c478bd9Sstevel@tonic-gate #include <sys/netconfig.h> 5645916cd2Sjpk #include <sys/mntent.h> 5745916cd2Sjpk #include <sys/tsol/label.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 7739d3e169Sevanl static int pathconf_copyin(struct nfs_args *, struct pathcnf *); 7839d3e169Sevanl static int pathconf_get(struct mntinfo *, struct nfs_args *); 797c478bd9Sstevel@tonic-gate static void pathconf_rele(struct mntinfo *); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * The order and contents of this structure must be kept in sync with that of 837c478bd9Sstevel@tonic-gate * rfsreqcnt_v2_tmpl in nfs_stats.c 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate static char *rfsnames_v2[] = { 867c478bd9Sstevel@tonic-gate "null", "getattr", "setattr", "unused", "lookup", "readlink", "read", 877c478bd9Sstevel@tonic-gate "unused", "write", "create", "remove", "rename", "link", "symlink", 887c478bd9Sstevel@tonic-gate "mkdir", "rmdir", "readdir", "fsstat" 897c478bd9Sstevel@tonic-gate }; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * This table maps from NFS protocol number into call type. 937c478bd9Sstevel@tonic-gate * Zero means a "Lookup" type call 947c478bd9Sstevel@tonic-gate * One means a "Read" type call 957c478bd9Sstevel@tonic-gate * Two means a "Write" type call 967c478bd9Sstevel@tonic-gate * This is used to select a default time-out. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate static uchar_t call_type_v2[] = { 997c478bd9Sstevel@tonic-gate 0, 0, 1, 0, 0, 0, 1, 1007c478bd9Sstevel@tonic-gate 0, 2, 2, 2, 2, 2, 2, 1017c478bd9Sstevel@tonic-gate 2, 2, 1, 0 1027c478bd9Sstevel@tonic-gate }; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * Similar table, but to determine which timer to use 1067c478bd9Sstevel@tonic-gate * (only real reads and writes!) 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate static uchar_t timer_type_v2[] = { 1097c478bd9Sstevel@tonic-gate 0, 0, 0, 0, 0, 0, 1, 1107c478bd9Sstevel@tonic-gate 0, 2, 0, 0, 0, 0, 0, 1117c478bd9Sstevel@tonic-gate 0, 0, 1, 0 1127c478bd9Sstevel@tonic-gate }; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * This table maps from NFS protocol number into a call type 1167c478bd9Sstevel@tonic-gate * for the semisoft mount option. 1177c478bd9Sstevel@tonic-gate * Zero means do not repeat operation. 1187c478bd9Sstevel@tonic-gate * One means repeat. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate static uchar_t ss_call_type_v2[] = { 1217c478bd9Sstevel@tonic-gate 0, 0, 1, 0, 0, 0, 0, 1227c478bd9Sstevel@tonic-gate 0, 1, 1, 1, 1, 1, 1, 1237c478bd9Sstevel@tonic-gate 1, 1, 0, 0 1247c478bd9Sstevel@tonic-gate }; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * nfs vfs operations. 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate static int nfs_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *); 1307c478bd9Sstevel@tonic-gate static int nfs_unmount(vfs_t *, int, cred_t *); 1317c478bd9Sstevel@tonic-gate static int nfs_root(vfs_t *, vnode_t **); 1327c478bd9Sstevel@tonic-gate static int nfs_statvfs(vfs_t *, struct statvfs64 *); 1337c478bd9Sstevel@tonic-gate static int nfs_sync(vfs_t *, short, cred_t *); 1347c478bd9Sstevel@tonic-gate static int nfs_vget(vfs_t *, vnode_t **, fid_t *); 1357c478bd9Sstevel@tonic-gate static int nfs_mountroot(vfs_t *, whymountroot_t); 1367c478bd9Sstevel@tonic-gate static void nfs_freevfs(vfs_t *); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate static int nfsrootvp(vnode_t **, vfs_t *, struct servinfo *, 1397c478bd9Sstevel@tonic-gate int, cred_t *, zone_t *); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * Initialize the vfs structure 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate int nfsfstyp; 1467c478bd9Sstevel@tonic-gate vfsops_t *nfs_vfsops; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* 1497c478bd9Sstevel@tonic-gate * Debug variable to check for rdma based 1507c478bd9Sstevel@tonic-gate * transport startup and cleanup. Controlled 1517c478bd9Sstevel@tonic-gate * through /etc/system. Off by default. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate int rdma_debug = 0; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate int 1567c478bd9Sstevel@tonic-gate nfsinit(int fstyp, char *name) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate static const fs_operation_def_t nfs_vfsops_template[] = { 159aa59c4cbSrsb VFSNAME_MOUNT, { .vfs_mount = nfs_mount }, 160aa59c4cbSrsb VFSNAME_UNMOUNT, { .vfs_unmount = nfs_unmount }, 161aa59c4cbSrsb VFSNAME_ROOT, { .vfs_root = nfs_root }, 162aa59c4cbSrsb VFSNAME_STATVFS, { .vfs_statvfs = nfs_statvfs }, 163aa59c4cbSrsb VFSNAME_SYNC, { .vfs_sync = nfs_sync }, 164aa59c4cbSrsb VFSNAME_VGET, { .vfs_vget = nfs_vget }, 165aa59c4cbSrsb VFSNAME_MOUNTROOT, { .vfs_mountroot = nfs_mountroot }, 166aa59c4cbSrsb VFSNAME_FREEVFS, { .vfs_freevfs = nfs_freevfs }, 167aa59c4cbSrsb NULL, NULL 1687c478bd9Sstevel@tonic-gate }; 1697c478bd9Sstevel@tonic-gate int error; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate error = vfs_setfsops(fstyp, nfs_vfsops_template, &nfs_vfsops); 1727c478bd9Sstevel@tonic-gate if (error != 0) { 1737c478bd9Sstevel@tonic-gate zcmn_err(GLOBAL_ZONEID, CE_WARN, 1747c478bd9Sstevel@tonic-gate "nfsinit: bad vfs ops template"); 1757c478bd9Sstevel@tonic-gate return (error); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate error = vn_make_ops(name, nfs_vnodeops_template, &nfs_vnodeops); 1797c478bd9Sstevel@tonic-gate if (error != 0) { 1807c478bd9Sstevel@tonic-gate (void) vfs_freevfsops_by_type(fstyp); 1817c478bd9Sstevel@tonic-gate zcmn_err(GLOBAL_ZONEID, CE_WARN, 1827c478bd9Sstevel@tonic-gate "nfsinit: bad vnode ops template"); 1837c478bd9Sstevel@tonic-gate return (error); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate nfsfstyp = fstyp; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate return (0); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate void 1937c478bd9Sstevel@tonic-gate nfsfini(void) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 19739d3e169Sevanl static void 19839d3e169Sevanl nfs_free_args(struct nfs_args *nargs, nfs_fhandle *fh) 19939d3e169Sevanl { 20039d3e169Sevanl 20139d3e169Sevanl if (fh) 20239d3e169Sevanl kmem_free(fh, sizeof (*fh)); 20339d3e169Sevanl 20439d3e169Sevanl if (nargs->pathconf) { 20539d3e169Sevanl kmem_free(nargs->pathconf, sizeof (struct pathcnf)); 20639d3e169Sevanl nargs->pathconf = NULL; 20739d3e169Sevanl } 20839d3e169Sevanl 20939d3e169Sevanl if (nargs->knconf) { 21039d3e169Sevanl if (nargs->knconf->knc_protofmly) 211*dcedb507SMarcel Telka kmem_free(nargs->knconf->knc_protofmly, KNC_STRSIZE); 21239d3e169Sevanl if (nargs->knconf->knc_proto) 21339d3e169Sevanl kmem_free(nargs->knconf->knc_proto, KNC_STRSIZE); 21439d3e169Sevanl kmem_free(nargs->knconf, sizeof (*nargs->knconf)); 21539d3e169Sevanl nargs->knconf = NULL; 21639d3e169Sevanl } 21739d3e169Sevanl 21839d3e169Sevanl if (nargs->fh) { 21939d3e169Sevanl kmem_free(nargs->fh, strlen(nargs->fh) + 1); 22039d3e169Sevanl nargs->fh = NULL; 22139d3e169Sevanl } 22239d3e169Sevanl 22339d3e169Sevanl if (nargs->hostname) { 22439d3e169Sevanl kmem_free(nargs->hostname, strlen(nargs->hostname) + 1); 22539d3e169Sevanl nargs->hostname = NULL; 22639d3e169Sevanl } 22739d3e169Sevanl 22839d3e169Sevanl if (nargs->addr) { 22939d3e169Sevanl if (nargs->addr->buf) { 23039d3e169Sevanl ASSERT(nargs->addr->len); 23139d3e169Sevanl kmem_free(nargs->addr->buf, nargs->addr->len); 23239d3e169Sevanl } 23339d3e169Sevanl kmem_free(nargs->addr, sizeof (struct netbuf)); 23439d3e169Sevanl nargs->addr = NULL; 23539d3e169Sevanl } 23639d3e169Sevanl 23739d3e169Sevanl if (nargs->syncaddr) { 23839d3e169Sevanl ASSERT(nargs->syncaddr->len); 23939d3e169Sevanl if (nargs->syncaddr->buf) { 24039d3e169Sevanl ASSERT(nargs->syncaddr->len); 24139d3e169Sevanl kmem_free(nargs->syncaddr->buf, nargs->syncaddr->len); 24239d3e169Sevanl } 24339d3e169Sevanl kmem_free(nargs->syncaddr, sizeof (struct netbuf)); 24439d3e169Sevanl nargs->syncaddr = NULL; 24539d3e169Sevanl } 24639d3e169Sevanl 24739d3e169Sevanl if (nargs->netname) { 24839d3e169Sevanl kmem_free(nargs->netname, strlen(nargs->netname) + 1); 24939d3e169Sevanl nargs->netname = NULL; 25039d3e169Sevanl } 25139d3e169Sevanl 25239d3e169Sevanl if (nargs->nfs_ext_u.nfs_extA.secdata) { 253*dcedb507SMarcel Telka sec_clnt_freeinfo(nargs->nfs_ext_u.nfs_extA.secdata); 25439d3e169Sevanl nargs->nfs_ext_u.nfs_extA.secdata = NULL; 25539d3e169Sevanl } 25639d3e169Sevanl } 25739d3e169Sevanl 25839d3e169Sevanl static int 25939d3e169Sevanl nfs_copyin(char *data, int datalen, struct nfs_args *nargs, nfs_fhandle *fh) 26039d3e169Sevanl { 26139d3e169Sevanl 26239d3e169Sevanl int error; 26339d3e169Sevanl size_t nlen; /* length of netname */ 26439d3e169Sevanl size_t hlen; /* length of hostname */ 26539d3e169Sevanl char netname[MAXNETNAMELEN+1]; /* server's netname */ 26639d3e169Sevanl struct netbuf addr; /* server's address */ 26739d3e169Sevanl struct netbuf syncaddr; /* AUTH_DES time sync addr */ 26839d3e169Sevanl struct knetconfig *knconf; /* transport knetconfig structure */ 26939d3e169Sevanl struct sec_data *secdata = NULL; /* security data */ 27039d3e169Sevanl STRUCT_DECL(nfs_args, args); /* nfs mount arguments */ 27139d3e169Sevanl STRUCT_DECL(knetconfig, knconf_tmp); 27239d3e169Sevanl STRUCT_DECL(netbuf, addr_tmp); 27339d3e169Sevanl int flags; 27439d3e169Sevanl struct pathcnf *pc; /* Pathconf */ 27539d3e169Sevanl char *p, *pf; 27639d3e169Sevanl char *userbufptr; 27739d3e169Sevanl 27839d3e169Sevanl 27939d3e169Sevanl bzero(nargs, sizeof (*nargs)); 28039d3e169Sevanl 28139d3e169Sevanl STRUCT_INIT(args, get_udatamodel()); 28239d3e169Sevanl bzero(STRUCT_BUF(args), SIZEOF_STRUCT(nfs_args, DATAMODEL_NATIVE)); 283*dcedb507SMarcel Telka if (copyin(data, STRUCT_BUF(args), MIN(datalen, STRUCT_SIZE(args)))) 28439d3e169Sevanl return (EFAULT); 28539d3e169Sevanl 28639d3e169Sevanl nargs->wsize = STRUCT_FGET(args, wsize); 28739d3e169Sevanl nargs->rsize = STRUCT_FGET(args, rsize); 28839d3e169Sevanl nargs->timeo = STRUCT_FGET(args, timeo); 28939d3e169Sevanl nargs->retrans = STRUCT_FGET(args, retrans); 29039d3e169Sevanl nargs->acregmin = STRUCT_FGET(args, acregmin); 29139d3e169Sevanl nargs->acregmax = STRUCT_FGET(args, acregmax); 29239d3e169Sevanl nargs->acdirmin = STRUCT_FGET(args, acdirmin); 29339d3e169Sevanl nargs->acdirmax = STRUCT_FGET(args, acdirmax); 29439d3e169Sevanl 29539d3e169Sevanl flags = STRUCT_FGET(args, flags); 29639d3e169Sevanl nargs->flags = flags; 29739d3e169Sevanl 29839d3e169Sevanl 29939d3e169Sevanl addr.buf = NULL; 30039d3e169Sevanl syncaddr.buf = NULL; 30139d3e169Sevanl 30239d3e169Sevanl /* 30339d3e169Sevanl * Allocate space for a knetconfig structure and 30439d3e169Sevanl * its strings and copy in from user-land. 30539d3e169Sevanl */ 30639d3e169Sevanl knconf = kmem_zalloc(sizeof (*knconf), KM_SLEEP); 30739d3e169Sevanl STRUCT_INIT(knconf_tmp, get_udatamodel()); 30839d3e169Sevanl if (copyin(STRUCT_FGETP(args, knconf), STRUCT_BUF(knconf_tmp), 309*dcedb507SMarcel Telka STRUCT_SIZE(knconf_tmp))) { 31039d3e169Sevanl kmem_free(knconf, sizeof (*knconf)); 31139d3e169Sevanl return (EFAULT); 31239d3e169Sevanl } 31339d3e169Sevanl 31439d3e169Sevanl knconf->knc_semantics = STRUCT_FGET(knconf_tmp, knc_semantics); 31539d3e169Sevanl knconf->knc_protofmly = STRUCT_FGETP(knconf_tmp, knc_protofmly); 31639d3e169Sevanl knconf->knc_proto = STRUCT_FGETP(knconf_tmp, knc_proto); 31739d3e169Sevanl if (get_udatamodel() != DATAMODEL_LP64) { 31839d3e169Sevanl knconf->knc_rdev = expldev(STRUCT_FGET(knconf_tmp, knc_rdev)); 31939d3e169Sevanl } else { 32039d3e169Sevanl knconf->knc_rdev = STRUCT_FGET(knconf_tmp, knc_rdev); 32139d3e169Sevanl } 32239d3e169Sevanl 32339d3e169Sevanl pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 32439d3e169Sevanl p = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 32539d3e169Sevanl error = copyinstr(knconf->knc_protofmly, pf, KNC_STRSIZE, NULL); 32639d3e169Sevanl if (error) { 32739d3e169Sevanl kmem_free(pf, KNC_STRSIZE); 32839d3e169Sevanl kmem_free(p, KNC_STRSIZE); 32939d3e169Sevanl kmem_free(knconf, sizeof (*knconf)); 33039d3e169Sevanl return (error); 33139d3e169Sevanl } 33239d3e169Sevanl 33339d3e169Sevanl error = copyinstr(knconf->knc_proto, p, KNC_STRSIZE, NULL); 33439d3e169Sevanl if (error) { 33539d3e169Sevanl kmem_free(pf, KNC_STRSIZE); 33639d3e169Sevanl kmem_free(p, KNC_STRSIZE); 33739d3e169Sevanl kmem_free(knconf, sizeof (*knconf)); 33839d3e169Sevanl return (error); 33939d3e169Sevanl } 34039d3e169Sevanl 34139d3e169Sevanl 34239d3e169Sevanl knconf->knc_protofmly = pf; 34339d3e169Sevanl knconf->knc_proto = p; 34439d3e169Sevanl 34539d3e169Sevanl nargs->knconf = knconf; 34639d3e169Sevanl 34739d3e169Sevanl /* Copyin pathconf if there is one */ 34839d3e169Sevanl if (STRUCT_FGETP(args, pathconf) != NULL) { 34939d3e169Sevanl pc = kmem_alloc(sizeof (*pc), KM_SLEEP); 35039d3e169Sevanl error = pathconf_copyin(STRUCT_BUF(args), pc); 35139d3e169Sevanl nargs->pathconf = pc; 35239d3e169Sevanl if (error) 35339d3e169Sevanl goto errout; 35439d3e169Sevanl } 35539d3e169Sevanl 35639d3e169Sevanl /* 35739d3e169Sevanl * Get server address 35839d3e169Sevanl */ 35939d3e169Sevanl STRUCT_INIT(addr_tmp, get_udatamodel()); 36039d3e169Sevanl if (copyin(STRUCT_FGETP(args, addr), STRUCT_BUF(addr_tmp), 361*dcedb507SMarcel Telka STRUCT_SIZE(addr_tmp))) { 36239d3e169Sevanl error = EFAULT; 36339d3e169Sevanl goto errout; 36439d3e169Sevanl } 36539d3e169Sevanl nargs->addr = kmem_alloc(sizeof (struct netbuf), KM_SLEEP); 36639d3e169Sevanl userbufptr = STRUCT_FGETP(addr_tmp, buf); 36739d3e169Sevanl addr.len = STRUCT_FGET(addr_tmp, len); 36839d3e169Sevanl addr.buf = kmem_alloc(addr.len, KM_SLEEP); 36939d3e169Sevanl addr.maxlen = addr.len; 37039d3e169Sevanl if (copyin(userbufptr, addr.buf, addr.len)) { 37139d3e169Sevanl kmem_free(addr.buf, addr.len); 37239d3e169Sevanl error = EFAULT; 37339d3e169Sevanl goto errout; 37439d3e169Sevanl } 37539d3e169Sevanl bcopy(&addr, nargs->addr, sizeof (struct netbuf)); 37639d3e169Sevanl 37739d3e169Sevanl /* 37839d3e169Sevanl * Get the root fhandle 37939d3e169Sevanl */ 38039d3e169Sevanl 38139d3e169Sevanl if (copyin(STRUCT_FGETP(args, fh), &fh->fh_buf, NFS_FHSIZE)) { 38239d3e169Sevanl error = EFAULT; 38339d3e169Sevanl goto errout; 38439d3e169Sevanl } 38539d3e169Sevanl fh->fh_len = NFS_FHSIZE; 38639d3e169Sevanl 38739d3e169Sevanl /* 38839d3e169Sevanl * Get server's hostname 38939d3e169Sevanl */ 39039d3e169Sevanl if (flags & NFSMNT_HOSTNAME) { 391*dcedb507SMarcel Telka error = copyinstr(STRUCT_FGETP(args, hostname), netname, 392*dcedb507SMarcel Telka sizeof (netname), &hlen); 39339d3e169Sevanl if (error) 39439d3e169Sevanl goto errout; 39539d3e169Sevanl nargs->hostname = kmem_zalloc(hlen, KM_SLEEP); 39639d3e169Sevanl (void) strcpy(nargs->hostname, netname); 39739d3e169Sevanl 39839d3e169Sevanl } else { 39939d3e169Sevanl nargs->hostname = NULL; 40039d3e169Sevanl } 40139d3e169Sevanl 40239d3e169Sevanl 40339d3e169Sevanl /* 40439d3e169Sevanl * If there are syncaddr and netname data, load them in. This is 40539d3e169Sevanl * to support data needed for NFSV4 when AUTH_DH is the negotiated 40639d3e169Sevanl * flavor via SECINFO. (instead of using MOUNT protocol in V3). 40739d3e169Sevanl */ 40839d3e169Sevanl netname[0] = '\0'; 40939d3e169Sevanl if (flags & NFSMNT_SECURE) { 41039d3e169Sevanl if (STRUCT_FGETP(args, syncaddr) == NULL) { 41139d3e169Sevanl error = EINVAL; 41239d3e169Sevanl goto errout; 41339d3e169Sevanl } 41439d3e169Sevanl /* get syncaddr */ 41539d3e169Sevanl STRUCT_INIT(addr_tmp, get_udatamodel()); 41639d3e169Sevanl if (copyin(STRUCT_FGETP(args, syncaddr), STRUCT_BUF(addr_tmp), 417*dcedb507SMarcel Telka STRUCT_SIZE(addr_tmp))) { 41839d3e169Sevanl error = EINVAL; 41939d3e169Sevanl goto errout; 42039d3e169Sevanl } 42139d3e169Sevanl userbufptr = STRUCT_FGETP(addr_tmp, buf); 42239d3e169Sevanl syncaddr.len = STRUCT_FGET(addr_tmp, len); 42339d3e169Sevanl syncaddr.buf = kmem_alloc(syncaddr.len, KM_SLEEP); 42439d3e169Sevanl syncaddr.maxlen = syncaddr.len; 42539d3e169Sevanl if (copyin(userbufptr, syncaddr.buf, syncaddr.len)) { 42639d3e169Sevanl kmem_free(syncaddr.buf, syncaddr.len); 42739d3e169Sevanl error = EFAULT; 42839d3e169Sevanl goto errout; 42939d3e169Sevanl } 43039d3e169Sevanl 43139d3e169Sevanl nargs->syncaddr = kmem_alloc(sizeof (struct netbuf), KM_SLEEP); 43239d3e169Sevanl bcopy(&syncaddr, nargs->syncaddr, sizeof (struct netbuf)); 43339d3e169Sevanl 43439d3e169Sevanl ASSERT(STRUCT_FGETP(args, netname)); 43539d3e169Sevanl if (copyinstr(STRUCT_FGETP(args, netname), netname, 436*dcedb507SMarcel Telka sizeof (netname), &nlen)) { 43739d3e169Sevanl error = EFAULT; 43839d3e169Sevanl goto errout; 43939d3e169Sevanl } 44039d3e169Sevanl 44139d3e169Sevanl netname[nlen] = '\0'; 44239d3e169Sevanl nargs->netname = kmem_zalloc(nlen, KM_SLEEP); 44339d3e169Sevanl (void) strcpy(nargs->netname, netname); 44439d3e169Sevanl } 44539d3e169Sevanl 44639d3e169Sevanl /* 44739d3e169Sevanl * Get the extention data which has the security data structure. 44839d3e169Sevanl * This includes data for AUTH_SYS as well. 44939d3e169Sevanl */ 45039d3e169Sevanl if (flags & NFSMNT_NEWARGS) { 45139d3e169Sevanl nargs->nfs_args_ext = STRUCT_FGET(args, nfs_args_ext); 45239d3e169Sevanl if (nargs->nfs_args_ext == NFS_ARGS_EXTA || 453*dcedb507SMarcel Telka nargs->nfs_args_ext == NFS_ARGS_EXTB) { 45439d3e169Sevanl /* 45539d3e169Sevanl * Indicating the application is using the new 45639d3e169Sevanl * sec_data structure to pass in the security 45739d3e169Sevanl * data. 45839d3e169Sevanl */ 45939d3e169Sevanl if (STRUCT_FGETP(args, 460*dcedb507SMarcel Telka nfs_ext_u.nfs_extA.secdata) != NULL) { 46139d3e169Sevanl error = sec_clnt_loadinfo( 462*dcedb507SMarcel Telka (struct sec_data *)STRUCT_FGETP(args, 463*dcedb507SMarcel Telka nfs_ext_u.nfs_extA.secdata), &secdata, 464*dcedb507SMarcel Telka get_udatamodel()); 46539d3e169Sevanl } 46639d3e169Sevanl nargs->nfs_ext_u.nfs_extA.secdata = secdata; 46739d3e169Sevanl } 46839d3e169Sevanl } 46939d3e169Sevanl 47039d3e169Sevanl if (error) 47139d3e169Sevanl goto errout; 47239d3e169Sevanl 47339d3e169Sevanl /* 47439d3e169Sevanl * Failover support: 47539d3e169Sevanl * 47639d3e169Sevanl * We may have a linked list of nfs_args structures, 47739d3e169Sevanl * which means the user is looking for failover. If 47839d3e169Sevanl * the mount is either not "read-only" or "soft", 47939d3e169Sevanl * we want to bail out with EINVAL. 48039d3e169Sevanl */ 48139d3e169Sevanl if (nargs->nfs_args_ext == NFS_ARGS_EXTB) 48239d3e169Sevanl nargs->nfs_ext_u.nfs_extB.next = 483*dcedb507SMarcel Telka STRUCT_FGETP(args, nfs_ext_u.nfs_extB.next); 48439d3e169Sevanl 48539d3e169Sevanl errout: 48639d3e169Sevanl if (error) 48739d3e169Sevanl nfs_free_args(nargs, fh); 48839d3e169Sevanl 48939d3e169Sevanl return (error); 49039d3e169Sevanl } 49139d3e169Sevanl 49239d3e169Sevanl 4937c478bd9Sstevel@tonic-gate /* 4947c478bd9Sstevel@tonic-gate * nfs mount vfsop 4957c478bd9Sstevel@tonic-gate * Set up mount info record and attach it to vfs struct. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate static int 4987c478bd9Sstevel@tonic-gate nfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate char *data = uap->dataptr; 5017c478bd9Sstevel@tonic-gate int error; 5027c478bd9Sstevel@tonic-gate vnode_t *rtvp; /* the server's root */ 5037c478bd9Sstevel@tonic-gate mntinfo_t *mi; /* mount info, pointed at by vfs */ 5047c478bd9Sstevel@tonic-gate size_t nlen; /* length of netname */ 5057c478bd9Sstevel@tonic-gate struct knetconfig *knconf; /* transport knetconfig structure */ 5067c478bd9Sstevel@tonic-gate struct knetconfig *rdma_knconf; /* rdma transport structure */ 5077c478bd9Sstevel@tonic-gate rnode_t *rp; 5087c478bd9Sstevel@tonic-gate struct servinfo *svp; /* nfs server info */ 5097c478bd9Sstevel@tonic-gate struct servinfo *svp_tail = NULL; /* previous nfs server info */ 5107c478bd9Sstevel@tonic-gate struct servinfo *svp_head; /* first nfs server info */ 5117c478bd9Sstevel@tonic-gate struct servinfo *svp_2ndlast; /* 2nd last in the server info list */ 5127c478bd9Sstevel@tonic-gate struct sec_data *secdata; /* security data */ 51339d3e169Sevanl struct nfs_args *args = NULL; 5147c478bd9Sstevel@tonic-gate int flags, addr_type; 515108322fbScarlsonj zone_t *zone = nfs_zone(); 51645916cd2Sjpk zone_t *mntzone = NULL; 51739d3e169Sevanl nfs_fhandle *fhandle = NULL; 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0) 5207c478bd9Sstevel@tonic-gate return (error); 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate if (mvp->v_type != VDIR) 5237c478bd9Sstevel@tonic-gate return (ENOTDIR); 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate /* 5267c478bd9Sstevel@tonic-gate * get arguments 5277c478bd9Sstevel@tonic-gate * 5287c478bd9Sstevel@tonic-gate * nfs_args is now versioned and is extensible, so 5297c478bd9Sstevel@tonic-gate * uap->datalen might be different from sizeof (args) 5307c478bd9Sstevel@tonic-gate * in a compatible situation. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate more: 5337c478bd9Sstevel@tonic-gate 53439d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) { 53539d3e169Sevanl if (args == NULL) 53639d3e169Sevanl args = kmem_alloc(sizeof (struct nfs_args), KM_SLEEP); 53739d3e169Sevanl else { 53839d3e169Sevanl nfs_free_args(args, fhandle); 53939d3e169Sevanl fhandle = NULL; 54039d3e169Sevanl } 54139d3e169Sevanl if (fhandle == NULL) 54239d3e169Sevanl fhandle = kmem_zalloc(sizeof (nfs_fhandle), KM_SLEEP); 54339d3e169Sevanl error = nfs_copyin(data, uap->datalen, args, fhandle); 54439d3e169Sevanl if (error) { 54539d3e169Sevanl if (args) 54639d3e169Sevanl kmem_free(args, sizeof (*args)); 54739d3e169Sevanl return (error); 54839d3e169Sevanl } 54939d3e169Sevanl } else { 55039d3e169Sevanl args = (struct nfs_args *)data; 55139d3e169Sevanl fhandle = (nfs_fhandle *)args->fh; 55239d3e169Sevanl } 55339d3e169Sevanl 55439d3e169Sevanl 55539d3e169Sevanl flags = args->flags; 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate if (uap->flags & MS_REMOUNT) { 5587c478bd9Sstevel@tonic-gate size_t n; 5597c478bd9Sstevel@tonic-gate char name[FSTYPSZ]; 5607c478bd9Sstevel@tonic-gate 56118b3347eSevanl if (uap->flags & MS_SYSSPACE) 5627c478bd9Sstevel@tonic-gate error = copystr(uap->fstype, name, FSTYPSZ, &n); 56318b3347eSevanl else 5647c478bd9Sstevel@tonic-gate error = copyinstr(uap->fstype, name, FSTYPSZ, &n); 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate if (error) { 5677c478bd9Sstevel@tonic-gate if (error == ENAMETOOLONG) 5687c478bd9Sstevel@tonic-gate return (EINVAL); 5697c478bd9Sstevel@tonic-gate return (error); 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 57239d3e169Sevanl 5737c478bd9Sstevel@tonic-gate /* 5747c478bd9Sstevel@tonic-gate * This check is to ensure that the request is a 5757c478bd9Sstevel@tonic-gate * genuine nfs remount request. 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate if (strncmp(name, "nfs", 3) != 0) 5797c478bd9Sstevel@tonic-gate return (EINVAL); 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * If the request changes the locking type, disallow the 5837c478bd9Sstevel@tonic-gate * remount, 5847c478bd9Sstevel@tonic-gate * because it's questionable whether we can transfer the 5857c478bd9Sstevel@tonic-gate * locking state correctly. 5867c478bd9Sstevel@tonic-gate * 5877c478bd9Sstevel@tonic-gate * Remounts need to save the pathconf information. 5887c478bd9Sstevel@tonic-gate * Part of the infamous static kludge. 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate if ((mi = VFTOMI(vfsp)) != NULL) { 5927c478bd9Sstevel@tonic-gate uint_t new_mi_llock; 5937c478bd9Sstevel@tonic-gate uint_t old_mi_llock; 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate new_mi_llock = (flags & NFSMNT_LLOCK) ? 1 : 0; 5967c478bd9Sstevel@tonic-gate old_mi_llock = (mi->mi_flags & MI_LLOCK) ? 1 : 0; 5977c478bd9Sstevel@tonic-gate if (old_mi_llock != new_mi_llock) 5987c478bd9Sstevel@tonic-gate return (EBUSY); 5997c478bd9Sstevel@tonic-gate } 60039d3e169Sevanl error = pathconf_get((struct mntinfo *)vfsp->vfs_data, args); 60139d3e169Sevanl 60218b3347eSevanl if (!(uap->flags & MS_SYSSPACE)) { 60318b3347eSevanl nfs_free_args(args, fhandle); 60418b3347eSevanl kmem_free(args, sizeof (*args)); 60518b3347eSevanl } 60618b3347eSevanl 60739d3e169Sevanl return (error); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate mutex_enter(&mvp->v_lock); 6117c478bd9Sstevel@tonic-gate if (!(uap->flags & MS_OVERLAY) && 6127c478bd9Sstevel@tonic-gate (mvp->v_count != 1 || (mvp->v_flag & VROOT))) { 6137c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 61418b3347eSevanl if (!(uap->flags & MS_SYSSPACE)) { 61539d3e169Sevanl nfs_free_args(args, fhandle); 61639d3e169Sevanl kmem_free(args, sizeof (*args)); 61739d3e169Sevanl } 6187c478bd9Sstevel@tonic-gate return (EBUSY); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate mutex_exit(&mvp->v_lock); 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate /* make sure things are zeroed for errout: */ 6237c478bd9Sstevel@tonic-gate rtvp = NULL; 6247c478bd9Sstevel@tonic-gate mi = NULL; 6257c478bd9Sstevel@tonic-gate secdata = NULL; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* 6287c478bd9Sstevel@tonic-gate * A valid knetconfig structure is required. 6297c478bd9Sstevel@tonic-gate */ 63039d3e169Sevanl if (!(flags & NFSMNT_KNCONF)) { 63139d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) { 63239d3e169Sevanl nfs_free_args(args, fhandle); 63339d3e169Sevanl kmem_free(args, sizeof (*args)); 63439d3e169Sevanl } 63539d3e169Sevanl return (EINVAL); 63639d3e169Sevanl } 63739d3e169Sevanl 63839d3e169Sevanl if ((strlen(args->knconf->knc_protofmly) >= KNC_STRSIZE) || 639*dcedb507SMarcel Telka (strlen(args->knconf->knc_proto) >= KNC_STRSIZE)) { 64039d3e169Sevanl if (!(uap->flags & MS_SYSSPACE)) { 64139d3e169Sevanl nfs_free_args(args, fhandle); 64239d3e169Sevanl kmem_free(args, sizeof (*args)); 64339d3e169Sevanl } 6447c478bd9Sstevel@tonic-gate return (EINVAL); 64539d3e169Sevanl } 64639d3e169Sevanl 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* 6497c478bd9Sstevel@tonic-gate * Allocate a servinfo struct. 6507c478bd9Sstevel@tonic-gate */ 6517c478bd9Sstevel@tonic-gate svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); 6527c478bd9Sstevel@tonic-gate mutex_init(&svp->sv_lock, NULL, MUTEX_DEFAULT, NULL); 6537c478bd9Sstevel@tonic-gate if (svp_tail) { 6547c478bd9Sstevel@tonic-gate svp_2ndlast = svp_tail; 6557c478bd9Sstevel@tonic-gate svp_tail->sv_next = svp; 6567c478bd9Sstevel@tonic-gate } else { 6577c478bd9Sstevel@tonic-gate svp_head = svp; 6587c478bd9Sstevel@tonic-gate svp_2ndlast = svp; 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate svp_tail = svp; 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 66439d3e169Sevanl * Get knetconfig and server address 6657c478bd9Sstevel@tonic-gate */ 66639d3e169Sevanl svp->sv_knconf = args->knconf; 66739d3e169Sevanl args->knconf = NULL; 6687c478bd9Sstevel@tonic-gate 66939d3e169Sevanl if (args->addr == NULL || args->addr->buf == NULL) { 67039d3e169Sevanl error = EINVAL; 67139d3e169Sevanl goto errout; 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 67439d3e169Sevanl svp->sv_addr.maxlen = args->addr->maxlen; 67539d3e169Sevanl svp->sv_addr.len = args->addr->len; 67639d3e169Sevanl svp->sv_addr.buf = args->addr->buf; 67739d3e169Sevanl args->addr->buf = NULL; 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate /* 6807c478bd9Sstevel@tonic-gate * Get the root fhandle 6817c478bd9Sstevel@tonic-gate */ 68239d3e169Sevanl ASSERT(fhandle); 68339d3e169Sevanl 68439d3e169Sevanl bcopy(&fhandle->fh_buf, &svp->sv_fhandle.fh_buf, fhandle->fh_len); 68539d3e169Sevanl svp->sv_fhandle.fh_len = fhandle->fh_len; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate /* 6887c478bd9Sstevel@tonic-gate * Get server's hostname 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate if (flags & NFSMNT_HOSTNAME) { 69139d3e169Sevanl if (args->hostname == NULL) { 69239d3e169Sevanl error = EINVAL; 6937c478bd9Sstevel@tonic-gate goto errout; 69439d3e169Sevanl } 69539d3e169Sevanl svp->sv_hostnamelen = strlen(args->hostname) + 1; 69639d3e169Sevanl svp->sv_hostname = args->hostname; 69739d3e169Sevanl args->hostname = NULL; 6987c478bd9Sstevel@tonic-gate } else { 6997c478bd9Sstevel@tonic-gate char *p = "unknown-host"; 70039d3e169Sevanl svp->sv_hostnamelen = strlen(p) + 1; 70139d3e169Sevanl svp->sv_hostname = kmem_zalloc(svp->sv_hostnamelen, KM_SLEEP); 70239d3e169Sevanl (void) strcpy(svp->sv_hostname, p); 7037c478bd9Sstevel@tonic-gate } 70439d3e169Sevanl 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * RDMA MOUNT SUPPORT FOR NFS v2: 7087c478bd9Sstevel@tonic-gate * Establish, is it possible to use RDMA, if so overload the 7097c478bd9Sstevel@tonic-gate * knconf with rdma specific knconf and free the orignal. 7107c478bd9Sstevel@tonic-gate */ 7117c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_TRYRDMA) || (flags & NFSMNT_DORDMA)) { 7127c478bd9Sstevel@tonic-gate /* 7137c478bd9Sstevel@tonic-gate * Determine the addr type for RDMA, IPv4 or v6. 7147c478bd9Sstevel@tonic-gate */ 7157c478bd9Sstevel@tonic-gate if (strcmp(svp->sv_knconf->knc_protofmly, NC_INET) == 0) 7167c478bd9Sstevel@tonic-gate addr_type = AF_INET; 7177c478bd9Sstevel@tonic-gate else if (strcmp(svp->sv_knconf->knc_protofmly, NC_INET6) == 0) 7187c478bd9Sstevel@tonic-gate addr_type = AF_INET6; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate if (rdma_reachable(addr_type, &svp->sv_addr, 721*dcedb507SMarcel Telka &rdma_knconf) == 0) { 7227c478bd9Sstevel@tonic-gate /* 7237c478bd9Sstevel@tonic-gate * If successful, hijack, the orignal knconf and 7247c478bd9Sstevel@tonic-gate * replace with a new one, depending on the flags. 7257c478bd9Sstevel@tonic-gate */ 7267c478bd9Sstevel@tonic-gate svp->sv_origknconf = svp->sv_knconf; 7277c478bd9Sstevel@tonic-gate svp->sv_knconf = rdma_knconf; 7287c478bd9Sstevel@tonic-gate knconf = rdma_knconf; 7297c478bd9Sstevel@tonic-gate } else { 7307c478bd9Sstevel@tonic-gate if (flags & NFSMNT_TRYRDMA) { 7317c478bd9Sstevel@tonic-gate #ifdef DEBUG 7327c478bd9Sstevel@tonic-gate if (rdma_debug) 7337c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), CE_WARN, 7347c478bd9Sstevel@tonic-gate "no RDMA onboard, revert\n"); 7357c478bd9Sstevel@tonic-gate #endif 7367c478bd9Sstevel@tonic-gate } 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate if (flags & NFSMNT_DORDMA) { 7397c478bd9Sstevel@tonic-gate /* 7407c478bd9Sstevel@tonic-gate * If proto=rdma is specified and no RDMA 7417c478bd9Sstevel@tonic-gate * path to this server is avialable then 7427c478bd9Sstevel@tonic-gate * ditch this server. 7437c478bd9Sstevel@tonic-gate * This is not included in the mountable 7447c478bd9Sstevel@tonic-gate * server list or the replica list. 7457c478bd9Sstevel@tonic-gate * Check if more servers are specified; 7467c478bd9Sstevel@tonic-gate * Failover case, otherwise bail out of mount. 7477c478bd9Sstevel@tonic-gate */ 748*dcedb507SMarcel Telka if (args->nfs_args_ext == NFS_ARGS_EXTB && 749*dcedb507SMarcel Telka args->nfs_ext_u.nfs_extB.next != NULL) { 75039d3e169Sevanl data = (char *) 751*dcedb507SMarcel Telka args->nfs_ext_u.nfs_extB.next; 7527c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY && 7537c478bd9Sstevel@tonic-gate !(flags & NFSMNT_SOFT)) { 7547c478bd9Sstevel@tonic-gate if (svp_head->sv_next == NULL) { 7557c478bd9Sstevel@tonic-gate svp_tail = NULL; 7567c478bd9Sstevel@tonic-gate svp_2ndlast = NULL; 7577c478bd9Sstevel@tonic-gate sv_free(svp_head); 7587c478bd9Sstevel@tonic-gate goto more; 7597c478bd9Sstevel@tonic-gate } else { 7607c478bd9Sstevel@tonic-gate svp_tail = svp_2ndlast; 7617c478bd9Sstevel@tonic-gate svp_2ndlast->sv_next = 7627c478bd9Sstevel@tonic-gate NULL; 7637c478bd9Sstevel@tonic-gate sv_free(svp); 7647c478bd9Sstevel@tonic-gate goto more; 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate } else { 7687c478bd9Sstevel@tonic-gate /* 7697c478bd9Sstevel@tonic-gate * This is the last server specified 7707c478bd9Sstevel@tonic-gate * in the nfs_args list passed down 7717c478bd9Sstevel@tonic-gate * and its not rdma capable. 7727c478bd9Sstevel@tonic-gate */ 7737c478bd9Sstevel@tonic-gate if (svp_head->sv_next == NULL) { 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * Is this the only one 7767c478bd9Sstevel@tonic-gate */ 7777c478bd9Sstevel@tonic-gate error = EINVAL; 7787c478bd9Sstevel@tonic-gate #ifdef DEBUG 7797c478bd9Sstevel@tonic-gate if (rdma_debug) 7807c478bd9Sstevel@tonic-gate zcmn_err(getzoneid(), 7817c478bd9Sstevel@tonic-gate CE_WARN, 7827c478bd9Sstevel@tonic-gate "No RDMA srv"); 7837c478bd9Sstevel@tonic-gate #endif 7847c478bd9Sstevel@tonic-gate goto errout; 7857c478bd9Sstevel@tonic-gate } else { 7867c478bd9Sstevel@tonic-gate /* 7877c478bd9Sstevel@tonic-gate * There is list, since some 7887c478bd9Sstevel@tonic-gate * servers specified before 7897c478bd9Sstevel@tonic-gate * this passed all requirements 7907c478bd9Sstevel@tonic-gate */ 7917c478bd9Sstevel@tonic-gate svp_tail = svp_2ndlast; 7927c478bd9Sstevel@tonic-gate svp_2ndlast->sv_next = NULL; 7937c478bd9Sstevel@tonic-gate sv_free(svp); 7947c478bd9Sstevel@tonic-gate goto proceed; 7957c478bd9Sstevel@tonic-gate } 7967c478bd9Sstevel@tonic-gate } 7977c478bd9Sstevel@tonic-gate } 7987c478bd9Sstevel@tonic-gate } 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate /* 8027c478bd9Sstevel@tonic-gate * Get the extention data which has the new security data structure. 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate if (flags & NFSMNT_NEWARGS) { 80539d3e169Sevanl switch (args->nfs_args_ext) { 8067c478bd9Sstevel@tonic-gate case NFS_ARGS_EXTA: 8077c478bd9Sstevel@tonic-gate case NFS_ARGS_EXTB: 8087c478bd9Sstevel@tonic-gate /* 8097c478bd9Sstevel@tonic-gate * Indicating the application is using the new 8107c478bd9Sstevel@tonic-gate * sec_data structure to pass in the security 8117c478bd9Sstevel@tonic-gate * data. 8127c478bd9Sstevel@tonic-gate */ 81339d3e169Sevanl secdata = args->nfs_ext_u.nfs_extA.secdata; 81439d3e169Sevanl if (secdata == NULL) { 8157c478bd9Sstevel@tonic-gate error = EINVAL; 8167c478bd9Sstevel@tonic-gate } else { 81739d3e169Sevanl /* 81839d3e169Sevanl * Need to validate the flavor here if 81939d3e169Sevanl * sysspace, userspace was already 82039d3e169Sevanl * validate from the nfs_copyin function. 82139d3e169Sevanl */ 82239d3e169Sevanl switch (secdata->rpcflavor) { 82339d3e169Sevanl case AUTH_NONE: 82439d3e169Sevanl case AUTH_UNIX: 82539d3e169Sevanl case AUTH_LOOPBACK: 82639d3e169Sevanl case AUTH_DES: 82739d3e169Sevanl case RPCSEC_GSS: 82839d3e169Sevanl break; 82939d3e169Sevanl default: 83039d3e169Sevanl error = EINVAL; 83139d3e169Sevanl goto errout; 83239d3e169Sevanl } 8337c478bd9Sstevel@tonic-gate } 83439d3e169Sevanl args->nfs_ext_u.nfs_extA.secdata = NULL; 8357c478bd9Sstevel@tonic-gate break; 8367c478bd9Sstevel@tonic-gate 8377c478bd9Sstevel@tonic-gate default: 8387c478bd9Sstevel@tonic-gate error = EINVAL; 8397c478bd9Sstevel@tonic-gate break; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate } else if (flags & NFSMNT_SECURE) { 8427c478bd9Sstevel@tonic-gate /* 8437c478bd9Sstevel@tonic-gate * Keep this for backward compatibility to support 8447c478bd9Sstevel@tonic-gate * NFSMNT_SECURE/NFSMNT_RPCTIMESYNC flags. 8457c478bd9Sstevel@tonic-gate */ 84639d3e169Sevanl if (args->syncaddr == NULL || args->syncaddr->buf == NULL) { 8477c478bd9Sstevel@tonic-gate error = EINVAL; 84839d3e169Sevanl goto errout; 84939d3e169Sevanl } 8507c478bd9Sstevel@tonic-gate 85139d3e169Sevanl /* 85239d3e169Sevanl * get time sync address. 85339d3e169Sevanl */ 85439d3e169Sevanl if (args->syncaddr == NULL) { 85539d3e169Sevanl error = EFAULT; 85639d3e169Sevanl goto errout; 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * Move security related data to the sec_data structure. 8617c478bd9Sstevel@tonic-gate */ 86239d3e169Sevanl { 8637c478bd9Sstevel@tonic-gate dh_k4_clntdata_t *data; 8647c478bd9Sstevel@tonic-gate char *pf, *p; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate secdata = kmem_alloc(sizeof (*secdata), KM_SLEEP); 8677c478bd9Sstevel@tonic-gate if (flags & NFSMNT_RPCTIMESYNC) 8687c478bd9Sstevel@tonic-gate secdata->flags |= AUTH_F_RPCTIMESYNC; 8697c478bd9Sstevel@tonic-gate data = kmem_alloc(sizeof (*data), KM_SLEEP); 87039d3e169Sevanl bcopy(args->syncaddr, &data->syncaddr, 871*dcedb507SMarcel Telka sizeof (*args->syncaddr)); 87239d3e169Sevanl 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate /* 8757c478bd9Sstevel@tonic-gate * duplicate the knconf information for the 8767c478bd9Sstevel@tonic-gate * new opaque data. 8777c478bd9Sstevel@tonic-gate */ 8787c478bd9Sstevel@tonic-gate data->knconf = kmem_alloc(sizeof (*knconf), KM_SLEEP); 8797c478bd9Sstevel@tonic-gate *data->knconf = *knconf; 8807c478bd9Sstevel@tonic-gate pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 8817c478bd9Sstevel@tonic-gate p = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 8827c478bd9Sstevel@tonic-gate bcopy(knconf->knc_protofmly, pf, KNC_STRSIZE); 8837c478bd9Sstevel@tonic-gate bcopy(knconf->knc_proto, pf, KNC_STRSIZE); 8847c478bd9Sstevel@tonic-gate data->knconf->knc_protofmly = pf; 8857c478bd9Sstevel@tonic-gate data->knconf->knc_proto = p; 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate /* move server netname to the sec_data structure */ 88839d3e169Sevanl nlen = strlen(args->hostname) + 1; 8897c478bd9Sstevel@tonic-gate if (nlen != 0) { 8907c478bd9Sstevel@tonic-gate data->netname = kmem_alloc(nlen, KM_SLEEP); 89139d3e169Sevanl bcopy(args->hostname, data->netname, nlen); 8927c478bd9Sstevel@tonic-gate data->netnamelen = (int)nlen; 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate secdata->secmod = secdata->rpcflavor = AUTH_DES; 8957c478bd9Sstevel@tonic-gate secdata->data = (caddr_t)data; 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate } else { 8987c478bd9Sstevel@tonic-gate secdata = kmem_alloc(sizeof (*secdata), KM_SLEEP); 8997c478bd9Sstevel@tonic-gate secdata->secmod = secdata->rpcflavor = AUTH_UNIX; 9007c478bd9Sstevel@tonic-gate secdata->data = NULL; 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate svp->sv_secdata = secdata; 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate /* 9057c478bd9Sstevel@tonic-gate * See bug 1180236. 9067c478bd9Sstevel@tonic-gate * If mount secure failed, we will fall back to AUTH_NONE 9077c478bd9Sstevel@tonic-gate * and try again. nfs3rootvp() will turn this back off. 9087c478bd9Sstevel@tonic-gate * 9097c478bd9Sstevel@tonic-gate * The NFS Version 2 mount uses GETATTR and STATFS procedures. 9107c478bd9Sstevel@tonic-gate * The server does not care if these procedures have the proper 9117c478bd9Sstevel@tonic-gate * authentication flavor, so if mount retries using AUTH_NONE 9127c478bd9Sstevel@tonic-gate * that does not require a credential setup for root then the 9137c478bd9Sstevel@tonic-gate * automounter would work without requiring root to be 9147c478bd9Sstevel@tonic-gate * keylogged into AUTH_DES. 9157c478bd9Sstevel@tonic-gate */ 9167c478bd9Sstevel@tonic-gate if (secdata->rpcflavor != AUTH_UNIX && 9177c478bd9Sstevel@tonic-gate secdata->rpcflavor != AUTH_LOOPBACK) 9187c478bd9Sstevel@tonic-gate secdata->flags |= AUTH_F_TRYNONE; 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate /* 9217c478bd9Sstevel@tonic-gate * Failover support: 9227c478bd9Sstevel@tonic-gate * 9237c478bd9Sstevel@tonic-gate * We may have a linked list of nfs_args structures, 9247c478bd9Sstevel@tonic-gate * which means the user is looking for failover. If 9257c478bd9Sstevel@tonic-gate * the mount is either not "read-only" or "soft", 9267c478bd9Sstevel@tonic-gate * we want to bail out with EINVAL. 9277c478bd9Sstevel@tonic-gate */ 92839d3e169Sevanl if (args->nfs_args_ext == NFS_ARGS_EXTB && 92939d3e169Sevanl args->nfs_ext_u.nfs_extB.next != NULL) { 9307c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY && !(flags & NFSMNT_SOFT)) { 93139d3e169Sevanl data = (char *)args->nfs_ext_u.nfs_extB.next; 9327c478bd9Sstevel@tonic-gate goto more; 9337c478bd9Sstevel@tonic-gate } 9347c478bd9Sstevel@tonic-gate error = EINVAL; 9357c478bd9Sstevel@tonic-gate goto errout; 9367c478bd9Sstevel@tonic-gate } 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate /* 9397c478bd9Sstevel@tonic-gate * Determine the zone we're being mounted into. 9407c478bd9Sstevel@tonic-gate */ 94145916cd2Sjpk zone_hold(mntzone = zone); /* start with this assumption */ 9427c478bd9Sstevel@tonic-gate if (getzoneid() == GLOBAL_ZONEID) { 94345916cd2Sjpk zone_rele(mntzone); 9447c478bd9Sstevel@tonic-gate mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt)); 9457c478bd9Sstevel@tonic-gate ASSERT(mntzone != NULL); 9467c478bd9Sstevel@tonic-gate if (mntzone != zone) { 9477c478bd9Sstevel@tonic-gate error = EBUSY; 9487c478bd9Sstevel@tonic-gate goto errout; 9497c478bd9Sstevel@tonic-gate } 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate 95245916cd2Sjpk if (is_system_labeled()) { 95345916cd2Sjpk error = nfs_mount_label_policy(vfsp, &svp->sv_addr, 95445916cd2Sjpk svp->sv_knconf, cr); 95545916cd2Sjpk 95645916cd2Sjpk if (error > 0) 95745916cd2Sjpk goto errout; 95845916cd2Sjpk 95945916cd2Sjpk if (error == -1) { 96045916cd2Sjpk /* change mount to read-only to prevent write-down */ 96145916cd2Sjpk vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0); 96245916cd2Sjpk } 96345916cd2Sjpk } 96445916cd2Sjpk 9657c478bd9Sstevel@tonic-gate /* 9667c478bd9Sstevel@tonic-gate * Stop the mount from going any further if the zone is going away. 9677c478bd9Sstevel@tonic-gate */ 96845916cd2Sjpk if (zone_status_get(mntzone) >= ZONE_IS_SHUTTING_DOWN) { 9697c478bd9Sstevel@tonic-gate error = EBUSY; 9707c478bd9Sstevel@tonic-gate goto errout; 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * Get root vnode. 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate proceed: 97745916cd2Sjpk error = nfsrootvp(&rtvp, vfsp, svp_head, flags, cr, mntzone); 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate if (error) 9807c478bd9Sstevel@tonic-gate goto errout; 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate /* 9837c478bd9Sstevel@tonic-gate * Set option fields in the mount info record 9847c478bd9Sstevel@tonic-gate */ 9857c478bd9Sstevel@tonic-gate mi = VTOMI(rtvp); 9867c478bd9Sstevel@tonic-gate 9877c478bd9Sstevel@tonic-gate if (svp_head->sv_next) 9887c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_LLOCK; 9897c478bd9Sstevel@tonic-gate 99039d3e169Sevanl error = nfs_setopts(rtvp, DATAMODEL_NATIVE, args); 9917c478bd9Sstevel@tonic-gate if (!error) { 9927c478bd9Sstevel@tonic-gate /* static pathconf kludge */ 99339d3e169Sevanl error = pathconf_get(mi, args); 9947c478bd9Sstevel@tonic-gate } 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate errout: 997*dcedb507SMarcel Telka if (rtvp != NULL) { 998*dcedb507SMarcel Telka if (error) { 9997c478bd9Sstevel@tonic-gate rp = VTOR(rtvp); 10007c478bd9Sstevel@tonic-gate if (rp->r_flags & RHASHED) 10017c478bd9Sstevel@tonic-gate rp_rmhash(rp); 10027c478bd9Sstevel@tonic-gate } 1003*dcedb507SMarcel Telka VN_RELE(rtvp); 1004*dcedb507SMarcel Telka } 1005*dcedb507SMarcel Telka 1006*dcedb507SMarcel Telka if (error) { 10077c478bd9Sstevel@tonic-gate sv_free(svp_head); 10087c478bd9Sstevel@tonic-gate if (mi != NULL) { 10097c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp); 10107c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp); 10117c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) { 10127c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats); 10137c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL; 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) { 10167c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats); 10177c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL; 10187c478bd9Sstevel@tonic-gate } 10197c478bd9Sstevel@tonic-gate nfs_free_mi(mi); 10207c478bd9Sstevel@tonic-gate } 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate 102318b3347eSevanl if (!(uap->flags & MS_SYSSPACE)) { 102439d3e169Sevanl nfs_free_args(args, fhandle); 102539d3e169Sevanl kmem_free(args, sizeof (*args)); 102639d3e169Sevanl } 102739d3e169Sevanl 102845916cd2Sjpk if (mntzone != NULL) 102945916cd2Sjpk zone_rele(mntzone); 103045916cd2Sjpk 10317c478bd9Sstevel@tonic-gate return (error); 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate /* 10357c478bd9Sstevel@tonic-gate * The pathconf information is kept on a linked list of kmem_alloc'ed 10367c478bd9Sstevel@tonic-gate * structs. We search the list & add a new struct iff there is no other 10377c478bd9Sstevel@tonic-gate * struct with the same information. 10387c478bd9Sstevel@tonic-gate * See sys/pathconf.h for ``the rest of the story.'' 10397c478bd9Sstevel@tonic-gate */ 10407c478bd9Sstevel@tonic-gate static struct pathcnf *allpc = NULL; 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate static int 104339d3e169Sevanl pathconf_copyin(struct nfs_args *args, struct pathcnf *pc) 10447c478bd9Sstevel@tonic-gate { 10457c478bd9Sstevel@tonic-gate STRUCT_DECL(pathcnf, pc_tmp); 10467c478bd9Sstevel@tonic-gate STRUCT_HANDLE(nfs_args, ap); 10477c478bd9Sstevel@tonic-gate int i; 104839d3e169Sevanl model_t model; 10497c478bd9Sstevel@tonic-gate 105039d3e169Sevanl model = get_udatamodel(); 10517c478bd9Sstevel@tonic-gate STRUCT_INIT(pc_tmp, model); 10527c478bd9Sstevel@tonic-gate STRUCT_SET_HANDLE(ap, model, args); 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate if ((STRUCT_FGET(ap, flags) & NFSMNT_POSIX) && 10557c478bd9Sstevel@tonic-gate STRUCT_FGETP(ap, pathconf) != NULL) { 10567c478bd9Sstevel@tonic-gate if (copyin(STRUCT_FGETP(ap, pathconf), STRUCT_BUF(pc_tmp), 10577c478bd9Sstevel@tonic-gate STRUCT_SIZE(pc_tmp))) 10587c478bd9Sstevel@tonic-gate return (EFAULT); 10597c478bd9Sstevel@tonic-gate if (_PC_ISSET(_PC_ERROR, STRUCT_FGET(pc_tmp, pc_mask))) 10607c478bd9Sstevel@tonic-gate return (EINVAL); 10617c478bd9Sstevel@tonic-gate 106239d3e169Sevanl pc->pc_link_max = STRUCT_FGET(pc_tmp, pc_link_max); 106339d3e169Sevanl pc->pc_max_canon = STRUCT_FGET(pc_tmp, pc_max_canon); 106439d3e169Sevanl pc->pc_max_input = STRUCT_FGET(pc_tmp, pc_max_input); 106539d3e169Sevanl pc->pc_name_max = STRUCT_FGET(pc_tmp, pc_name_max); 106639d3e169Sevanl pc->pc_path_max = STRUCT_FGET(pc_tmp, pc_path_max); 106739d3e169Sevanl pc->pc_pipe_buf = STRUCT_FGET(pc_tmp, pc_pipe_buf); 106839d3e169Sevanl pc->pc_vdisable = STRUCT_FGET(pc_tmp, pc_vdisable); 106939d3e169Sevanl pc->pc_xxx = STRUCT_FGET(pc_tmp, pc_xxx); 10707c478bd9Sstevel@tonic-gate for (i = 0; i < _PC_N; i++) 107139d3e169Sevanl pc->pc_mask[i] = STRUCT_FGET(pc_tmp, pc_mask[i]); 107239d3e169Sevanl } 107339d3e169Sevanl return (0); 107439d3e169Sevanl } 107539d3e169Sevanl 107639d3e169Sevanl static int 107739d3e169Sevanl pathconf_get(struct mntinfo *mi, struct nfs_args *args) 107839d3e169Sevanl { 107939d3e169Sevanl struct pathcnf *p, *pc; 108039d3e169Sevanl 108139d3e169Sevanl pc = args->pathconf; 108239d3e169Sevanl if (mi->mi_pathconf != NULL) { 108339d3e169Sevanl pathconf_rele(mi); 108439d3e169Sevanl mi->mi_pathconf = NULL; 108539d3e169Sevanl } 108639d3e169Sevanl 1087*dcedb507SMarcel Telka if (args->flags & NFSMNT_POSIX && args->pathconf != NULL) { 108839d3e169Sevanl if (_PC_ISSET(_PC_ERROR, pc->pc_mask)) 108939d3e169Sevanl return (EINVAL); 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate for (p = allpc; p != NULL; p = p->pc_next) { 109239d3e169Sevanl if (PCCMP(p, pc) == 0) 10937c478bd9Sstevel@tonic-gate break; 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate if (p != NULL) { 10967c478bd9Sstevel@tonic-gate mi->mi_pathconf = p; 10977c478bd9Sstevel@tonic-gate p->pc_refcnt++; 10987c478bd9Sstevel@tonic-gate } else { 10997c478bd9Sstevel@tonic-gate p = kmem_alloc(sizeof (*p), KM_SLEEP); 110039d3e169Sevanl bcopy(pc, p, sizeof (struct pathcnf)); 11017c478bd9Sstevel@tonic-gate p->pc_next = allpc; 11027c478bd9Sstevel@tonic-gate p->pc_refcnt = 1; 11037c478bd9Sstevel@tonic-gate allpc = mi->mi_pathconf = p; 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate } 11067c478bd9Sstevel@tonic-gate return (0); 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate /* 11107c478bd9Sstevel@tonic-gate * release the static pathconf information 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate static void 11137c478bd9Sstevel@tonic-gate pathconf_rele(struct mntinfo *mi) 11147c478bd9Sstevel@tonic-gate { 11157c478bd9Sstevel@tonic-gate if (mi->mi_pathconf != NULL) { 11167c478bd9Sstevel@tonic-gate if (--mi->mi_pathconf->pc_refcnt == 0) { 11177c478bd9Sstevel@tonic-gate struct pathcnf *p; 11187c478bd9Sstevel@tonic-gate struct pathcnf *p2; 11197c478bd9Sstevel@tonic-gate 11207c478bd9Sstevel@tonic-gate p2 = p = allpc; 11217c478bd9Sstevel@tonic-gate while (p != NULL && p != mi->mi_pathconf) { 11227c478bd9Sstevel@tonic-gate p2 = p; 11237c478bd9Sstevel@tonic-gate p = p->pc_next; 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate if (p == NULL) { 11267c478bd9Sstevel@tonic-gate panic("mi->pathconf"); 11277c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 11287c478bd9Sstevel@tonic-gate } 11297c478bd9Sstevel@tonic-gate if (p == allpc) 11307c478bd9Sstevel@tonic-gate allpc = p->pc_next; 11317c478bd9Sstevel@tonic-gate else 11327c478bd9Sstevel@tonic-gate p2->pc_next = p->pc_next; 11337c478bd9Sstevel@tonic-gate kmem_free(p, sizeof (*p)); 11347c478bd9Sstevel@tonic-gate mi->mi_pathconf = NULL; 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate } 11377c478bd9Sstevel@tonic-gate } 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate static int nfs_dynamic = 1; /* global variable to enable dynamic retrans. */ 11407c478bd9Sstevel@tonic-gate static ushort_t nfs_max_threads = 8; /* max number of active async threads */ 11417c478bd9Sstevel@tonic-gate static uint_t nfs_async_clusters = 1; /* # of reqs from each async queue */ 11427c478bd9Sstevel@tonic-gate static uint_t nfs_cots_timeo = NFS_COTS_TIMEO; 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate static int 11457c478bd9Sstevel@tonic-gate nfsrootvp(vnode_t **rtvpp, vfs_t *vfsp, struct servinfo *svp, 11467c478bd9Sstevel@tonic-gate int flags, cred_t *cr, zone_t *zone) 11477c478bd9Sstevel@tonic-gate { 11487c478bd9Sstevel@tonic-gate vnode_t *rtvp; 11497c478bd9Sstevel@tonic-gate mntinfo_t *mi; 11507c478bd9Sstevel@tonic-gate dev_t nfs_dev; 11517c478bd9Sstevel@tonic-gate struct vattr va; 11527c478bd9Sstevel@tonic-gate int error; 11537c478bd9Sstevel@tonic-gate rnode_t *rp; 11547c478bd9Sstevel@tonic-gate int i; 11557c478bd9Sstevel@tonic-gate struct nfs_stats *nfsstatsp; 11567c478bd9Sstevel@tonic-gate cred_t *lcr = NULL, *tcr = cr; 11577c478bd9Sstevel@tonic-gate 1158108322fbScarlsonj nfsstatsp = zone_getspecific(nfsstat_zone_key, nfs_zone()); 11597c478bd9Sstevel@tonic-gate ASSERT(nfsstatsp != NULL); 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate /* 11627c478bd9Sstevel@tonic-gate * Create a mount record and link it to the vfs struct. 11637c478bd9Sstevel@tonic-gate */ 11647c478bd9Sstevel@tonic-gate mi = kmem_zalloc(sizeof (*mi), KM_SLEEP); 11657c478bd9Sstevel@tonic-gate mutex_init(&mi->mi_lock, NULL, MUTEX_DEFAULT, NULL); 1166e8dc3b7dSvv mutex_init(&mi->mi_remap_lock, NULL, MUTEX_DEFAULT, NULL); 11677c478bd9Sstevel@tonic-gate mi->mi_flags = MI_ACL | MI_EXTATTR; 11687c478bd9Sstevel@tonic-gate if (!(flags & NFSMNT_SOFT)) 11697c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_HARD; 11707c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_SEMISOFT)) 11717c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_SEMISOFT; 11727c478bd9Sstevel@tonic-gate if ((flags & NFSMNT_NOPRINT)) 11737c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_NOPRINT; 11747c478bd9Sstevel@tonic-gate if (flags & NFSMNT_INT) 11757c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_INT; 11767c478bd9Sstevel@tonic-gate mi->mi_retrans = NFS_RETRIES; 11777c478bd9Sstevel@tonic-gate if (svp->sv_knconf->knc_semantics == NC_TPI_COTS_ORD || 11787c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_semantics == NC_TPI_COTS) 11797c478bd9Sstevel@tonic-gate mi->mi_timeo = nfs_cots_timeo; 11807c478bd9Sstevel@tonic-gate else 11817c478bd9Sstevel@tonic-gate mi->mi_timeo = NFS_TIMEO; 11827c478bd9Sstevel@tonic-gate mi->mi_prog = NFS_PROGRAM; 11837c478bd9Sstevel@tonic-gate mi->mi_vers = NFS_VERSION; 11847c478bd9Sstevel@tonic-gate mi->mi_rfsnames = rfsnames_v2; 11857c478bd9Sstevel@tonic-gate mi->mi_reqs = nfsstatsp->nfs_stats_v2.rfsreqcnt_ptr; 11867c478bd9Sstevel@tonic-gate mi->mi_call_type = call_type_v2; 11877c478bd9Sstevel@tonic-gate mi->mi_ss_call_type = ss_call_type_v2; 11887c478bd9Sstevel@tonic-gate mi->mi_timer_type = timer_type_v2; 11897c478bd9Sstevel@tonic-gate mi->mi_aclnames = aclnames_v2; 11907c478bd9Sstevel@tonic-gate mi->mi_aclreqs = nfsstatsp->nfs_stats_v2.aclreqcnt_ptr; 11917c478bd9Sstevel@tonic-gate mi->mi_acl_call_type = acl_call_type_v2; 11927c478bd9Sstevel@tonic-gate mi->mi_acl_ss_call_type = acl_ss_call_type_v2; 11937c478bd9Sstevel@tonic-gate mi->mi_acl_timer_type = acl_timer_type_v2; 11947c478bd9Sstevel@tonic-gate cv_init(&mi->mi_failover_cv, NULL, CV_DEFAULT, NULL); 11957c478bd9Sstevel@tonic-gate mi->mi_servers = svp; 11967c478bd9Sstevel@tonic-gate mi->mi_curr_serv = svp; 11977c478bd9Sstevel@tonic-gate mi->mi_acregmin = SEC2HR(ACREGMIN); 11987c478bd9Sstevel@tonic-gate mi->mi_acregmax = SEC2HR(ACREGMAX); 11997c478bd9Sstevel@tonic-gate mi->mi_acdirmin = SEC2HR(ACDIRMIN); 12007c478bd9Sstevel@tonic-gate mi->mi_acdirmax = SEC2HR(ACDIRMAX); 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate if (nfs_dynamic) 12037c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_DYNAMIC; 12047c478bd9Sstevel@tonic-gate 12057c478bd9Sstevel@tonic-gate if (flags & NFSMNT_DIRECTIO) 12067c478bd9Sstevel@tonic-gate mi->mi_flags |= MI_DIRECTIO; 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate /* 12097c478bd9Sstevel@tonic-gate * Make a vfs struct for nfs. We do this here instead of below 12107c478bd9Sstevel@tonic-gate * because rtvp needs a vfs before we can do a getattr on it. 12117c478bd9Sstevel@tonic-gate * 12127c478bd9Sstevel@tonic-gate * Assign a unique device id to the mount 12137c478bd9Sstevel@tonic-gate */ 12147c478bd9Sstevel@tonic-gate mutex_enter(&nfs_minor_lock); 12157c478bd9Sstevel@tonic-gate do { 12167c478bd9Sstevel@tonic-gate nfs_minor = (nfs_minor + 1) & MAXMIN32; 12177c478bd9Sstevel@tonic-gate nfs_dev = makedevice(nfs_major, nfs_minor); 12187c478bd9Sstevel@tonic-gate } while (vfs_devismounted(nfs_dev)); 12197c478bd9Sstevel@tonic-gate mutex_exit(&nfs_minor_lock); 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate vfsp->vfs_dev = nfs_dev; 12227c478bd9Sstevel@tonic-gate vfs_make_fsid(&vfsp->vfs_fsid, nfs_dev, nfsfstyp); 12237c478bd9Sstevel@tonic-gate vfsp->vfs_data = (caddr_t)mi; 12247c478bd9Sstevel@tonic-gate vfsp->vfs_fstype = nfsfstyp; 12257c478bd9Sstevel@tonic-gate vfsp->vfs_bsize = NFS_MAXDATA; 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate /* 12287c478bd9Sstevel@tonic-gate * Initialize fields used to support async putpage operations. 12297c478bd9Sstevel@tonic-gate */ 12307c478bd9Sstevel@tonic-gate for (i = 0; i < NFS_ASYNC_TYPES; i++) 12317c478bd9Sstevel@tonic-gate mi->mi_async_clusters[i] = nfs_async_clusters; 12327c478bd9Sstevel@tonic-gate mi->mi_async_init_clusters = nfs_async_clusters; 12337c478bd9Sstevel@tonic-gate mi->mi_async_curr = &mi->mi_async_reqs[0]; 12347c478bd9Sstevel@tonic-gate mi->mi_max_threads = nfs_max_threads; 12357c478bd9Sstevel@tonic-gate mutex_init(&mi->mi_async_lock, NULL, MUTEX_DEFAULT, NULL); 12367c478bd9Sstevel@tonic-gate cv_init(&mi->mi_async_reqs_cv, NULL, CV_DEFAULT, NULL); 12377c478bd9Sstevel@tonic-gate cv_init(&mi->mi_async_work_cv, NULL, CV_DEFAULT, NULL); 12387c478bd9Sstevel@tonic-gate cv_init(&mi->mi_async_cv, NULL, CV_DEFAULT, NULL); 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate mi->mi_vfsp = vfsp; 12417c478bd9Sstevel@tonic-gate zone_hold(mi->mi_zone = zone); 12427c478bd9Sstevel@tonic-gate nfs_mi_zonelist_add(mi); 12437c478bd9Sstevel@tonic-gate 12447c478bd9Sstevel@tonic-gate /* 12457c478bd9Sstevel@tonic-gate * Make the root vnode, use it to get attributes, 12467c478bd9Sstevel@tonic-gate * then remake it with the attributes. 12477c478bd9Sstevel@tonic-gate */ 12487c478bd9Sstevel@tonic-gate rtvp = makenfsnode((fhandle_t *)svp->sv_fhandle.fh_buf, 12497c478bd9Sstevel@tonic-gate NULL, vfsp, gethrtime(), cr, NULL, NULL); 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate va.va_mask = AT_ALL; 12527c478bd9Sstevel@tonic-gate 12537c478bd9Sstevel@tonic-gate /* 12547c478bd9Sstevel@tonic-gate * If the uid is set then set the creds for secure mounts 12557c478bd9Sstevel@tonic-gate * by proxy processes such as automountd. 12567c478bd9Sstevel@tonic-gate */ 12577c478bd9Sstevel@tonic-gate if (svp->sv_secdata->uid != 0 && 12587c478bd9Sstevel@tonic-gate svp->sv_secdata->rpcflavor == RPCSEC_GSS) { 12597c478bd9Sstevel@tonic-gate lcr = crdup(cr); 12607c478bd9Sstevel@tonic-gate (void) crsetugid(lcr, svp->sv_secdata->uid, crgetgid(cr)); 12617c478bd9Sstevel@tonic-gate tcr = lcr; 12627c478bd9Sstevel@tonic-gate } 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate error = nfsgetattr(rtvp, &va, tcr); 12657c478bd9Sstevel@tonic-gate if (error) 12667c478bd9Sstevel@tonic-gate goto bad; 12677c478bd9Sstevel@tonic-gate rtvp->v_type = va.va_type; 12687c478bd9Sstevel@tonic-gate 12697c478bd9Sstevel@tonic-gate /* 12707c478bd9Sstevel@tonic-gate * Poll every server to get the filesystem stats; we're 12717c478bd9Sstevel@tonic-gate * only interested in the server's transfer size, and we 12727c478bd9Sstevel@tonic-gate * want the minimum. 12737c478bd9Sstevel@tonic-gate * 12747c478bd9Sstevel@tonic-gate * While we're looping, we'll turn off AUTH_F_TRYNONE, 12757c478bd9Sstevel@tonic-gate * which is only for the mount operation. 12767c478bd9Sstevel@tonic-gate */ 12777c478bd9Sstevel@tonic-gate 12787c478bd9Sstevel@tonic-gate mi->mi_tsize = MIN(NFS_MAXDATA, nfstsize()); 12797c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(NFS_MAXDATA, nfstsize()); 12807c478bd9Sstevel@tonic-gate 12817c478bd9Sstevel@tonic-gate for (svp = mi->mi_servers; svp != NULL; svp = svp->sv_next) { 12827c478bd9Sstevel@tonic-gate struct nfsstatfs fs; 12837c478bd9Sstevel@tonic-gate int douprintf; 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate douprintf = 1; 12867c478bd9Sstevel@tonic-gate mi->mi_curr_serv = svp; 12877c478bd9Sstevel@tonic-gate 1288*dcedb507SMarcel Telka error = rfs2call(mi, RFS_STATFS, xdr_fhandle, 1289*dcedb507SMarcel Telka (caddr_t)svp->sv_fhandle.fh_buf, xdr_statfs, (caddr_t)&fs, 1290*dcedb507SMarcel Telka tcr, &douprintf, &fs.fs_status, 0, NULL); 12917c478bd9Sstevel@tonic-gate if (error) 12927c478bd9Sstevel@tonic-gate goto bad; 12937c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(mi->mi_stsize, fs.fs_tsize); 12947c478bd9Sstevel@tonic-gate svp->sv_secdata->flags &= ~AUTH_F_TRYNONE; 12957c478bd9Sstevel@tonic-gate } 12967c478bd9Sstevel@tonic-gate mi->mi_curr_serv = mi->mi_servers; 12977c478bd9Sstevel@tonic-gate mi->mi_curread = mi->mi_tsize; 12987c478bd9Sstevel@tonic-gate mi->mi_curwrite = mi->mi_stsize; 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate /* 13017c478bd9Sstevel@tonic-gate * Start the manager thread responsible for handling async worker 13027c478bd9Sstevel@tonic-gate * threads. 13037c478bd9Sstevel@tonic-gate */ 13047c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); /* add reference for thread */ 13057c478bd9Sstevel@tonic-gate mi->mi_manager_thread = zthread_create(NULL, 0, nfs_async_manager, 1306*dcedb507SMarcel Telka vfsp, 0, minclsyspri); 13077c478bd9Sstevel@tonic-gate ASSERT(mi->mi_manager_thread != NULL); 13087c478bd9Sstevel@tonic-gate 13097c478bd9Sstevel@tonic-gate /* 13107c478bd9Sstevel@tonic-gate * Initialize kstats 13117c478bd9Sstevel@tonic-gate */ 13127c478bd9Sstevel@tonic-gate nfs_mnt_kstat_init(vfsp); 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate mi->mi_type = rtvp->v_type; 13157c478bd9Sstevel@tonic-gate 13167c478bd9Sstevel@tonic-gate *rtvpp = rtvp; 13177c478bd9Sstevel@tonic-gate if (lcr != NULL) 13187c478bd9Sstevel@tonic-gate crfree(lcr); 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate return (0); 13217c478bd9Sstevel@tonic-gate bad: 13227c478bd9Sstevel@tonic-gate /* 13237c478bd9Sstevel@tonic-gate * An error occurred somewhere, need to clean up... 13247c478bd9Sstevel@tonic-gate * We need to release our reference to the root vnode and 13257c478bd9Sstevel@tonic-gate * destroy the mntinfo struct that we just created. 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate if (lcr != NULL) 13287c478bd9Sstevel@tonic-gate crfree(lcr); 13297c478bd9Sstevel@tonic-gate rp = VTOR(rtvp); 13307c478bd9Sstevel@tonic-gate if (rp->r_flags & RHASHED) 13317c478bd9Sstevel@tonic-gate rp_rmhash(rp); 13327c478bd9Sstevel@tonic-gate VN_RELE(rtvp); 13337c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp); 13347c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp); 13357c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) { 13367c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats); 13377c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL; 13387c478bd9Sstevel@tonic-gate } 13397c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) { 13407c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats); 13417c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL; 13427c478bd9Sstevel@tonic-gate } 13437c478bd9Sstevel@tonic-gate nfs_free_mi(mi); 13447c478bd9Sstevel@tonic-gate *rtvpp = NULL; 13457c478bd9Sstevel@tonic-gate return (error); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate /* 13497c478bd9Sstevel@tonic-gate * vfs operations 13507c478bd9Sstevel@tonic-gate */ 13517c478bd9Sstevel@tonic-gate static int 13527c478bd9Sstevel@tonic-gate nfs_unmount(vfs_t *vfsp, int flag, cred_t *cr) 13537c478bd9Sstevel@tonic-gate { 13547c478bd9Sstevel@tonic-gate mntinfo_t *mi; 13557c478bd9Sstevel@tonic-gate ushort_t omax; 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate if (secpolicy_fs_unmount(cr, vfsp) != 0) 13587c478bd9Sstevel@tonic-gate return (EPERM); 13597c478bd9Sstevel@tonic-gate 13607c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp); 13617c478bd9Sstevel@tonic-gate if (flag & MS_FORCE) { 1362423be36cSmaheshvs 13637c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_UNMOUNTED; 1364423be36cSmaheshvs 1365423be36cSmaheshvs /* 1366423be36cSmaheshvs * We are about to stop the async manager. 1367423be36cSmaheshvs * Let every one know not to schedule any 1368423be36cSmaheshvs * more async requests. 1369423be36cSmaheshvs */ 1370423be36cSmaheshvs mutex_enter(&mi->mi_async_lock); 1371423be36cSmaheshvs mi->mi_max_threads = 0; 1372423be36cSmaheshvs cv_broadcast(&mi->mi_async_work_cv); 1373423be36cSmaheshvs mutex_exit(&mi->mi_async_lock); 1374423be36cSmaheshvs 13757c478bd9Sstevel@tonic-gate /* 13767c478bd9Sstevel@tonic-gate * We need to stop the manager thread explicitly; the worker 13777c478bd9Sstevel@tonic-gate * threads can time out and exit on their own. 13787c478bd9Sstevel@tonic-gate */ 13797c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp); 13807c478bd9Sstevel@tonic-gate destroy_rtable(vfsp, cr); 13817c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) { 13827c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats); 13837c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL; 13847c478bd9Sstevel@tonic-gate } 13857c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) { 13867c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats); 13877c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL; 13887c478bd9Sstevel@tonic-gate } 13897c478bd9Sstevel@tonic-gate return (0); 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate /* 13927c478bd9Sstevel@tonic-gate * Wait until all asynchronous putpage operations on 13937c478bd9Sstevel@tonic-gate * this file system are complete before flushing rnodes 13947c478bd9Sstevel@tonic-gate * from the cache. 13957c478bd9Sstevel@tonic-gate */ 13967c478bd9Sstevel@tonic-gate omax = mi->mi_max_threads; 13977c478bd9Sstevel@tonic-gate if (nfs_async_stop_sig(vfsp)) { 13987c478bd9Sstevel@tonic-gate return (EINTR); 13997c478bd9Sstevel@tonic-gate } 14007c478bd9Sstevel@tonic-gate rflush(vfsp, cr); 14017c478bd9Sstevel@tonic-gate /* 14027c478bd9Sstevel@tonic-gate * If there are any active vnodes on this file system, 14037c478bd9Sstevel@tonic-gate * then the file system is busy and can't be umounted. 14047c478bd9Sstevel@tonic-gate */ 14057c478bd9Sstevel@tonic-gate if (check_rtable(vfsp)) { 14067c478bd9Sstevel@tonic-gate mutex_enter(&mi->mi_async_lock); 14077c478bd9Sstevel@tonic-gate mi->mi_max_threads = omax; 14087c478bd9Sstevel@tonic-gate mutex_exit(&mi->mi_async_lock); 14097c478bd9Sstevel@tonic-gate return (EBUSY); 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate /* 14127c478bd9Sstevel@tonic-gate * The unmount can't fail from now on; stop the manager thread. 14137c478bd9Sstevel@tonic-gate */ 14147c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp); 14157c478bd9Sstevel@tonic-gate /* 14167c478bd9Sstevel@tonic-gate * Destroy all rnodes belonging to this file system from the 14177c478bd9Sstevel@tonic-gate * rnode hash queues and purge any resources allocated to 14187c478bd9Sstevel@tonic-gate * them. 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate destroy_rtable(vfsp, cr); 14217c478bd9Sstevel@tonic-gate if (mi->mi_io_kstats) { 14227c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_io_kstats); 14237c478bd9Sstevel@tonic-gate mi->mi_io_kstats = NULL; 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate if (mi->mi_ro_kstats) { 14267c478bd9Sstevel@tonic-gate kstat_delete(mi->mi_ro_kstats); 14277c478bd9Sstevel@tonic-gate mi->mi_ro_kstats = NULL; 14287c478bd9Sstevel@tonic-gate } 14297c478bd9Sstevel@tonic-gate return (0); 14307c478bd9Sstevel@tonic-gate } 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate /* 14337c478bd9Sstevel@tonic-gate * find root of nfs 14347c478bd9Sstevel@tonic-gate */ 14357c478bd9Sstevel@tonic-gate static int 14367c478bd9Sstevel@tonic-gate nfs_root(vfs_t *vfsp, vnode_t **vpp) 14377c478bd9Sstevel@tonic-gate { 14387c478bd9Sstevel@tonic-gate mntinfo_t *mi; 14397c478bd9Sstevel@tonic-gate vnode_t *vp; 14407c478bd9Sstevel@tonic-gate servinfo_t *svp; 1441210225b5Sgt rnode_t *rp; 1442210225b5Sgt int error = 0; 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp); 14457c478bd9Sstevel@tonic-gate 1446108322fbScarlsonj if (nfs_zone() != mi->mi_zone) 14477c478bd9Sstevel@tonic-gate return (EPERM); 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate svp = mi->mi_curr_serv; 14507c478bd9Sstevel@tonic-gate if (svp && (svp->sv_flags & SV_ROOT_STALE)) { 14517c478bd9Sstevel@tonic-gate mutex_enter(&svp->sv_lock); 14527c478bd9Sstevel@tonic-gate svp->sv_flags &= ~SV_ROOT_STALE; 14537c478bd9Sstevel@tonic-gate mutex_exit(&svp->sv_lock); 1454210225b5Sgt error = ENOENT; 14557c478bd9Sstevel@tonic-gate } 14567c478bd9Sstevel@tonic-gate 14577c478bd9Sstevel@tonic-gate vp = makenfsnode((fhandle_t *)mi->mi_curr_serv->sv_fhandle.fh_buf, 14587c478bd9Sstevel@tonic-gate NULL, vfsp, gethrtime(), CRED(), NULL, NULL); 14597c478bd9Sstevel@tonic-gate 1460210225b5Sgt /* 1461210225b5Sgt * if the SV_ROOT_STALE flag was reset above, reset the 1462210225b5Sgt * RSTALE flag if needed and return an error 1463210225b5Sgt */ 1464210225b5Sgt if (error == ENOENT) { 1465210225b5Sgt rp = VTOR(vp); 1466210225b5Sgt if (svp && rp->r_flags & RSTALE) { 1467210225b5Sgt mutex_enter(&rp->r_statelock); 1468210225b5Sgt rp->r_flags &= ~RSTALE; 1469210225b5Sgt mutex_exit(&rp->r_statelock); 1470210225b5Sgt } 14717c478bd9Sstevel@tonic-gate VN_RELE(vp); 1472210225b5Sgt return (error); 14737c478bd9Sstevel@tonic-gate } 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate ASSERT(vp->v_type == VNON || vp->v_type == mi->mi_type); 14767c478bd9Sstevel@tonic-gate 14777c478bd9Sstevel@tonic-gate vp->v_type = mi->mi_type; 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate *vpp = vp; 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate return (0); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* 14857c478bd9Sstevel@tonic-gate * Get file system statistics. 14867c478bd9Sstevel@tonic-gate */ 14877c478bd9Sstevel@tonic-gate static int 14887c478bd9Sstevel@tonic-gate nfs_statvfs(vfs_t *vfsp, struct statvfs64 *sbp) 14897c478bd9Sstevel@tonic-gate { 14907c478bd9Sstevel@tonic-gate int error; 14917c478bd9Sstevel@tonic-gate mntinfo_t *mi; 14927c478bd9Sstevel@tonic-gate struct nfsstatfs fs; 14937c478bd9Sstevel@tonic-gate int douprintf; 14947c478bd9Sstevel@tonic-gate failinfo_t fi; 14957c478bd9Sstevel@tonic-gate vnode_t *vp; 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate error = nfs_root(vfsp, &vp); 14987c478bd9Sstevel@tonic-gate if (error) 14997c478bd9Sstevel@tonic-gate return (error); 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp); 15027c478bd9Sstevel@tonic-gate douprintf = 1; 15037c478bd9Sstevel@tonic-gate fi.vp = vp; 15047c478bd9Sstevel@tonic-gate fi.fhp = NULL; /* no need to update, filehandle not copied */ 15057c478bd9Sstevel@tonic-gate fi.copyproc = nfscopyfh; 15067c478bd9Sstevel@tonic-gate fi.lookupproc = nfslookup; 15077c478bd9Sstevel@tonic-gate fi.xattrdirproc = acl_getxattrdir2; 15087c478bd9Sstevel@tonic-gate 1509*dcedb507SMarcel Telka error = rfs2call(mi, RFS_STATFS, xdr_fhandle, (caddr_t)VTOFH(vp), 1510*dcedb507SMarcel Telka xdr_statfs, (caddr_t)&fs, CRED(), &douprintf, &fs.fs_status, 0, 1511*dcedb507SMarcel Telka &fi); 15127c478bd9Sstevel@tonic-gate 15137c478bd9Sstevel@tonic-gate if (!error) { 15147c478bd9Sstevel@tonic-gate error = geterrno(fs.fs_status); 15157c478bd9Sstevel@tonic-gate if (!error) { 15167c478bd9Sstevel@tonic-gate mutex_enter(&mi->mi_lock); 15177c478bd9Sstevel@tonic-gate if (mi->mi_stsize) { 15187c478bd9Sstevel@tonic-gate mi->mi_stsize = MIN(mi->mi_stsize, fs.fs_tsize); 15197c478bd9Sstevel@tonic-gate } else { 15207c478bd9Sstevel@tonic-gate mi->mi_stsize = fs.fs_tsize; 15217c478bd9Sstevel@tonic-gate mi->mi_curwrite = mi->mi_stsize; 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate mutex_exit(&mi->mi_lock); 15247c478bd9Sstevel@tonic-gate sbp->f_bsize = fs.fs_bsize; 15257c478bd9Sstevel@tonic-gate sbp->f_frsize = fs.fs_bsize; 15267c478bd9Sstevel@tonic-gate sbp->f_blocks = (fsblkcnt64_t)fs.fs_blocks; 15277c478bd9Sstevel@tonic-gate sbp->f_bfree = (fsblkcnt64_t)fs.fs_bfree; 15287c478bd9Sstevel@tonic-gate /* 15297c478bd9Sstevel@tonic-gate * Some servers may return negative available 15307c478bd9Sstevel@tonic-gate * block counts. They may do this because they 15317c478bd9Sstevel@tonic-gate * calculate the number of available blocks by 15327c478bd9Sstevel@tonic-gate * subtracting the number of used blocks from 15337c478bd9Sstevel@tonic-gate * the total number of blocks modified by the 15347c478bd9Sstevel@tonic-gate * minimum free value. For example, if the 15357c478bd9Sstevel@tonic-gate * minumum free percentage is 10 and the file 15367c478bd9Sstevel@tonic-gate * system is greater than 90 percent full, then 15377c478bd9Sstevel@tonic-gate * 90 percent of the total blocks minus the 15387c478bd9Sstevel@tonic-gate * actual number of used blocks may be a 15397c478bd9Sstevel@tonic-gate * negative number. 15407c478bd9Sstevel@tonic-gate * 15417c478bd9Sstevel@tonic-gate * In this case, we need to sign extend the 15427c478bd9Sstevel@tonic-gate * negative number through the assignment from 15437c478bd9Sstevel@tonic-gate * the 32 bit bavail count to the 64 bit bavail 15447c478bd9Sstevel@tonic-gate * count. 15457c478bd9Sstevel@tonic-gate * 15467c478bd9Sstevel@tonic-gate * We need to be able to discern between there 15477c478bd9Sstevel@tonic-gate * just being a lot of available blocks on the 15487c478bd9Sstevel@tonic-gate * file system and the case described above. 15497c478bd9Sstevel@tonic-gate * We are making the assumption that it does 15507c478bd9Sstevel@tonic-gate * not make sense to have more available blocks 15517c478bd9Sstevel@tonic-gate * than there are free blocks. So, if there 15527c478bd9Sstevel@tonic-gate * are, then we treat the number as if it were 15537c478bd9Sstevel@tonic-gate * a negative number and arrange to have it 15547c478bd9Sstevel@tonic-gate * sign extended when it is converted from 32 15557c478bd9Sstevel@tonic-gate * bits to 64 bits. 15567c478bd9Sstevel@tonic-gate */ 15577c478bd9Sstevel@tonic-gate if (fs.fs_bavail <= fs.fs_bfree) 15587c478bd9Sstevel@tonic-gate sbp->f_bavail = (fsblkcnt64_t)fs.fs_bavail; 15597c478bd9Sstevel@tonic-gate else { 15607c478bd9Sstevel@tonic-gate sbp->f_bavail = 1561*dcedb507SMarcel Telka (fsblkcnt64_t)((long)fs.fs_bavail); 15627c478bd9Sstevel@tonic-gate } 15637c478bd9Sstevel@tonic-gate sbp->f_files = (fsfilcnt64_t)-1; 15647c478bd9Sstevel@tonic-gate sbp->f_ffree = (fsfilcnt64_t)-1; 15657c478bd9Sstevel@tonic-gate sbp->f_favail = (fsfilcnt64_t)-1; 15667c478bd9Sstevel@tonic-gate sbp->f_fsid = (unsigned long)vfsp->vfs_fsid.val[0]; 15677c478bd9Sstevel@tonic-gate (void) strncpy(sbp->f_basetype, 1568*dcedb507SMarcel Telka vfssw[vfsp->vfs_fstype].vsw_name, FSTYPSZ); 15697c478bd9Sstevel@tonic-gate sbp->f_flag = vf_to_stf(vfsp->vfs_flag); 15707c478bd9Sstevel@tonic-gate sbp->f_namemax = (uint32_t)-1; 15717c478bd9Sstevel@tonic-gate } else { 15727c478bd9Sstevel@tonic-gate PURGE_STALE_FH(error, vp, CRED()); 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate } 15757c478bd9Sstevel@tonic-gate 15767c478bd9Sstevel@tonic-gate VN_RELE(vp); 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate return (error); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate 15817c478bd9Sstevel@tonic-gate static kmutex_t nfs_syncbusy; 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate /* 15847c478bd9Sstevel@tonic-gate * Flush dirty nfs files for file system vfsp. 15857c478bd9Sstevel@tonic-gate * If vfsp == NULL, all nfs files are flushed. 15867c478bd9Sstevel@tonic-gate */ 15877c478bd9Sstevel@tonic-gate /* ARGSUSED */ 15887c478bd9Sstevel@tonic-gate static int 15897c478bd9Sstevel@tonic-gate nfs_sync(vfs_t *vfsp, short flag, cred_t *cr) 15907c478bd9Sstevel@tonic-gate { 15917c478bd9Sstevel@tonic-gate /* 15927c478bd9Sstevel@tonic-gate * Cross-zone calls are OK here, since this translates to a 15937c478bd9Sstevel@tonic-gate * VOP_PUTPAGE(B_ASYNC), which gets picked up by the right zone. 15947c478bd9Sstevel@tonic-gate */ 15957c478bd9Sstevel@tonic-gate if (!(flag & SYNC_ATTR) && mutex_tryenter(&nfs_syncbusy) != 0) { 15967c478bd9Sstevel@tonic-gate rflush(vfsp, cr); 15977c478bd9Sstevel@tonic-gate mutex_exit(&nfs_syncbusy); 15987c478bd9Sstevel@tonic-gate } 15997c478bd9Sstevel@tonic-gate return (0); 16007c478bd9Sstevel@tonic-gate } 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate /* ARGSUSED */ 16037c478bd9Sstevel@tonic-gate static int 16047c478bd9Sstevel@tonic-gate nfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp) 16057c478bd9Sstevel@tonic-gate { 16067c478bd9Sstevel@tonic-gate int error; 16077c478bd9Sstevel@tonic-gate vnode_t *vp; 16087c478bd9Sstevel@tonic-gate struct vattr va; 16097c478bd9Sstevel@tonic-gate struct nfs_fid *nfsfidp = (struct nfs_fid *)fidp; 16107c478bd9Sstevel@tonic-gate zoneid_t zoneid = VFTOMI(vfsp)->mi_zone->zone_id; 16117c478bd9Sstevel@tonic-gate 1612108322fbScarlsonj if (nfs_zone() != VFTOMI(vfsp)->mi_zone) 16137c478bd9Sstevel@tonic-gate return (EPERM); 16147c478bd9Sstevel@tonic-gate if (fidp->fid_len != (sizeof (*nfsfidp) - sizeof (short))) { 16157c478bd9Sstevel@tonic-gate #ifdef DEBUG 16167c478bd9Sstevel@tonic-gate zcmn_err(zoneid, CE_WARN, 16177c478bd9Sstevel@tonic-gate "nfs_vget: bad fid len, %d/%d", fidp->fid_len, 16187c478bd9Sstevel@tonic-gate (int)(sizeof (*nfsfidp) - sizeof (short))); 16197c478bd9Sstevel@tonic-gate #endif 16207c478bd9Sstevel@tonic-gate *vpp = NULL; 16217c478bd9Sstevel@tonic-gate return (ESTALE); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate 16247c478bd9Sstevel@tonic-gate vp = makenfsnode((fhandle_t *)(nfsfidp->nf_data), NULL, vfsp, 16257c478bd9Sstevel@tonic-gate gethrtime(), CRED(), NULL, NULL); 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate if (VTOR(vp)->r_flags & RSTALE) { 16287c478bd9Sstevel@tonic-gate VN_RELE(vp); 16297c478bd9Sstevel@tonic-gate *vpp = NULL; 16307c478bd9Sstevel@tonic-gate return (ENOENT); 16317c478bd9Sstevel@tonic-gate } 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate if (vp->v_type == VNON) { 16347c478bd9Sstevel@tonic-gate va.va_mask = AT_ALL; 16357c478bd9Sstevel@tonic-gate error = nfsgetattr(vp, &va, CRED()); 16367c478bd9Sstevel@tonic-gate if (error) { 16377c478bd9Sstevel@tonic-gate VN_RELE(vp); 16387c478bd9Sstevel@tonic-gate *vpp = NULL; 16397c478bd9Sstevel@tonic-gate return (error); 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate vp->v_type = va.va_type; 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate 16447c478bd9Sstevel@tonic-gate *vpp = vp; 16457c478bd9Sstevel@tonic-gate 16467c478bd9Sstevel@tonic-gate return (0); 16477c478bd9Sstevel@tonic-gate } 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate /* ARGSUSED */ 16507c478bd9Sstevel@tonic-gate static int 16517c478bd9Sstevel@tonic-gate nfs_mountroot(vfs_t *vfsp, whymountroot_t why) 16527c478bd9Sstevel@tonic-gate { 16537c478bd9Sstevel@tonic-gate vnode_t *rtvp; 16547c478bd9Sstevel@tonic-gate char root_hostname[SYS_NMLN+1]; 16557c478bd9Sstevel@tonic-gate struct servinfo *svp; 16567c478bd9Sstevel@tonic-gate int error; 16577c478bd9Sstevel@tonic-gate int vfsflags; 16587c478bd9Sstevel@tonic-gate size_t size; 16597c478bd9Sstevel@tonic-gate char *root_path; 16607c478bd9Sstevel@tonic-gate struct pathname pn; 16617c478bd9Sstevel@tonic-gate char *name; 16627c478bd9Sstevel@tonic-gate cred_t *cr; 16637c478bd9Sstevel@tonic-gate struct nfs_args args; /* nfs mount arguments */ 16647c478bd9Sstevel@tonic-gate static char token[10]; 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate bzero(&args, sizeof (args)); 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate /* do this BEFORE getfile which causes xid stamps to be initialized */ 16697c478bd9Sstevel@tonic-gate clkset(-1L); /* hack for now - until we get time svc? */ 16707c478bd9Sstevel@tonic-gate 16717c478bd9Sstevel@tonic-gate if (why == ROOT_REMOUNT) { 16727c478bd9Sstevel@tonic-gate /* 16737c478bd9Sstevel@tonic-gate * Shouldn't happen. 16747c478bd9Sstevel@tonic-gate */ 16757c478bd9Sstevel@tonic-gate panic("nfs_mountroot: why == ROOT_REMOUNT"); 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate if (why == ROOT_UNMOUNT) { 16797c478bd9Sstevel@tonic-gate /* 16807c478bd9Sstevel@tonic-gate * Nothing to do for NFS. 16817c478bd9Sstevel@tonic-gate */ 16827c478bd9Sstevel@tonic-gate return (0); 16837c478bd9Sstevel@tonic-gate } 16847c478bd9Sstevel@tonic-gate 16857c478bd9Sstevel@tonic-gate /* 16867c478bd9Sstevel@tonic-gate * why == ROOT_INIT 16877c478bd9Sstevel@tonic-gate */ 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate name = token; 16907c478bd9Sstevel@tonic-gate *name = 0; 16917c478bd9Sstevel@tonic-gate getfsname("root", name, sizeof (token)); 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate pn_alloc(&pn); 16947c478bd9Sstevel@tonic-gate root_path = pn.pn_path; 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate svp = kmem_zalloc(sizeof (*svp), KM_SLEEP); 16977c478bd9Sstevel@tonic-gate svp->sv_knconf = kmem_zalloc(sizeof (*svp->sv_knconf), KM_SLEEP); 16987c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_protofmly = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 16997c478bd9Sstevel@tonic-gate svp->sv_knconf->knc_proto = kmem_alloc(KNC_STRSIZE, KM_SLEEP); 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate /* 17027c478bd9Sstevel@tonic-gate * Get server address 17037c478bd9Sstevel@tonic-gate * Get the root fhandle 17047c478bd9Sstevel@tonic-gate * Get server's transport 17057c478bd9Sstevel@tonic-gate * Get server's hostname 17067c478bd9Sstevel@tonic-gate * Get options 17077c478bd9Sstevel@tonic-gate */ 17087c478bd9Sstevel@tonic-gate args.addr = &svp->sv_addr; 17097c478bd9Sstevel@tonic-gate args.fh = (char *)&svp->sv_fhandle.fh_buf; 17107c478bd9Sstevel@tonic-gate args.knconf = svp->sv_knconf; 17117c478bd9Sstevel@tonic-gate args.hostname = root_hostname; 17127c478bd9Sstevel@tonic-gate vfsflags = 0; 17137c478bd9Sstevel@tonic-gate if (error = mount_root(*name ? name : "root", root_path, NFS_VERSION, 17147c478bd9Sstevel@tonic-gate &args, &vfsflags)) { 17157c478bd9Sstevel@tonic-gate nfs_cmn_err(error, CE_WARN, 17167c478bd9Sstevel@tonic-gate "nfs_mountroot: mount_root failed: %m"); 17177c478bd9Sstevel@tonic-gate sv_free(svp); 17187c478bd9Sstevel@tonic-gate pn_free(&pn); 17197c478bd9Sstevel@tonic-gate return (error); 17207c478bd9Sstevel@tonic-gate } 17217c478bd9Sstevel@tonic-gate svp->sv_fhandle.fh_len = NFS_FHSIZE; 17227c478bd9Sstevel@tonic-gate svp->sv_hostnamelen = (int)(strlen(root_hostname) + 1); 17237c478bd9Sstevel@tonic-gate svp->sv_hostname = kmem_alloc(svp->sv_hostnamelen, KM_SLEEP); 17247c478bd9Sstevel@tonic-gate (void) strcpy(svp->sv_hostname, root_hostname); 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate /* 17277c478bd9Sstevel@tonic-gate * Force root partition to always be mounted with AUTH_UNIX for now 17287c478bd9Sstevel@tonic-gate */ 17297c478bd9Sstevel@tonic-gate svp->sv_secdata = kmem_alloc(sizeof (*svp->sv_secdata), KM_SLEEP); 17307c478bd9Sstevel@tonic-gate svp->sv_secdata->secmod = AUTH_UNIX; 17317c478bd9Sstevel@tonic-gate svp->sv_secdata->rpcflavor = AUTH_UNIX; 17327c478bd9Sstevel@tonic-gate svp->sv_secdata->data = NULL; 17337c478bd9Sstevel@tonic-gate 17347c478bd9Sstevel@tonic-gate cr = crgetcred(); 17357c478bd9Sstevel@tonic-gate rtvp = NULL; 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate error = nfsrootvp(&rtvp, vfsp, svp, args.flags, cr, global_zone); 17387c478bd9Sstevel@tonic-gate 17397c478bd9Sstevel@tonic-gate crfree(cr); 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate if (error) { 17427c478bd9Sstevel@tonic-gate pn_free(&pn); 1743ab7762b6Smaheshvs sv_free(svp); 1744ab7762b6Smaheshvs return (error); 17457c478bd9Sstevel@tonic-gate } 17467c478bd9Sstevel@tonic-gate 17477c478bd9Sstevel@tonic-gate error = nfs_setopts(rtvp, DATAMODEL_NATIVE, &args); 17487c478bd9Sstevel@tonic-gate if (error) { 17497c478bd9Sstevel@tonic-gate nfs_cmn_err(error, CE_WARN, 17507c478bd9Sstevel@tonic-gate "nfs_mountroot: invalid root mount options"); 17517c478bd9Sstevel@tonic-gate pn_free(&pn); 17527c478bd9Sstevel@tonic-gate goto errout; 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate (void) vfs_lock_wait(vfsp); 17567c478bd9Sstevel@tonic-gate vfs_add(NULL, vfsp, vfsflags); 17577c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 17587c478bd9Sstevel@tonic-gate 17597c478bd9Sstevel@tonic-gate size = strlen(svp->sv_hostname); 17607c478bd9Sstevel@tonic-gate (void) strcpy(rootfs.bo_name, svp->sv_hostname); 17617c478bd9Sstevel@tonic-gate rootfs.bo_name[size] = ':'; 17627c478bd9Sstevel@tonic-gate (void) strcpy(&rootfs.bo_name[size + 1], root_path); 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate pn_free(&pn); 17657c478bd9Sstevel@tonic-gate 17667c478bd9Sstevel@tonic-gate errout: 17677c478bd9Sstevel@tonic-gate if (error) { 17687c478bd9Sstevel@tonic-gate sv_free(svp); 17697c478bd9Sstevel@tonic-gate nfs_async_stop(vfsp); 17707c478bd9Sstevel@tonic-gate nfs_async_manager_stop(vfsp); 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate if (rtvp != NULL) 17747c478bd9Sstevel@tonic-gate VN_RELE(rtvp); 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate return (error); 17777c478bd9Sstevel@tonic-gate } 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate /* 17807c478bd9Sstevel@tonic-gate * Initialization routine for VFS routines. Should only be called once 17817c478bd9Sstevel@tonic-gate */ 17827c478bd9Sstevel@tonic-gate int 17837c478bd9Sstevel@tonic-gate nfs_vfsinit(void) 17847c478bd9Sstevel@tonic-gate { 17857c478bd9Sstevel@tonic-gate mutex_init(&nfs_syncbusy, NULL, MUTEX_DEFAULT, NULL); 17867c478bd9Sstevel@tonic-gate return (0); 17877c478bd9Sstevel@tonic-gate } 17887c478bd9Sstevel@tonic-gate 17897c478bd9Sstevel@tonic-gate void 17907c478bd9Sstevel@tonic-gate nfs_vfsfini(void) 17917c478bd9Sstevel@tonic-gate { 17927c478bd9Sstevel@tonic-gate mutex_destroy(&nfs_syncbusy); 17937c478bd9Sstevel@tonic-gate } 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate void 17967c478bd9Sstevel@tonic-gate nfs_freevfs(vfs_t *vfsp) 17977c478bd9Sstevel@tonic-gate { 17987c478bd9Sstevel@tonic-gate mntinfo_t *mi; 17997c478bd9Sstevel@tonic-gate servinfo_t *svp; 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate /* free up the resources */ 18027c478bd9Sstevel@tonic-gate mi = VFTOMI(vfsp); 18037c478bd9Sstevel@tonic-gate pathconf_rele(mi); 18047c478bd9Sstevel@tonic-gate svp = mi->mi_servers; 18057c478bd9Sstevel@tonic-gate mi->mi_servers = mi->mi_curr_serv = NULL; 18067c478bd9Sstevel@tonic-gate sv_free(svp); 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate /* 18097c478bd9Sstevel@tonic-gate * By this time we should have already deleted the 18107c478bd9Sstevel@tonic-gate * mi kstats in the unmount code. If they are still around 18117c478bd9Sstevel@tonic-gate * somethings wrong 18127c478bd9Sstevel@tonic-gate */ 18137c478bd9Sstevel@tonic-gate ASSERT(mi->mi_io_kstats == NULL); 18147c478bd9Sstevel@tonic-gate nfs_free_mi(mi); 18157c478bd9Sstevel@tonic-gate } 1816