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 5*5a59a8b3Srsb * Common Development and Distribution License (the "License"). 6*5a59a8b3Srsb * 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*5a59a8b3Srsb * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 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 * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/types.h> 437c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 447c478bd9Sstevel@tonic-gate #include <sys/param.h> 457c478bd9Sstevel@tonic-gate #include <sys/errno.h> 467c478bd9Sstevel@tonic-gate #include <sys/user.h> 477c478bd9Sstevel@tonic-gate #include <sys/fstyp.h> 487c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 497c478bd9Sstevel@tonic-gate #include <sys/systm.h> 507c478bd9Sstevel@tonic-gate #include <sys/proc.h> 517c478bd9Sstevel@tonic-gate #include <sys/mount.h> 527c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 537c478bd9Sstevel@tonic-gate #include <sys/fem.h> 547c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 557c478bd9Sstevel@tonic-gate #include <sys/stat.h> 567c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 577c478bd9Sstevel@tonic-gate #include <sys/statfs.h> 587c478bd9Sstevel@tonic-gate #include <sys/cred.h> 597c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 607c478bd9Sstevel@tonic-gate #include <sys/rwstlock.h> 617c478bd9Sstevel@tonic-gate #include <sys/dnlc.h> 627c478bd9Sstevel@tonic-gate #include <sys/file.h> 637c478bd9Sstevel@tonic-gate #include <sys/time.h> 647c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 657c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 667c478bd9Sstevel@tonic-gate #include <sys/buf.h> 677c478bd9Sstevel@tonic-gate #include <sys/swap.h> 687c478bd9Sstevel@tonic-gate #include <sys/debug.h> 697c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 707c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 717c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 727c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 737c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 747c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 757c478bd9Sstevel@tonic-gate #include <sys/dc_ki.h> 767c478bd9Sstevel@tonic-gate #include <sys/poll.h> 777c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 787c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 797c478bd9Sstevel@tonic-gate #include <sys/zone.h> 807c478bd9Sstevel@tonic-gate #include <sys/policy.h> 817c478bd9Sstevel@tonic-gate #include <sys/ctfs.h> 827c478bd9Sstevel@tonic-gate #include <sys/objfs.h> 837c478bd9Sstevel@tonic-gate #include <sys/console.h> 847c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #include <vm/page.h> 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h> 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static void vfs_clearmntopt_nolock(mntopts_t *, const char *, int); 917c478bd9Sstevel@tonic-gate static void vfs_setmntopt_nolock(mntopts_t *, const char *, 927c478bd9Sstevel@tonic-gate const char *, int, int); 937c478bd9Sstevel@tonic-gate static int vfs_optionisset_nolock(const mntopts_t *, const char *, char **); 947c478bd9Sstevel@tonic-gate static void vfs_freemnttab(struct vfs *); 957c478bd9Sstevel@tonic-gate static void vfs_freeopt(mntopt_t *); 967c478bd9Sstevel@tonic-gate static void vfs_swapopttbl_nolock(mntopts_t *, mntopts_t *); 977c478bd9Sstevel@tonic-gate static void vfs_swapopttbl(mntopts_t *, mntopts_t *); 987c478bd9Sstevel@tonic-gate static void vfs_copyopttbl_extend(const mntopts_t *, mntopts_t *, int); 997c478bd9Sstevel@tonic-gate static void vfs_createopttbl_extend(mntopts_t *, const char *, 1007c478bd9Sstevel@tonic-gate const mntopts_t *); 1017c478bd9Sstevel@tonic-gate static char **vfs_copycancelopt_extend(char **const, int); 1027c478bd9Sstevel@tonic-gate static void vfs_freecancelopt(char **); 1037c478bd9Sstevel@tonic-gate static char *getrootfs(void); 1047c478bd9Sstevel@tonic-gate static int getmacpath(dev_info_t *, void *); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate struct ipmnt { 1077c478bd9Sstevel@tonic-gate struct ipmnt *mip_next; 1087c478bd9Sstevel@tonic-gate dev_t mip_dev; 1097c478bd9Sstevel@tonic-gate struct vfs *mip_vfsp; 1107c478bd9Sstevel@tonic-gate }; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate static kmutex_t vfs_miplist_mutex; 1137c478bd9Sstevel@tonic-gate static struct ipmnt *vfs_miplist = NULL; 1147c478bd9Sstevel@tonic-gate static struct ipmnt *vfs_miplist_end = NULL; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * VFS global data. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate vnode_t *rootdir; /* pointer to root inode vnode. */ 1207c478bd9Sstevel@tonic-gate vnode_t *devicesdir; /* pointer to inode of devices root */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate char *server_rootpath; /* root path for diskless clients */ 1237c478bd9Sstevel@tonic-gate char *server_hostname; /* hostname of diskless server */ 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate static struct vfs root; 1267c478bd9Sstevel@tonic-gate static struct vfs devices; 1277c478bd9Sstevel@tonic-gate struct vfs *rootvfs = &root; /* pointer to root vfs; head of VFS list. */ 1287c478bd9Sstevel@tonic-gate rvfs_t *rvfs_list; /* array of vfs ptrs for vfs hash list */ 1297c478bd9Sstevel@tonic-gate int vfshsz = 512; /* # of heads/locks in vfs hash arrays */ 1307c478bd9Sstevel@tonic-gate /* must be power of 2! */ 1317c478bd9Sstevel@tonic-gate timespec_t vfs_mnttab_ctime; /* mnttab created time */ 1327c478bd9Sstevel@tonic-gate timespec_t vfs_mnttab_mtime; /* mnttab last modified time */ 1337c478bd9Sstevel@tonic-gate char *vfs_dummyfstype = "\0"; 1347c478bd9Sstevel@tonic-gate struct pollhead vfs_pollhd; /* for mnttab pollers */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * Table for generic options recognized in the VFS layer and acted 1387c478bd9Sstevel@tonic-gate * on at this level before parsing file system specific options. 1397c478bd9Sstevel@tonic-gate * The nosuid option is stronger than any of the devices and setuid 1407c478bd9Sstevel@tonic-gate * options, so those are canceled when nosuid is seen. 1417c478bd9Sstevel@tonic-gate * 1427c478bd9Sstevel@tonic-gate * All options which are added here need to be added to the 1437c478bd9Sstevel@tonic-gate * list of standard options in usr/src/cmd/fs.d/fslib.c as well. 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * VFS Mount options table 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL }; 1497c478bd9Sstevel@tonic-gate static char *rw_cancel[] = { MNTOPT_RO, NULL }; 1507c478bd9Sstevel@tonic-gate static char *suid_cancel[] = { MNTOPT_NOSUID, NULL }; 1517c478bd9Sstevel@tonic-gate static char *nosuid_cancel[] = { MNTOPT_SUID, MNTOPT_DEVICES, MNTOPT_NODEVICES, 1527c478bd9Sstevel@tonic-gate MNTOPT_NOSETUID, MNTOPT_SETUID, NULL }; 1537c478bd9Sstevel@tonic-gate static char *devices_cancel[] = { MNTOPT_NODEVICES, NULL }; 1547c478bd9Sstevel@tonic-gate static char *nodevices_cancel[] = { MNTOPT_DEVICES, NULL }; 1557c478bd9Sstevel@tonic-gate static char *setuid_cancel[] = { MNTOPT_NOSETUID, NULL }; 1567c478bd9Sstevel@tonic-gate static char *nosetuid_cancel[] = { MNTOPT_SETUID, NULL }; 1577c478bd9Sstevel@tonic-gate static char *nbmand_cancel[] = { MNTOPT_NONBMAND, NULL }; 1587c478bd9Sstevel@tonic-gate static char *nonbmand_cancel[] = { MNTOPT_NBMAND, NULL }; 1597c478bd9Sstevel@tonic-gate static char *exec_cancel[] = { MNTOPT_NOEXEC, NULL }; 1607c478bd9Sstevel@tonic-gate static char *noexec_cancel[] = { MNTOPT_EXEC, NULL }; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate static const mntopt_t mntopts[] = { 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * option name cancel options default arg flags 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate { MNTOPT_REMOUNT, NULL, NULL, 1677c478bd9Sstevel@tonic-gate MO_NODISPLAY, (void *)0 }, 1687c478bd9Sstevel@tonic-gate { MNTOPT_RO, ro_cancel, NULL, 0, 1697c478bd9Sstevel@tonic-gate (void *)0 }, 1707c478bd9Sstevel@tonic-gate { MNTOPT_RW, rw_cancel, NULL, 0, 1717c478bd9Sstevel@tonic-gate (void *)0 }, 1727c478bd9Sstevel@tonic-gate { MNTOPT_SUID, suid_cancel, NULL, 0, 1737c478bd9Sstevel@tonic-gate (void *)0 }, 1747c478bd9Sstevel@tonic-gate { MNTOPT_NOSUID, nosuid_cancel, NULL, 0, 1757c478bd9Sstevel@tonic-gate (void *)0 }, 1767c478bd9Sstevel@tonic-gate { MNTOPT_DEVICES, devices_cancel, NULL, 0, 1777c478bd9Sstevel@tonic-gate (void *)0 }, 1787c478bd9Sstevel@tonic-gate { MNTOPT_NODEVICES, nodevices_cancel, NULL, 0, 1797c478bd9Sstevel@tonic-gate (void *)0 }, 1807c478bd9Sstevel@tonic-gate { MNTOPT_SETUID, setuid_cancel, NULL, 0, 1817c478bd9Sstevel@tonic-gate (void *)0 }, 1827c478bd9Sstevel@tonic-gate { MNTOPT_NOSETUID, nosetuid_cancel, NULL, 0, 1837c478bd9Sstevel@tonic-gate (void *)0 }, 1847c478bd9Sstevel@tonic-gate { MNTOPT_NBMAND, nbmand_cancel, NULL, 0, 1857c478bd9Sstevel@tonic-gate (void *)0 }, 1867c478bd9Sstevel@tonic-gate { MNTOPT_NONBMAND, nonbmand_cancel, NULL, 0, 1877c478bd9Sstevel@tonic-gate (void *)0 }, 1887c478bd9Sstevel@tonic-gate { MNTOPT_EXEC, exec_cancel, NULL, 0, 1897c478bd9Sstevel@tonic-gate (void *)0 }, 1907c478bd9Sstevel@tonic-gate { MNTOPT_NOEXEC, noexec_cancel, NULL, 0, 1917c478bd9Sstevel@tonic-gate (void *)0 }, 1927c478bd9Sstevel@tonic-gate }; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate const mntopts_t vfs_mntopts = { 1957c478bd9Sstevel@tonic-gate sizeof (mntopts) / sizeof (mntopt_t), 1967c478bd9Sstevel@tonic-gate (mntopt_t *)&mntopts[0] 1977c478bd9Sstevel@tonic-gate }; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * File system operation dispatch functions. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate int 2047c478bd9Sstevel@tonic-gate fsop_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_mount)(vfsp, mvp, uap, cr); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate int 2107c478bd9Sstevel@tonic-gate fsop_unmount(vfs_t *vfsp, int flag, cred_t *cr) 2117c478bd9Sstevel@tonic-gate { 2127c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_unmount)(vfsp, flag, cr); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate int 2167c478bd9Sstevel@tonic-gate fsop_root(vfs_t *vfsp, vnode_t **vpp) 2177c478bd9Sstevel@tonic-gate { 2187c478bd9Sstevel@tonic-gate refstr_t *mntpt; 2197c478bd9Sstevel@tonic-gate int ret = (*(vfsp)->vfs_op->vfs_root)(vfsp, vpp); 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * Make sure this root has a path. With lofs, it is possible to have 2227c478bd9Sstevel@tonic-gate * a NULL mountpoint. 2237c478bd9Sstevel@tonic-gate */ 224ca2c3138Seschrock if (ret == 0 && vfsp->vfs_mntpt != NULL && (*vpp)->v_path == NULL) { 2257c478bd9Sstevel@tonic-gate mntpt = vfs_getmntpoint(vfsp); 2267c478bd9Sstevel@tonic-gate vn_setpath_str(*vpp, refstr_value(mntpt), 2277c478bd9Sstevel@tonic-gate strlen(refstr_value(mntpt))); 2287c478bd9Sstevel@tonic-gate refstr_rele(mntpt); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate return (ret); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate int 2357c478bd9Sstevel@tonic-gate fsop_statfs(vfs_t *vfsp, statvfs64_t *sp) 2367c478bd9Sstevel@tonic-gate { 2377c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_statvfs)(vfsp, sp); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate int 2417c478bd9Sstevel@tonic-gate fsop_sync(vfs_t *vfsp, short flag, cred_t *cr) 2427c478bd9Sstevel@tonic-gate { 2437c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_sync)(vfsp, flag, cr); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate int 2477c478bd9Sstevel@tonic-gate fsop_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp) 2487c478bd9Sstevel@tonic-gate { 2497c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_vget)(vfsp, vpp, fidp); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate int 2537c478bd9Sstevel@tonic-gate fsop_mountroot(vfs_t *vfsp, enum whymountroot reason) 2547c478bd9Sstevel@tonic-gate { 2557c478bd9Sstevel@tonic-gate return (*(vfsp)->vfs_op->vfs_mountroot)(vfsp, reason); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate void 2597c478bd9Sstevel@tonic-gate fsop_freefs(vfs_t *vfsp) 2607c478bd9Sstevel@tonic-gate { 2617c478bd9Sstevel@tonic-gate (*(vfsp)->vfs_op->vfs_freevfs)(vfsp); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate int 2657c478bd9Sstevel@tonic-gate fsop_vnstate(vfs_t *vfsp, vnode_t *vp, vntrans_t nstate) 2667c478bd9Sstevel@tonic-gate { 2677c478bd9Sstevel@tonic-gate return ((*(vfsp)->vfs_op->vfs_vnstate)(vfsp, vp, nstate)); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate int 2717c478bd9Sstevel@tonic-gate fsop_sync_by_kind(int fstype, short flag, cred_t *cr) 2727c478bd9Sstevel@tonic-gate { 2737c478bd9Sstevel@tonic-gate ASSERT((fstype >= 0) && (fstype < nfstype)); 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate if (ALLOCATED_VFSSW(&vfssw[fstype]) && VFS_INSTALLED(&vfssw[fstype])) 2767c478bd9Sstevel@tonic-gate return (*vfssw[fstype].vsw_vfsops.vfs_sync) (NULL, flag, cr); 2777c478bd9Sstevel@tonic-gate else 2787c478bd9Sstevel@tonic-gate return (ENOTSUP); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate /* 2827c478bd9Sstevel@tonic-gate * File system initialization. vfs_setfsops() must be called from a file 2837c478bd9Sstevel@tonic-gate * system's init routine. 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate static int 2877c478bd9Sstevel@tonic-gate fs_copyfsops(const fs_operation_def_t *template, vfsops_t *actual, 2887c478bd9Sstevel@tonic-gate int *unused_ops) 2897c478bd9Sstevel@tonic-gate { 2907c478bd9Sstevel@tonic-gate static const fs_operation_trans_def_t vfs_ops_table[] = { 2917c478bd9Sstevel@tonic-gate VFSNAME_MOUNT, offsetof(vfsops_t, vfs_mount), 2927c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate VFSNAME_UNMOUNT, offsetof(vfsops_t, vfs_unmount), 2957c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate VFSNAME_ROOT, offsetof(vfsops_t, vfs_root), 2987c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate VFSNAME_STATVFS, offsetof(vfsops_t, vfs_statvfs), 3017c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate VFSNAME_SYNC, offsetof(vfsops_t, vfs_sync), 3047c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_sync, 3057c478bd9Sstevel@tonic-gate (fs_generic_func_p) fs_sync, /* No errors allowed */ 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate VFSNAME_VGET, offsetof(vfsops_t, vfs_vget), 3087c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate VFSNAME_MOUNTROOT, offsetof(vfsops_t, vfs_mountroot), 3117c478bd9Sstevel@tonic-gate fs_nosys, fs_nosys, 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate VFSNAME_FREEVFS, offsetof(vfsops_t, vfs_freevfs), 3147c478bd9Sstevel@tonic-gate (fs_generic_func_p)fs_freevfs, 3157c478bd9Sstevel@tonic-gate (fs_generic_func_p)fs_freevfs, /* Shouldn't fail */ 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate VFSNAME_VNSTATE, offsetof(vfsops_t, vfs_vnstate), 3187c478bd9Sstevel@tonic-gate (fs_generic_func_p)fs_nosys, 3197c478bd9Sstevel@tonic-gate (fs_generic_func_p)fs_nosys, 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate NULL, 0, NULL, NULL 3227c478bd9Sstevel@tonic-gate }; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate return (fs_build_vector(actual, unused_ops, vfs_ops_table, template)); 3257c478bd9Sstevel@tonic-gate } 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate int 3287c478bd9Sstevel@tonic-gate vfs_setfsops(int fstype, const fs_operation_def_t *template, vfsops_t **actual) 3297c478bd9Sstevel@tonic-gate { 3307c478bd9Sstevel@tonic-gate int error; 3317c478bd9Sstevel@tonic-gate int unused_ops; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* Verify that fstype refers to a loaded fs (and not fsid 0). */ 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate if ((fstype <= 0) || (fstype >= nfstype)) 3367c478bd9Sstevel@tonic-gate return (EINVAL); 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate if (!ALLOCATED_VFSSW(&vfssw[fstype])) 3397c478bd9Sstevel@tonic-gate return (EINVAL); 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* Set up the operations vector. */ 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate error = fs_copyfsops(template, &vfssw[fstype].vsw_vfsops, &unused_ops); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate if (error != 0) 3467c478bd9Sstevel@tonic-gate return (error); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate vfssw[fstype].vsw_flag |= VSW_INSTALLED; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate if (actual != NULL) 3517c478bd9Sstevel@tonic-gate *actual = &vfssw[fstype].vsw_vfsops; 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate #if DEBUG 3547c478bd9Sstevel@tonic-gate if (unused_ops != 0) 3557c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "vfs_setfsops: %s: %d operations supplied " 3567c478bd9Sstevel@tonic-gate "but not used", vfssw[fstype].vsw_name, unused_ops); 3577c478bd9Sstevel@tonic-gate #endif 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate return (0); 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate int 3637c478bd9Sstevel@tonic-gate vfs_makefsops(const fs_operation_def_t *template, vfsops_t **actual) 3647c478bd9Sstevel@tonic-gate { 3657c478bd9Sstevel@tonic-gate int error; 3667c478bd9Sstevel@tonic-gate int unused_ops; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate *actual = (vfsops_t *)kmem_alloc(sizeof (vfsops_t), KM_SLEEP); 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate error = fs_copyfsops(template, *actual, &unused_ops); 3717c478bd9Sstevel@tonic-gate if (error != 0) { 3727c478bd9Sstevel@tonic-gate kmem_free(*actual, sizeof (vfsops_t)); 3737c478bd9Sstevel@tonic-gate *actual = NULL; 3747c478bd9Sstevel@tonic-gate return (error); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate return (0); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * Free a vfsops structure created as a result of vfs_makefsops(). 3827c478bd9Sstevel@tonic-gate * NOTE: For a vfsops structure initialized by vfs_setfsops(), use 3837c478bd9Sstevel@tonic-gate * vfs_freevfsops_by_type(). 3847c478bd9Sstevel@tonic-gate */ 3857c478bd9Sstevel@tonic-gate void 3867c478bd9Sstevel@tonic-gate vfs_freevfsops(vfsops_t *vfsops) 3877c478bd9Sstevel@tonic-gate { 3887c478bd9Sstevel@tonic-gate kmem_free(vfsops, sizeof (vfsops_t)); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate /* 3927c478bd9Sstevel@tonic-gate * Since the vfsops structure is part of the vfssw table and wasn't 3937c478bd9Sstevel@tonic-gate * really allocated, we're not really freeing anything. We keep 3947c478bd9Sstevel@tonic-gate * the name for consistency with vfs_freevfsops(). We do, however, 3957c478bd9Sstevel@tonic-gate * need to take care of a little bookkeeping. 3967c478bd9Sstevel@tonic-gate * NOTE: For a vfsops structure created by vfs_setfsops(), use 3977c478bd9Sstevel@tonic-gate * vfs_freevfsops_by_type(). 3987c478bd9Sstevel@tonic-gate */ 3997c478bd9Sstevel@tonic-gate int 4007c478bd9Sstevel@tonic-gate vfs_freevfsops_by_type(int fstype) 4017c478bd9Sstevel@tonic-gate { 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate /* Verify that fstype refers to a loaded fs (and not fsid 0). */ 4047c478bd9Sstevel@tonic-gate if ((fstype <= 0) || (fstype >= nfstype)) 4057c478bd9Sstevel@tonic-gate return (EINVAL); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate WLOCK_VFSSW(); 4087c478bd9Sstevel@tonic-gate if ((vfssw[fstype].vsw_flag & VSW_INSTALLED) == 0) { 4097c478bd9Sstevel@tonic-gate WUNLOCK_VFSSW(); 4107c478bd9Sstevel@tonic-gate return (EINVAL); 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate vfssw[fstype].vsw_flag &= ~VSW_INSTALLED; 4147c478bd9Sstevel@tonic-gate WUNLOCK_VFSSW(); 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate return (0); 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate /* Support routines used to reference vfs_op */ 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate /* Set the operations vector for a vfs */ 4227c478bd9Sstevel@tonic-gate void 4237c478bd9Sstevel@tonic-gate vfs_setops(vfs_t *vfsp, vfsops_t *vfsops) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate vfsops_t *op; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate ASSERT(vfsp != NULL); 4287c478bd9Sstevel@tonic-gate ASSERT(vfsops != NULL); 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate op = vfsp->vfs_op; 4317c478bd9Sstevel@tonic-gate membar_consumer(); 4327c478bd9Sstevel@tonic-gate if (vfsp->vfs_femhead == NULL && 4337c478bd9Sstevel@tonic-gate casptr(&vfsp->vfs_op, op, vfsops) == op) { 4347c478bd9Sstevel@tonic-gate return; 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate fsem_setvfsops(vfsp, vfsops); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate /* Retrieve the operations vector for a vfs */ 4407c478bd9Sstevel@tonic-gate vfsops_t * 4417c478bd9Sstevel@tonic-gate vfs_getops(vfs_t *vfsp) 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate vfsops_t *op; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate ASSERT(vfsp != NULL); 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate op = vfsp->vfs_op; 4487c478bd9Sstevel@tonic-gate membar_consumer(); 4497c478bd9Sstevel@tonic-gate if (vfsp->vfs_femhead == NULL && op == vfsp->vfs_op) { 4507c478bd9Sstevel@tonic-gate return (op); 4517c478bd9Sstevel@tonic-gate } else { 4527c478bd9Sstevel@tonic-gate return (fsem_getvfsops(vfsp)); 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate /* 4577c478bd9Sstevel@tonic-gate * Returns non-zero (1) if the vfsops matches that of the vfs. 4587c478bd9Sstevel@tonic-gate * Returns zero (0) if not. 4597c478bd9Sstevel@tonic-gate */ 4607c478bd9Sstevel@tonic-gate int 4617c478bd9Sstevel@tonic-gate vfs_matchops(vfs_t *vfsp, vfsops_t *vfsops) 4627c478bd9Sstevel@tonic-gate { 4637c478bd9Sstevel@tonic-gate return (vfs_getops(vfsp) == vfsops); 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate /* 4677c478bd9Sstevel@tonic-gate * Returns non-zero (1) if the file system has installed a non-default, 4687c478bd9Sstevel@tonic-gate * non-error vfs_sync routine. Returns zero (0) otherwise. 4697c478bd9Sstevel@tonic-gate */ 4707c478bd9Sstevel@tonic-gate int 4717c478bd9Sstevel@tonic-gate vfs_can_sync(vfs_t *vfsp) 4727c478bd9Sstevel@tonic-gate { 4737c478bd9Sstevel@tonic-gate /* vfs_sync() routine is not the default/error function */ 4747c478bd9Sstevel@tonic-gate return (vfs_getops(vfsp)->vfs_sync != fs_sync); 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate /* 4787c478bd9Sstevel@tonic-gate * Initialize a vfs structure. 4797c478bd9Sstevel@tonic-gate */ 4807c478bd9Sstevel@tonic-gate void 4817c478bd9Sstevel@tonic-gate vfs_init(vfs_t *vfsp, vfsops_t *op, void *data) 4827c478bd9Sstevel@tonic-gate { 4837c478bd9Sstevel@tonic-gate vfsp->vfs_count = 0; 4847c478bd9Sstevel@tonic-gate vfsp->vfs_next = vfsp; 4857c478bd9Sstevel@tonic-gate vfsp->vfs_prev = vfsp; 4867c478bd9Sstevel@tonic-gate vfsp->vfs_zone_next = vfsp; 4877c478bd9Sstevel@tonic-gate vfsp->vfs_zone_prev = vfsp; 4887c478bd9Sstevel@tonic-gate vfsp->vfs_flag = 0; 4897c478bd9Sstevel@tonic-gate vfsp->vfs_data = (data); 4907c478bd9Sstevel@tonic-gate vfsp->vfs_resource = NULL; 4917c478bd9Sstevel@tonic-gate vfsp->vfs_mntpt = NULL; 4927c478bd9Sstevel@tonic-gate vfsp->vfs_mntopts.mo_count = 0; 4937c478bd9Sstevel@tonic-gate vfsp->vfs_mntopts.mo_list = NULL; 4947c478bd9Sstevel@tonic-gate vfsp->vfs_femhead = NULL; 4957c478bd9Sstevel@tonic-gate vfsp->vfs_zone = NULL; 496*5a59a8b3Srsb /* 497*5a59a8b3Srsb * Note: Don't initialize vfs_vskap, vfs_fstypevsp since it 498*5a59a8b3Srsb * could be a problem for unbundled file systems. 499*5a59a8b3Srsb */ 5007c478bd9Sstevel@tonic-gate vfs_setops((vfsp), (op)); 5017c478bd9Sstevel@tonic-gate sema_init(&vfsp->vfs_reflock, 1, NULL, SEMA_DEFAULT, NULL); 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate /* 5067c478bd9Sstevel@tonic-gate * VFS system calls: mount, umount, syssync, statfs, fstatfs, statvfs, 5077c478bd9Sstevel@tonic-gate * fstatvfs, and sysfs moved to common/syscall. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* 5117c478bd9Sstevel@tonic-gate * Update every mounted file system. We call the vfs_sync operation of 5127c478bd9Sstevel@tonic-gate * each file system type, passing it a NULL vfsp to indicate that all 5137c478bd9Sstevel@tonic-gate * mounted file systems of that type should be updated. 5147c478bd9Sstevel@tonic-gate */ 5157c478bd9Sstevel@tonic-gate void 5167c478bd9Sstevel@tonic-gate vfs_sync(int flag) 5177c478bd9Sstevel@tonic-gate { 5187c478bd9Sstevel@tonic-gate struct vfssw *vswp; 5197c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 5207c478bd9Sstevel@tonic-gate for (vswp = &vfssw[1]; vswp < &vfssw[nfstype]; vswp++) { 5217c478bd9Sstevel@tonic-gate if (ALLOCATED_VFSSW(vswp) && VFS_INSTALLED(vswp)) { 5227c478bd9Sstevel@tonic-gate vfs_refvfssw(vswp); 5237c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 5247c478bd9Sstevel@tonic-gate (void) (*vswp->vsw_vfsops.vfs_sync)(NULL, flag, 5257c478bd9Sstevel@tonic-gate CRED()); 5267c478bd9Sstevel@tonic-gate vfs_unrefvfssw(vswp); 5277c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate void 5347c478bd9Sstevel@tonic-gate sync(void) 5357c478bd9Sstevel@tonic-gate { 5367c478bd9Sstevel@tonic-gate vfs_sync(0); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * External routines. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate krwlock_t vfssw_lock; /* lock accesses to vfssw */ 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate /* 5467c478bd9Sstevel@tonic-gate * Lock for accessing the vfs linked list. Initialized in vfs_mountroot(), 5477c478bd9Sstevel@tonic-gate * but otherwise should be accessed only via vfs_list_lock() and 5487c478bd9Sstevel@tonic-gate * vfs_list_unlock(). Also used to protect the timestamp for mods to the list. 5497c478bd9Sstevel@tonic-gate */ 5507c478bd9Sstevel@tonic-gate static krwlock_t vfslist; 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate /* 5537c478bd9Sstevel@tonic-gate * Mount devfs on /devices. This is done right after root is mounted 5547c478bd9Sstevel@tonic-gate * to provide device access support for the system 5557c478bd9Sstevel@tonic-gate */ 5567c478bd9Sstevel@tonic-gate static void 5577c478bd9Sstevel@tonic-gate vfs_mountdevices(void) 5587c478bd9Sstevel@tonic-gate { 5597c478bd9Sstevel@tonic-gate struct vfssw *vsw; 5607c478bd9Sstevel@tonic-gate struct vnode *mvp; 5617c478bd9Sstevel@tonic-gate struct mounta mounta = { /* fake mounta for devfs_mount() */ 5627c478bd9Sstevel@tonic-gate NULL, 5637c478bd9Sstevel@tonic-gate NULL, 5647c478bd9Sstevel@tonic-gate MS_SYSSPACE, 5657c478bd9Sstevel@tonic-gate NULL, 5667c478bd9Sstevel@tonic-gate NULL, 5677c478bd9Sstevel@tonic-gate 0, 5687c478bd9Sstevel@tonic-gate NULL, 5697c478bd9Sstevel@tonic-gate 0 5707c478bd9Sstevel@tonic-gate }; 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate /* 5737c478bd9Sstevel@tonic-gate * _init devfs module to fill in the vfssw 5747c478bd9Sstevel@tonic-gate */ 5757c478bd9Sstevel@tonic-gate if (modload("fs", "devfs") == -1) 5767c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "Cannot _init devfs module\n"); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate /* 5797c478bd9Sstevel@tonic-gate * Hold vfs 5807c478bd9Sstevel@tonic-gate */ 5817c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 5827c478bd9Sstevel@tonic-gate vsw = vfs_getvfsswbyname("devfs"); 5837c478bd9Sstevel@tonic-gate VFS_INIT(&devices, &vsw->vsw_vfsops, NULL); 5847c478bd9Sstevel@tonic-gate VFS_HOLD(&devices); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate /* 5877c478bd9Sstevel@tonic-gate * Locate mount point 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate if (lookupname("/devices", UIO_SYSSPACE, FOLLOW, NULLVPP, &mvp)) 5907c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "Cannot find /devices\n"); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate /* 5937c478bd9Sstevel@tonic-gate * Perform the mount of /devices 5947c478bd9Sstevel@tonic-gate */ 5957c478bd9Sstevel@tonic-gate if (VFS_MOUNT(&devices, mvp, &mounta, CRED())) 5967c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "Cannot mount /devices\n"); 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate /* 6017c478bd9Sstevel@tonic-gate * Set appropriate members and add to vfs list for mnttab display 6027c478bd9Sstevel@tonic-gate */ 6037c478bd9Sstevel@tonic-gate vfs_setresource(&devices, "/devices"); 6047c478bd9Sstevel@tonic-gate vfs_setmntpoint(&devices, "/devices"); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate /* 6077c478bd9Sstevel@tonic-gate * Hold the root of /devices so it won't go away 6087c478bd9Sstevel@tonic-gate */ 6097c478bd9Sstevel@tonic-gate if (VFS_ROOT(&devices, &devicesdir)) 6107c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vfs_mountdevices: not devices root"); 6117c478bd9Sstevel@tonic-gate VN_HOLD(devicesdir); 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate if (vfs_lock(&devices) != 0) { 6147c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot acquire vfs_lock of /devices"); 6157c478bd9Sstevel@tonic-gate return; 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate if (vn_vfswlock(mvp) != 0) { 6197c478bd9Sstevel@tonic-gate vfs_unlock(&devices); 6207c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot acquire vfswlock of /devices"); 6217c478bd9Sstevel@tonic-gate return; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate vfs_add(mvp, &devices, 0); 6257c478bd9Sstevel@tonic-gate vn_vfsunlock(mvp); 6267c478bd9Sstevel@tonic-gate vfs_unlock(&devices); 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * Mount required filesystem. This is done right after root is mounted. 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate static void 6337c478bd9Sstevel@tonic-gate vfs_mountfs(char *module, char *spec, char *path) 6347c478bd9Sstevel@tonic-gate { 6357c478bd9Sstevel@tonic-gate struct vnode *mvp; 6367c478bd9Sstevel@tonic-gate struct mounta mounta; 6377c478bd9Sstevel@tonic-gate vfs_t *vfsp; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate mounta.flags = MS_SYSSPACE | MS_DATA; 6407c478bd9Sstevel@tonic-gate mounta.fstype = module; 6417c478bd9Sstevel@tonic-gate mounta.spec = spec; 6427c478bd9Sstevel@tonic-gate mounta.dir = path; 6437c478bd9Sstevel@tonic-gate if (lookupname(path, UIO_SYSSPACE, FOLLOW, NULLVPP, &mvp)) { 6447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Cannot find %s\n", path); 6457c478bd9Sstevel@tonic-gate return; 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate if (domount(NULL, &mounta, mvp, CRED(), &vfsp)) 6487c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Cannot mount %s\n", path); 6497c478bd9Sstevel@tonic-gate else 6507c478bd9Sstevel@tonic-gate VFS_RELE(vfsp); 6517c478bd9Sstevel@tonic-gate VN_RELE(mvp); 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate /* 6557c478bd9Sstevel@tonic-gate * vfs_mountroot is called by main() to mount the root filesystem. 6567c478bd9Sstevel@tonic-gate */ 6577c478bd9Sstevel@tonic-gate void 6587c478bd9Sstevel@tonic-gate vfs_mountroot(void) 6597c478bd9Sstevel@tonic-gate { 6607c478bd9Sstevel@tonic-gate struct vnode *rvp = NULL; 6617c478bd9Sstevel@tonic-gate char *path; 6627c478bd9Sstevel@tonic-gate size_t plen; 663*5a59a8b3Srsb struct vfssw *vswp; 664*5a59a8b3Srsb extern void setup_vopstats(vfs_t *); 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate rw_init(&vfssw_lock, NULL, RW_DEFAULT, NULL); 6677c478bd9Sstevel@tonic-gate rw_init(&vfslist, NULL, RW_DEFAULT, NULL); 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /* 6707c478bd9Sstevel@tonic-gate * Alloc the vfs hash bucket array and locks 6717c478bd9Sstevel@tonic-gate */ 6727c478bd9Sstevel@tonic-gate rvfs_list = kmem_zalloc(vfshsz * sizeof (rvfs_t), KM_SLEEP); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * Call machine-dependent routine "rootconf" to choose a root 6767c478bd9Sstevel@tonic-gate * file system type. 6777c478bd9Sstevel@tonic-gate */ 6787c478bd9Sstevel@tonic-gate if (rootconf()) 6797c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vfs_mountroot: cannot mount root"); 6807c478bd9Sstevel@tonic-gate /* 6817c478bd9Sstevel@tonic-gate * Get vnode for '/'. Set up rootdir, u.u_rdir and u.u_cdir 6827c478bd9Sstevel@tonic-gate * to point to it. These are used by lookuppn() so that it 6837c478bd9Sstevel@tonic-gate * knows where to start from ('/' or '.'). 6847c478bd9Sstevel@tonic-gate */ 6857c478bd9Sstevel@tonic-gate vfs_setmntpoint(rootvfs, "/"); 6867c478bd9Sstevel@tonic-gate if (VFS_ROOT(rootvfs, &rootdir)) 6877c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vfs_mountroot: no root vnode"); 6887c478bd9Sstevel@tonic-gate u.u_cdir = rootdir; 6897c478bd9Sstevel@tonic-gate VN_HOLD(u.u_cdir); 6907c478bd9Sstevel@tonic-gate u.u_rdir = NULL; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate /* 6937c478bd9Sstevel@tonic-gate * Setup the global zone's rootvp, now that it exists. 6947c478bd9Sstevel@tonic-gate */ 6957c478bd9Sstevel@tonic-gate global_zone->zone_rootvp = rootdir; 6967c478bd9Sstevel@tonic-gate VN_HOLD(global_zone->zone_rootvp); 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate /* 6997c478bd9Sstevel@tonic-gate * Notify the module code that it can begin using the 7007c478bd9Sstevel@tonic-gate * root filesystem instead of the boot program's services. 7017c478bd9Sstevel@tonic-gate */ 7027c478bd9Sstevel@tonic-gate modrootloaded = 1; 7037c478bd9Sstevel@tonic-gate /* 7047c478bd9Sstevel@tonic-gate * Set up mnttab information for root 7057c478bd9Sstevel@tonic-gate */ 7067c478bd9Sstevel@tonic-gate vfs_setresource(rootvfs, rootfs.bo_name); 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * Notify cluster software that the root filesystem is available. 7107c478bd9Sstevel@tonic-gate */ 7117c478bd9Sstevel@tonic-gate clboot_mountroot(); 7127c478bd9Sstevel@tonic-gate 713*5a59a8b3Srsb /* Now that we're all done with the root FS, set up its vopstats */ 714*5a59a8b3Srsb if ((vswp = vfs_getvfsswbyvfsops(vfs_getops(rootvfs))) != NULL) { 715*5a59a8b3Srsb /* Set flag for statistics collection */ 716*5a59a8b3Srsb if (vswp->vsw_flag & VSW_STATS) { 717*5a59a8b3Srsb rootvfs->vfs_flag |= VFS_STATS; 718*5a59a8b3Srsb } 719*5a59a8b3Srsb vfs_unrefvfssw(vswp); 720*5a59a8b3Srsb } 721*5a59a8b3Srsb setup_vopstats(rootvfs); 722*5a59a8b3Srsb 7237c478bd9Sstevel@tonic-gate /* 7247c478bd9Sstevel@tonic-gate * Mount /devices, /system/contract, /etc/mnttab, /etc/svc/volatile, 7257c478bd9Sstevel@tonic-gate * /system/object, and /proc. 7267c478bd9Sstevel@tonic-gate */ 7277c478bd9Sstevel@tonic-gate vfs_mountdevices(); 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate vfs_mountfs("ctfs", "ctfs", CTFS_ROOT); 7307c478bd9Sstevel@tonic-gate vfs_mountfs("proc", "/proc", "/proc"); 7317c478bd9Sstevel@tonic-gate vfs_mountfs("mntfs", "/etc/mnttab", "/etc/mnttab"); 7327c478bd9Sstevel@tonic-gate vfs_mountfs("tmpfs", "/etc/svc/volatile", "/etc/svc/volatile"); 7337c478bd9Sstevel@tonic-gate vfs_mountfs("objfs", "objfs", OBJFS_ROOT); 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate #ifdef __sparc 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * This bit of magic can go away when we convert sparc to 7387c478bd9Sstevel@tonic-gate * the new boot architecture based on ramdisk. 7397c478bd9Sstevel@tonic-gate * 7407c478bd9Sstevel@tonic-gate * Booting off a mirrored root volume: 7417c478bd9Sstevel@tonic-gate * At this point, we have booted and mounted root on a 7427c478bd9Sstevel@tonic-gate * single component of the mirror. Complete the boot 7437c478bd9Sstevel@tonic-gate * by configuring SVM and converting the root to the 7447c478bd9Sstevel@tonic-gate * dev_t of the mirrored root device. This dev_t conversion 7457c478bd9Sstevel@tonic-gate * only works because the underlying device doesn't change. 7467c478bd9Sstevel@tonic-gate */ 7477c478bd9Sstevel@tonic-gate if (root_is_svm) { 7487c478bd9Sstevel@tonic-gate if (svm_rootconf()) { 7497c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vfs_mountroot: cannot remount root"); 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* 7537c478bd9Sstevel@tonic-gate * mnttab should reflect the new root device 7547c478bd9Sstevel@tonic-gate */ 7557c478bd9Sstevel@tonic-gate vfs_lock_wait(rootvfs); 7567c478bd9Sstevel@tonic-gate vfs_setresource(rootvfs, rootfs.bo_name); 7577c478bd9Sstevel@tonic-gate vfs_unlock(rootvfs); 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate #endif /* __sparc */ 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate * Look up the root device via devfs so that a dv_node is 7637c478bd9Sstevel@tonic-gate * created for it. The vnode is never VN_RELE()ed. 7647c478bd9Sstevel@tonic-gate * We allocate more than MAXPATHLEN so that the 7657c478bd9Sstevel@tonic-gate * buffer passed to i_ddi_prompath_to_devfspath() is 7667c478bd9Sstevel@tonic-gate * exactly MAXPATHLEN (the function expects a buffer 7677c478bd9Sstevel@tonic-gate * of that length). 7687c478bd9Sstevel@tonic-gate */ 7697c478bd9Sstevel@tonic-gate plen = strlen("/devices"); 7707c478bd9Sstevel@tonic-gate path = kmem_alloc(plen + MAXPATHLEN, KM_SLEEP); 7717c478bd9Sstevel@tonic-gate (void) strcpy(path, "/devices"); 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate if (i_ddi_prompath_to_devfspath(rootfs.bo_name, path + plen) 7747c478bd9Sstevel@tonic-gate != DDI_SUCCESS || 7757c478bd9Sstevel@tonic-gate lookupname(path, UIO_SYSSPACE, FOLLOW, NULLVPP, &rvp)) { 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate /* NUL terminate in case "path" has garbage */ 7787c478bd9Sstevel@tonic-gate path[plen + MAXPATHLEN - 1] = '\0'; 7797c478bd9Sstevel@tonic-gate #ifdef DEBUG 7807c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!Cannot lookup root device: %s", path); 7817c478bd9Sstevel@tonic-gate #endif 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate kmem_free(path, plen + MAXPATHLEN); 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 786fcad04f7Sevanl /* 787fcad04f7Sevanl * If remount failed and we're in a zone we need to check for the zone 788fcad04f7Sevanl * root path and strip it before the call to vfs_setpath(). 789fcad04f7Sevanl * 790fcad04f7Sevanl * If strpath doesn't begin with the zone_rootpath the original 791fcad04f7Sevanl * strpath is returned unchanged. 792fcad04f7Sevanl */ 793fcad04f7Sevanl static const char * 794fcad04f7Sevanl stripzonepath(const char *strpath) 795fcad04f7Sevanl { 796fcad04f7Sevanl char *str1, *str2; 797fcad04f7Sevanl int i; 798fcad04f7Sevanl zone_t *zonep = curproc->p_zone; 799fcad04f7Sevanl 800fcad04f7Sevanl if (zonep->zone_rootpath == NULL || strpath == NULL) { 801fcad04f7Sevanl return (NULL); 802fcad04f7Sevanl } 803fcad04f7Sevanl 804fcad04f7Sevanl /* 805fcad04f7Sevanl * we check for the end of the string at one past the 806fcad04f7Sevanl * current position because the zone_rootpath always 807fcad04f7Sevanl * ends with "/" but we don't want to strip that off. 808fcad04f7Sevanl */ 809fcad04f7Sevanl str1 = zonep->zone_rootpath; 810fcad04f7Sevanl str2 = (char *)strpath; 811fcad04f7Sevanl ASSERT(str1[0] != '\0'); 812fcad04f7Sevanl for (i = 0; str1[i + 1] != '\0'; i++) { 813fcad04f7Sevanl if (str1[i] != str2[i]) 814fcad04f7Sevanl return ((char *)strpath); 815fcad04f7Sevanl } 816fcad04f7Sevanl return (&str2[i]); 817fcad04f7Sevanl } 818fcad04f7Sevanl 8197c478bd9Sstevel@tonic-gate /* 8207c478bd9Sstevel@tonic-gate * Common mount code. Called from the system call entry point, from autofs, 8217c478bd9Sstevel@tonic-gate * and from pxfs. 8227c478bd9Sstevel@tonic-gate * 8237c478bd9Sstevel@tonic-gate * Takes the effective file system type, mount arguments, the mount point 8247c478bd9Sstevel@tonic-gate * vnode, flags specifying whether the mount is a remount and whether it 8257c478bd9Sstevel@tonic-gate * should be entered into the vfs list, and credentials. Fills in its vfspp 8267c478bd9Sstevel@tonic-gate * parameter with the mounted file system instance's vfs. 8277c478bd9Sstevel@tonic-gate * 8287c478bd9Sstevel@tonic-gate * Note that the effective file system type is specified as a string. It may 8297c478bd9Sstevel@tonic-gate * be null, in which case it's determined from the mount arguments, and may 8307c478bd9Sstevel@tonic-gate * differ from the type specified in the mount arguments; this is a hook to 8317c478bd9Sstevel@tonic-gate * allow interposition when instantiating file system instances. 8327c478bd9Sstevel@tonic-gate * 8337c478bd9Sstevel@tonic-gate * The caller is responsible for releasing its own hold on the mount point 8347c478bd9Sstevel@tonic-gate * vp (this routine does its own hold when necessary). 8357c478bd9Sstevel@tonic-gate * Also note that for remounts, the mount point vp should be the vnode for 8367c478bd9Sstevel@tonic-gate * the root of the file system rather than the vnode that the file system 8377c478bd9Sstevel@tonic-gate * is mounted on top of. 8387c478bd9Sstevel@tonic-gate */ 8397c478bd9Sstevel@tonic-gate int 8407c478bd9Sstevel@tonic-gate domount(char *fsname, struct mounta *uap, vnode_t *vp, struct cred *credp, 8417c478bd9Sstevel@tonic-gate struct vfs **vfspp) 8427c478bd9Sstevel@tonic-gate { 8437c478bd9Sstevel@tonic-gate struct vfssw *vswp; 8447c478bd9Sstevel@tonic-gate vfsops_t *vfsops; 8457c478bd9Sstevel@tonic-gate struct vfs *vfsp; 8467c478bd9Sstevel@tonic-gate struct vnode *bvp; 8477c478bd9Sstevel@tonic-gate dev_t bdev = 0; 8487c478bd9Sstevel@tonic-gate mntopts_t mnt_mntopts; 8497c478bd9Sstevel@tonic-gate int error = 0; 8507c478bd9Sstevel@tonic-gate int copyout_error = 0; 8517c478bd9Sstevel@tonic-gate int ovflags; 8527c478bd9Sstevel@tonic-gate char *opts = uap->optptr; 8537c478bd9Sstevel@tonic-gate char *inargs = opts; 8547c478bd9Sstevel@tonic-gate int optlen = uap->optlen; 8557c478bd9Sstevel@tonic-gate int remount; 8567c478bd9Sstevel@tonic-gate int rdonly; 8577c478bd9Sstevel@tonic-gate int nbmand = 0; 8587c478bd9Sstevel@tonic-gate int delmip = 0; 8597c478bd9Sstevel@tonic-gate int addmip = 0; 8607c478bd9Sstevel@tonic-gate int splice = ((uap->flags & MS_NOSPLICE) == 0); 8617c478bd9Sstevel@tonic-gate int fromspace = (uap->flags & MS_SYSSPACE) ? 8627c478bd9Sstevel@tonic-gate UIO_SYSSPACE : UIO_USERSPACE; 8637c478bd9Sstevel@tonic-gate char *resource = NULL, *mountpt = NULL; 8647c478bd9Sstevel@tonic-gate refstr_t *oldresource, *oldmntpt; 8657c478bd9Sstevel@tonic-gate struct pathname pn, rpn; 866*5a59a8b3Srsb extern void setup_vopstats(vfs_t *); 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 8697c478bd9Sstevel@tonic-gate * The v_flag value for the mount point vp is permanently set 8707c478bd9Sstevel@tonic-gate * to VVFSLOCK so that no one bypasses the vn_vfs*locks routine 8717c478bd9Sstevel@tonic-gate * for mount point locking. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate mutex_enter(&vp->v_lock); 8747c478bd9Sstevel@tonic-gate vp->v_flag |= VVFSLOCK; 8757c478bd9Sstevel@tonic-gate mutex_exit(&vp->v_lock); 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate mnt_mntopts.mo_count = 0; 8787c478bd9Sstevel@tonic-gate /* 8797c478bd9Sstevel@tonic-gate * Find the ops vector to use to invoke the file system-specific mount 8807c478bd9Sstevel@tonic-gate * method. If the fsname argument is non-NULL, use it directly. 8817c478bd9Sstevel@tonic-gate * Otherwise, dig the file system type information out of the mount 8827c478bd9Sstevel@tonic-gate * arguments. 8837c478bd9Sstevel@tonic-gate * 8847c478bd9Sstevel@tonic-gate * A side effect is to hold the vfssw entry. 8857c478bd9Sstevel@tonic-gate * 8867c478bd9Sstevel@tonic-gate * Mount arguments can be specified in several ways, which are 8877c478bd9Sstevel@tonic-gate * distinguished by flag bit settings. The preferred way is to set 8887c478bd9Sstevel@tonic-gate * MS_OPTIONSTR, indicating an 8 argument mount with the file system 8897c478bd9Sstevel@tonic-gate * type supplied as a character string and the last two arguments 8907c478bd9Sstevel@tonic-gate * being a pointer to a character buffer and the size of the buffer. 8917c478bd9Sstevel@tonic-gate * On entry, the buffer holds a null terminated list of options; on 8927c478bd9Sstevel@tonic-gate * return, the string is the list of options the file system 8937c478bd9Sstevel@tonic-gate * recognized. If MS_DATA is set arguments five and six point to a 8947c478bd9Sstevel@tonic-gate * block of binary data which the file system interprets. 8957c478bd9Sstevel@tonic-gate * A further wrinkle is that some callers don't set MS_FSS and MS_DATA 8967c478bd9Sstevel@tonic-gate * consistently with these conventions. To handle them, we check to 8977c478bd9Sstevel@tonic-gate * see whether the pointer to the file system name has a numeric value 8987c478bd9Sstevel@tonic-gate * less than 256. If so, we treat it as an index. 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate if (fsname != NULL) { 9017c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfssw(fsname)) == NULL) { 9027c478bd9Sstevel@tonic-gate return (EINVAL); 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate } else if (uap->flags & (MS_OPTIONSTR | MS_DATA | MS_FSS)) { 9057c478bd9Sstevel@tonic-gate size_t n; 9067c478bd9Sstevel@tonic-gate uint_t fstype; 9077c478bd9Sstevel@tonic-gate char name[FSTYPSZ]; 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate if ((fstype = (uintptr_t)uap->fstype) < 256) { 9107c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 9117c478bd9Sstevel@tonic-gate if (fstype == 0 || fstype >= nfstype || 9127c478bd9Sstevel@tonic-gate !ALLOCATED_VFSSW(&vfssw[fstype])) { 9137c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 9147c478bd9Sstevel@tonic-gate return (EINVAL); 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate (void) strcpy(name, vfssw[fstype].vsw_name); 9177c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 9187c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfssw(name)) == NULL) 9197c478bd9Sstevel@tonic-gate return (EINVAL); 9207c478bd9Sstevel@tonic-gate } else { 9217c478bd9Sstevel@tonic-gate /* 9227c478bd9Sstevel@tonic-gate * Handle either kernel or user address space. 9237c478bd9Sstevel@tonic-gate */ 9247c478bd9Sstevel@tonic-gate if (uap->flags & MS_SYSSPACE) { 9257c478bd9Sstevel@tonic-gate error = copystr(uap->fstype, name, 9267c478bd9Sstevel@tonic-gate FSTYPSZ, &n); 9277c478bd9Sstevel@tonic-gate } else { 9287c478bd9Sstevel@tonic-gate error = copyinstr(uap->fstype, name, 9297c478bd9Sstevel@tonic-gate FSTYPSZ, &n); 9307c478bd9Sstevel@tonic-gate } 9317c478bd9Sstevel@tonic-gate if (error) { 9327c478bd9Sstevel@tonic-gate if (error == ENAMETOOLONG) 9337c478bd9Sstevel@tonic-gate return (EINVAL); 9347c478bd9Sstevel@tonic-gate return (error); 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfssw(name)) == NULL) 9377c478bd9Sstevel@tonic-gate return (EINVAL); 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate } else { 9407c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfsswbyvfsops(vfs_getops(rootvfs))) == NULL) 9417c478bd9Sstevel@tonic-gate return (EINVAL); 9427c478bd9Sstevel@tonic-gate } 9437c478bd9Sstevel@tonic-gate if (!VFS_INSTALLED(vswp)) 9447c478bd9Sstevel@tonic-gate return (EINVAL); 9457c478bd9Sstevel@tonic-gate vfsops = &vswp->vsw_vfsops; 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate vfs_copyopttbl(&vswp->vsw_optproto, &mnt_mntopts); 9487c478bd9Sstevel@tonic-gate /* 9497c478bd9Sstevel@tonic-gate * Fetch mount options and parse them for generic vfs options 9507c478bd9Sstevel@tonic-gate */ 9517c478bd9Sstevel@tonic-gate if (uap->flags & MS_OPTIONSTR) { 9527c478bd9Sstevel@tonic-gate /* 9537c478bd9Sstevel@tonic-gate * Limit the buffer size 9547c478bd9Sstevel@tonic-gate */ 9557c478bd9Sstevel@tonic-gate if (optlen < 0 || optlen > MAX_MNTOPT_STR) { 9567c478bd9Sstevel@tonic-gate error = EINVAL; 9577c478bd9Sstevel@tonic-gate goto errout; 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate if ((uap->flags & MS_SYSSPACE) == 0) { 9607c478bd9Sstevel@tonic-gate inargs = kmem_alloc(MAX_MNTOPT_STR, KM_SLEEP); 9617c478bd9Sstevel@tonic-gate inargs[0] = '\0'; 9627c478bd9Sstevel@tonic-gate if (optlen) { 9637c478bd9Sstevel@tonic-gate error = copyinstr(opts, inargs, (size_t)optlen, 9647c478bd9Sstevel@tonic-gate NULL); 9657c478bd9Sstevel@tonic-gate if (error) { 9667c478bd9Sstevel@tonic-gate goto errout; 9677c478bd9Sstevel@tonic-gate } 9687c478bd9Sstevel@tonic-gate } 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate vfs_parsemntopts(&mnt_mntopts, inargs, 0); 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate /* 9737c478bd9Sstevel@tonic-gate * Flag bits override the options string. 9747c478bd9Sstevel@tonic-gate */ 9757c478bd9Sstevel@tonic-gate if (uap->flags & MS_REMOUNT) 9767c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(&mnt_mntopts, MNTOPT_REMOUNT, NULL, 0, 0); 9777c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY) 9787c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(&mnt_mntopts, MNTOPT_RO, NULL, 0, 0); 9797c478bd9Sstevel@tonic-gate if (uap->flags & MS_NOSUID) 9807c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(&mnt_mntopts, MNTOPT_NOSUID, NULL, 0, 0); 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate /* 9837c478bd9Sstevel@tonic-gate * Check if this is a remount; must be set in the option string and 9847c478bd9Sstevel@tonic-gate * the file system must support a remount option. 9857c478bd9Sstevel@tonic-gate */ 9867c478bd9Sstevel@tonic-gate if (remount = vfs_optionisset_nolock(&mnt_mntopts, 9877c478bd9Sstevel@tonic-gate MNTOPT_REMOUNT, NULL)) { 9887c478bd9Sstevel@tonic-gate if (!(vswp->vsw_flag & VSW_CANREMOUNT)) { 9897c478bd9Sstevel@tonic-gate error = ENOTSUP; 9907c478bd9Sstevel@tonic-gate goto errout; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate uap->flags |= MS_REMOUNT; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate /* 9967c478bd9Sstevel@tonic-gate * uap->flags and vfs_optionisset() should agree. 9977c478bd9Sstevel@tonic-gate */ 9987c478bd9Sstevel@tonic-gate if (rdonly = vfs_optionisset_nolock(&mnt_mntopts, MNTOPT_RO, NULL)) { 9997c478bd9Sstevel@tonic-gate uap->flags |= MS_RDONLY; 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate if (vfs_optionisset_nolock(&mnt_mntopts, MNTOPT_NOSUID, NULL)) { 10027c478bd9Sstevel@tonic-gate uap->flags |= MS_NOSUID; 10037c478bd9Sstevel@tonic-gate } 10047c478bd9Sstevel@tonic-gate nbmand = vfs_optionisset_nolock(&mnt_mntopts, MNTOPT_NBMAND, NULL); 10057c478bd9Sstevel@tonic-gate ASSERT(splice || !remount); 10067c478bd9Sstevel@tonic-gate /* 10077c478bd9Sstevel@tonic-gate * If we are splicing the fs into the namespace, 10087c478bd9Sstevel@tonic-gate * perform mount point checks. 10097c478bd9Sstevel@tonic-gate * 10107c478bd9Sstevel@tonic-gate * We want to resolve the path for the mount point to eliminate 10117c478bd9Sstevel@tonic-gate * '.' and ".." and symlinks in mount points; we can't do the 10127c478bd9Sstevel@tonic-gate * same for the resource string, since it would turn 10137c478bd9Sstevel@tonic-gate * "/dev/dsk/c0t0d0s0" into "/devices/pci@...". We need to do 10147c478bd9Sstevel@tonic-gate * this before grabbing vn_vfswlock(), because otherwise we 10157c478bd9Sstevel@tonic-gate * would deadlock with lookuppn(). 10167c478bd9Sstevel@tonic-gate */ 10177c478bd9Sstevel@tonic-gate if (splice) { 10187c478bd9Sstevel@tonic-gate ASSERT(vp->v_count > 0); 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate /* 10217c478bd9Sstevel@tonic-gate * Pick up mount point and device from appropriate space. 10227c478bd9Sstevel@tonic-gate */ 10237c478bd9Sstevel@tonic-gate if (pn_get(uap->spec, fromspace, &pn) == 0) { 10247c478bd9Sstevel@tonic-gate resource = kmem_alloc(pn.pn_pathlen + 1, 10257c478bd9Sstevel@tonic-gate KM_SLEEP); 10267c478bd9Sstevel@tonic-gate (void) strcpy(resource, pn.pn_path); 10277c478bd9Sstevel@tonic-gate pn_free(&pn); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate /* 10307c478bd9Sstevel@tonic-gate * Do a lookupname prior to taking the 10317c478bd9Sstevel@tonic-gate * writelock. Mark this as completed if 10327c478bd9Sstevel@tonic-gate * successful for later cleanup and addition to 10337c478bd9Sstevel@tonic-gate * the mount in progress table. 10347c478bd9Sstevel@tonic-gate */ 10357c478bd9Sstevel@tonic-gate if ((uap->flags & MS_GLOBAL) == 0 && 10367c478bd9Sstevel@tonic-gate lookupname(uap->spec, fromspace, 10377c478bd9Sstevel@tonic-gate FOLLOW, NULL, &bvp) == 0) { 10387c478bd9Sstevel@tonic-gate addmip = 1; 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate if ((error = pn_get(uap->dir, fromspace, &pn)) == 0) { 10427c478bd9Sstevel@tonic-gate pathname_t *pnp; 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate if (*pn.pn_path != '/') { 10457c478bd9Sstevel@tonic-gate error = EINVAL; 10467c478bd9Sstevel@tonic-gate pn_free(&pn); 10477c478bd9Sstevel@tonic-gate goto errout; 10487c478bd9Sstevel@tonic-gate } 10497c478bd9Sstevel@tonic-gate pn_alloc(&rpn); 10507c478bd9Sstevel@tonic-gate /* 10517c478bd9Sstevel@tonic-gate * Kludge to prevent autofs from deadlocking with 10527c478bd9Sstevel@tonic-gate * itself when it calls domount(). 10537c478bd9Sstevel@tonic-gate * 10547c478bd9Sstevel@tonic-gate * If autofs is calling, it is because it is doing 10557c478bd9Sstevel@tonic-gate * (autofs) mounts in the process of an NFS mount. A 10567c478bd9Sstevel@tonic-gate * lookuppn() here would cause us to block waiting for 10577c478bd9Sstevel@tonic-gate * said NFS mount to complete, which can't since this 10587c478bd9Sstevel@tonic-gate * is the thread that was supposed to doing it. 10597c478bd9Sstevel@tonic-gate */ 10607c478bd9Sstevel@tonic-gate if (fromspace == UIO_USERSPACE) { 10617c478bd9Sstevel@tonic-gate if ((error = lookuppn(&pn, &rpn, FOLLOW, NULL, 10627c478bd9Sstevel@tonic-gate NULL)) == 0) { 10637c478bd9Sstevel@tonic-gate pnp = &rpn; 10647c478bd9Sstevel@tonic-gate } else { 10657c478bd9Sstevel@tonic-gate /* 10667c478bd9Sstevel@tonic-gate * The file disappeared or otherwise 10677c478bd9Sstevel@tonic-gate * became inaccessible since we opened 10687c478bd9Sstevel@tonic-gate * it; might as well fail the mount 10697c478bd9Sstevel@tonic-gate * since the mount point is no longer 10707c478bd9Sstevel@tonic-gate * accessible. 10717c478bd9Sstevel@tonic-gate */ 10727c478bd9Sstevel@tonic-gate pn_free(&rpn); 10737c478bd9Sstevel@tonic-gate pn_free(&pn); 10747c478bd9Sstevel@tonic-gate goto errout; 10757c478bd9Sstevel@tonic-gate } 10767c478bd9Sstevel@tonic-gate } else { 10777c478bd9Sstevel@tonic-gate pnp = &pn; 10787c478bd9Sstevel@tonic-gate } 10797c478bd9Sstevel@tonic-gate mountpt = kmem_alloc(pnp->pn_pathlen + 1, KM_SLEEP); 10807c478bd9Sstevel@tonic-gate (void) strcpy(mountpt, pnp->pn_path); 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* 10837c478bd9Sstevel@tonic-gate * If the addition of the zone's rootpath 10847c478bd9Sstevel@tonic-gate * would push us over a total path length 10857c478bd9Sstevel@tonic-gate * of MAXPATHLEN, we fail the mount with 10867c478bd9Sstevel@tonic-gate * ENAMETOOLONG, which is what we would have 10877c478bd9Sstevel@tonic-gate * gotten if we were trying to perform the same 10887c478bd9Sstevel@tonic-gate * mount in the global zone. 10897c478bd9Sstevel@tonic-gate * 10907c478bd9Sstevel@tonic-gate * strlen() doesn't count the trailing 10917c478bd9Sstevel@tonic-gate * '\0', but zone_rootpathlen counts both a 10927c478bd9Sstevel@tonic-gate * trailing '/' and the terminating '\0'. 10937c478bd9Sstevel@tonic-gate */ 10947c478bd9Sstevel@tonic-gate if ((curproc->p_zone->zone_rootpathlen - 1 + 10957c478bd9Sstevel@tonic-gate strlen(mountpt)) > MAXPATHLEN || 10967c478bd9Sstevel@tonic-gate (resource != NULL && 10977c478bd9Sstevel@tonic-gate (curproc->p_zone->zone_rootpathlen - 1 + 10987c478bd9Sstevel@tonic-gate strlen(resource)) > MAXPATHLEN)) { 10997c478bd9Sstevel@tonic-gate error = ENAMETOOLONG; 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate pn_free(&rpn); 11037c478bd9Sstevel@tonic-gate pn_free(&pn); 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate if (error) 11077c478bd9Sstevel@tonic-gate goto errout; 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate /* 11107c478bd9Sstevel@tonic-gate * Prevent path name resolution from proceeding past 11117c478bd9Sstevel@tonic-gate * the mount point. 11127c478bd9Sstevel@tonic-gate */ 11137c478bd9Sstevel@tonic-gate if (vn_vfswlock(vp) != 0) { 11147c478bd9Sstevel@tonic-gate error = EBUSY; 11157c478bd9Sstevel@tonic-gate goto errout; 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate /* 11197c478bd9Sstevel@tonic-gate * Verify that it's legitimate to establish a mount on 11207c478bd9Sstevel@tonic-gate * the prospective mount point. 11217c478bd9Sstevel@tonic-gate */ 11227c478bd9Sstevel@tonic-gate if (vn_mountedvfs(vp) != NULL) { 11237c478bd9Sstevel@tonic-gate /* 11247c478bd9Sstevel@tonic-gate * The mount point lock was obtained after some 11257c478bd9Sstevel@tonic-gate * other thread raced through and established a mount. 11267c478bd9Sstevel@tonic-gate */ 11277c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 11287c478bd9Sstevel@tonic-gate error = EBUSY; 11297c478bd9Sstevel@tonic-gate goto errout; 11307c478bd9Sstevel@tonic-gate } 11317c478bd9Sstevel@tonic-gate if (vp->v_flag & VNOMOUNT) { 11327c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 11337c478bd9Sstevel@tonic-gate error = EINVAL; 11347c478bd9Sstevel@tonic-gate goto errout; 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate } 11377c478bd9Sstevel@tonic-gate if ((uap->flags & (MS_DATA | MS_OPTIONSTR)) == 0) { 11387c478bd9Sstevel@tonic-gate uap->dataptr = NULL; 11397c478bd9Sstevel@tonic-gate uap->datalen = 0; 11407c478bd9Sstevel@tonic-gate } 11417c478bd9Sstevel@tonic-gate 11427c478bd9Sstevel@tonic-gate /* 11437c478bd9Sstevel@tonic-gate * If this is a remount, we don't want to create a new VFS. 11447c478bd9Sstevel@tonic-gate * Instead, we pass the existing one with a remount flag. 11457c478bd9Sstevel@tonic-gate */ 11467c478bd9Sstevel@tonic-gate if (remount) { 11477c478bd9Sstevel@tonic-gate /* 11487c478bd9Sstevel@tonic-gate * Confirm that the mount point is the root vnode of the 11497c478bd9Sstevel@tonic-gate * file system that is being remounted. 11507c478bd9Sstevel@tonic-gate * This can happen if the user specifies a different 11517c478bd9Sstevel@tonic-gate * mount point directory pathname in the (re)mount command. 11527c478bd9Sstevel@tonic-gate * 11537c478bd9Sstevel@tonic-gate * Code below can only be reached if splice is true, so it's 11547c478bd9Sstevel@tonic-gate * safe to do vn_vfsunlock() here. 11557c478bd9Sstevel@tonic-gate */ 11567c478bd9Sstevel@tonic-gate if ((vp->v_flag & VROOT) == 0) { 11577c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 11587c478bd9Sstevel@tonic-gate error = ENOENT; 11597c478bd9Sstevel@tonic-gate goto errout; 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate /* 11627c478bd9Sstevel@tonic-gate * Disallow making file systems read-only unless file system 11637c478bd9Sstevel@tonic-gate * explicitly allows it in its vfssw. Ignore other flags. 11647c478bd9Sstevel@tonic-gate */ 11657c478bd9Sstevel@tonic-gate if (rdonly && vn_is_readonly(vp) == 0 && 11667c478bd9Sstevel@tonic-gate (vswp->vsw_flag & VSW_CANRWRO) == 0) { 11677c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 11687c478bd9Sstevel@tonic-gate error = EINVAL; 11697c478bd9Sstevel@tonic-gate goto errout; 11707c478bd9Sstevel@tonic-gate } 11717c478bd9Sstevel@tonic-gate /* 11727c478bd9Sstevel@tonic-gate * Changing the NBMAND setting on remounts is permitted 11737c478bd9Sstevel@tonic-gate * but logged since it can lead to unexpected behavior. 11747c478bd9Sstevel@tonic-gate * We also counsel against using it for / and /usr. 11757c478bd9Sstevel@tonic-gate */ 11767c478bd9Sstevel@tonic-gate if ((nbmand && ((vp->v_vfsp->vfs_flag & VFS_NBMAND) == 0)) || 11777c478bd9Sstevel@tonic-gate (!nbmand && (vp->v_vfsp->vfs_flag & VFS_NBMAND))) { 11787c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "domount: nbmand turned %s via " 11797c478bd9Sstevel@tonic-gate "remounting %s", nbmand ? "on" : "off", 11807c478bd9Sstevel@tonic-gate refstr_value(vp->v_vfsp->vfs_mntpt)); 11817c478bd9Sstevel@tonic-gate } 11827c478bd9Sstevel@tonic-gate vfsp = vp->v_vfsp; 11837c478bd9Sstevel@tonic-gate ovflags = vfsp->vfs_flag; 11847c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_REMOUNT; 11857c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_RDONLY; 11867c478bd9Sstevel@tonic-gate } else { 11877c478bd9Sstevel@tonic-gate vfsp = kmem_alloc(sizeof (vfs_t), KM_SLEEP); 11887c478bd9Sstevel@tonic-gate VFS_INIT(vfsp, vfsops, NULL); 11897c478bd9Sstevel@tonic-gate } 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); 11927c478bd9Sstevel@tonic-gate 11937c478bd9Sstevel@tonic-gate /* 11947c478bd9Sstevel@tonic-gate * The vfs_reflock is not used anymore the code below explicitly 11957c478bd9Sstevel@tonic-gate * holds it preventing others accesing it directly. 11967c478bd9Sstevel@tonic-gate */ 11977c478bd9Sstevel@tonic-gate if ((sema_tryp(&vfsp->vfs_reflock) == 0) && 11987c478bd9Sstevel@tonic-gate !(vfsp->vfs_flag & VFS_REMOUNT)) 11997c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 12007c478bd9Sstevel@tonic-gate "mount type %s couldn't get vfs_reflock\n", vswp->vsw_name); 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate /* 12037c478bd9Sstevel@tonic-gate * Lock the vfs. If this is a remount we want to avoid spurious umount 12047c478bd9Sstevel@tonic-gate * failures that happen as a side-effect of fsflush() and other mount 12057c478bd9Sstevel@tonic-gate * and unmount operations that might be going on simultaneously and 12067c478bd9Sstevel@tonic-gate * may have locked the vfs currently. To not return EBUSY immediately 12077c478bd9Sstevel@tonic-gate * here we use vfs_lock_wait() instead vfs_lock() for the remount case. 12087c478bd9Sstevel@tonic-gate */ 12097c478bd9Sstevel@tonic-gate if (!remount) { 12107c478bd9Sstevel@tonic-gate if (error = vfs_lock(vfsp)) { 12117c478bd9Sstevel@tonic-gate vfsp->vfs_flag = ovflags; 12127c478bd9Sstevel@tonic-gate if (splice) 12137c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 12147c478bd9Sstevel@tonic-gate kmem_free(vfsp, sizeof (struct vfs)); 12157c478bd9Sstevel@tonic-gate goto errout; 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate } else { 12187c478bd9Sstevel@tonic-gate vfs_lock_wait(vfsp); 12197c478bd9Sstevel@tonic-gate } 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate /* 12227c478bd9Sstevel@tonic-gate * Add device to mount in progress table, global mounts require special 12237c478bd9Sstevel@tonic-gate * handling. It is possible that we have already done the lookupname 12247c478bd9Sstevel@tonic-gate * on a spliced, non-global fs. If so, we don't want to do it again 12257c478bd9Sstevel@tonic-gate * since we cannot do a lookupname after taking the 12267c478bd9Sstevel@tonic-gate * wlock above. This case is for a non-spliced, non-global filesystem. 12277c478bd9Sstevel@tonic-gate */ 12287c478bd9Sstevel@tonic-gate if (!addmip) { 12297c478bd9Sstevel@tonic-gate if ((uap->flags & MS_GLOBAL) == 0 && 12307c478bd9Sstevel@tonic-gate lookupname(uap->spec, fromspace, FOLLOW, NULL, &bvp) == 0) { 12317c478bd9Sstevel@tonic-gate addmip = 1; 12327c478bd9Sstevel@tonic-gate } 12337c478bd9Sstevel@tonic-gate } 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate if (addmip) { 12367c478bd9Sstevel@tonic-gate bdev = bvp->v_rdev; 12377c478bd9Sstevel@tonic-gate VN_RELE(bvp); 12387c478bd9Sstevel@tonic-gate vfs_addmip(bdev, vfsp); 12397c478bd9Sstevel@tonic-gate addmip = 0; 12407c478bd9Sstevel@tonic-gate delmip = 1; 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate /* 12437c478bd9Sstevel@tonic-gate * Invalidate cached entry for the mount point. 12447c478bd9Sstevel@tonic-gate */ 12457c478bd9Sstevel@tonic-gate if (splice) 12467c478bd9Sstevel@tonic-gate dnlc_purge_vp(vp); 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate /* 12497c478bd9Sstevel@tonic-gate * If have an option string but the filesystem doesn't supply a 12507c478bd9Sstevel@tonic-gate * prototype options table, create a table with the global 12517c478bd9Sstevel@tonic-gate * options and sufficient room to accept all the options in the 12527c478bd9Sstevel@tonic-gate * string. Then parse the passed in option string 12537c478bd9Sstevel@tonic-gate * accepting all the options in the string. This gives us an 12547c478bd9Sstevel@tonic-gate * option table with all the proper cancel properties for the 12557c478bd9Sstevel@tonic-gate * global options. 12567c478bd9Sstevel@tonic-gate * 12577c478bd9Sstevel@tonic-gate * Filesystems that supply a prototype options table are handled 12587c478bd9Sstevel@tonic-gate * earlier in this function. 12597c478bd9Sstevel@tonic-gate */ 12607c478bd9Sstevel@tonic-gate if (uap->flags & MS_OPTIONSTR) { 12617c478bd9Sstevel@tonic-gate if (!(vswp->vsw_flag & VSW_HASPROTO)) { 12627c478bd9Sstevel@tonic-gate mntopts_t tmp_mntopts; 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate tmp_mntopts.mo_count = 0; 12657c478bd9Sstevel@tonic-gate vfs_createopttbl_extend(&tmp_mntopts, inargs, 12667c478bd9Sstevel@tonic-gate &mnt_mntopts); 12677c478bd9Sstevel@tonic-gate vfs_parsemntopts(&tmp_mntopts, inargs, 1); 12687c478bd9Sstevel@tonic-gate vfs_swapopttbl_nolock(&mnt_mntopts, &tmp_mntopts); 12697c478bd9Sstevel@tonic-gate vfs_freeopttbl(&tmp_mntopts); 12707c478bd9Sstevel@tonic-gate } 12717c478bd9Sstevel@tonic-gate } 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate /* 12747c478bd9Sstevel@tonic-gate * Serialize with zone creations. 12757c478bd9Sstevel@tonic-gate */ 12767c478bd9Sstevel@tonic-gate mount_in_progress(); 12777c478bd9Sstevel@tonic-gate /* 12787c478bd9Sstevel@tonic-gate * Instantiate (or reinstantiate) the file system. If appropriate, 12797c478bd9Sstevel@tonic-gate * splice it into the file system name space. 12807c478bd9Sstevel@tonic-gate * 12817c478bd9Sstevel@tonic-gate * We want VFS_MOUNT() to be able to override the vfs_resource 12827c478bd9Sstevel@tonic-gate * string if necessary (ie, mntfs), and also for a remount to 12837c478bd9Sstevel@tonic-gate * change the same (necessary when remounting '/' during boot). 12847c478bd9Sstevel@tonic-gate * So we set up vfs_mntpt and vfs_resource to what we think they 12857c478bd9Sstevel@tonic-gate * should be, then hand off control to VFS_MOUNT() which can 12867c478bd9Sstevel@tonic-gate * override this. 12877c478bd9Sstevel@tonic-gate * 12887c478bd9Sstevel@tonic-gate * For safety's sake, when changing vfs_resource or vfs_mntpt of 12897c478bd9Sstevel@tonic-gate * a vfs which is on the vfs list (i.e. during a remount), we must 12907c478bd9Sstevel@tonic-gate * never set those fields to NULL. Several bits of code make 12917c478bd9Sstevel@tonic-gate * assumptions that the fields are always valid. 12927c478bd9Sstevel@tonic-gate */ 12937c478bd9Sstevel@tonic-gate vfs_swapopttbl(&mnt_mntopts, &vfsp->vfs_mntopts); 12947c478bd9Sstevel@tonic-gate if (remount) { 12957c478bd9Sstevel@tonic-gate if ((oldresource = vfsp->vfs_resource) != NULL) 12967c478bd9Sstevel@tonic-gate refstr_hold(oldresource); 12977c478bd9Sstevel@tonic-gate if ((oldmntpt = vfsp->vfs_mntpt) != NULL) 12987c478bd9Sstevel@tonic-gate refstr_hold(oldmntpt); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate vfs_setresource(vfsp, resource); 13017c478bd9Sstevel@tonic-gate vfs_setmntpoint(vfsp, mountpt); 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate error = VFS_MOUNT(vfsp, vp, uap, credp); 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate if (uap->flags & MS_RDONLY) 13067c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0); 13077c478bd9Sstevel@tonic-gate if (uap->flags & MS_NOSUID) 13087c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_NOSUID, NULL, 0); 13097c478bd9Sstevel@tonic-gate if (uap->flags & MS_GLOBAL) 13107c478bd9Sstevel@tonic-gate vfs_setmntopt(vfsp, MNTOPT_GLOBAL, NULL, 0); 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate if (error) { 13137c478bd9Sstevel@tonic-gate if (remount) { 13147c478bd9Sstevel@tonic-gate /* put back pre-remount options */ 13157c478bd9Sstevel@tonic-gate vfs_swapopttbl(&mnt_mntopts, &vfsp->vfs_mntopts); 1316fcad04f7Sevanl vfs_setmntpoint(vfsp, (stripzonepath( 1317fcad04f7Sevanl refstr_value(oldmntpt)))); 13187c478bd9Sstevel@tonic-gate if (oldmntpt) 13197c478bd9Sstevel@tonic-gate refstr_rele(oldmntpt); 1320fcad04f7Sevanl vfs_setresource(vfsp, (stripzonepath( 1321fcad04f7Sevanl refstr_value(oldresource)))); 13227c478bd9Sstevel@tonic-gate if (oldresource) 13237c478bd9Sstevel@tonic-gate refstr_rele(oldresource); 13247c478bd9Sstevel@tonic-gate vfsp->vfs_flag = ovflags; 13257c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 13267c478bd9Sstevel@tonic-gate VFS_RELE(vfsp); 13277c478bd9Sstevel@tonic-gate } else { 13287c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 13297c478bd9Sstevel@tonic-gate vfs_freemnttab(vfsp); 13307c478bd9Sstevel@tonic-gate kmem_free(vfsp, sizeof (struct vfs)); 13317c478bd9Sstevel@tonic-gate } 13327c478bd9Sstevel@tonic-gate } else { 13337c478bd9Sstevel@tonic-gate /* 13347c478bd9Sstevel@tonic-gate * Set the mount time to now 13357c478bd9Sstevel@tonic-gate */ 13367c478bd9Sstevel@tonic-gate vfsp->vfs_mtime = ddi_get_time(); 13377c478bd9Sstevel@tonic-gate if (remount) { 13387c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_REMOUNT; 13397c478bd9Sstevel@tonic-gate if (oldresource) 13407c478bd9Sstevel@tonic-gate refstr_rele(oldresource); 13417c478bd9Sstevel@tonic-gate if (oldmntpt) 13427c478bd9Sstevel@tonic-gate refstr_rele(oldmntpt); 13437c478bd9Sstevel@tonic-gate } else if (splice) { 13447c478bd9Sstevel@tonic-gate /* 13457c478bd9Sstevel@tonic-gate * Link vfsp into the name space at the mount 13467c478bd9Sstevel@tonic-gate * point. Vfs_add() is responsible for 13477c478bd9Sstevel@tonic-gate * holding the mount point which will be 13487c478bd9Sstevel@tonic-gate * released when vfs_remove() is called. 13497c478bd9Sstevel@tonic-gate */ 13507c478bd9Sstevel@tonic-gate vfs_add(vp, vfsp, uap->flags); 13517c478bd9Sstevel@tonic-gate } else { 13527c478bd9Sstevel@tonic-gate /* 13537c478bd9Sstevel@tonic-gate * Hold the reference to file system which is 13547c478bd9Sstevel@tonic-gate * not linked into the name space. 13557c478bd9Sstevel@tonic-gate */ 13567c478bd9Sstevel@tonic-gate vfsp->vfs_zone = NULL; 13577c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); 13587c478bd9Sstevel@tonic-gate vfsp->vfs_vnodecovered = NULL; 13597c478bd9Sstevel@tonic-gate } 13607c478bd9Sstevel@tonic-gate /* 13617c478bd9Sstevel@tonic-gate * Set flags for global options encountered 13627c478bd9Sstevel@tonic-gate */ 13637c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_RO, NULL)) 13647c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_RDONLY; 13657c478bd9Sstevel@tonic-gate else 13667c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_RDONLY; 13677c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) { 13687c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= (VFS_NOSETUID|VFS_NODEVICES); 13697c478bd9Sstevel@tonic-gate } else { 13707c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) 13717c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_NODEVICES; 13727c478bd9Sstevel@tonic-gate else 13737c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_NODEVICES; 13747c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) 13757c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_NOSETUID; 13767c478bd9Sstevel@tonic-gate else 13777c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_NOSETUID; 13787c478bd9Sstevel@tonic-gate } 13797c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) 13807c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_NBMAND; 13817c478bd9Sstevel@tonic-gate else 13827c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_NBMAND; 13837c478bd9Sstevel@tonic-gate 13847c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) 13857c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_XATTR; 13867c478bd9Sstevel@tonic-gate else 13877c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_XATTR; 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) 13907c478bd9Sstevel@tonic-gate vfsp->vfs_flag |= VFS_NOEXEC; 13917c478bd9Sstevel@tonic-gate else 13927c478bd9Sstevel@tonic-gate vfsp->vfs_flag &= ~VFS_NOEXEC; 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate /* 13957c478bd9Sstevel@tonic-gate * Now construct the output option string of options 13967c478bd9Sstevel@tonic-gate * we recognized. 13977c478bd9Sstevel@tonic-gate */ 13987c478bd9Sstevel@tonic-gate if (uap->flags & MS_OPTIONSTR) { 13997c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 14007c478bd9Sstevel@tonic-gate copyout_error = vfs_buildoptionstr( 14017c478bd9Sstevel@tonic-gate &vfsp->vfs_mntopts, inargs, optlen); 14027c478bd9Sstevel@tonic-gate vfs_list_unlock(); 14037c478bd9Sstevel@tonic-gate if (copyout_error == 0 && 14047c478bd9Sstevel@tonic-gate (uap->flags & MS_SYSSPACE) == 0) { 14057c478bd9Sstevel@tonic-gate copyout_error = copyoutstr(inargs, opts, 14067c478bd9Sstevel@tonic-gate optlen, NULL); 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate } 1409*5a59a8b3Srsb 1410*5a59a8b3Srsb /* Set flag for statistics collection */ 1411*5a59a8b3Srsb if (vswp->vsw_flag & VSW_STATS) { 1412*5a59a8b3Srsb vfsp->vfs_flag |= VFS_STATS; 1413*5a59a8b3Srsb } 1414*5a59a8b3Srsb 14157c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 14167c478bd9Sstevel@tonic-gate } 14177c478bd9Sstevel@tonic-gate mount_completed(); 14187c478bd9Sstevel@tonic-gate if (splice) 14197c478bd9Sstevel@tonic-gate vn_vfsunlock(vp); 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate if ((error == 0) && (copyout_error == 0)) { 1422*5a59a8b3Srsb /* 1423*5a59a8b3Srsb * If this isn't a remount, set up the vopstats before 1424*5a59a8b3Srsb * anyone can touch this 1425*5a59a8b3Srsb */ 1426*5a59a8b3Srsb if (!remount) 1427*5a59a8b3Srsb setup_vopstats(vfsp); 1428*5a59a8b3Srsb 1429*5a59a8b3Srsb /* Return vfsp to caller. */ 14307c478bd9Sstevel@tonic-gate *vfspp = vfsp; 14317c478bd9Sstevel@tonic-gate } 14327c478bd9Sstevel@tonic-gate errout: 14337c478bd9Sstevel@tonic-gate vfs_freeopttbl(&mnt_mntopts); 14347c478bd9Sstevel@tonic-gate if (resource != NULL) 14357c478bd9Sstevel@tonic-gate kmem_free(resource, strlen(resource) + 1); 14367c478bd9Sstevel@tonic-gate if (mountpt != NULL) 14377c478bd9Sstevel@tonic-gate kmem_free(mountpt, strlen(mountpt) + 1); 14387c478bd9Sstevel@tonic-gate /* 14397c478bd9Sstevel@tonic-gate * It is possible we errored prior to adding to mount in progress 14407c478bd9Sstevel@tonic-gate * table. Must free vnode we acquired with successful lookupname. 14417c478bd9Sstevel@tonic-gate */ 14427c478bd9Sstevel@tonic-gate if (addmip) 14437c478bd9Sstevel@tonic-gate VN_RELE(bvp); 14447c478bd9Sstevel@tonic-gate if (delmip) 14457c478bd9Sstevel@tonic-gate vfs_delmip(vfsp); 14467c478bd9Sstevel@tonic-gate ASSERT(vswp != NULL); 14477c478bd9Sstevel@tonic-gate vfs_unrefvfssw(vswp); 14487c478bd9Sstevel@tonic-gate if (inargs != opts) 14497c478bd9Sstevel@tonic-gate kmem_free(inargs, MAX_MNTOPT_STR); 14507c478bd9Sstevel@tonic-gate if (copyout_error) { 14517c478bd9Sstevel@tonic-gate VFS_RELE(vfsp); 14527c478bd9Sstevel@tonic-gate error = copyout_error; 14537c478bd9Sstevel@tonic-gate } 14547c478bd9Sstevel@tonic-gate return (error); 14557c478bd9Sstevel@tonic-gate } 14567c478bd9Sstevel@tonic-gate 14577c478bd9Sstevel@tonic-gate static void 14587c478bd9Sstevel@tonic-gate vfs_setpath(struct vfs *vfsp, refstr_t **refp, const char *newpath) 14597c478bd9Sstevel@tonic-gate { 14607c478bd9Sstevel@tonic-gate size_t len; 14617c478bd9Sstevel@tonic-gate refstr_t *ref; 14627c478bd9Sstevel@tonic-gate zone_t *zone = curproc->p_zone; 14637c478bd9Sstevel@tonic-gate char *sp; 14647c478bd9Sstevel@tonic-gate int have_list_lock = 0; 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate ASSERT(!VFS_ON_LIST(vfsp) || vfs_lock_held(vfsp)); 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate /* 14697c478bd9Sstevel@tonic-gate * New path must be less than MAXPATHLEN because mntfs 14707c478bd9Sstevel@tonic-gate * will only display up to MAXPATHLEN bytes. This is currently 14717c478bd9Sstevel@tonic-gate * safe, because domount() uses pn_get(), and other callers 14727c478bd9Sstevel@tonic-gate * similarly cap the size to fewer than MAXPATHLEN bytes. 14737c478bd9Sstevel@tonic-gate */ 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate ASSERT(strlen(newpath) < MAXPATHLEN); 14767c478bd9Sstevel@tonic-gate 14777c478bd9Sstevel@tonic-gate /* mntfs requires consistency while vfs list lock is held */ 14787c478bd9Sstevel@tonic-gate 14797c478bd9Sstevel@tonic-gate if (VFS_ON_LIST(vfsp)) { 14807c478bd9Sstevel@tonic-gate have_list_lock = 1; 14817c478bd9Sstevel@tonic-gate vfs_list_lock(); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate if (*refp != NULL) 14857c478bd9Sstevel@tonic-gate refstr_rele(*refp); 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate /* Do we need to modify the path? */ 14887c478bd9Sstevel@tonic-gate 14897c478bd9Sstevel@tonic-gate if (zone == global_zone || *newpath != '/') { 14907c478bd9Sstevel@tonic-gate ref = refstr_alloc(newpath); 14917c478bd9Sstevel@tonic-gate goto out; 14927c478bd9Sstevel@tonic-gate } 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate /* 14957c478bd9Sstevel@tonic-gate * Truncate the trailing '/' in the zoneroot, and merge 14967c478bd9Sstevel@tonic-gate * in the zone's rootpath with the "newpath" (resource 14977c478bd9Sstevel@tonic-gate * or mountpoint) passed in. 14987c478bd9Sstevel@tonic-gate * 14997c478bd9Sstevel@tonic-gate * The size of the required buffer is thus the size of 15007c478bd9Sstevel@tonic-gate * the buffer required for the passed-in newpath 15017c478bd9Sstevel@tonic-gate * (strlen(newpath) + 1), plus the size of the buffer 15027c478bd9Sstevel@tonic-gate * required to hold zone_rootpath (zone_rootpathlen) 15037c478bd9Sstevel@tonic-gate * minus one for one of the now-superfluous NUL 15047c478bd9Sstevel@tonic-gate * terminations, minus one for the trailing '/'. 15057c478bd9Sstevel@tonic-gate * 15067c478bd9Sstevel@tonic-gate * That gives us: 15077c478bd9Sstevel@tonic-gate * 15087c478bd9Sstevel@tonic-gate * (strlen(newpath) + 1) + zone_rootpathlen - 1 - 1 15097c478bd9Sstevel@tonic-gate * 15107c478bd9Sstevel@tonic-gate * Which is what we have below. 15117c478bd9Sstevel@tonic-gate */ 15127c478bd9Sstevel@tonic-gate 15137c478bd9Sstevel@tonic-gate len = strlen(newpath) + zone->zone_rootpathlen - 1; 15147c478bd9Sstevel@tonic-gate sp = kmem_alloc(len, KM_SLEEP); 15157c478bd9Sstevel@tonic-gate 15167c478bd9Sstevel@tonic-gate /* 15177c478bd9Sstevel@tonic-gate * Copy everything including the trailing slash, which 15187c478bd9Sstevel@tonic-gate * we then overwrite with the NUL character. 15197c478bd9Sstevel@tonic-gate */ 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate (void) strcpy(sp, zone->zone_rootpath); 15227c478bd9Sstevel@tonic-gate sp[zone->zone_rootpathlen - 2] = '\0'; 15237c478bd9Sstevel@tonic-gate (void) strcat(sp, newpath); 15247c478bd9Sstevel@tonic-gate 15257c478bd9Sstevel@tonic-gate ref = refstr_alloc(sp); 15267c478bd9Sstevel@tonic-gate kmem_free(sp, len); 15277c478bd9Sstevel@tonic-gate out: 15287c478bd9Sstevel@tonic-gate *refp = ref; 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate if (have_list_lock) { 15317c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 15327c478bd9Sstevel@tonic-gate vfs_list_unlock(); 15337c478bd9Sstevel@tonic-gate } 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate /* 15377c478bd9Sstevel@tonic-gate * Record a mounted resource name in a vfs structure. 15387c478bd9Sstevel@tonic-gate * If vfsp is already mounted, caller must hold the vfs lock. 15397c478bd9Sstevel@tonic-gate */ 15407c478bd9Sstevel@tonic-gate void 15417c478bd9Sstevel@tonic-gate vfs_setresource(struct vfs *vfsp, const char *resource) 15427c478bd9Sstevel@tonic-gate { 15437c478bd9Sstevel@tonic-gate if (resource == NULL || resource[0] == '\0') 15447c478bd9Sstevel@tonic-gate resource = VFS_NORESOURCE; 15457c478bd9Sstevel@tonic-gate vfs_setpath(vfsp, &vfsp->vfs_resource, resource); 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate /* 15497c478bd9Sstevel@tonic-gate * Record a mount point name in a vfs structure. 15507c478bd9Sstevel@tonic-gate * If vfsp is already mounted, caller must hold the vfs lock. 15517c478bd9Sstevel@tonic-gate */ 15527c478bd9Sstevel@tonic-gate void 15537c478bd9Sstevel@tonic-gate vfs_setmntpoint(struct vfs *vfsp, const char *mntpt) 15547c478bd9Sstevel@tonic-gate { 15557c478bd9Sstevel@tonic-gate if (mntpt == NULL || mntpt[0] == '\0') 15567c478bd9Sstevel@tonic-gate mntpt = VFS_NOMNTPT; 15577c478bd9Sstevel@tonic-gate vfs_setpath(vfsp, &vfsp->vfs_mntpt, mntpt); 15587c478bd9Sstevel@tonic-gate } 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate /* Returns the vfs_resource. Caller must call refstr_rele() when finished. */ 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate refstr_t * 15637c478bd9Sstevel@tonic-gate vfs_getresource(const struct vfs *vfsp) 15647c478bd9Sstevel@tonic-gate { 15657c478bd9Sstevel@tonic-gate refstr_t *resource; 15667c478bd9Sstevel@tonic-gate 15677c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 15687c478bd9Sstevel@tonic-gate resource = vfsp->vfs_resource; 15697c478bd9Sstevel@tonic-gate refstr_hold(resource); 15707c478bd9Sstevel@tonic-gate vfs_list_unlock(); 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate return (resource); 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate /* Returns the vfs_mntpt. Caller must call refstr_rele() when finished. */ 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate refstr_t * 15787c478bd9Sstevel@tonic-gate vfs_getmntpoint(const struct vfs *vfsp) 15797c478bd9Sstevel@tonic-gate { 15807c478bd9Sstevel@tonic-gate refstr_t *mntpt; 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 15837c478bd9Sstevel@tonic-gate mntpt = vfsp->vfs_mntpt; 15847c478bd9Sstevel@tonic-gate refstr_hold(mntpt); 15857c478bd9Sstevel@tonic-gate vfs_list_unlock(); 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate return (mntpt); 15887c478bd9Sstevel@tonic-gate } 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate /* 15917c478bd9Sstevel@tonic-gate * Create an empty options table with enough empty slots to hold all 15927c478bd9Sstevel@tonic-gate * The options in the options string passed as an argument. 15937c478bd9Sstevel@tonic-gate * Potentially prepend another options table. 15947c478bd9Sstevel@tonic-gate * 15957c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 15967c478bd9Sstevel@tonic-gate * to protect mops. 15977c478bd9Sstevel@tonic-gate */ 15987c478bd9Sstevel@tonic-gate static void 15997c478bd9Sstevel@tonic-gate vfs_createopttbl_extend(mntopts_t *mops, const char *opts, 16007c478bd9Sstevel@tonic-gate const mntopts_t *mtmpl) 16017c478bd9Sstevel@tonic-gate { 16027c478bd9Sstevel@tonic-gate const char *s = opts; 16037c478bd9Sstevel@tonic-gate uint_t count; 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate if (opts == NULL || *opts == '\0') { 16067c478bd9Sstevel@tonic-gate count = 0; 16077c478bd9Sstevel@tonic-gate } else { 16087c478bd9Sstevel@tonic-gate count = 1; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate /* 16117c478bd9Sstevel@tonic-gate * Count number of options in the string 16127c478bd9Sstevel@tonic-gate */ 16137c478bd9Sstevel@tonic-gate for (s = strchr(s, ','); s != NULL; s = strchr(s, ',')) { 16147c478bd9Sstevel@tonic-gate count++; 16157c478bd9Sstevel@tonic-gate s++; 16167c478bd9Sstevel@tonic-gate } 16177c478bd9Sstevel@tonic-gate } 16187c478bd9Sstevel@tonic-gate vfs_copyopttbl_extend(mtmpl, mops, count); 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate 16217c478bd9Sstevel@tonic-gate /* 16227c478bd9Sstevel@tonic-gate * Create an empty options table with enough empty slots to hold all 16237c478bd9Sstevel@tonic-gate * The options in the options string passed as an argument. 16247c478bd9Sstevel@tonic-gate * 16257c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 16267c478bd9Sstevel@tonic-gate * 16277c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 16287c478bd9Sstevel@tonic-gate * to protect mops. 16297c478bd9Sstevel@tonic-gate */ 16307c478bd9Sstevel@tonic-gate void 16317c478bd9Sstevel@tonic-gate vfs_createopttbl(mntopts_t *mops, const char *opts) 16327c478bd9Sstevel@tonic-gate { 16337c478bd9Sstevel@tonic-gate vfs_createopttbl_extend(mops, opts, NULL); 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate 16367c478bd9Sstevel@tonic-gate 16377c478bd9Sstevel@tonic-gate /* 16387c478bd9Sstevel@tonic-gate * Swap two mount options tables 16397c478bd9Sstevel@tonic-gate */ 16407c478bd9Sstevel@tonic-gate static void 16417c478bd9Sstevel@tonic-gate vfs_swapopttbl_nolock(mntopts_t *optbl1, mntopts_t *optbl2) 16427c478bd9Sstevel@tonic-gate { 16437c478bd9Sstevel@tonic-gate uint_t tmpcnt; 16447c478bd9Sstevel@tonic-gate mntopt_t *tmplist; 16457c478bd9Sstevel@tonic-gate 16467c478bd9Sstevel@tonic-gate tmpcnt = optbl2->mo_count; 16477c478bd9Sstevel@tonic-gate tmplist = optbl2->mo_list; 16487c478bd9Sstevel@tonic-gate optbl2->mo_count = optbl1->mo_count; 16497c478bd9Sstevel@tonic-gate optbl2->mo_list = optbl1->mo_list; 16507c478bd9Sstevel@tonic-gate optbl1->mo_count = tmpcnt; 16517c478bd9Sstevel@tonic-gate optbl1->mo_list = tmplist; 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate static void 16557c478bd9Sstevel@tonic-gate vfs_swapopttbl(mntopts_t *optbl1, mntopts_t *optbl2) 16567c478bd9Sstevel@tonic-gate { 16577c478bd9Sstevel@tonic-gate vfs_list_lock(); 16587c478bd9Sstevel@tonic-gate vfs_swapopttbl_nolock(optbl1, optbl2); 16597c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 16607c478bd9Sstevel@tonic-gate vfs_list_unlock(); 16617c478bd9Sstevel@tonic-gate } 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate static char ** 16647c478bd9Sstevel@tonic-gate vfs_copycancelopt_extend(char **const moc, int extend) 16657c478bd9Sstevel@tonic-gate { 16667c478bd9Sstevel@tonic-gate int i = 0; 16677c478bd9Sstevel@tonic-gate int j; 16687c478bd9Sstevel@tonic-gate char **result; 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate if (moc != NULL) { 16717c478bd9Sstevel@tonic-gate for (; moc[i] != NULL; i++) 16727c478bd9Sstevel@tonic-gate /* count number of options to cancel */; 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate if (i + extend == 0) 16767c478bd9Sstevel@tonic-gate return (NULL); 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate result = kmem_alloc((i + extend + 1) * sizeof (char *), KM_SLEEP); 16797c478bd9Sstevel@tonic-gate 16807c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 16817c478bd9Sstevel@tonic-gate result[j] = kmem_alloc(strlen(moc[j]) + 1, KM_SLEEP); 16827c478bd9Sstevel@tonic-gate (void) strcpy(result[j], moc[j]); 16837c478bd9Sstevel@tonic-gate } 16847c478bd9Sstevel@tonic-gate for (; j <= i + extend; j++) 16857c478bd9Sstevel@tonic-gate result[j] = NULL; 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate return (result); 16887c478bd9Sstevel@tonic-gate } 16897c478bd9Sstevel@tonic-gate 16907c478bd9Sstevel@tonic-gate static void 16917c478bd9Sstevel@tonic-gate vfs_copyopt(const mntopt_t *s, mntopt_t *d) 16927c478bd9Sstevel@tonic-gate { 16937c478bd9Sstevel@tonic-gate char *sp, *dp; 16947c478bd9Sstevel@tonic-gate 16957c478bd9Sstevel@tonic-gate d->mo_flags = s->mo_flags; 16967c478bd9Sstevel@tonic-gate d->mo_data = s->mo_data; 16977c478bd9Sstevel@tonic-gate sp = s->mo_name; 16987c478bd9Sstevel@tonic-gate if (sp != NULL) { 16997c478bd9Sstevel@tonic-gate dp = kmem_alloc(strlen(sp) + 1, KM_SLEEP); 17007c478bd9Sstevel@tonic-gate (void) strcpy(dp, sp); 17017c478bd9Sstevel@tonic-gate d->mo_name = dp; 17027c478bd9Sstevel@tonic-gate } else { 17037c478bd9Sstevel@tonic-gate d->mo_name = NULL; /* should never happen */ 17047c478bd9Sstevel@tonic-gate } 17057c478bd9Sstevel@tonic-gate 17067c478bd9Sstevel@tonic-gate d->mo_cancel = vfs_copycancelopt_extend(s->mo_cancel, 0); 17077c478bd9Sstevel@tonic-gate 17087c478bd9Sstevel@tonic-gate sp = s->mo_arg; 17097c478bd9Sstevel@tonic-gate if (sp != NULL) { 17107c478bd9Sstevel@tonic-gate dp = kmem_alloc(strlen(sp) + 1, KM_SLEEP); 17117c478bd9Sstevel@tonic-gate (void) strcpy(dp, sp); 17127c478bd9Sstevel@tonic-gate d->mo_arg = dp; 17137c478bd9Sstevel@tonic-gate } else { 17147c478bd9Sstevel@tonic-gate d->mo_arg = NULL; 17157c478bd9Sstevel@tonic-gate } 17167c478bd9Sstevel@tonic-gate } 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* 17197c478bd9Sstevel@tonic-gate * Copy a mount options table, possibly allocating some spare 17207c478bd9Sstevel@tonic-gate * slots at the end. It is permissible to copy_extend the NULL table. 17217c478bd9Sstevel@tonic-gate */ 17227c478bd9Sstevel@tonic-gate static void 17237c478bd9Sstevel@tonic-gate vfs_copyopttbl_extend(const mntopts_t *smo, mntopts_t *dmo, int extra) 17247c478bd9Sstevel@tonic-gate { 17257c478bd9Sstevel@tonic-gate uint_t i, count; 17267c478bd9Sstevel@tonic-gate mntopt_t *motbl; 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate /* 17297c478bd9Sstevel@tonic-gate * Clear out any existing stuff in the options table being initialized 17307c478bd9Sstevel@tonic-gate */ 17317c478bd9Sstevel@tonic-gate vfs_freeopttbl(dmo); 17327c478bd9Sstevel@tonic-gate count = (smo == NULL) ? 0 : smo->mo_count; 17337c478bd9Sstevel@tonic-gate if ((count + extra) == 0) /* nothing to do */ 17347c478bd9Sstevel@tonic-gate return; 17357c478bd9Sstevel@tonic-gate dmo->mo_count = count + extra; 17367c478bd9Sstevel@tonic-gate motbl = kmem_zalloc((count + extra) * sizeof (mntopt_t), KM_SLEEP); 17377c478bd9Sstevel@tonic-gate dmo->mo_list = motbl; 17387c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 17397c478bd9Sstevel@tonic-gate vfs_copyopt(&smo->mo_list[i], &motbl[i]); 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate for (i = count; i < count + extra; i++) { 17427c478bd9Sstevel@tonic-gate motbl[i].mo_flags = MO_EMPTY; 17437c478bd9Sstevel@tonic-gate } 17447c478bd9Sstevel@tonic-gate } 17457c478bd9Sstevel@tonic-gate 17467c478bd9Sstevel@tonic-gate /* 17477c478bd9Sstevel@tonic-gate * Copy a mount options table. 17487c478bd9Sstevel@tonic-gate * 17497c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 17507c478bd9Sstevel@tonic-gate * 17517c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 17527c478bd9Sstevel@tonic-gate * to protect smo and dmo. 17537c478bd9Sstevel@tonic-gate */ 17547c478bd9Sstevel@tonic-gate void 17557c478bd9Sstevel@tonic-gate vfs_copyopttbl(const mntopts_t *smo, mntopts_t *dmo) 17567c478bd9Sstevel@tonic-gate { 17577c478bd9Sstevel@tonic-gate vfs_copyopttbl_extend(smo, dmo, 0); 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate static char ** 17617c478bd9Sstevel@tonic-gate vfs_mergecancelopts(const mntopt_t *mop1, const mntopt_t *mop2) 17627c478bd9Sstevel@tonic-gate { 17637c478bd9Sstevel@tonic-gate int c1 = 0; 17647c478bd9Sstevel@tonic-gate int c2 = 0; 17657c478bd9Sstevel@tonic-gate char **result; 17667c478bd9Sstevel@tonic-gate char **sp1, **sp2, **dp; 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate /* 17697c478bd9Sstevel@tonic-gate * First we count both lists of cancel options. 17707c478bd9Sstevel@tonic-gate * If either is NULL or has no elements, we return a copy of 17717c478bd9Sstevel@tonic-gate * the other. 17727c478bd9Sstevel@tonic-gate */ 17737c478bd9Sstevel@tonic-gate if (mop1->mo_cancel != NULL) { 17747c478bd9Sstevel@tonic-gate for (; mop1->mo_cancel[c1] != NULL; c1++) 17757c478bd9Sstevel@tonic-gate /* count cancel options in mop1 */; 17767c478bd9Sstevel@tonic-gate } 17777c478bd9Sstevel@tonic-gate 17787c478bd9Sstevel@tonic-gate if (c1 == 0) 17797c478bd9Sstevel@tonic-gate return (vfs_copycancelopt_extend(mop2->mo_cancel, 0)); 17807c478bd9Sstevel@tonic-gate 17817c478bd9Sstevel@tonic-gate if (mop2->mo_cancel != NULL) { 17827c478bd9Sstevel@tonic-gate for (; mop2->mo_cancel[c2] != NULL; c2++) 17837c478bd9Sstevel@tonic-gate /* count cancel options in mop2 */; 17847c478bd9Sstevel@tonic-gate } 17857c478bd9Sstevel@tonic-gate 17867c478bd9Sstevel@tonic-gate result = vfs_copycancelopt_extend(mop1->mo_cancel, c2); 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate if (c2 == 0) 17897c478bd9Sstevel@tonic-gate return (result); 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate /* 17927c478bd9Sstevel@tonic-gate * When we get here, we've got two sets of cancel options; 17937c478bd9Sstevel@tonic-gate * we need to merge the two sets. We know that the result 17947c478bd9Sstevel@tonic-gate * array has "c1+c2+1" entries and in the end we might shrink 17957c478bd9Sstevel@tonic-gate * it. 17967c478bd9Sstevel@tonic-gate * Result now has a copy of the c1 entries from mop1; we'll 17977c478bd9Sstevel@tonic-gate * now lookup all the entries of mop2 in mop1 and copy it if 17987c478bd9Sstevel@tonic-gate * it is unique. 17997c478bd9Sstevel@tonic-gate * This operation is O(n^2) but it's only called once per 18007c478bd9Sstevel@tonic-gate * filesystem per duplicate option. This is a situation 18017c478bd9Sstevel@tonic-gate * which doesn't arise with the filesystems in ON and 18027c478bd9Sstevel@tonic-gate * n is generally 1. 18037c478bd9Sstevel@tonic-gate */ 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate dp = &result[c1]; 18067c478bd9Sstevel@tonic-gate for (sp2 = mop2->mo_cancel; *sp2 != NULL; sp2++) { 18077c478bd9Sstevel@tonic-gate for (sp1 = mop1->mo_cancel; *sp1 != NULL; sp1++) { 18087c478bd9Sstevel@tonic-gate if (strcmp(*sp1, *sp2) == 0) 18097c478bd9Sstevel@tonic-gate break; 18107c478bd9Sstevel@tonic-gate } 18117c478bd9Sstevel@tonic-gate if (*sp1 == NULL) { 18127c478bd9Sstevel@tonic-gate /* 18137c478bd9Sstevel@tonic-gate * Option *sp2 not found in mop1, so copy it. 18147c478bd9Sstevel@tonic-gate * The calls to vfs_copycancelopt_extend() 18157c478bd9Sstevel@tonic-gate * guarantee that there's enough room. 18167c478bd9Sstevel@tonic-gate */ 18177c478bd9Sstevel@tonic-gate *dp = kmem_alloc(strlen(*sp2) + 1, KM_SLEEP); 18187c478bd9Sstevel@tonic-gate (void) strcpy(*dp++, *sp2); 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate } 18217c478bd9Sstevel@tonic-gate if (dp != &result[c1+c2]) { 18227c478bd9Sstevel@tonic-gate size_t bytes = (dp - result + 1) * sizeof (char *); 18237c478bd9Sstevel@tonic-gate char **nres = kmem_alloc(bytes, KM_SLEEP); 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate bcopy(result, nres, bytes); 18267c478bd9Sstevel@tonic-gate kmem_free(result, (c1 + c2 + 1) * sizeof (char *)); 18277c478bd9Sstevel@tonic-gate result = nres; 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate return (result); 18307c478bd9Sstevel@tonic-gate } 18317c478bd9Sstevel@tonic-gate 18327c478bd9Sstevel@tonic-gate /* 18337c478bd9Sstevel@tonic-gate * Merge two mount option tables (outer and inner) into one. This is very 18347c478bd9Sstevel@tonic-gate * similar to "merging" global variables and automatic variables in C. 18357c478bd9Sstevel@tonic-gate * 18367c478bd9Sstevel@tonic-gate * This isn't (and doesn't have to be) fast. 18377c478bd9Sstevel@tonic-gate * 18387c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 18397c478bd9Sstevel@tonic-gate * 18407c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 18417c478bd9Sstevel@tonic-gate * to protect omo, imo & dmo. 18427c478bd9Sstevel@tonic-gate */ 18437c478bd9Sstevel@tonic-gate void 18447c478bd9Sstevel@tonic-gate vfs_mergeopttbl(const mntopts_t *omo, const mntopts_t *imo, mntopts_t *dmo) 18457c478bd9Sstevel@tonic-gate { 18467c478bd9Sstevel@tonic-gate uint_t i, count; 18477c478bd9Sstevel@tonic-gate mntopt_t *mop, *motbl; 18487c478bd9Sstevel@tonic-gate uint_t freeidx; 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate /* 18517c478bd9Sstevel@tonic-gate * First determine how much space we need to allocate. 18527c478bd9Sstevel@tonic-gate */ 18537c478bd9Sstevel@tonic-gate count = omo->mo_count; 18547c478bd9Sstevel@tonic-gate for (i = 0; i < imo->mo_count; i++) { 18557c478bd9Sstevel@tonic-gate if (imo->mo_list[i].mo_flags & MO_EMPTY) 18567c478bd9Sstevel@tonic-gate continue; 18577c478bd9Sstevel@tonic-gate if (vfs_hasopt(omo, imo->mo_list[i].mo_name) == NULL) 18587c478bd9Sstevel@tonic-gate count++; 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate ASSERT(count >= omo->mo_count && 18617c478bd9Sstevel@tonic-gate count <= omo->mo_count + imo->mo_count); 18627c478bd9Sstevel@tonic-gate motbl = kmem_alloc(count * sizeof (mntopt_t), KM_SLEEP); 18637c478bd9Sstevel@tonic-gate for (i = 0; i < omo->mo_count; i++) 18647c478bd9Sstevel@tonic-gate vfs_copyopt(&omo->mo_list[i], &motbl[i]); 18657c478bd9Sstevel@tonic-gate freeidx = omo->mo_count; 18667c478bd9Sstevel@tonic-gate for (i = 0; i < imo->mo_count; i++) { 18677c478bd9Sstevel@tonic-gate if (imo->mo_list[i].mo_flags & MO_EMPTY) 18687c478bd9Sstevel@tonic-gate continue; 18697c478bd9Sstevel@tonic-gate if ((mop = vfs_hasopt(omo, imo->mo_list[i].mo_name)) != NULL) { 18707c478bd9Sstevel@tonic-gate char **newcanp; 18717c478bd9Sstevel@tonic-gate uint_t index = mop - omo->mo_list; 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate newcanp = vfs_mergecancelopts(mop, &motbl[index]); 18747c478bd9Sstevel@tonic-gate 18757c478bd9Sstevel@tonic-gate vfs_freeopt(&motbl[index]); 18767c478bd9Sstevel@tonic-gate vfs_copyopt(&imo->mo_list[i], &motbl[index]); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate vfs_freecancelopt(motbl[index].mo_cancel); 18797c478bd9Sstevel@tonic-gate motbl[index].mo_cancel = newcanp; 18807c478bd9Sstevel@tonic-gate } else { 18817c478bd9Sstevel@tonic-gate /* 18827c478bd9Sstevel@tonic-gate * If it's a new option, just copy it over to the first 18837c478bd9Sstevel@tonic-gate * free location. 18847c478bd9Sstevel@tonic-gate */ 18857c478bd9Sstevel@tonic-gate vfs_copyopt(&imo->mo_list[i], &motbl[freeidx++]); 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate dmo->mo_count = count; 18897c478bd9Sstevel@tonic-gate dmo->mo_list = motbl; 18907c478bd9Sstevel@tonic-gate } 18917c478bd9Sstevel@tonic-gate 18927c478bd9Sstevel@tonic-gate /* 18937c478bd9Sstevel@tonic-gate * Functions to set and clear mount options in a mount options table. 18947c478bd9Sstevel@tonic-gate */ 18957c478bd9Sstevel@tonic-gate 18967c478bd9Sstevel@tonic-gate /* 18977c478bd9Sstevel@tonic-gate * Clear a mount option, if it exists. 18987c478bd9Sstevel@tonic-gate * 18997c478bd9Sstevel@tonic-gate * The update_mnttab arg indicates whether mops is part of a vfs that is on 19007c478bd9Sstevel@tonic-gate * the vfs list. 19017c478bd9Sstevel@tonic-gate */ 19027c478bd9Sstevel@tonic-gate static void 19037c478bd9Sstevel@tonic-gate vfs_clearmntopt_nolock(mntopts_t *mops, const char *opt, int update_mnttab) 19047c478bd9Sstevel@tonic-gate { 19057c478bd9Sstevel@tonic-gate struct mntopt *mop; 19067c478bd9Sstevel@tonic-gate uint_t i, count; 19077c478bd9Sstevel@tonic-gate 19087c478bd9Sstevel@tonic-gate ASSERT(!update_mnttab || RW_WRITE_HELD(&vfslist)); 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate count = mops->mo_count; 19117c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 19127c478bd9Sstevel@tonic-gate mop = &mops->mo_list[i]; 19137c478bd9Sstevel@tonic-gate 19147c478bd9Sstevel@tonic-gate if (mop->mo_flags & MO_EMPTY) 19157c478bd9Sstevel@tonic-gate continue; 19167c478bd9Sstevel@tonic-gate if (strcmp(opt, mop->mo_name)) 19177c478bd9Sstevel@tonic-gate continue; 19187c478bd9Sstevel@tonic-gate mop->mo_flags &= ~MO_SET; 19197c478bd9Sstevel@tonic-gate if (mop->mo_arg != NULL) { 19207c478bd9Sstevel@tonic-gate kmem_free(mop->mo_arg, strlen(mop->mo_arg) + 1); 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate mop->mo_arg = NULL; 19237c478bd9Sstevel@tonic-gate if (update_mnttab) 19247c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 19257c478bd9Sstevel@tonic-gate break; 19267c478bd9Sstevel@tonic-gate } 19277c478bd9Sstevel@tonic-gate } 19287c478bd9Sstevel@tonic-gate 19297c478bd9Sstevel@tonic-gate void 19307c478bd9Sstevel@tonic-gate vfs_clearmntopt(struct vfs *vfsp, const char *opt) 19317c478bd9Sstevel@tonic-gate { 19327c478bd9Sstevel@tonic-gate int gotlock = 0; 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate if (VFS_ON_LIST(vfsp)) { 19357c478bd9Sstevel@tonic-gate gotlock = 1; 19367c478bd9Sstevel@tonic-gate vfs_list_lock(); 19377c478bd9Sstevel@tonic-gate } 19387c478bd9Sstevel@tonic-gate vfs_clearmntopt_nolock(&vfsp->vfs_mntopts, opt, gotlock); 19397c478bd9Sstevel@tonic-gate if (gotlock) 19407c478bd9Sstevel@tonic-gate vfs_list_unlock(); 19417c478bd9Sstevel@tonic-gate } 19427c478bd9Sstevel@tonic-gate 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate /* 19457c478bd9Sstevel@tonic-gate * Set a mount option on. If it's not found in the table, it's silently 19467c478bd9Sstevel@tonic-gate * ignored. If the option has MO_IGNORE set, it is still set unless the 19477c478bd9Sstevel@tonic-gate * VFS_NOFORCEOPT bit is set in the flags. Also, VFS_DISPLAY/VFS_NODISPLAY flag 19487c478bd9Sstevel@tonic-gate * bits can be used to toggle the MO_NODISPLAY bit for the option. 19497c478bd9Sstevel@tonic-gate * If the VFS_CREATEOPT flag bit is set then the first option slot with 19507c478bd9Sstevel@tonic-gate * MO_EMPTY set is created as the option passed in. 19517c478bd9Sstevel@tonic-gate * 19527c478bd9Sstevel@tonic-gate * The update_mnttab arg indicates whether mops is part of a vfs that is on 19537c478bd9Sstevel@tonic-gate * the vfs list. 19547c478bd9Sstevel@tonic-gate */ 19557c478bd9Sstevel@tonic-gate static void 19567c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(mntopts_t *mops, const char *opt, 19577c478bd9Sstevel@tonic-gate const char *arg, int flags, int update_mnttab) 19587c478bd9Sstevel@tonic-gate { 19597c478bd9Sstevel@tonic-gate mntopt_t *mop; 19607c478bd9Sstevel@tonic-gate uint_t i, count; 19617c478bd9Sstevel@tonic-gate char *sp; 19627c478bd9Sstevel@tonic-gate 19637c478bd9Sstevel@tonic-gate ASSERT(!update_mnttab || RW_WRITE_HELD(&vfslist)); 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate if (flags & VFS_CREATEOPT) { 19667c478bd9Sstevel@tonic-gate if (vfs_hasopt(mops, opt) != NULL) { 19677c478bd9Sstevel@tonic-gate flags &= ~VFS_CREATEOPT; 19687c478bd9Sstevel@tonic-gate } 19697c478bd9Sstevel@tonic-gate } 19707c478bd9Sstevel@tonic-gate count = mops->mo_count; 19717c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 19727c478bd9Sstevel@tonic-gate mop = &mops->mo_list[i]; 19737c478bd9Sstevel@tonic-gate 19747c478bd9Sstevel@tonic-gate if (mop->mo_flags & MO_EMPTY) { 19757c478bd9Sstevel@tonic-gate if ((flags & VFS_CREATEOPT) == 0) 19767c478bd9Sstevel@tonic-gate continue; 19777c478bd9Sstevel@tonic-gate sp = kmem_alloc(strlen(opt) + 1, KM_SLEEP); 19787c478bd9Sstevel@tonic-gate (void) strcpy(sp, opt); 19797c478bd9Sstevel@tonic-gate mop->mo_name = sp; 19807c478bd9Sstevel@tonic-gate if (arg != NULL) 19817c478bd9Sstevel@tonic-gate mop->mo_flags = MO_HASVALUE; 19827c478bd9Sstevel@tonic-gate else 19837c478bd9Sstevel@tonic-gate mop->mo_flags = 0; 19847c478bd9Sstevel@tonic-gate } else if (strcmp(opt, mop->mo_name)) { 19857c478bd9Sstevel@tonic-gate continue; 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate if ((mop->mo_flags & MO_IGNORE) && (flags & VFS_NOFORCEOPT)) 19887c478bd9Sstevel@tonic-gate break; 19897c478bd9Sstevel@tonic-gate if (arg != NULL && (mop->mo_flags & MO_HASVALUE) != 0) { 19907c478bd9Sstevel@tonic-gate sp = kmem_alloc(strlen(arg) + 1, KM_SLEEP); 19917c478bd9Sstevel@tonic-gate (void) strcpy(sp, arg); 19927c478bd9Sstevel@tonic-gate } else { 19937c478bd9Sstevel@tonic-gate sp = NULL; 19947c478bd9Sstevel@tonic-gate } 19957c478bd9Sstevel@tonic-gate if (mop->mo_arg != NULL) 19967c478bd9Sstevel@tonic-gate kmem_free(mop->mo_arg, strlen(mop->mo_arg) + 1); 19977c478bd9Sstevel@tonic-gate mop->mo_arg = sp; 19987c478bd9Sstevel@tonic-gate if (flags & VFS_DISPLAY) 19997c478bd9Sstevel@tonic-gate mop->mo_flags &= ~MO_NODISPLAY; 20007c478bd9Sstevel@tonic-gate if (flags & VFS_NODISPLAY) 20017c478bd9Sstevel@tonic-gate mop->mo_flags |= MO_NODISPLAY; 20027c478bd9Sstevel@tonic-gate mop->mo_flags |= MO_SET; 20037c478bd9Sstevel@tonic-gate if (mop->mo_cancel != NULL) { 20047c478bd9Sstevel@tonic-gate char **cp; 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate for (cp = mop->mo_cancel; *cp != NULL; cp++) 20077c478bd9Sstevel@tonic-gate vfs_clearmntopt_nolock(mops, *cp, 0); 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate if (update_mnttab) 20107c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 20117c478bd9Sstevel@tonic-gate break; 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate } 20147c478bd9Sstevel@tonic-gate 20157c478bd9Sstevel@tonic-gate void 20167c478bd9Sstevel@tonic-gate vfs_setmntopt(struct vfs *vfsp, const char *opt, const char *arg, int flags) 20177c478bd9Sstevel@tonic-gate { 20187c478bd9Sstevel@tonic-gate int gotlock = 0; 20197c478bd9Sstevel@tonic-gate 20207c478bd9Sstevel@tonic-gate if (VFS_ON_LIST(vfsp)) { 20217c478bd9Sstevel@tonic-gate gotlock = 1; 20227c478bd9Sstevel@tonic-gate vfs_list_lock(); 20237c478bd9Sstevel@tonic-gate } 20247c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(&vfsp->vfs_mntopts, opt, arg, flags, gotlock); 20257c478bd9Sstevel@tonic-gate if (gotlock) 20267c478bd9Sstevel@tonic-gate vfs_list_unlock(); 20277c478bd9Sstevel@tonic-gate } 20287c478bd9Sstevel@tonic-gate 20297c478bd9Sstevel@tonic-gate 20307c478bd9Sstevel@tonic-gate /* 20317c478bd9Sstevel@tonic-gate * Add a "tag" option to a mounted file system's options list. 20327c478bd9Sstevel@tonic-gate * 20337c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 20347c478bd9Sstevel@tonic-gate * to protect mops. 20357c478bd9Sstevel@tonic-gate */ 20367c478bd9Sstevel@tonic-gate static mntopt_t * 20377c478bd9Sstevel@tonic-gate vfs_addtag(mntopts_t *mops, const char *tag) 20387c478bd9Sstevel@tonic-gate { 20397c478bd9Sstevel@tonic-gate uint_t count; 20407c478bd9Sstevel@tonic-gate mntopt_t *mop, *motbl; 20417c478bd9Sstevel@tonic-gate 20427c478bd9Sstevel@tonic-gate count = mops->mo_count + 1; 20437c478bd9Sstevel@tonic-gate motbl = kmem_zalloc(count * sizeof (mntopt_t), KM_SLEEP); 20447c478bd9Sstevel@tonic-gate if (mops->mo_count) { 20457c478bd9Sstevel@tonic-gate size_t len = (count - 1) * sizeof (mntopt_t); 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate bcopy(mops->mo_list, motbl, len); 20487c478bd9Sstevel@tonic-gate kmem_free(mops->mo_list, len); 20497c478bd9Sstevel@tonic-gate } 20507c478bd9Sstevel@tonic-gate mops->mo_count = count; 20517c478bd9Sstevel@tonic-gate mops->mo_list = motbl; 20527c478bd9Sstevel@tonic-gate mop = &motbl[count - 1]; 20537c478bd9Sstevel@tonic-gate mop->mo_flags = MO_TAG; 20547c478bd9Sstevel@tonic-gate mop->mo_name = kmem_alloc(strlen(tag) + 1, KM_SLEEP); 20557c478bd9Sstevel@tonic-gate (void) strcpy(mop->mo_name, tag); 20567c478bd9Sstevel@tonic-gate return (mop); 20577c478bd9Sstevel@tonic-gate } 20587c478bd9Sstevel@tonic-gate 20597c478bd9Sstevel@tonic-gate /* 20607c478bd9Sstevel@tonic-gate * Allow users to set arbitrary "tags" in a vfs's mount options. 20617c478bd9Sstevel@tonic-gate * Broader use within the kernel is discouraged. 20627c478bd9Sstevel@tonic-gate */ 20637c478bd9Sstevel@tonic-gate int 20647c478bd9Sstevel@tonic-gate vfs_settag(uint_t major, uint_t minor, const char *mntpt, const char *tag, 20657c478bd9Sstevel@tonic-gate cred_t *cr) 20667c478bd9Sstevel@tonic-gate { 20677c478bd9Sstevel@tonic-gate vfs_t *vfsp; 20687c478bd9Sstevel@tonic-gate mntopts_t *mops; 20697c478bd9Sstevel@tonic-gate mntopt_t *mop; 20707c478bd9Sstevel@tonic-gate int found = 0; 20717c478bd9Sstevel@tonic-gate dev_t dev = makedevice(major, minor); 20727c478bd9Sstevel@tonic-gate int err = 0; 20737c478bd9Sstevel@tonic-gate char *buf = kmem_alloc(MAX_MNTOPT_STR, KM_SLEEP); 20747c478bd9Sstevel@tonic-gate 20757c478bd9Sstevel@tonic-gate /* 20767c478bd9Sstevel@tonic-gate * Find the desired mounted file system 20777c478bd9Sstevel@tonic-gate */ 20787c478bd9Sstevel@tonic-gate vfs_list_lock(); 20797c478bd9Sstevel@tonic-gate vfsp = rootvfs; 20807c478bd9Sstevel@tonic-gate do { 20817c478bd9Sstevel@tonic-gate if (vfsp->vfs_dev == dev && 20827c478bd9Sstevel@tonic-gate strcmp(mntpt, refstr_value(vfsp->vfs_mntpt)) == 0) { 20837c478bd9Sstevel@tonic-gate found = 1; 20847c478bd9Sstevel@tonic-gate break; 20857c478bd9Sstevel@tonic-gate } 20867c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_next; 20877c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs); 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate if (!found) { 20907c478bd9Sstevel@tonic-gate err = EINVAL; 20917c478bd9Sstevel@tonic-gate goto out; 20927c478bd9Sstevel@tonic-gate } 20937c478bd9Sstevel@tonic-gate err = secpolicy_fs_config(cr, vfsp); 20947c478bd9Sstevel@tonic-gate if (err != 0) 20957c478bd9Sstevel@tonic-gate goto out; 20967c478bd9Sstevel@tonic-gate 20977c478bd9Sstevel@tonic-gate mops = &vfsp->vfs_mntopts; 20987c478bd9Sstevel@tonic-gate /* 20997c478bd9Sstevel@tonic-gate * Add tag if it doesn't already exist 21007c478bd9Sstevel@tonic-gate */ 21017c478bd9Sstevel@tonic-gate if ((mop = vfs_hasopt(mops, tag)) == NULL) { 21027c478bd9Sstevel@tonic-gate int len; 21037c478bd9Sstevel@tonic-gate 21047c478bd9Sstevel@tonic-gate (void) vfs_buildoptionstr(mops, buf, MAX_MNTOPT_STR); 21057c478bd9Sstevel@tonic-gate len = strlen(buf); 21067c478bd9Sstevel@tonic-gate if (len + strlen(tag) + 2 > MAX_MNTOPT_STR) { 21077c478bd9Sstevel@tonic-gate err = ENAMETOOLONG; 21087c478bd9Sstevel@tonic-gate goto out; 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate mop = vfs_addtag(mops, tag); 21117c478bd9Sstevel@tonic-gate } 21127c478bd9Sstevel@tonic-gate if ((mop->mo_flags & MO_TAG) == 0) { 21137c478bd9Sstevel@tonic-gate err = EINVAL; 21147c478bd9Sstevel@tonic-gate goto out; 21157c478bd9Sstevel@tonic-gate } 21167c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(mops, tag, NULL, 0, 1); 21177c478bd9Sstevel@tonic-gate out: 21187c478bd9Sstevel@tonic-gate vfs_list_unlock(); 21197c478bd9Sstevel@tonic-gate kmem_free(buf, MAX_MNTOPT_STR); 21207c478bd9Sstevel@tonic-gate return (err); 21217c478bd9Sstevel@tonic-gate } 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate /* 21247c478bd9Sstevel@tonic-gate * Allow users to remove arbitrary "tags" in a vfs's mount options. 21257c478bd9Sstevel@tonic-gate * Broader use within the kernel is discouraged. 21267c478bd9Sstevel@tonic-gate */ 21277c478bd9Sstevel@tonic-gate int 21287c478bd9Sstevel@tonic-gate vfs_clrtag(uint_t major, uint_t minor, const char *mntpt, const char *tag, 21297c478bd9Sstevel@tonic-gate cred_t *cr) 21307c478bd9Sstevel@tonic-gate { 21317c478bd9Sstevel@tonic-gate vfs_t *vfsp; 21327c478bd9Sstevel@tonic-gate mntopt_t *mop; 21337c478bd9Sstevel@tonic-gate int found = 0; 21347c478bd9Sstevel@tonic-gate dev_t dev = makedevice(major, minor); 21357c478bd9Sstevel@tonic-gate int err = 0; 21367c478bd9Sstevel@tonic-gate 21377c478bd9Sstevel@tonic-gate /* 21387c478bd9Sstevel@tonic-gate * Find the desired mounted file system 21397c478bd9Sstevel@tonic-gate */ 21407c478bd9Sstevel@tonic-gate vfs_list_lock(); 21417c478bd9Sstevel@tonic-gate vfsp = rootvfs; 21427c478bd9Sstevel@tonic-gate do { 21437c478bd9Sstevel@tonic-gate if (vfsp->vfs_dev == dev && 21447c478bd9Sstevel@tonic-gate strcmp(mntpt, refstr_value(vfsp->vfs_mntpt)) == 0) { 21457c478bd9Sstevel@tonic-gate found = 1; 21467c478bd9Sstevel@tonic-gate break; 21477c478bd9Sstevel@tonic-gate } 21487c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_next; 21497c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs); 21507c478bd9Sstevel@tonic-gate 21517c478bd9Sstevel@tonic-gate if (!found) { 21527c478bd9Sstevel@tonic-gate err = EINVAL; 21537c478bd9Sstevel@tonic-gate goto out; 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate err = secpolicy_fs_config(cr, vfsp); 21567c478bd9Sstevel@tonic-gate if (err != 0) 21577c478bd9Sstevel@tonic-gate goto out; 21587c478bd9Sstevel@tonic-gate 21597c478bd9Sstevel@tonic-gate if ((mop = vfs_hasopt(&vfsp->vfs_mntopts, tag)) == NULL) { 21607c478bd9Sstevel@tonic-gate err = EINVAL; 21617c478bd9Sstevel@tonic-gate goto out; 21627c478bd9Sstevel@tonic-gate } 21637c478bd9Sstevel@tonic-gate if ((mop->mo_flags & MO_TAG) == 0) { 21647c478bd9Sstevel@tonic-gate err = EINVAL; 21657c478bd9Sstevel@tonic-gate goto out; 21667c478bd9Sstevel@tonic-gate } 21677c478bd9Sstevel@tonic-gate vfs_clearmntopt_nolock(&vfsp->vfs_mntopts, tag, 1); 21687c478bd9Sstevel@tonic-gate out: 21697c478bd9Sstevel@tonic-gate vfs_list_unlock(); 21707c478bd9Sstevel@tonic-gate return (err); 21717c478bd9Sstevel@tonic-gate } 21727c478bd9Sstevel@tonic-gate 21737c478bd9Sstevel@tonic-gate /* 21747c478bd9Sstevel@tonic-gate * Function to parse an option string and fill in a mount options table. 21757c478bd9Sstevel@tonic-gate * Unknown options are silently ignored. The input option string is modified 21767c478bd9Sstevel@tonic-gate * by replacing separators with nulls. If the create flag is set, options 21777c478bd9Sstevel@tonic-gate * not found in the table are just added on the fly. The table must have 21787c478bd9Sstevel@tonic-gate * an option slot marked MO_EMPTY to add an option on the fly. 21797c478bd9Sstevel@tonic-gate * 21807c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 21817c478bd9Sstevel@tonic-gate * 21827c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 21837c478bd9Sstevel@tonic-gate * to protect mops.. 21847c478bd9Sstevel@tonic-gate */ 21857c478bd9Sstevel@tonic-gate void 21867c478bd9Sstevel@tonic-gate vfs_parsemntopts(mntopts_t *mops, char *osp, int create) 21877c478bd9Sstevel@tonic-gate { 21887c478bd9Sstevel@tonic-gate char *s = osp, *p, *nextop, *valp, *cp, *ep; 21897c478bd9Sstevel@tonic-gate int setflg = VFS_NOFORCEOPT; 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate if (osp == NULL) 21927c478bd9Sstevel@tonic-gate return; 21937c478bd9Sstevel@tonic-gate while (*s != '\0') { 21947c478bd9Sstevel@tonic-gate p = strchr(s, ','); /* find next option */ 21957c478bd9Sstevel@tonic-gate if (p == NULL) { 21967c478bd9Sstevel@tonic-gate cp = NULL; 21977c478bd9Sstevel@tonic-gate p = s + strlen(s); 21987c478bd9Sstevel@tonic-gate } else { 21997c478bd9Sstevel@tonic-gate cp = p; /* save location of comma */ 22007c478bd9Sstevel@tonic-gate *p++ = '\0'; /* mark end and point to next option */ 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate nextop = p; 22037c478bd9Sstevel@tonic-gate p = strchr(s, '='); /* look for value */ 22047c478bd9Sstevel@tonic-gate if (p == NULL) { 22057c478bd9Sstevel@tonic-gate valp = NULL; /* no value supplied */ 22067c478bd9Sstevel@tonic-gate } else { 22077c478bd9Sstevel@tonic-gate ep = p; /* save location of equals */ 22087c478bd9Sstevel@tonic-gate *p++ = '\0'; /* end option and point to value */ 22097c478bd9Sstevel@tonic-gate valp = p; 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate /* 22127c478bd9Sstevel@tonic-gate * set option into options table 22137c478bd9Sstevel@tonic-gate */ 22147c478bd9Sstevel@tonic-gate if (create) 22157c478bd9Sstevel@tonic-gate setflg |= VFS_CREATEOPT; 22167c478bd9Sstevel@tonic-gate vfs_setmntopt_nolock(mops, s, valp, setflg, 0); 22177c478bd9Sstevel@tonic-gate if (cp != NULL) 22187c478bd9Sstevel@tonic-gate *cp = ','; /* restore the comma */ 22197c478bd9Sstevel@tonic-gate if (valp != NULL) 22207c478bd9Sstevel@tonic-gate *ep = '='; /* restore the equals */ 22217c478bd9Sstevel@tonic-gate s = nextop; 22227c478bd9Sstevel@tonic-gate } 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate /* 22267c478bd9Sstevel@tonic-gate * Function to inquire if an option exists in a mount options table. 22277c478bd9Sstevel@tonic-gate * Returns a pointer to the option if it exists, else NULL. 22287c478bd9Sstevel@tonic-gate * 22297c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 22307c478bd9Sstevel@tonic-gate * 22317c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 22327c478bd9Sstevel@tonic-gate * to protect mops. 22337c478bd9Sstevel@tonic-gate */ 22347c478bd9Sstevel@tonic-gate struct mntopt * 22357c478bd9Sstevel@tonic-gate vfs_hasopt(const mntopts_t *mops, const char *opt) 22367c478bd9Sstevel@tonic-gate { 22377c478bd9Sstevel@tonic-gate struct mntopt *mop; 22387c478bd9Sstevel@tonic-gate uint_t i, count; 22397c478bd9Sstevel@tonic-gate 22407c478bd9Sstevel@tonic-gate count = mops->mo_count; 22417c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 22427c478bd9Sstevel@tonic-gate mop = &mops->mo_list[i]; 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate if (mop->mo_flags & MO_EMPTY) 22457c478bd9Sstevel@tonic-gate continue; 22467c478bd9Sstevel@tonic-gate if (strcmp(opt, mop->mo_name) == 0) 22477c478bd9Sstevel@tonic-gate return (mop); 22487c478bd9Sstevel@tonic-gate } 22497c478bd9Sstevel@tonic-gate return (NULL); 22507c478bd9Sstevel@tonic-gate } 22517c478bd9Sstevel@tonic-gate 22527c478bd9Sstevel@tonic-gate /* 22537c478bd9Sstevel@tonic-gate * Function to inquire if an option is set in a mount options table. 22547c478bd9Sstevel@tonic-gate * Returns non-zero if set and fills in the arg pointer with a pointer to 22557c478bd9Sstevel@tonic-gate * the argument string or NULL if there is no argument string. 22567c478bd9Sstevel@tonic-gate */ 22577c478bd9Sstevel@tonic-gate static int 22587c478bd9Sstevel@tonic-gate vfs_optionisset_nolock(const mntopts_t *mops, const char *opt, char **argp) 22597c478bd9Sstevel@tonic-gate { 22607c478bd9Sstevel@tonic-gate struct mntopt *mop; 22617c478bd9Sstevel@tonic-gate uint_t i, count; 22627c478bd9Sstevel@tonic-gate 22637c478bd9Sstevel@tonic-gate count = mops->mo_count; 22647c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 22657c478bd9Sstevel@tonic-gate mop = &mops->mo_list[i]; 22667c478bd9Sstevel@tonic-gate 22677c478bd9Sstevel@tonic-gate if (mop->mo_flags & MO_EMPTY) 22687c478bd9Sstevel@tonic-gate continue; 22697c478bd9Sstevel@tonic-gate if (strcmp(opt, mop->mo_name)) 22707c478bd9Sstevel@tonic-gate continue; 22717c478bd9Sstevel@tonic-gate if ((mop->mo_flags & MO_SET) == 0) 22727c478bd9Sstevel@tonic-gate return (0); 22737c478bd9Sstevel@tonic-gate if (argp != NULL && (mop->mo_flags & MO_HASVALUE) != 0) 22747c478bd9Sstevel@tonic-gate *argp = mop->mo_arg; 22757c478bd9Sstevel@tonic-gate return (1); 22767c478bd9Sstevel@tonic-gate } 22777c478bd9Sstevel@tonic-gate return (0); 22787c478bd9Sstevel@tonic-gate } 22797c478bd9Sstevel@tonic-gate 22807c478bd9Sstevel@tonic-gate 22817c478bd9Sstevel@tonic-gate int 22827c478bd9Sstevel@tonic-gate vfs_optionisset(const struct vfs *vfsp, const char *opt, char **argp) 22837c478bd9Sstevel@tonic-gate { 22847c478bd9Sstevel@tonic-gate int ret; 22857c478bd9Sstevel@tonic-gate 22867c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 22877c478bd9Sstevel@tonic-gate ret = vfs_optionisset_nolock(&vfsp->vfs_mntopts, opt, argp); 22887c478bd9Sstevel@tonic-gate vfs_list_unlock(); 22897c478bd9Sstevel@tonic-gate return (ret); 22907c478bd9Sstevel@tonic-gate } 22917c478bd9Sstevel@tonic-gate 22927c478bd9Sstevel@tonic-gate 22937c478bd9Sstevel@tonic-gate /* 22947c478bd9Sstevel@tonic-gate * Construct a comma separated string of the options set in the given 22957c478bd9Sstevel@tonic-gate * mount table, return the string in the given buffer. Return non-zero if 22967c478bd9Sstevel@tonic-gate * the buffer would overflow. 22977c478bd9Sstevel@tonic-gate * 22987c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 22997c478bd9Sstevel@tonic-gate * 23007c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 23017c478bd9Sstevel@tonic-gate * to protect mp. 23027c478bd9Sstevel@tonic-gate */ 23037c478bd9Sstevel@tonic-gate int 23047c478bd9Sstevel@tonic-gate vfs_buildoptionstr(const mntopts_t *mp, char *buf, int len) 23057c478bd9Sstevel@tonic-gate { 23067c478bd9Sstevel@tonic-gate char *cp; 23077c478bd9Sstevel@tonic-gate uint_t i; 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate buf[0] = '\0'; 23107c478bd9Sstevel@tonic-gate cp = buf; 23117c478bd9Sstevel@tonic-gate for (i = 0; i < mp->mo_count; i++) { 23127c478bd9Sstevel@tonic-gate struct mntopt *mop; 23137c478bd9Sstevel@tonic-gate 23147c478bd9Sstevel@tonic-gate mop = &mp->mo_list[i]; 23157c478bd9Sstevel@tonic-gate if (mop->mo_flags & MO_SET) { 23167c478bd9Sstevel@tonic-gate int optlen, comma = 0; 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate if (buf[0] != '\0') 23197c478bd9Sstevel@tonic-gate comma = 1; 23207c478bd9Sstevel@tonic-gate optlen = strlen(mop->mo_name); 23217c478bd9Sstevel@tonic-gate if (strlen(buf) + comma + optlen + 1 > len) 23227c478bd9Sstevel@tonic-gate goto err; 23237c478bd9Sstevel@tonic-gate if (comma) 23247c478bd9Sstevel@tonic-gate *cp++ = ','; 23257c478bd9Sstevel@tonic-gate (void) strcpy(cp, mop->mo_name); 23267c478bd9Sstevel@tonic-gate cp += optlen; 23277c478bd9Sstevel@tonic-gate /* 23287c478bd9Sstevel@tonic-gate * Append option value if there is one 23297c478bd9Sstevel@tonic-gate */ 23307c478bd9Sstevel@tonic-gate if (mop->mo_arg != NULL) { 23317c478bd9Sstevel@tonic-gate int arglen; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate arglen = strlen(mop->mo_arg); 23347c478bd9Sstevel@tonic-gate if (strlen(buf) + arglen + 2 > len) 23357c478bd9Sstevel@tonic-gate goto err; 23367c478bd9Sstevel@tonic-gate *cp++ = '='; 23377c478bd9Sstevel@tonic-gate (void) strcpy(cp, mop->mo_arg); 23387c478bd9Sstevel@tonic-gate cp += arglen; 23397c478bd9Sstevel@tonic-gate } 23407c478bd9Sstevel@tonic-gate } 23417c478bd9Sstevel@tonic-gate } 23427c478bd9Sstevel@tonic-gate return (0); 23437c478bd9Sstevel@tonic-gate err: 23447c478bd9Sstevel@tonic-gate return (EOVERFLOW); 23457c478bd9Sstevel@tonic-gate } 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate static void 23487c478bd9Sstevel@tonic-gate vfs_freecancelopt(char **moc) 23497c478bd9Sstevel@tonic-gate { 23507c478bd9Sstevel@tonic-gate if (moc != NULL) { 23517c478bd9Sstevel@tonic-gate int ccnt = 0; 23527c478bd9Sstevel@tonic-gate char **cp; 23537c478bd9Sstevel@tonic-gate 23547c478bd9Sstevel@tonic-gate for (cp = moc; *cp != NULL; cp++) { 23557c478bd9Sstevel@tonic-gate kmem_free(*cp, strlen(*cp) + 1); 23567c478bd9Sstevel@tonic-gate ccnt++; 23577c478bd9Sstevel@tonic-gate } 23587c478bd9Sstevel@tonic-gate kmem_free(moc, (ccnt + 1) * sizeof (char *)); 23597c478bd9Sstevel@tonic-gate } 23607c478bd9Sstevel@tonic-gate } 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate static void 23637c478bd9Sstevel@tonic-gate vfs_freeopt(mntopt_t *mop) 23647c478bd9Sstevel@tonic-gate { 23657c478bd9Sstevel@tonic-gate if (mop->mo_name != NULL) 23667c478bd9Sstevel@tonic-gate kmem_free(mop->mo_name, strlen(mop->mo_name) + 1); 23677c478bd9Sstevel@tonic-gate 23687c478bd9Sstevel@tonic-gate vfs_freecancelopt(mop->mo_cancel); 23697c478bd9Sstevel@tonic-gate 23707c478bd9Sstevel@tonic-gate if (mop->mo_arg != NULL) 23717c478bd9Sstevel@tonic-gate kmem_free(mop->mo_arg, strlen(mop->mo_arg) + 1); 23727c478bd9Sstevel@tonic-gate } 23737c478bd9Sstevel@tonic-gate 23747c478bd9Sstevel@tonic-gate /* 23757c478bd9Sstevel@tonic-gate * Free a mount options table 23767c478bd9Sstevel@tonic-gate * 23777c478bd9Sstevel@tonic-gate * This function is *not* for general use by filesystems. 23787c478bd9Sstevel@tonic-gate * 23797c478bd9Sstevel@tonic-gate * Note: caller is responsible for locking the vfs list, if needed, 23807c478bd9Sstevel@tonic-gate * to protect mp. 23817c478bd9Sstevel@tonic-gate */ 23827c478bd9Sstevel@tonic-gate void 23837c478bd9Sstevel@tonic-gate vfs_freeopttbl(mntopts_t *mp) 23847c478bd9Sstevel@tonic-gate { 23857c478bd9Sstevel@tonic-gate uint_t i, count; 23867c478bd9Sstevel@tonic-gate 23877c478bd9Sstevel@tonic-gate count = mp->mo_count; 23887c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) { 23897c478bd9Sstevel@tonic-gate vfs_freeopt(&mp->mo_list[i]); 23907c478bd9Sstevel@tonic-gate } 23917c478bd9Sstevel@tonic-gate if (count) { 23927c478bd9Sstevel@tonic-gate kmem_free(mp->mo_list, sizeof (mntopt_t) * count); 23937c478bd9Sstevel@tonic-gate mp->mo_count = 0; 23947c478bd9Sstevel@tonic-gate mp->mo_list = NULL; 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate } 23977c478bd9Sstevel@tonic-gate 23987c478bd9Sstevel@tonic-gate /* 23997c478bd9Sstevel@tonic-gate * Free any mnttab information recorded in the vfs struct. 24007c478bd9Sstevel@tonic-gate * The vfs must not be on the vfs list. 24017c478bd9Sstevel@tonic-gate */ 24027c478bd9Sstevel@tonic-gate static void 24037c478bd9Sstevel@tonic-gate vfs_freemnttab(struct vfs *vfsp) 24047c478bd9Sstevel@tonic-gate { 24057c478bd9Sstevel@tonic-gate ASSERT(!VFS_ON_LIST(vfsp)); 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate /* 24087c478bd9Sstevel@tonic-gate * Free device and mount point information 24097c478bd9Sstevel@tonic-gate */ 24107c478bd9Sstevel@tonic-gate if (vfsp->vfs_mntpt != NULL) { 24117c478bd9Sstevel@tonic-gate refstr_rele(vfsp->vfs_mntpt); 24127c478bd9Sstevel@tonic-gate vfsp->vfs_mntpt = NULL; 24137c478bd9Sstevel@tonic-gate } 24147c478bd9Sstevel@tonic-gate if (vfsp->vfs_resource != NULL) { 24157c478bd9Sstevel@tonic-gate refstr_rele(vfsp->vfs_resource); 24167c478bd9Sstevel@tonic-gate vfsp->vfs_resource = NULL; 24177c478bd9Sstevel@tonic-gate } 24187c478bd9Sstevel@tonic-gate /* 24197c478bd9Sstevel@tonic-gate * Now free mount options information 24207c478bd9Sstevel@tonic-gate */ 24217c478bd9Sstevel@tonic-gate vfs_freeopttbl(&vfsp->vfs_mntopts); 24227c478bd9Sstevel@tonic-gate } 24237c478bd9Sstevel@tonic-gate 24247c478bd9Sstevel@tonic-gate /* 24257c478bd9Sstevel@tonic-gate * Return the last mnttab modification time 24267c478bd9Sstevel@tonic-gate */ 24277c478bd9Sstevel@tonic-gate void 24287c478bd9Sstevel@tonic-gate vfs_mnttab_modtime(timespec_t *ts) 24297c478bd9Sstevel@tonic-gate { 24307c478bd9Sstevel@tonic-gate ASSERT(RW_LOCK_HELD(&vfslist)); 24317c478bd9Sstevel@tonic-gate *ts = vfs_mnttab_mtime; 24327c478bd9Sstevel@tonic-gate } 24337c478bd9Sstevel@tonic-gate 24347c478bd9Sstevel@tonic-gate /* 24357c478bd9Sstevel@tonic-gate * See if mnttab is changed 24367c478bd9Sstevel@tonic-gate */ 24377c478bd9Sstevel@tonic-gate void 24387c478bd9Sstevel@tonic-gate vfs_mnttab_poll(timespec_t *old, struct pollhead **phpp) 24397c478bd9Sstevel@tonic-gate { 24407c478bd9Sstevel@tonic-gate int changed; 24417c478bd9Sstevel@tonic-gate 24427c478bd9Sstevel@tonic-gate *phpp = (struct pollhead *)NULL; 24437c478bd9Sstevel@tonic-gate 24447c478bd9Sstevel@tonic-gate /* 24457c478bd9Sstevel@tonic-gate * Note: don't grab vfs list lock before accessing vfs_mnttab_mtime. 24467c478bd9Sstevel@tonic-gate * Can lead to deadlock against vfs_mnttab_modtimeupd(). It is safe 24477c478bd9Sstevel@tonic-gate * to not grab the vfs list lock because tv_sec is monotonically 24487c478bd9Sstevel@tonic-gate * increasing. 24497c478bd9Sstevel@tonic-gate */ 24507c478bd9Sstevel@tonic-gate 24517c478bd9Sstevel@tonic-gate changed = (old->tv_nsec != vfs_mnttab_mtime.tv_nsec) || 24527c478bd9Sstevel@tonic-gate (old->tv_sec != vfs_mnttab_mtime.tv_sec); 24537c478bd9Sstevel@tonic-gate if (!changed) { 24547c478bd9Sstevel@tonic-gate *phpp = &vfs_pollhd; 24557c478bd9Sstevel@tonic-gate } 24567c478bd9Sstevel@tonic-gate } 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate /* 24597c478bd9Sstevel@tonic-gate * Update the mnttab modification time and wake up any waiters for 24607c478bd9Sstevel@tonic-gate * mnttab changes 24617c478bd9Sstevel@tonic-gate */ 24627c478bd9Sstevel@tonic-gate void 24637c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd() 24647c478bd9Sstevel@tonic-gate { 24657c478bd9Sstevel@tonic-gate hrtime_t oldhrt, newhrt; 24667c478bd9Sstevel@tonic-gate 24677c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&vfslist)); 24687c478bd9Sstevel@tonic-gate oldhrt = ts2hrt(&vfs_mnttab_mtime); 24697c478bd9Sstevel@tonic-gate gethrestime(&vfs_mnttab_mtime); 24707c478bd9Sstevel@tonic-gate newhrt = ts2hrt(&vfs_mnttab_mtime); 24717c478bd9Sstevel@tonic-gate if (oldhrt == (hrtime_t)0) 24727c478bd9Sstevel@tonic-gate vfs_mnttab_ctime = vfs_mnttab_mtime; 24737c478bd9Sstevel@tonic-gate /* 24747c478bd9Sstevel@tonic-gate * Attempt to provide unique mtime (like uniqtime but not). 24757c478bd9Sstevel@tonic-gate */ 24767c478bd9Sstevel@tonic-gate if (newhrt == oldhrt) { 24777c478bd9Sstevel@tonic-gate newhrt++; 24787c478bd9Sstevel@tonic-gate hrt2ts(newhrt, &vfs_mnttab_mtime); 24797c478bd9Sstevel@tonic-gate } 24807c478bd9Sstevel@tonic-gate pollwakeup(&vfs_pollhd, (short)POLLRDBAND); 24817c478bd9Sstevel@tonic-gate } 24827c478bd9Sstevel@tonic-gate 24837c478bd9Sstevel@tonic-gate int 24847c478bd9Sstevel@tonic-gate dounmount(struct vfs *vfsp, int flag, cred_t *cr) 24857c478bd9Sstevel@tonic-gate { 24867c478bd9Sstevel@tonic-gate vnode_t *coveredvp; 24877c478bd9Sstevel@tonic-gate int error; 2488*5a59a8b3Srsb extern void teardown_vopstats(vfs_t *); 24897c478bd9Sstevel@tonic-gate 24907c478bd9Sstevel@tonic-gate /* 24917c478bd9Sstevel@tonic-gate * Get covered vnode. This will be NULL if the vfs is not linked 24927c478bd9Sstevel@tonic-gate * into the file system name space (i.e., domount() with MNT_NOSPICE). 24937c478bd9Sstevel@tonic-gate */ 24947c478bd9Sstevel@tonic-gate coveredvp = vfsp->vfs_vnodecovered; 24957c478bd9Sstevel@tonic-gate ASSERT(coveredvp == NULL || vn_vfswlock_held(coveredvp)); 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate /* 24987c478bd9Sstevel@tonic-gate * Purge all dnlc entries for this vfs. 24997c478bd9Sstevel@tonic-gate */ 25007c478bd9Sstevel@tonic-gate (void) dnlc_purge_vfsp(vfsp, 0); 25017c478bd9Sstevel@tonic-gate 25027c478bd9Sstevel@tonic-gate /* For forcible umount, skip VFS_SYNC() since it may hang */ 25037c478bd9Sstevel@tonic-gate if ((flag & MS_FORCE) == 0) 25047c478bd9Sstevel@tonic-gate (void) VFS_SYNC(vfsp, 0, cr); 25057c478bd9Sstevel@tonic-gate 25067c478bd9Sstevel@tonic-gate /* 25077c478bd9Sstevel@tonic-gate * Lock the vfs to maintain fs status quo during unmount. This 25087c478bd9Sstevel@tonic-gate * has to be done after the sync because ufs_update tries to acquire 25097c478bd9Sstevel@tonic-gate * the vfs_reflock. 25107c478bd9Sstevel@tonic-gate */ 25117c478bd9Sstevel@tonic-gate vfs_lock_wait(vfsp); 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate if (error = VFS_UNMOUNT(vfsp, flag, cr)) { 25147c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 25157c478bd9Sstevel@tonic-gate if (coveredvp != NULL) 25167c478bd9Sstevel@tonic-gate vn_vfsunlock(coveredvp); 25177c478bd9Sstevel@tonic-gate } else if (coveredvp != NULL) { 2518*5a59a8b3Srsb teardown_vopstats(vfsp); 25197c478bd9Sstevel@tonic-gate /* 25207c478bd9Sstevel@tonic-gate * vfs_remove() will do a VN_RELE(vfsp->vfs_vnodecovered) 25217c478bd9Sstevel@tonic-gate * when it frees vfsp so we do a VN_HOLD() so we can 25227c478bd9Sstevel@tonic-gate * continue to use coveredvp afterwards. 25237c478bd9Sstevel@tonic-gate */ 25247c478bd9Sstevel@tonic-gate VN_HOLD(coveredvp); 25257c478bd9Sstevel@tonic-gate vfs_remove(vfsp); 25267c478bd9Sstevel@tonic-gate vn_vfsunlock(coveredvp); 25277c478bd9Sstevel@tonic-gate VN_RELE(coveredvp); 25287c478bd9Sstevel@tonic-gate } else { 2529*5a59a8b3Srsb teardown_vopstats(vfsp); 25307c478bd9Sstevel@tonic-gate /* 25317c478bd9Sstevel@tonic-gate * Release the reference to vfs that is not linked 25327c478bd9Sstevel@tonic-gate * into the name space. 25337c478bd9Sstevel@tonic-gate */ 25347c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 25357c478bd9Sstevel@tonic-gate VFS_RELE(vfsp); 25367c478bd9Sstevel@tonic-gate } 25377c478bd9Sstevel@tonic-gate return (error); 25387c478bd9Sstevel@tonic-gate } 25397c478bd9Sstevel@tonic-gate 25407c478bd9Sstevel@tonic-gate 25417c478bd9Sstevel@tonic-gate /* 25427c478bd9Sstevel@tonic-gate * Vfs_unmountall() is called by uadmin() to unmount all 25437c478bd9Sstevel@tonic-gate * mounted file systems (except the root file system) during shutdown. 25447c478bd9Sstevel@tonic-gate * It follows the existing locking protocol when traversing the vfs list 25457c478bd9Sstevel@tonic-gate * to sync and unmount vfses. Even though there should be no 25467c478bd9Sstevel@tonic-gate * other thread running while the system is shutting down, it is prudent 25477c478bd9Sstevel@tonic-gate * to still follow the locking protocol. 25487c478bd9Sstevel@tonic-gate */ 25497c478bd9Sstevel@tonic-gate void 25507c478bd9Sstevel@tonic-gate vfs_unmountall(void) 25517c478bd9Sstevel@tonic-gate { 25527c478bd9Sstevel@tonic-gate struct vfs *vfsp; 25537c478bd9Sstevel@tonic-gate struct vfs *prev_vfsp = NULL; 25547c478bd9Sstevel@tonic-gate int error; 25557c478bd9Sstevel@tonic-gate 25567c478bd9Sstevel@tonic-gate /* 25577c478bd9Sstevel@tonic-gate * Toss all dnlc entries now so that the per-vfs sync 25587c478bd9Sstevel@tonic-gate * and unmount operations don't have to slog through 25597c478bd9Sstevel@tonic-gate * a bunch of uninteresting vnodes over and over again. 25607c478bd9Sstevel@tonic-gate */ 25617c478bd9Sstevel@tonic-gate dnlc_purge(); 25627c478bd9Sstevel@tonic-gate 25637c478bd9Sstevel@tonic-gate vfs_list_lock(); 25647c478bd9Sstevel@tonic-gate for (vfsp = rootvfs->vfs_prev; vfsp != rootvfs; vfsp = prev_vfsp) { 25657c478bd9Sstevel@tonic-gate prev_vfsp = vfsp->vfs_prev; 25667c478bd9Sstevel@tonic-gate 25677c478bd9Sstevel@tonic-gate if (vfs_lock(vfsp) != 0) 25687c478bd9Sstevel@tonic-gate continue; 25697c478bd9Sstevel@tonic-gate error = vn_vfswlock(vfsp->vfs_vnodecovered); 25707c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 25717c478bd9Sstevel@tonic-gate if (error) 25727c478bd9Sstevel@tonic-gate continue; 25737c478bd9Sstevel@tonic-gate 25747c478bd9Sstevel@tonic-gate vfs_list_unlock(); 25757c478bd9Sstevel@tonic-gate 25767c478bd9Sstevel@tonic-gate (void) VFS_SYNC(vfsp, SYNC_CLOSE, CRED()); 25777c478bd9Sstevel@tonic-gate (void) dounmount(vfsp, 0, CRED()); 25787c478bd9Sstevel@tonic-gate 25797c478bd9Sstevel@tonic-gate /* 25807c478bd9Sstevel@tonic-gate * Since we dropped the vfslist lock above we must 25817c478bd9Sstevel@tonic-gate * verify that next_vfsp still exists, else start over. 25827c478bd9Sstevel@tonic-gate */ 25837c478bd9Sstevel@tonic-gate vfs_list_lock(); 25847c478bd9Sstevel@tonic-gate for (vfsp = rootvfs->vfs_prev; 25857c478bd9Sstevel@tonic-gate vfsp != rootvfs; vfsp = vfsp->vfs_prev) 25867c478bd9Sstevel@tonic-gate if (vfsp == prev_vfsp) 25877c478bd9Sstevel@tonic-gate break; 25887c478bd9Sstevel@tonic-gate if (vfsp == rootvfs && prev_vfsp != rootvfs) 25897c478bd9Sstevel@tonic-gate prev_vfsp = rootvfs->vfs_prev; 25907c478bd9Sstevel@tonic-gate } 25917c478bd9Sstevel@tonic-gate vfs_list_unlock(); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate 25947c478bd9Sstevel@tonic-gate /* 25957c478bd9Sstevel@tonic-gate * Called to add an entry to the end of the vfs mount in progress list 25967c478bd9Sstevel@tonic-gate */ 25977c478bd9Sstevel@tonic-gate void 25987c478bd9Sstevel@tonic-gate vfs_addmip(dev_t dev, struct vfs *vfsp) 25997c478bd9Sstevel@tonic-gate { 26007c478bd9Sstevel@tonic-gate struct ipmnt *mipp; 26017c478bd9Sstevel@tonic-gate 26027c478bd9Sstevel@tonic-gate mipp = (struct ipmnt *)kmem_alloc(sizeof (struct ipmnt), KM_SLEEP); 26037c478bd9Sstevel@tonic-gate mipp->mip_next = NULL; 26047c478bd9Sstevel@tonic-gate mipp->mip_dev = dev; 26057c478bd9Sstevel@tonic-gate mipp->mip_vfsp = vfsp; 26067c478bd9Sstevel@tonic-gate mutex_enter(&vfs_miplist_mutex); 26077c478bd9Sstevel@tonic-gate if (vfs_miplist_end != NULL) 26087c478bd9Sstevel@tonic-gate vfs_miplist_end->mip_next = mipp; 26097c478bd9Sstevel@tonic-gate else 26107c478bd9Sstevel@tonic-gate vfs_miplist = mipp; 26117c478bd9Sstevel@tonic-gate vfs_miplist_end = mipp; 26127c478bd9Sstevel@tonic-gate mutex_exit(&vfs_miplist_mutex); 26137c478bd9Sstevel@tonic-gate } 26147c478bd9Sstevel@tonic-gate 26157c478bd9Sstevel@tonic-gate /* 26167c478bd9Sstevel@tonic-gate * Called to remove an entry from the mount in progress list 26177c478bd9Sstevel@tonic-gate * Either because the mount completed or it failed. 26187c478bd9Sstevel@tonic-gate */ 26197c478bd9Sstevel@tonic-gate void 26207c478bd9Sstevel@tonic-gate vfs_delmip(struct vfs *vfsp) 26217c478bd9Sstevel@tonic-gate { 26227c478bd9Sstevel@tonic-gate struct ipmnt *mipp, *mipprev; 26237c478bd9Sstevel@tonic-gate 26247c478bd9Sstevel@tonic-gate mutex_enter(&vfs_miplist_mutex); 26257c478bd9Sstevel@tonic-gate mipprev = NULL; 26267c478bd9Sstevel@tonic-gate for (mipp = vfs_miplist; 26277c478bd9Sstevel@tonic-gate mipp && mipp->mip_vfsp != vfsp; mipp = mipp->mip_next) { 26287c478bd9Sstevel@tonic-gate mipprev = mipp; 26297c478bd9Sstevel@tonic-gate } 26307c478bd9Sstevel@tonic-gate if (mipp == NULL) 26317c478bd9Sstevel@tonic-gate return; /* shouldn't happen */ 26327c478bd9Sstevel@tonic-gate if (mipp == vfs_miplist_end) 26337c478bd9Sstevel@tonic-gate vfs_miplist_end = mipprev; 26347c478bd9Sstevel@tonic-gate if (mipprev == NULL) 26357c478bd9Sstevel@tonic-gate vfs_miplist = mipp->mip_next; 26367c478bd9Sstevel@tonic-gate else 26377c478bd9Sstevel@tonic-gate mipprev->mip_next = mipp->mip_next; 26387c478bd9Sstevel@tonic-gate mutex_exit(&vfs_miplist_mutex); 26397c478bd9Sstevel@tonic-gate kmem_free(mipp, sizeof (struct ipmnt)); 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate 26427c478bd9Sstevel@tonic-gate /* 26437c478bd9Sstevel@tonic-gate * vfs_add is called by a specific filesystem's mount routine to add 26447c478bd9Sstevel@tonic-gate * the new vfs into the vfs list/hash and to cover the mounted-on vnode. 26457c478bd9Sstevel@tonic-gate * The vfs should already have been locked by the caller. 26467c478bd9Sstevel@tonic-gate * 26477c478bd9Sstevel@tonic-gate * coveredvp is NULL if this is the root. 26487c478bd9Sstevel@tonic-gate */ 26497c478bd9Sstevel@tonic-gate void 26507c478bd9Sstevel@tonic-gate vfs_add(vnode_t *coveredvp, struct vfs *vfsp, int mflag) 26517c478bd9Sstevel@tonic-gate { 26527c478bd9Sstevel@tonic-gate int newflag; 26537c478bd9Sstevel@tonic-gate 26547c478bd9Sstevel@tonic-gate ASSERT(vfs_lock_held(vfsp)); 26557c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); 26567c478bd9Sstevel@tonic-gate newflag = vfsp->vfs_flag; 26577c478bd9Sstevel@tonic-gate if (mflag & MS_RDONLY) 26587c478bd9Sstevel@tonic-gate newflag |= VFS_RDONLY; 26597c478bd9Sstevel@tonic-gate else 26607c478bd9Sstevel@tonic-gate newflag &= ~VFS_RDONLY; 26617c478bd9Sstevel@tonic-gate if (mflag & MS_NOSUID) 26627c478bd9Sstevel@tonic-gate newflag |= (VFS_NOSETUID|VFS_NODEVICES); 26637c478bd9Sstevel@tonic-gate else 26647c478bd9Sstevel@tonic-gate newflag &= ~(VFS_NOSETUID|VFS_NODEVICES); 26657c478bd9Sstevel@tonic-gate if (mflag & MS_NOMNTTAB) 26667c478bd9Sstevel@tonic-gate newflag |= VFS_NOMNTTAB; 26677c478bd9Sstevel@tonic-gate else 26687c478bd9Sstevel@tonic-gate newflag &= ~VFS_NOMNTTAB; 26697c478bd9Sstevel@tonic-gate 26707c478bd9Sstevel@tonic-gate if (coveredvp != NULL) { 26717c478bd9Sstevel@tonic-gate ASSERT(vn_vfswlock_held(coveredvp)); 26727c478bd9Sstevel@tonic-gate coveredvp->v_vfsmountedhere = vfsp; 26737c478bd9Sstevel@tonic-gate VN_HOLD(coveredvp); 26747c478bd9Sstevel@tonic-gate } 26757c478bd9Sstevel@tonic-gate vfsp->vfs_vnodecovered = coveredvp; 26767c478bd9Sstevel@tonic-gate vfsp->vfs_flag = newflag; 26777c478bd9Sstevel@tonic-gate 26787c478bd9Sstevel@tonic-gate vfs_list_add(vfsp); 26797c478bd9Sstevel@tonic-gate } 26807c478bd9Sstevel@tonic-gate 26817c478bd9Sstevel@tonic-gate /* 26827c478bd9Sstevel@tonic-gate * Remove a vfs from the vfs list, null out the pointer from the 26837c478bd9Sstevel@tonic-gate * covered vnode to the vfs (v_vfsmountedhere), and null out the pointer 26847c478bd9Sstevel@tonic-gate * from the vfs to the covered vnode (vfs_vnodecovered). Release the 26857c478bd9Sstevel@tonic-gate * reference to the vfs and to the covered vnode. 26867c478bd9Sstevel@tonic-gate * 26877c478bd9Sstevel@tonic-gate * Called from dounmount after it's confirmed with the file system 26887c478bd9Sstevel@tonic-gate * that the unmount is legal. 26897c478bd9Sstevel@tonic-gate */ 26907c478bd9Sstevel@tonic-gate void 26917c478bd9Sstevel@tonic-gate vfs_remove(struct vfs *vfsp) 26927c478bd9Sstevel@tonic-gate { 26937c478bd9Sstevel@tonic-gate vnode_t *vp; 26947c478bd9Sstevel@tonic-gate 26957c478bd9Sstevel@tonic-gate ASSERT(vfs_lock_held(vfsp)); 26967c478bd9Sstevel@tonic-gate 26977c478bd9Sstevel@tonic-gate /* 26987c478bd9Sstevel@tonic-gate * Can't unmount root. Should never happen because fs will 26997c478bd9Sstevel@tonic-gate * be busy. 27007c478bd9Sstevel@tonic-gate */ 27017c478bd9Sstevel@tonic-gate if (vfsp == rootvfs) 27027c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "vfs_remove: unmounting root"); 27037c478bd9Sstevel@tonic-gate 27047c478bd9Sstevel@tonic-gate vfs_list_remove(vfsp); 27057c478bd9Sstevel@tonic-gate 27067c478bd9Sstevel@tonic-gate /* 27077c478bd9Sstevel@tonic-gate * Unhook from the file system name space. 27087c478bd9Sstevel@tonic-gate */ 27097c478bd9Sstevel@tonic-gate vp = vfsp->vfs_vnodecovered; 27107c478bd9Sstevel@tonic-gate ASSERT(vn_vfswlock_held(vp)); 27117c478bd9Sstevel@tonic-gate vp->v_vfsmountedhere = NULL; 27127c478bd9Sstevel@tonic-gate vfsp->vfs_vnodecovered = NULL; 27137c478bd9Sstevel@tonic-gate VN_RELE(vp); 27147c478bd9Sstevel@tonic-gate 27157c478bd9Sstevel@tonic-gate /* 27167c478bd9Sstevel@tonic-gate * Release lock and wakeup anybody waiting. 27177c478bd9Sstevel@tonic-gate */ 27187c478bd9Sstevel@tonic-gate vfs_unlock(vfsp); 27197c478bd9Sstevel@tonic-gate VFS_RELE(vfsp); 27207c478bd9Sstevel@tonic-gate } 27217c478bd9Sstevel@tonic-gate 27227c478bd9Sstevel@tonic-gate /* 27237c478bd9Sstevel@tonic-gate * Lock a filesystem to prevent access to it while mounting, 27247c478bd9Sstevel@tonic-gate * unmounting and syncing. Return EBUSY immediately if lock 27257c478bd9Sstevel@tonic-gate * can't be acquired. 27267c478bd9Sstevel@tonic-gate */ 27277c478bd9Sstevel@tonic-gate int 27287c478bd9Sstevel@tonic-gate vfs_lock(vfs_t *vfsp) 27297c478bd9Sstevel@tonic-gate { 27307c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 27317c478bd9Sstevel@tonic-gate 27327c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 27337c478bd9Sstevel@tonic-gate if (rwst_tryenter(&vpvfsentry->ve_lock, RW_WRITER)) 27347c478bd9Sstevel@tonic-gate return (0); 27357c478bd9Sstevel@tonic-gate 27367c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 27377c478bd9Sstevel@tonic-gate return (EBUSY); 27387c478bd9Sstevel@tonic-gate } 27397c478bd9Sstevel@tonic-gate 27407c478bd9Sstevel@tonic-gate int 27417c478bd9Sstevel@tonic-gate vfs_rlock(vfs_t *vfsp) 27427c478bd9Sstevel@tonic-gate { 27437c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 27447c478bd9Sstevel@tonic-gate 27457c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 27467c478bd9Sstevel@tonic-gate 27477c478bd9Sstevel@tonic-gate if (rwst_tryenter(&vpvfsentry->ve_lock, RW_READER)) 27487c478bd9Sstevel@tonic-gate return (0); 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 27517c478bd9Sstevel@tonic-gate return (EBUSY); 27527c478bd9Sstevel@tonic-gate } 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate void 27557c478bd9Sstevel@tonic-gate vfs_lock_wait(vfs_t *vfsp) 27567c478bd9Sstevel@tonic-gate { 27577c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 27587c478bd9Sstevel@tonic-gate 27597c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 27607c478bd9Sstevel@tonic-gate rwst_enter(&vpvfsentry->ve_lock, RW_WRITER); 27617c478bd9Sstevel@tonic-gate } 27627c478bd9Sstevel@tonic-gate 27637c478bd9Sstevel@tonic-gate void 27647c478bd9Sstevel@tonic-gate vfs_rlock_wait(vfs_t *vfsp) 27657c478bd9Sstevel@tonic-gate { 27667c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 27677c478bd9Sstevel@tonic-gate 27687c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 27697c478bd9Sstevel@tonic-gate rwst_enter(&vpvfsentry->ve_lock, RW_READER); 27707c478bd9Sstevel@tonic-gate } 27717c478bd9Sstevel@tonic-gate 27727c478bd9Sstevel@tonic-gate /* 27737c478bd9Sstevel@tonic-gate * Unlock a locked filesystem. 27747c478bd9Sstevel@tonic-gate */ 27757c478bd9Sstevel@tonic-gate void 27767c478bd9Sstevel@tonic-gate vfs_unlock(vfs_t *vfsp) 27777c478bd9Sstevel@tonic-gate { 27787c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 27797c478bd9Sstevel@tonic-gate 27807c478bd9Sstevel@tonic-gate /* 27817c478bd9Sstevel@tonic-gate * vfs_unlock will mimic sema_v behaviour to fix 4748018. 27827c478bd9Sstevel@tonic-gate * And these changes should remain for the patch changes as it is. 27837c478bd9Sstevel@tonic-gate */ 27847c478bd9Sstevel@tonic-gate if (panicstr) 27857c478bd9Sstevel@tonic-gate return; 27867c478bd9Sstevel@tonic-gate 27877c478bd9Sstevel@tonic-gate /* 27887c478bd9Sstevel@tonic-gate * ve_refcount needs to be dropped twice here. 27897c478bd9Sstevel@tonic-gate * 1. To release refernce after a call to vfs_locks_getlock() 27907c478bd9Sstevel@tonic-gate * 2. To release the reference from the locking routines like 27917c478bd9Sstevel@tonic-gate * vfs_rlock_wait/vfs_wlock_wait/vfs_wlock etc,. 27927c478bd9Sstevel@tonic-gate */ 27937c478bd9Sstevel@tonic-gate 27947c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 27957c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 27967c478bd9Sstevel@tonic-gate 27977c478bd9Sstevel@tonic-gate rwst_exit(&vpvfsentry->ve_lock); 27987c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 27997c478bd9Sstevel@tonic-gate } 28007c478bd9Sstevel@tonic-gate 28017c478bd9Sstevel@tonic-gate /* 28027c478bd9Sstevel@tonic-gate * Utility routine that allows a filesystem to construct its 28037c478bd9Sstevel@tonic-gate * fsid in "the usual way" - by munging some underlying dev_t and 28047c478bd9Sstevel@tonic-gate * the filesystem type number into the 64-bit fsid. Note that 28057c478bd9Sstevel@tonic-gate * this implicitly relies on dev_t persistence to make filesystem 28067c478bd9Sstevel@tonic-gate * id's persistent. 28077c478bd9Sstevel@tonic-gate * 28087c478bd9Sstevel@tonic-gate * There's nothing to prevent an individual fs from constructing its 28097c478bd9Sstevel@tonic-gate * fsid in a different way, and indeed they should. 28107c478bd9Sstevel@tonic-gate * 28117c478bd9Sstevel@tonic-gate * Since we want fsids to be 32-bit quantities (so that they can be 28127c478bd9Sstevel@tonic-gate * exported identically by either 32-bit or 64-bit APIs, as well as 28137c478bd9Sstevel@tonic-gate * the fact that fsid's are "known" to NFS), we compress the device 28147c478bd9Sstevel@tonic-gate * number given down to 32-bits, and panic if that isn't possible. 28157c478bd9Sstevel@tonic-gate */ 28167c478bd9Sstevel@tonic-gate void 28177c478bd9Sstevel@tonic-gate vfs_make_fsid(fsid_t *fsi, dev_t dev, int val) 28187c478bd9Sstevel@tonic-gate { 28197c478bd9Sstevel@tonic-gate if (!cmpldev((dev32_t *)&fsi->val[0], dev)) 28207c478bd9Sstevel@tonic-gate panic("device number too big for fsid!"); 28217c478bd9Sstevel@tonic-gate fsi->val[1] = val; 28227c478bd9Sstevel@tonic-gate } 28237c478bd9Sstevel@tonic-gate 28247c478bd9Sstevel@tonic-gate int 28257c478bd9Sstevel@tonic-gate vfs_lock_held(vfs_t *vfsp) 28267c478bd9Sstevel@tonic-gate { 28277c478bd9Sstevel@tonic-gate int held; 28287c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 28297c478bd9Sstevel@tonic-gate 28307c478bd9Sstevel@tonic-gate /* 28317c478bd9Sstevel@tonic-gate * vfs_lock_held will mimic sema_held behaviour 28327c478bd9Sstevel@tonic-gate * if panicstr is set. And these changes should remain 28337c478bd9Sstevel@tonic-gate * for the patch changes as it is. 28347c478bd9Sstevel@tonic-gate */ 28357c478bd9Sstevel@tonic-gate if (panicstr) 28367c478bd9Sstevel@tonic-gate return (1); 28377c478bd9Sstevel@tonic-gate 28387c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 28397c478bd9Sstevel@tonic-gate held = rwst_lock_held(&vpvfsentry->ve_lock, RW_WRITER); 28407c478bd9Sstevel@tonic-gate 28417c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 28427c478bd9Sstevel@tonic-gate return (held); 28437c478bd9Sstevel@tonic-gate } 28447c478bd9Sstevel@tonic-gate 28457c478bd9Sstevel@tonic-gate struct _kthread * 28467c478bd9Sstevel@tonic-gate vfs_lock_owner(vfs_t *vfsp) 28477c478bd9Sstevel@tonic-gate { 28487c478bd9Sstevel@tonic-gate struct _kthread *owner; 28497c478bd9Sstevel@tonic-gate vn_vfslocks_entry_t *vpvfsentry; 28507c478bd9Sstevel@tonic-gate 28517c478bd9Sstevel@tonic-gate /* 28527c478bd9Sstevel@tonic-gate * vfs_wlock_held will mimic sema_held behaviour 28537c478bd9Sstevel@tonic-gate * if panicstr is set. And these changes should remain 28547c478bd9Sstevel@tonic-gate * for the patch changes as it is. 28557c478bd9Sstevel@tonic-gate */ 28567c478bd9Sstevel@tonic-gate if (panicstr) 28577c478bd9Sstevel@tonic-gate return (NULL); 28587c478bd9Sstevel@tonic-gate 28597c478bd9Sstevel@tonic-gate vpvfsentry = vn_vfslocks_getlock(vfsp); 28607c478bd9Sstevel@tonic-gate owner = rwst_owner(&vpvfsentry->ve_lock); 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate vn_vfslocks_rele(vpvfsentry); 28637c478bd9Sstevel@tonic-gate return (owner); 28647c478bd9Sstevel@tonic-gate } 28657c478bd9Sstevel@tonic-gate 28667c478bd9Sstevel@tonic-gate /* 28677c478bd9Sstevel@tonic-gate * vfs list locking. 28687c478bd9Sstevel@tonic-gate * 28697c478bd9Sstevel@tonic-gate * Rather than manipulate the vfslist lock directly, we abstract into lock 28707c478bd9Sstevel@tonic-gate * and unlock routines to allow the locking implementation to be changed for 28717c478bd9Sstevel@tonic-gate * clustering. 28727c478bd9Sstevel@tonic-gate * 28737c478bd9Sstevel@tonic-gate * Whenever the vfs list is modified through its hash links, the overall list 28747c478bd9Sstevel@tonic-gate * lock must be obtained before locking the relevant hash bucket. But to see 28757c478bd9Sstevel@tonic-gate * whether a given vfs is on the list, it suffices to obtain the lock for the 28767c478bd9Sstevel@tonic-gate * hash bucket without getting the overall list lock. (See getvfs() below.) 28777c478bd9Sstevel@tonic-gate */ 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate void 28807c478bd9Sstevel@tonic-gate vfs_list_lock() 28817c478bd9Sstevel@tonic-gate { 28827c478bd9Sstevel@tonic-gate rw_enter(&vfslist, RW_WRITER); 28837c478bd9Sstevel@tonic-gate } 28847c478bd9Sstevel@tonic-gate 28857c478bd9Sstevel@tonic-gate void 28867c478bd9Sstevel@tonic-gate vfs_list_read_lock() 28877c478bd9Sstevel@tonic-gate { 28887c478bd9Sstevel@tonic-gate rw_enter(&vfslist, RW_READER); 28897c478bd9Sstevel@tonic-gate } 28907c478bd9Sstevel@tonic-gate 28917c478bd9Sstevel@tonic-gate void 28927c478bd9Sstevel@tonic-gate vfs_list_unlock() 28937c478bd9Sstevel@tonic-gate { 28947c478bd9Sstevel@tonic-gate rw_exit(&vfslist); 28957c478bd9Sstevel@tonic-gate } 28967c478bd9Sstevel@tonic-gate 28977c478bd9Sstevel@tonic-gate /* 28987c478bd9Sstevel@tonic-gate * Low level worker routines for adding entries to and removing entries from 28997c478bd9Sstevel@tonic-gate * the vfs list. 29007c478bd9Sstevel@tonic-gate */ 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate static void 29037c478bd9Sstevel@tonic-gate vfs_hash_add(struct vfs *vfsp, int insert_at_head) 29047c478bd9Sstevel@tonic-gate { 29057c478bd9Sstevel@tonic-gate int vhno; 29067c478bd9Sstevel@tonic-gate struct vfs **hp; 29077c478bd9Sstevel@tonic-gate dev_t dev; 29087c478bd9Sstevel@tonic-gate 29097c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&vfslist)); 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate dev = expldev(vfsp->vfs_fsid.val[0]); 29127c478bd9Sstevel@tonic-gate vhno = VFSHASH(getmajor(dev), getminor(dev)); 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate mutex_enter(&rvfs_list[vhno].rvfs_lock); 29157c478bd9Sstevel@tonic-gate 29167c478bd9Sstevel@tonic-gate /* 29177c478bd9Sstevel@tonic-gate * Link into the hash table, inserting it at the end, so that LOFS 29187c478bd9Sstevel@tonic-gate * with the same fsid as UFS (or other) file systems will not hide the 29197c478bd9Sstevel@tonic-gate * UFS. 29207c478bd9Sstevel@tonic-gate */ 29217c478bd9Sstevel@tonic-gate if (insert_at_head) { 29227c478bd9Sstevel@tonic-gate vfsp->vfs_hash = rvfs_list[vhno].rvfs_head; 29237c478bd9Sstevel@tonic-gate rvfs_list[vhno].rvfs_head = vfsp; 29247c478bd9Sstevel@tonic-gate } else { 29257c478bd9Sstevel@tonic-gate for (hp = &rvfs_list[vhno].rvfs_head; *hp != NULL; 29267c478bd9Sstevel@tonic-gate hp = &(*hp)->vfs_hash) 29277c478bd9Sstevel@tonic-gate continue; 29287c478bd9Sstevel@tonic-gate /* 29297c478bd9Sstevel@tonic-gate * hp now contains the address of the pointer to update 29307c478bd9Sstevel@tonic-gate * to effect the insertion. 29317c478bd9Sstevel@tonic-gate */ 29327c478bd9Sstevel@tonic-gate vfsp->vfs_hash = NULL; 29337c478bd9Sstevel@tonic-gate *hp = vfsp; 29347c478bd9Sstevel@tonic-gate } 29357c478bd9Sstevel@tonic-gate 29367c478bd9Sstevel@tonic-gate rvfs_list[vhno].rvfs_len++; 29377c478bd9Sstevel@tonic-gate mutex_exit(&rvfs_list[vhno].rvfs_lock); 29387c478bd9Sstevel@tonic-gate } 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate 29417c478bd9Sstevel@tonic-gate static void 29427c478bd9Sstevel@tonic-gate vfs_hash_remove(struct vfs *vfsp) 29437c478bd9Sstevel@tonic-gate { 29447c478bd9Sstevel@tonic-gate int vhno; 29457c478bd9Sstevel@tonic-gate struct vfs *tvfsp; 29467c478bd9Sstevel@tonic-gate dev_t dev; 29477c478bd9Sstevel@tonic-gate 29487c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&vfslist)); 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate dev = expldev(vfsp->vfs_fsid.val[0]); 29517c478bd9Sstevel@tonic-gate vhno = VFSHASH(getmajor(dev), getminor(dev)); 29527c478bd9Sstevel@tonic-gate 29537c478bd9Sstevel@tonic-gate mutex_enter(&rvfs_list[vhno].rvfs_lock); 29547c478bd9Sstevel@tonic-gate 29557c478bd9Sstevel@tonic-gate /* 29567c478bd9Sstevel@tonic-gate * Remove from hash. 29577c478bd9Sstevel@tonic-gate */ 29587c478bd9Sstevel@tonic-gate if (rvfs_list[vhno].rvfs_head == vfsp) { 29597c478bd9Sstevel@tonic-gate rvfs_list[vhno].rvfs_head = vfsp->vfs_hash; 29607c478bd9Sstevel@tonic-gate rvfs_list[vhno].rvfs_len--; 29617c478bd9Sstevel@tonic-gate goto foundit; 29627c478bd9Sstevel@tonic-gate } 29637c478bd9Sstevel@tonic-gate for (tvfsp = rvfs_list[vhno].rvfs_head; tvfsp != NULL; 29647c478bd9Sstevel@tonic-gate tvfsp = tvfsp->vfs_hash) { 29657c478bd9Sstevel@tonic-gate if (tvfsp->vfs_hash == vfsp) { 29667c478bd9Sstevel@tonic-gate tvfsp->vfs_hash = vfsp->vfs_hash; 29677c478bd9Sstevel@tonic-gate rvfs_list[vhno].rvfs_len--; 29687c478bd9Sstevel@tonic-gate goto foundit; 29697c478bd9Sstevel@tonic-gate } 29707c478bd9Sstevel@tonic-gate } 29717c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "vfs_list_remove: vfs not found in hash"); 29727c478bd9Sstevel@tonic-gate 29737c478bd9Sstevel@tonic-gate foundit: 29747c478bd9Sstevel@tonic-gate 29757c478bd9Sstevel@tonic-gate mutex_exit(&rvfs_list[vhno].rvfs_lock); 29767c478bd9Sstevel@tonic-gate } 29777c478bd9Sstevel@tonic-gate 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate void 29807c478bd9Sstevel@tonic-gate vfs_list_add(struct vfs *vfsp) 29817c478bd9Sstevel@tonic-gate { 29827c478bd9Sstevel@tonic-gate zone_t *zone; 29837c478bd9Sstevel@tonic-gate 29847c478bd9Sstevel@tonic-gate /* 29857c478bd9Sstevel@tonic-gate * The zone that owns the mount is the one that performed the mount. 29867c478bd9Sstevel@tonic-gate * Note that this isn't necessarily the same as the zone mounted into. 29877c478bd9Sstevel@tonic-gate * The corresponding zone_rele() will be done when the vfs_t is 29887c478bd9Sstevel@tonic-gate * being free'd. 29897c478bd9Sstevel@tonic-gate */ 29907c478bd9Sstevel@tonic-gate vfsp->vfs_zone = curproc->p_zone; 29917c478bd9Sstevel@tonic-gate zone_hold(vfsp->vfs_zone); 29927c478bd9Sstevel@tonic-gate 29937c478bd9Sstevel@tonic-gate /* 29947c478bd9Sstevel@tonic-gate * Find the zone mounted into, and put this mount on its vfs list. 29957c478bd9Sstevel@tonic-gate */ 29967c478bd9Sstevel@tonic-gate zone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt)); 29977c478bd9Sstevel@tonic-gate ASSERT(zone != NULL); 29987c478bd9Sstevel@tonic-gate /* 29997c478bd9Sstevel@tonic-gate * Special casing for the root vfs. This structure is allocated 30007c478bd9Sstevel@tonic-gate * statically and hooked onto rootvfs at link time. During the 30017c478bd9Sstevel@tonic-gate * vfs_mountroot call at system startup time, the root file system's 30027c478bd9Sstevel@tonic-gate * VFS_MOUNTROOT routine will call vfs_add with this root vfs struct 30037c478bd9Sstevel@tonic-gate * as argument. The code below must detect and handle this special 30047c478bd9Sstevel@tonic-gate * case. The only apparent justification for this special casing is 30057c478bd9Sstevel@tonic-gate * to ensure that the root file system appears at the head of the 30067c478bd9Sstevel@tonic-gate * list. 30077c478bd9Sstevel@tonic-gate * 30087c478bd9Sstevel@tonic-gate * XXX: I'm assuming that it's ok to do normal list locking when 30097c478bd9Sstevel@tonic-gate * adding the entry for the root file system (this used to be 30107c478bd9Sstevel@tonic-gate * done with no locks held). 30117c478bd9Sstevel@tonic-gate */ 30127c478bd9Sstevel@tonic-gate vfs_list_lock(); 30137c478bd9Sstevel@tonic-gate /* 30147c478bd9Sstevel@tonic-gate * Link into the vfs list proper. 30157c478bd9Sstevel@tonic-gate */ 30167c478bd9Sstevel@tonic-gate if (vfsp == &root) { 30177c478bd9Sstevel@tonic-gate /* 30187c478bd9Sstevel@tonic-gate * Assert: This vfs is already on the list as its first entry. 30197c478bd9Sstevel@tonic-gate * Thus, there's nothing to do. 30207c478bd9Sstevel@tonic-gate */ 30217c478bd9Sstevel@tonic-gate ASSERT(rootvfs == vfsp); 30227c478bd9Sstevel@tonic-gate /* 30237c478bd9Sstevel@tonic-gate * Add it to the head of the global zone's vfslist. 30247c478bd9Sstevel@tonic-gate */ 30257c478bd9Sstevel@tonic-gate ASSERT(zone == global_zone); 30267c478bd9Sstevel@tonic-gate ASSERT(zone->zone_vfslist == NULL); 30277c478bd9Sstevel@tonic-gate zone->zone_vfslist = vfsp; 30287c478bd9Sstevel@tonic-gate } else { 30297c478bd9Sstevel@tonic-gate /* 30307c478bd9Sstevel@tonic-gate * Link to end of list using vfs_prev (as rootvfs is now a 30317c478bd9Sstevel@tonic-gate * doubly linked circular list) so list is in mount order for 30327c478bd9Sstevel@tonic-gate * mnttab use. 30337c478bd9Sstevel@tonic-gate */ 30347c478bd9Sstevel@tonic-gate rootvfs->vfs_prev->vfs_next = vfsp; 30357c478bd9Sstevel@tonic-gate vfsp->vfs_prev = rootvfs->vfs_prev; 30367c478bd9Sstevel@tonic-gate rootvfs->vfs_prev = vfsp; 30377c478bd9Sstevel@tonic-gate vfsp->vfs_next = rootvfs; 30387c478bd9Sstevel@tonic-gate 30397c478bd9Sstevel@tonic-gate /* 30407c478bd9Sstevel@tonic-gate * Do it again for the zone-private list (which may be NULL). 30417c478bd9Sstevel@tonic-gate */ 30427c478bd9Sstevel@tonic-gate if (zone->zone_vfslist == NULL) { 30437c478bd9Sstevel@tonic-gate ASSERT(zone != global_zone); 30447c478bd9Sstevel@tonic-gate zone->zone_vfslist = vfsp; 30457c478bd9Sstevel@tonic-gate } else { 30467c478bd9Sstevel@tonic-gate zone->zone_vfslist->vfs_zone_prev->vfs_zone_next = vfsp; 30477c478bd9Sstevel@tonic-gate vfsp->vfs_zone_prev = zone->zone_vfslist->vfs_zone_prev; 30487c478bd9Sstevel@tonic-gate zone->zone_vfslist->vfs_zone_prev = vfsp; 30497c478bd9Sstevel@tonic-gate vfsp->vfs_zone_next = zone->zone_vfslist; 30507c478bd9Sstevel@tonic-gate } 30517c478bd9Sstevel@tonic-gate } 30527c478bd9Sstevel@tonic-gate 30537c478bd9Sstevel@tonic-gate /* 30547c478bd9Sstevel@tonic-gate * Link into the hash table, inserting it at the end, so that LOFS 30557c478bd9Sstevel@tonic-gate * with the same fsid as UFS (or other) file systems will not hide 30567c478bd9Sstevel@tonic-gate * the UFS. 30577c478bd9Sstevel@tonic-gate */ 30587c478bd9Sstevel@tonic-gate vfs_hash_add(vfsp, 0); 30597c478bd9Sstevel@tonic-gate 30607c478bd9Sstevel@tonic-gate /* 30617c478bd9Sstevel@tonic-gate * update the mnttab modification time 30627c478bd9Sstevel@tonic-gate */ 30637c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 30647c478bd9Sstevel@tonic-gate vfs_list_unlock(); 30657c478bd9Sstevel@tonic-gate zone_rele(zone); 30667c478bd9Sstevel@tonic-gate } 30677c478bd9Sstevel@tonic-gate 30687c478bd9Sstevel@tonic-gate void 30697c478bd9Sstevel@tonic-gate vfs_list_remove(struct vfs *vfsp) 30707c478bd9Sstevel@tonic-gate { 30717c478bd9Sstevel@tonic-gate zone_t *zone; 30727c478bd9Sstevel@tonic-gate 30737c478bd9Sstevel@tonic-gate zone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt)); 30747c478bd9Sstevel@tonic-gate ASSERT(zone != NULL); 30757c478bd9Sstevel@tonic-gate /* 30767c478bd9Sstevel@tonic-gate * Callers are responsible for preventing attempts to unmount the 30777c478bd9Sstevel@tonic-gate * root. 30787c478bd9Sstevel@tonic-gate */ 30797c478bd9Sstevel@tonic-gate ASSERT(vfsp != rootvfs); 30807c478bd9Sstevel@tonic-gate 30817c478bd9Sstevel@tonic-gate vfs_list_lock(); 30827c478bd9Sstevel@tonic-gate 30837c478bd9Sstevel@tonic-gate /* 30847c478bd9Sstevel@tonic-gate * Remove from hash. 30857c478bd9Sstevel@tonic-gate */ 30867c478bd9Sstevel@tonic-gate vfs_hash_remove(vfsp); 30877c478bd9Sstevel@tonic-gate 30887c478bd9Sstevel@tonic-gate /* 30897c478bd9Sstevel@tonic-gate * Remove from vfs list. 30907c478bd9Sstevel@tonic-gate */ 30917c478bd9Sstevel@tonic-gate vfsp->vfs_prev->vfs_next = vfsp->vfs_next; 30927c478bd9Sstevel@tonic-gate vfsp->vfs_next->vfs_prev = vfsp->vfs_prev; 30937c478bd9Sstevel@tonic-gate vfsp->vfs_next = vfsp->vfs_prev = NULL; 30947c478bd9Sstevel@tonic-gate 30957c478bd9Sstevel@tonic-gate /* 30967c478bd9Sstevel@tonic-gate * Remove from zone-specific vfs list. 30977c478bd9Sstevel@tonic-gate */ 30987c478bd9Sstevel@tonic-gate if (zone->zone_vfslist == vfsp) 30997c478bd9Sstevel@tonic-gate zone->zone_vfslist = vfsp->vfs_zone_next; 31007c478bd9Sstevel@tonic-gate 31017c478bd9Sstevel@tonic-gate if (vfsp->vfs_zone_next == vfsp) { 31027c478bd9Sstevel@tonic-gate ASSERT(vfsp->vfs_zone_prev == vfsp); 31037c478bd9Sstevel@tonic-gate ASSERT(zone->zone_vfslist == vfsp); 31047c478bd9Sstevel@tonic-gate zone->zone_vfslist = NULL; 31057c478bd9Sstevel@tonic-gate } 31067c478bd9Sstevel@tonic-gate 31077c478bd9Sstevel@tonic-gate vfsp->vfs_zone_prev->vfs_zone_next = vfsp->vfs_zone_next; 31087c478bd9Sstevel@tonic-gate vfsp->vfs_zone_next->vfs_zone_prev = vfsp->vfs_zone_prev; 31097c478bd9Sstevel@tonic-gate vfsp->vfs_zone_next = vfsp->vfs_zone_prev = NULL; 31107c478bd9Sstevel@tonic-gate 31117c478bd9Sstevel@tonic-gate /* 31127c478bd9Sstevel@tonic-gate * update the mnttab modification time 31137c478bd9Sstevel@tonic-gate */ 31147c478bd9Sstevel@tonic-gate vfs_mnttab_modtimeupd(); 31157c478bd9Sstevel@tonic-gate vfs_list_unlock(); 31167c478bd9Sstevel@tonic-gate zone_rele(zone); 31177c478bd9Sstevel@tonic-gate } 31187c478bd9Sstevel@tonic-gate 31197c478bd9Sstevel@tonic-gate struct vfs * 31207c478bd9Sstevel@tonic-gate getvfs(fsid_t *fsid) 31217c478bd9Sstevel@tonic-gate { 31227c478bd9Sstevel@tonic-gate struct vfs *vfsp; 31237c478bd9Sstevel@tonic-gate int val0 = fsid->val[0]; 31247c478bd9Sstevel@tonic-gate int val1 = fsid->val[1]; 31257c478bd9Sstevel@tonic-gate dev_t dev = expldev(val0); 31267c478bd9Sstevel@tonic-gate int vhno = VFSHASH(getmajor(dev), getminor(dev)); 31277c478bd9Sstevel@tonic-gate kmutex_t *hmp = &rvfs_list[vhno].rvfs_lock; 31287c478bd9Sstevel@tonic-gate 31297c478bd9Sstevel@tonic-gate mutex_enter(hmp); 31307c478bd9Sstevel@tonic-gate for (vfsp = rvfs_list[vhno].rvfs_head; vfsp; vfsp = vfsp->vfs_hash) { 31317c478bd9Sstevel@tonic-gate if (vfsp->vfs_fsid.val[0] == val0 && 31327c478bd9Sstevel@tonic-gate vfsp->vfs_fsid.val[1] == val1) { 31337c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); 31347c478bd9Sstevel@tonic-gate mutex_exit(hmp); 31357c478bd9Sstevel@tonic-gate return (vfsp); 31367c478bd9Sstevel@tonic-gate } 31377c478bd9Sstevel@tonic-gate } 31387c478bd9Sstevel@tonic-gate mutex_exit(hmp); 31397c478bd9Sstevel@tonic-gate return (NULL); 31407c478bd9Sstevel@tonic-gate } 31417c478bd9Sstevel@tonic-gate 31427c478bd9Sstevel@tonic-gate /* 31437c478bd9Sstevel@tonic-gate * Search the vfs mount in progress list for a specified device/vfs entry. 31447c478bd9Sstevel@tonic-gate * Returns 0 if the first entry in the list that the device matches has the 31457c478bd9Sstevel@tonic-gate * given vfs pointer as well. If the device matches but a different vfs 31467c478bd9Sstevel@tonic-gate * pointer is encountered in the list before the given vfs pointer then 31477c478bd9Sstevel@tonic-gate * a 1 is returned. 31487c478bd9Sstevel@tonic-gate */ 31497c478bd9Sstevel@tonic-gate 31507c478bd9Sstevel@tonic-gate int 31517c478bd9Sstevel@tonic-gate vfs_devmounting(dev_t dev, struct vfs *vfsp) 31527c478bd9Sstevel@tonic-gate { 31537c478bd9Sstevel@tonic-gate int retval = 0; 31547c478bd9Sstevel@tonic-gate struct ipmnt *mipp; 31557c478bd9Sstevel@tonic-gate 31567c478bd9Sstevel@tonic-gate mutex_enter(&vfs_miplist_mutex); 31577c478bd9Sstevel@tonic-gate for (mipp = vfs_miplist; mipp != NULL; mipp = mipp->mip_next) { 31587c478bd9Sstevel@tonic-gate if (mipp->mip_dev == dev) { 31597c478bd9Sstevel@tonic-gate if (mipp->mip_vfsp != vfsp) 31607c478bd9Sstevel@tonic-gate retval = 1; 31617c478bd9Sstevel@tonic-gate break; 31627c478bd9Sstevel@tonic-gate } 31637c478bd9Sstevel@tonic-gate } 31647c478bd9Sstevel@tonic-gate mutex_exit(&vfs_miplist_mutex); 31657c478bd9Sstevel@tonic-gate return (retval); 31667c478bd9Sstevel@tonic-gate } 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate /* 31697c478bd9Sstevel@tonic-gate * Search the vfs list for a specified device. Returns 1, if entry is found 31707c478bd9Sstevel@tonic-gate * or 0 if no suitable entry is found. 31717c478bd9Sstevel@tonic-gate */ 31727c478bd9Sstevel@tonic-gate 31737c478bd9Sstevel@tonic-gate int 31747c478bd9Sstevel@tonic-gate vfs_devismounted(dev_t dev) 31757c478bd9Sstevel@tonic-gate { 31767c478bd9Sstevel@tonic-gate struct vfs *vfsp; 31777c478bd9Sstevel@tonic-gate int found; 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 31807c478bd9Sstevel@tonic-gate vfsp = rootvfs; 31817c478bd9Sstevel@tonic-gate found = 0; 31827c478bd9Sstevel@tonic-gate do { 31837c478bd9Sstevel@tonic-gate if (vfsp->vfs_dev == dev) { 31847c478bd9Sstevel@tonic-gate found = 1; 31857c478bd9Sstevel@tonic-gate break; 31867c478bd9Sstevel@tonic-gate } 31877c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_next; 31887c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs); 31897c478bd9Sstevel@tonic-gate 31907c478bd9Sstevel@tonic-gate vfs_list_unlock(); 31917c478bd9Sstevel@tonic-gate return (found); 31927c478bd9Sstevel@tonic-gate } 31937c478bd9Sstevel@tonic-gate 31947c478bd9Sstevel@tonic-gate /* 31957c478bd9Sstevel@tonic-gate * Search the vfs list for a specified device. Returns a pointer to it 31967c478bd9Sstevel@tonic-gate * or NULL if no suitable entry is found. The caller of this routine 31977c478bd9Sstevel@tonic-gate * is responsible for releasing the returned vfs pointer. 31987c478bd9Sstevel@tonic-gate */ 31997c478bd9Sstevel@tonic-gate struct vfs * 32007c478bd9Sstevel@tonic-gate vfs_dev2vfsp(dev_t dev) 32017c478bd9Sstevel@tonic-gate { 32027c478bd9Sstevel@tonic-gate struct vfs *vfsp; 32037c478bd9Sstevel@tonic-gate int found; 32047c478bd9Sstevel@tonic-gate 32057c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 32067c478bd9Sstevel@tonic-gate vfsp = rootvfs; 32077c478bd9Sstevel@tonic-gate found = 0; 32087c478bd9Sstevel@tonic-gate do { 32097c478bd9Sstevel@tonic-gate /* 32107c478bd9Sstevel@tonic-gate * The following could be made more efficient by making 32117c478bd9Sstevel@tonic-gate * the entire loop use vfs_zone_next if the call is from 32127c478bd9Sstevel@tonic-gate * a zone. The only callers, however, ustat(2) and 32137c478bd9Sstevel@tonic-gate * umount2(2), don't seem to justify the added 32147c478bd9Sstevel@tonic-gate * complexity at present. 32157c478bd9Sstevel@tonic-gate */ 32167c478bd9Sstevel@tonic-gate if (vfsp->vfs_dev == dev && 32177c478bd9Sstevel@tonic-gate ZONE_PATH_VISIBLE(refstr_value(vfsp->vfs_mntpt), 32187c478bd9Sstevel@tonic-gate curproc->p_zone)) { 32197c478bd9Sstevel@tonic-gate VFS_HOLD(vfsp); 32207c478bd9Sstevel@tonic-gate found = 1; 32217c478bd9Sstevel@tonic-gate break; 32227c478bd9Sstevel@tonic-gate } 32237c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_next; 32247c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs); 32257c478bd9Sstevel@tonic-gate vfs_list_unlock(); 32267c478bd9Sstevel@tonic-gate return (found ? vfsp: NULL); 32277c478bd9Sstevel@tonic-gate } 32287c478bd9Sstevel@tonic-gate 32297c478bd9Sstevel@tonic-gate /* 32307c478bd9Sstevel@tonic-gate * Search the vfs list for a specified mntpoint. Returns a pointer to it 32317c478bd9Sstevel@tonic-gate * or NULL if no suitable entry is found. The caller of this routine 32327c478bd9Sstevel@tonic-gate * is responsible for releasing the returned vfs pointer. 32337c478bd9Sstevel@tonic-gate * 32347c478bd9Sstevel@tonic-gate * Note that if multiple mntpoints match, the last one matching is 32357c478bd9Sstevel@tonic-gate * returned in an attempt to return the "top" mount when overlay 32367c478bd9Sstevel@tonic-gate * mounts are covering the same mount point. This is accomplished by starting 32377c478bd9Sstevel@tonic-gate * at the end of the list and working our way backwards, stopping at the first 32387c478bd9Sstevel@tonic-gate * matching mount. 32397c478bd9Sstevel@tonic-gate */ 32407c478bd9Sstevel@tonic-gate struct vfs * 32417c478bd9Sstevel@tonic-gate vfs_mntpoint2vfsp(const char *mp) 32427c478bd9Sstevel@tonic-gate { 32437c478bd9Sstevel@tonic-gate struct vfs *vfsp; 32447c478bd9Sstevel@tonic-gate struct vfs *retvfsp = NULL; 32457c478bd9Sstevel@tonic-gate zone_t *zone = curproc->p_zone; 32467c478bd9Sstevel@tonic-gate struct vfs *list; 32477c478bd9Sstevel@tonic-gate 32487c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 32497c478bd9Sstevel@tonic-gate if (getzoneid() == GLOBAL_ZONEID) { 32507c478bd9Sstevel@tonic-gate /* 32517c478bd9Sstevel@tonic-gate * The global zone may see filesystems in any zone. 32527c478bd9Sstevel@tonic-gate */ 32537c478bd9Sstevel@tonic-gate vfsp = rootvfs->vfs_prev; 32547c478bd9Sstevel@tonic-gate do { 32557c478bd9Sstevel@tonic-gate if (strcmp(refstr_value(vfsp->vfs_mntpt), mp) == 0) { 32567c478bd9Sstevel@tonic-gate retvfsp = vfsp; 32577c478bd9Sstevel@tonic-gate break; 32587c478bd9Sstevel@tonic-gate } 32597c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_prev; 32607c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs->vfs_prev); 32617c478bd9Sstevel@tonic-gate } else if ((list = zone->zone_vfslist) != NULL) { 32627c478bd9Sstevel@tonic-gate const char *mntpt; 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate vfsp = list->vfs_zone_prev; 32657c478bd9Sstevel@tonic-gate do { 32667c478bd9Sstevel@tonic-gate mntpt = refstr_value(vfsp->vfs_mntpt); 32677c478bd9Sstevel@tonic-gate mntpt = ZONE_PATH_TRANSLATE(mntpt, zone); 32687c478bd9Sstevel@tonic-gate if (strcmp(mntpt, mp) == 0) { 32697c478bd9Sstevel@tonic-gate retvfsp = vfsp; 32707c478bd9Sstevel@tonic-gate break; 32717c478bd9Sstevel@tonic-gate } 32727c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_zone_prev; 32737c478bd9Sstevel@tonic-gate } while (vfsp != list->vfs_zone_prev); 32747c478bd9Sstevel@tonic-gate } 32757c478bd9Sstevel@tonic-gate if (retvfsp) 32767c478bd9Sstevel@tonic-gate VFS_HOLD(retvfsp); 32777c478bd9Sstevel@tonic-gate vfs_list_unlock(); 32787c478bd9Sstevel@tonic-gate return (retvfsp); 32797c478bd9Sstevel@tonic-gate } 32807c478bd9Sstevel@tonic-gate 32817c478bd9Sstevel@tonic-gate /* 32827c478bd9Sstevel@tonic-gate * Search the vfs list for a specified vfsops. 32837c478bd9Sstevel@tonic-gate * if vfs entry is found then return 1, else 0. 32847c478bd9Sstevel@tonic-gate */ 32857c478bd9Sstevel@tonic-gate int 32867c478bd9Sstevel@tonic-gate vfs_opsinuse(vfsops_t *ops) 32877c478bd9Sstevel@tonic-gate { 32887c478bd9Sstevel@tonic-gate struct vfs *vfsp; 32897c478bd9Sstevel@tonic-gate int found; 32907c478bd9Sstevel@tonic-gate 32917c478bd9Sstevel@tonic-gate vfs_list_read_lock(); 32927c478bd9Sstevel@tonic-gate vfsp = rootvfs; 32937c478bd9Sstevel@tonic-gate found = 0; 32947c478bd9Sstevel@tonic-gate do { 32957c478bd9Sstevel@tonic-gate if (vfs_getops(vfsp) == ops) { 32967c478bd9Sstevel@tonic-gate found = 1; 32977c478bd9Sstevel@tonic-gate break; 32987c478bd9Sstevel@tonic-gate } 32997c478bd9Sstevel@tonic-gate vfsp = vfsp->vfs_next; 33007c478bd9Sstevel@tonic-gate } while (vfsp != rootvfs); 33017c478bd9Sstevel@tonic-gate vfs_list_unlock(); 33027c478bd9Sstevel@tonic-gate return (found); 33037c478bd9Sstevel@tonic-gate } 33047c478bd9Sstevel@tonic-gate 33057c478bd9Sstevel@tonic-gate /* 33067c478bd9Sstevel@tonic-gate * Allocate an entry in vfssw for a file system type 33077c478bd9Sstevel@tonic-gate */ 33087c478bd9Sstevel@tonic-gate struct vfssw * 33097c478bd9Sstevel@tonic-gate allocate_vfssw(char *type) 33107c478bd9Sstevel@tonic-gate { 33117c478bd9Sstevel@tonic-gate struct vfssw *vswp; 33127c478bd9Sstevel@tonic-gate 33137c478bd9Sstevel@tonic-gate if (type[0] == '\0' || strlen(type) + 1 > _ST_FSTYPSZ) { 33147c478bd9Sstevel@tonic-gate /* 33157c478bd9Sstevel@tonic-gate * The vfssw table uses the empty string to identify an 33167c478bd9Sstevel@tonic-gate * available entry; we cannot add any type which has 33177c478bd9Sstevel@tonic-gate * a leading NUL. The string length is limited to 33187c478bd9Sstevel@tonic-gate * the size of the st_fstype array in struct stat. 33197c478bd9Sstevel@tonic-gate */ 33207c478bd9Sstevel@tonic-gate return (NULL); 33217c478bd9Sstevel@tonic-gate } 33227c478bd9Sstevel@tonic-gate 33237c478bd9Sstevel@tonic-gate ASSERT(VFSSW_WRITE_LOCKED()); 33247c478bd9Sstevel@tonic-gate for (vswp = &vfssw[1]; vswp < &vfssw[nfstype]; vswp++) 33257c478bd9Sstevel@tonic-gate if (!ALLOCATED_VFSSW(vswp)) { 33267c478bd9Sstevel@tonic-gate vswp->vsw_name = kmem_alloc(strlen(type) + 1, KM_SLEEP); 33277c478bd9Sstevel@tonic-gate (void) strcpy(vswp->vsw_name, type); 33287c478bd9Sstevel@tonic-gate ASSERT(vswp->vsw_count == 0); 33297c478bd9Sstevel@tonic-gate vswp->vsw_count = 1; 33307c478bd9Sstevel@tonic-gate mutex_init(&vswp->vsw_lock, NULL, MUTEX_DEFAULT, NULL); 33317c478bd9Sstevel@tonic-gate return (vswp); 33327c478bd9Sstevel@tonic-gate } 33337c478bd9Sstevel@tonic-gate return (NULL); 33347c478bd9Sstevel@tonic-gate } 33357c478bd9Sstevel@tonic-gate 33367c478bd9Sstevel@tonic-gate /* 33377c478bd9Sstevel@tonic-gate * Impose additional layer of translation between vfstype names 33387c478bd9Sstevel@tonic-gate * and module names in the filesystem. 33397c478bd9Sstevel@tonic-gate */ 33407c478bd9Sstevel@tonic-gate static char * 33417c478bd9Sstevel@tonic-gate vfs_to_modname(char *vfstype) 33427c478bd9Sstevel@tonic-gate { 33437c478bd9Sstevel@tonic-gate if (strcmp(vfstype, "proc") == 0) { 33447c478bd9Sstevel@tonic-gate vfstype = "procfs"; 33457c478bd9Sstevel@tonic-gate } else if (strcmp(vfstype, "fd") == 0) { 33467c478bd9Sstevel@tonic-gate vfstype = "fdfs"; 33477c478bd9Sstevel@tonic-gate } else if (strncmp(vfstype, "nfs", 3) == 0) { 33487c478bd9Sstevel@tonic-gate vfstype = "nfs"; 33497c478bd9Sstevel@tonic-gate } 33507c478bd9Sstevel@tonic-gate 33517c478bd9Sstevel@tonic-gate return (vfstype); 33527c478bd9Sstevel@tonic-gate } 33537c478bd9Sstevel@tonic-gate 33547c478bd9Sstevel@tonic-gate /* 33557c478bd9Sstevel@tonic-gate * Find a vfssw entry given a file system type name. 33567c478bd9Sstevel@tonic-gate * Try to autoload the filesystem if it's not found. 33577c478bd9Sstevel@tonic-gate * If it's installed, return the vfssw locked to prevent unloading. 33587c478bd9Sstevel@tonic-gate */ 33597c478bd9Sstevel@tonic-gate struct vfssw * 33607c478bd9Sstevel@tonic-gate vfs_getvfssw(char *type) 33617c478bd9Sstevel@tonic-gate { 33627c478bd9Sstevel@tonic-gate struct vfssw *vswp; 33637c478bd9Sstevel@tonic-gate char *modname; 33647c478bd9Sstevel@tonic-gate 33657c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 33667c478bd9Sstevel@tonic-gate vswp = vfs_getvfsswbyname(type); 33677c478bd9Sstevel@tonic-gate modname = vfs_to_modname(type); 33687c478bd9Sstevel@tonic-gate 33697c478bd9Sstevel@tonic-gate if (rootdir == NULL) { 33707c478bd9Sstevel@tonic-gate /* 33717c478bd9Sstevel@tonic-gate * If we haven't yet loaded the root file system, then our 33727c478bd9Sstevel@tonic-gate * _init won't be called until later. Allocate vfssw entry, 33737c478bd9Sstevel@tonic-gate * because mod_installfs won't be called. 33747c478bd9Sstevel@tonic-gate */ 33757c478bd9Sstevel@tonic-gate if (vswp == NULL) { 33767c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 33777c478bd9Sstevel@tonic-gate WLOCK_VFSSW(); 33787c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfsswbyname(type)) == NULL) { 33797c478bd9Sstevel@tonic-gate if ((vswp = allocate_vfssw(type)) == NULL) { 33807c478bd9Sstevel@tonic-gate WUNLOCK_VFSSW(); 33817c478bd9Sstevel@tonic-gate return (NULL); 33827c478bd9Sstevel@tonic-gate } 33837c478bd9Sstevel@tonic-gate } 33847c478bd9Sstevel@tonic-gate WUNLOCK_VFSSW(); 33857c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 33867c478bd9Sstevel@tonic-gate } 33877c478bd9Sstevel@tonic-gate if (!VFS_INSTALLED(vswp)) { 33887c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 33897c478bd9Sstevel@tonic-gate (void) modloadonly("fs", modname); 33907c478bd9Sstevel@tonic-gate } else 33917c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 33927c478bd9Sstevel@tonic-gate return (vswp); 33937c478bd9Sstevel@tonic-gate } 33947c478bd9Sstevel@tonic-gate 33957c478bd9Sstevel@tonic-gate /* 33967c478bd9Sstevel@tonic-gate * Try to load the filesystem. Before calling modload(), we drop 33977c478bd9Sstevel@tonic-gate * our lock on the VFS switch table, and pick it up after the 33987c478bd9Sstevel@tonic-gate * module is loaded. However, there is a potential race: the 33997c478bd9Sstevel@tonic-gate * module could be unloaded after the call to modload() completes 34007c478bd9Sstevel@tonic-gate * but before we pick up the lock and drive on. Therefore, 34017c478bd9Sstevel@tonic-gate * we keep reloading the module until we've loaded the module 34027c478bd9Sstevel@tonic-gate * _and_ we have the lock on the VFS switch table. 34037c478bd9Sstevel@tonic-gate */ 34047c478bd9Sstevel@tonic-gate while (vswp == NULL || !VFS_INSTALLED(vswp)) { 34057c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 34067c478bd9Sstevel@tonic-gate if (modload("fs", modname) == -1) 34077c478bd9Sstevel@tonic-gate return (NULL); 34087c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 34097c478bd9Sstevel@tonic-gate if (vswp == NULL) 34107c478bd9Sstevel@tonic-gate if ((vswp = vfs_getvfsswbyname(type)) == NULL) 34117c478bd9Sstevel@tonic-gate break; 34127c478bd9Sstevel@tonic-gate } 34137c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 34147c478bd9Sstevel@tonic-gate 34157c478bd9Sstevel@tonic-gate return (vswp); 34167c478bd9Sstevel@tonic-gate } 34177c478bd9Sstevel@tonic-gate 34187c478bd9Sstevel@tonic-gate /* 34197c478bd9Sstevel@tonic-gate * Find a vfssw entry given a file system type name. 34207c478bd9Sstevel@tonic-gate */ 34217c478bd9Sstevel@tonic-gate struct vfssw * 34227c478bd9Sstevel@tonic-gate vfs_getvfsswbyname(char *type) 34237c478bd9Sstevel@tonic-gate { 34247c478bd9Sstevel@tonic-gate struct vfssw *vswp; 34257c478bd9Sstevel@tonic-gate 34267c478bd9Sstevel@tonic-gate ASSERT(VFSSW_LOCKED()); 34277c478bd9Sstevel@tonic-gate if (type == NULL || *type == '\0') 34287c478bd9Sstevel@tonic-gate return (NULL); 34297c478bd9Sstevel@tonic-gate 34307c478bd9Sstevel@tonic-gate for (vswp = &vfssw[1]; vswp < &vfssw[nfstype]; vswp++) { 34317c478bd9Sstevel@tonic-gate if (strcmp(type, vswp->vsw_name) == 0) { 34327c478bd9Sstevel@tonic-gate vfs_refvfssw(vswp); 34337c478bd9Sstevel@tonic-gate return (vswp); 34347c478bd9Sstevel@tonic-gate } 34357c478bd9Sstevel@tonic-gate } 34367c478bd9Sstevel@tonic-gate 34377c478bd9Sstevel@tonic-gate return (NULL); 34387c478bd9Sstevel@tonic-gate } 34397c478bd9Sstevel@tonic-gate 34407c478bd9Sstevel@tonic-gate /* 34417c478bd9Sstevel@tonic-gate * Find a vfssw entry given a set of vfsops. 34427c478bd9Sstevel@tonic-gate */ 34437c478bd9Sstevel@tonic-gate struct vfssw * 34447c478bd9Sstevel@tonic-gate vfs_getvfsswbyvfsops(vfsops_t *vfsops) 34457c478bd9Sstevel@tonic-gate { 34467c478bd9Sstevel@tonic-gate struct vfssw *vswp; 34477c478bd9Sstevel@tonic-gate 34487c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 34497c478bd9Sstevel@tonic-gate for (vswp = &vfssw[1]; vswp < &vfssw[nfstype]; vswp++) { 34507c478bd9Sstevel@tonic-gate if (ALLOCATED_VFSSW(vswp) && &vswp->vsw_vfsops == vfsops) { 34517c478bd9Sstevel@tonic-gate vfs_refvfssw(vswp); 34527c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 34537c478bd9Sstevel@tonic-gate return (vswp); 34547c478bd9Sstevel@tonic-gate } 34557c478bd9Sstevel@tonic-gate } 34567c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 34577c478bd9Sstevel@tonic-gate 34587c478bd9Sstevel@tonic-gate return (NULL); 34597c478bd9Sstevel@tonic-gate } 34607c478bd9Sstevel@tonic-gate 34617c478bd9Sstevel@tonic-gate /* 34627c478bd9Sstevel@tonic-gate * Reference a vfssw entry. 34637c478bd9Sstevel@tonic-gate */ 34647c478bd9Sstevel@tonic-gate void 34657c478bd9Sstevel@tonic-gate vfs_refvfssw(struct vfssw *vswp) 34667c478bd9Sstevel@tonic-gate { 34677c478bd9Sstevel@tonic-gate 34687c478bd9Sstevel@tonic-gate mutex_enter(&vswp->vsw_lock); 34697c478bd9Sstevel@tonic-gate vswp->vsw_count++; 34707c478bd9Sstevel@tonic-gate mutex_exit(&vswp->vsw_lock); 34717c478bd9Sstevel@tonic-gate } 34727c478bd9Sstevel@tonic-gate 34737c478bd9Sstevel@tonic-gate /* 34747c478bd9Sstevel@tonic-gate * Unreference a vfssw entry. 34757c478bd9Sstevel@tonic-gate */ 34767c478bd9Sstevel@tonic-gate void 34777c478bd9Sstevel@tonic-gate vfs_unrefvfssw(struct vfssw *vswp) 34787c478bd9Sstevel@tonic-gate { 34797c478bd9Sstevel@tonic-gate 34807c478bd9Sstevel@tonic-gate mutex_enter(&vswp->vsw_lock); 34817c478bd9Sstevel@tonic-gate vswp->vsw_count--; 34827c478bd9Sstevel@tonic-gate mutex_exit(&vswp->vsw_lock); 34837c478bd9Sstevel@tonic-gate } 34847c478bd9Sstevel@tonic-gate 34857c478bd9Sstevel@tonic-gate int sync_timeout = 30; /* timeout for syncing a page during panic */ 34867c478bd9Sstevel@tonic-gate int sync_timeleft; /* portion of sync_timeout remaining */ 34877c478bd9Sstevel@tonic-gate 34887c478bd9Sstevel@tonic-gate static int sync_retries = 20; /* number of retries when not making progress */ 34897c478bd9Sstevel@tonic-gate static int sync_triesleft; /* portion of sync_retries remaining */ 34907c478bd9Sstevel@tonic-gate 34917c478bd9Sstevel@tonic-gate static pgcnt_t old_pgcnt, new_pgcnt; 34927c478bd9Sstevel@tonic-gate static int new_bufcnt, old_bufcnt; 34937c478bd9Sstevel@tonic-gate 34947c478bd9Sstevel@tonic-gate /* 34957c478bd9Sstevel@tonic-gate * Sync all of the mounted filesystems, and then wait for the actual i/o to 34967c478bd9Sstevel@tonic-gate * complete. We wait by counting the number of dirty pages and buffers, 34977c478bd9Sstevel@tonic-gate * pushing them out using bio_busy() and page_busy(), and then counting again. 34987c478bd9Sstevel@tonic-gate * This routine is used during both the uadmin A_SHUTDOWN code as well as 34997c478bd9Sstevel@tonic-gate * the SYNC phase of the panic code (see comments in panic.c). It should only 35007c478bd9Sstevel@tonic-gate * be used after some higher-level mechanism has quiesced the system so that 35017c478bd9Sstevel@tonic-gate * new writes are not being initiated while we are waiting for completion. 35027c478bd9Sstevel@tonic-gate * 35037c478bd9Sstevel@tonic-gate * To ensure finite running time, our algorithm uses two timeout mechanisms: 35047c478bd9Sstevel@tonic-gate * sync_timeleft (a timer implemented by the omnipresent deadman() cyclic), and 35057c478bd9Sstevel@tonic-gate * sync_triesleft (a progress counter used by the vfs_syncall() loop below). 35067c478bd9Sstevel@tonic-gate * Together these ensure that syncing completes if our i/o paths are stuck. 35077c478bd9Sstevel@tonic-gate * The counters are declared above so they can be found easily in the debugger. 35087c478bd9Sstevel@tonic-gate * 35097c478bd9Sstevel@tonic-gate * The sync_timeleft counter is reset by bio_busy() and page_busy() using the 35107c478bd9Sstevel@tonic-gate * vfs_syncprogress() subroutine whenever we make progress through the lists of 35117c478bd9Sstevel@tonic-gate * pages and buffers. It is decremented and expired by the deadman() cyclic. 35127c478bd9Sstevel@tonic-gate * When vfs_syncall() decides it is done, we disable the deadman() counter by 35137c478bd9Sstevel@tonic-gate * setting sync_timeleft to zero. This timer guards against vfs_syncall() 35147c478bd9Sstevel@tonic-gate * deadlocking or hanging inside of a broken filesystem or driver routine. 35157c478bd9Sstevel@tonic-gate * 35167c478bd9Sstevel@tonic-gate * The sync_triesleft counter is updated by vfs_syncall() itself. If we make 35177c478bd9Sstevel@tonic-gate * sync_retries consecutive calls to bio_busy() and page_busy() without 35187c478bd9Sstevel@tonic-gate * decreasing either the number of dirty buffers or dirty pages below the 35197c478bd9Sstevel@tonic-gate * lowest count we have seen so far, we give up and return from vfs_syncall(). 35207c478bd9Sstevel@tonic-gate * 35217c478bd9Sstevel@tonic-gate * Each loop iteration ends with a call to delay() one second to allow time for 35227c478bd9Sstevel@tonic-gate * i/o completion and to permit the user time to read our progress messages. 35237c478bd9Sstevel@tonic-gate */ 35247c478bd9Sstevel@tonic-gate void 35257c478bd9Sstevel@tonic-gate vfs_syncall(void) 35267c478bd9Sstevel@tonic-gate { 35277c478bd9Sstevel@tonic-gate if (rootdir == NULL && !modrootloaded) 35287c478bd9Sstevel@tonic-gate return; /* panic during boot - no filesystems yet */ 35297c478bd9Sstevel@tonic-gate 35307c478bd9Sstevel@tonic-gate printf("syncing file systems..."); 35317c478bd9Sstevel@tonic-gate vfs_syncprogress(); 35327c478bd9Sstevel@tonic-gate sync(); 35337c478bd9Sstevel@tonic-gate 35347c478bd9Sstevel@tonic-gate vfs_syncprogress(); 35357c478bd9Sstevel@tonic-gate sync_triesleft = sync_retries; 35367c478bd9Sstevel@tonic-gate 35377c478bd9Sstevel@tonic-gate old_bufcnt = new_bufcnt = INT_MAX; 35387c478bd9Sstevel@tonic-gate old_pgcnt = new_pgcnt = ULONG_MAX; 35397c478bd9Sstevel@tonic-gate 35407c478bd9Sstevel@tonic-gate while (sync_triesleft > 0) { 35417c478bd9Sstevel@tonic-gate old_bufcnt = MIN(old_bufcnt, new_bufcnt); 35427c478bd9Sstevel@tonic-gate old_pgcnt = MIN(old_pgcnt, new_pgcnt); 35437c478bd9Sstevel@tonic-gate 35447c478bd9Sstevel@tonic-gate new_bufcnt = bio_busy(B_TRUE); 35457c478bd9Sstevel@tonic-gate new_pgcnt = page_busy(B_TRUE); 35467c478bd9Sstevel@tonic-gate vfs_syncprogress(); 35477c478bd9Sstevel@tonic-gate 35487c478bd9Sstevel@tonic-gate if (new_bufcnt == 0 && new_pgcnt == 0) 35497c478bd9Sstevel@tonic-gate break; 35507c478bd9Sstevel@tonic-gate 35517c478bd9Sstevel@tonic-gate if (new_bufcnt < old_bufcnt || new_pgcnt < old_pgcnt) 35527c478bd9Sstevel@tonic-gate sync_triesleft = sync_retries; 35537c478bd9Sstevel@tonic-gate else 35547c478bd9Sstevel@tonic-gate sync_triesleft--; 35557c478bd9Sstevel@tonic-gate 35567c478bd9Sstevel@tonic-gate if (new_bufcnt) 35577c478bd9Sstevel@tonic-gate printf(" [%d]", new_bufcnt); 35587c478bd9Sstevel@tonic-gate if (new_pgcnt) 35597c478bd9Sstevel@tonic-gate printf(" %lu", new_pgcnt); 35607c478bd9Sstevel@tonic-gate 35617c478bd9Sstevel@tonic-gate delay(hz); 35627c478bd9Sstevel@tonic-gate } 35637c478bd9Sstevel@tonic-gate 35647c478bd9Sstevel@tonic-gate if (new_bufcnt != 0 || new_pgcnt != 0) 35657c478bd9Sstevel@tonic-gate printf(" done (not all i/o completed)\n"); 35667c478bd9Sstevel@tonic-gate else 35677c478bd9Sstevel@tonic-gate printf(" done\n"); 35687c478bd9Sstevel@tonic-gate 35697c478bd9Sstevel@tonic-gate sync_timeleft = 0; 35707c478bd9Sstevel@tonic-gate delay(hz); 35717c478bd9Sstevel@tonic-gate } 35727c478bd9Sstevel@tonic-gate 35737c478bd9Sstevel@tonic-gate /* 35747c478bd9Sstevel@tonic-gate * If we are in the middle of the sync phase of panic, reset sync_timeleft to 35757c478bd9Sstevel@tonic-gate * sync_timeout to indicate that we are making progress and the deadman() 35767c478bd9Sstevel@tonic-gate * omnipresent cyclic should not yet time us out. Note that it is safe to 35777c478bd9Sstevel@tonic-gate * store to sync_timeleft here since the deadman() is firing at high-level 35787c478bd9Sstevel@tonic-gate * on top of us. If we are racing with the deadman(), either the deadman() 35797c478bd9Sstevel@tonic-gate * will decrement the old value and then we will reset it, or we will 35807c478bd9Sstevel@tonic-gate * reset it and then the deadman() will immediately decrement it. In either 35817c478bd9Sstevel@tonic-gate * case, correct behavior results. 35827c478bd9Sstevel@tonic-gate */ 35837c478bd9Sstevel@tonic-gate void 35847c478bd9Sstevel@tonic-gate vfs_syncprogress(void) 35857c478bd9Sstevel@tonic-gate { 35867c478bd9Sstevel@tonic-gate if (panicstr) 35877c478bd9Sstevel@tonic-gate sync_timeleft = sync_timeout; 35887c478bd9Sstevel@tonic-gate } 35897c478bd9Sstevel@tonic-gate 35907c478bd9Sstevel@tonic-gate /* 35917c478bd9Sstevel@tonic-gate * Map VFS flags to statvfs flags. These shouldn't really be separate 35927c478bd9Sstevel@tonic-gate * flags at all. 35937c478bd9Sstevel@tonic-gate */ 35947c478bd9Sstevel@tonic-gate uint_t 35957c478bd9Sstevel@tonic-gate vf_to_stf(uint_t vf) 35967c478bd9Sstevel@tonic-gate { 35977c478bd9Sstevel@tonic-gate uint_t stf = 0; 35987c478bd9Sstevel@tonic-gate 35997c478bd9Sstevel@tonic-gate if (vf & VFS_RDONLY) 36007c478bd9Sstevel@tonic-gate stf |= ST_RDONLY; 36017c478bd9Sstevel@tonic-gate if (vf & VFS_NOSETUID) 36027c478bd9Sstevel@tonic-gate stf |= ST_NOSUID; 36037c478bd9Sstevel@tonic-gate if (vf & VFS_NOTRUNC) 36047c478bd9Sstevel@tonic-gate stf |= ST_NOTRUNC; 36057c478bd9Sstevel@tonic-gate 36067c478bd9Sstevel@tonic-gate return (stf); 36077c478bd9Sstevel@tonic-gate } 36087c478bd9Sstevel@tonic-gate 36097c478bd9Sstevel@tonic-gate /* 36107c478bd9Sstevel@tonic-gate * Use old-style function prototype for vfsstray() so 36117c478bd9Sstevel@tonic-gate * that we can use it anywhere in the vfsops structure. 36127c478bd9Sstevel@tonic-gate */ 36137c478bd9Sstevel@tonic-gate int vfsstray(); 36147c478bd9Sstevel@tonic-gate 36157c478bd9Sstevel@tonic-gate /* 36167c478bd9Sstevel@tonic-gate * Entries for (illegal) fstype 0. 36177c478bd9Sstevel@tonic-gate */ 36187c478bd9Sstevel@tonic-gate /* ARGSUSED */ 36197c478bd9Sstevel@tonic-gate int 36207c478bd9Sstevel@tonic-gate vfsstray_sync(struct vfs *vfsp, short arg, struct cred *cr) 36217c478bd9Sstevel@tonic-gate { 36227c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "stray vfs operation"); 36237c478bd9Sstevel@tonic-gate return (0); 36247c478bd9Sstevel@tonic-gate } 36257c478bd9Sstevel@tonic-gate 36267c478bd9Sstevel@tonic-gate vfsops_t vfs_strayops = { 36277c478bd9Sstevel@tonic-gate vfsstray, 36287c478bd9Sstevel@tonic-gate vfsstray, 36297c478bd9Sstevel@tonic-gate vfsstray, 36307c478bd9Sstevel@tonic-gate vfsstray, 36317c478bd9Sstevel@tonic-gate vfsstray_sync, 36327c478bd9Sstevel@tonic-gate vfsstray, 36337c478bd9Sstevel@tonic-gate vfsstray, 36347c478bd9Sstevel@tonic-gate vfsstray 36357c478bd9Sstevel@tonic-gate }; 36367c478bd9Sstevel@tonic-gate 36377c478bd9Sstevel@tonic-gate /* 36387c478bd9Sstevel@tonic-gate * Entries for (illegal) fstype 0. 36397c478bd9Sstevel@tonic-gate */ 36407c478bd9Sstevel@tonic-gate int 36417c478bd9Sstevel@tonic-gate vfsstray(void) 36427c478bd9Sstevel@tonic-gate { 36437c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "stray vfs operation"); 36447c478bd9Sstevel@tonic-gate return (0); 36457c478bd9Sstevel@tonic-gate } 36467c478bd9Sstevel@tonic-gate 36477c478bd9Sstevel@tonic-gate /* 36487c478bd9Sstevel@tonic-gate * Support for dealing with forced UFS unmount and its interaction with 36497c478bd9Sstevel@tonic-gate * LOFS. Could be used by any filesystem. 36507c478bd9Sstevel@tonic-gate * See bug 1203132. 36517c478bd9Sstevel@tonic-gate */ 36527c478bd9Sstevel@tonic-gate int 36537c478bd9Sstevel@tonic-gate vfs_EIO(void) 36547c478bd9Sstevel@tonic-gate { 36557c478bd9Sstevel@tonic-gate return (EIO); 36567c478bd9Sstevel@tonic-gate } 36577c478bd9Sstevel@tonic-gate 36587c478bd9Sstevel@tonic-gate /* 36597c478bd9Sstevel@tonic-gate * We've gotta define the op for sync separately, since the compiler gets 36607c478bd9Sstevel@tonic-gate * confused if we mix and match ANSI and normal style prototypes when 36617c478bd9Sstevel@tonic-gate * a "short" argument is present and spits out a warning. 36627c478bd9Sstevel@tonic-gate */ 36637c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 36647c478bd9Sstevel@tonic-gate int 36657c478bd9Sstevel@tonic-gate vfs_EIO_sync(struct vfs *vfsp, short arg, struct cred *cr) 36667c478bd9Sstevel@tonic-gate { 36677c478bd9Sstevel@tonic-gate return (EIO); 36687c478bd9Sstevel@tonic-gate } 36697c478bd9Sstevel@tonic-gate 36707c478bd9Sstevel@tonic-gate vfs_t EIO_vfs; 36717c478bd9Sstevel@tonic-gate vfsops_t *EIO_vfsops; 36727c478bd9Sstevel@tonic-gate 36737c478bd9Sstevel@tonic-gate /* 36747c478bd9Sstevel@tonic-gate * Called from startup() to initialize all loaded vfs's 36757c478bd9Sstevel@tonic-gate */ 36767c478bd9Sstevel@tonic-gate void 36777c478bd9Sstevel@tonic-gate vfsinit(void) 36787c478bd9Sstevel@tonic-gate { 36797c478bd9Sstevel@tonic-gate struct vfssw *vswp; 36807c478bd9Sstevel@tonic-gate int error; 3681*5a59a8b3Srsb extern void vopstats_startup(); 3682*5a59a8b3Srsb extern void setup_vopstats(vfs_t *); 36837c478bd9Sstevel@tonic-gate 36847c478bd9Sstevel@tonic-gate static const fs_operation_def_t EIO_vfsops_template[] = { 36857c478bd9Sstevel@tonic-gate VFSNAME_MOUNT, vfs_EIO, 36867c478bd9Sstevel@tonic-gate VFSNAME_UNMOUNT, vfs_EIO, 36877c478bd9Sstevel@tonic-gate VFSNAME_ROOT, vfs_EIO, 36887c478bd9Sstevel@tonic-gate VFSNAME_STATVFS, vfs_EIO, 36897c478bd9Sstevel@tonic-gate VFSNAME_SYNC, (fs_generic_func_p) vfs_EIO_sync, 36907c478bd9Sstevel@tonic-gate VFSNAME_VGET, vfs_EIO, 36917c478bd9Sstevel@tonic-gate VFSNAME_MOUNTROOT, vfs_EIO, 36927c478bd9Sstevel@tonic-gate VFSNAME_FREEVFS, vfs_EIO, 36937c478bd9Sstevel@tonic-gate VFSNAME_VNSTATE, vfs_EIO, 36947c478bd9Sstevel@tonic-gate NULL, NULL 36957c478bd9Sstevel@tonic-gate }; 36967c478bd9Sstevel@tonic-gate 36977c478bd9Sstevel@tonic-gate 36987c478bd9Sstevel@tonic-gate /* Initialize the vnode cache (file systems may use it during init). */ 36997c478bd9Sstevel@tonic-gate 37007c478bd9Sstevel@tonic-gate vn_create_cache(); 37017c478bd9Sstevel@tonic-gate 37027c478bd9Sstevel@tonic-gate /* Setup event monitor framework */ 37037c478bd9Sstevel@tonic-gate 37047c478bd9Sstevel@tonic-gate fem_init(); 37057c478bd9Sstevel@tonic-gate 37067c478bd9Sstevel@tonic-gate /* Initialize the dummy stray file system type. */ 37077c478bd9Sstevel@tonic-gate 37087c478bd9Sstevel@tonic-gate vfssw[0].vsw_vfsops = vfs_strayops; 37097c478bd9Sstevel@tonic-gate 37107c478bd9Sstevel@tonic-gate /* Initialize the dummy EIO file system. */ 37117c478bd9Sstevel@tonic-gate error = vfs_makefsops(EIO_vfsops_template, &EIO_vfsops); 37127c478bd9Sstevel@tonic-gate if (error != 0) { 37137c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "vfsinit: bad EIO vfs ops template"); 37147c478bd9Sstevel@tonic-gate /* Shouldn't happen, but not bad enough to panic */ 37157c478bd9Sstevel@tonic-gate } 37167c478bd9Sstevel@tonic-gate 37177c478bd9Sstevel@tonic-gate VFS_INIT(&EIO_vfs, EIO_vfsops, (caddr_t)NULL); 37187c478bd9Sstevel@tonic-gate 37197c478bd9Sstevel@tonic-gate /* 37207c478bd9Sstevel@tonic-gate * Default EIO_vfs.vfs_flag to VFS_UNMOUNTED so a lookup 37217c478bd9Sstevel@tonic-gate * on this vfs can immediately notice it's invalid. 37227c478bd9Sstevel@tonic-gate */ 37237c478bd9Sstevel@tonic-gate EIO_vfs.vfs_flag |= VFS_UNMOUNTED; 37247c478bd9Sstevel@tonic-gate 37257c478bd9Sstevel@tonic-gate /* 37267c478bd9Sstevel@tonic-gate * Call the init routines of non-loadable filesystems only. 37277c478bd9Sstevel@tonic-gate * Filesystems which are loaded as separate modules will be 37287c478bd9Sstevel@tonic-gate * initialized by the module loading code instead. 37297c478bd9Sstevel@tonic-gate */ 37307c478bd9Sstevel@tonic-gate 37317c478bd9Sstevel@tonic-gate for (vswp = &vfssw[1]; vswp < &vfssw[nfstype]; vswp++) { 37327c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 37337c478bd9Sstevel@tonic-gate if (vswp->vsw_init != NULL) 37347c478bd9Sstevel@tonic-gate (*vswp->vsw_init)(vswp - vfssw, vswp->vsw_name); 37357c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 37367c478bd9Sstevel@tonic-gate } 3737*5a59a8b3Srsb 3738*5a59a8b3Srsb vopstats_startup(); 3739*5a59a8b3Srsb setup_vopstats(&EIO_vfs); 37407c478bd9Sstevel@tonic-gate } 37417c478bd9Sstevel@tonic-gate 37427c478bd9Sstevel@tonic-gate /* 37437c478bd9Sstevel@tonic-gate * Increments the vfs reference count by one atomically. 37447c478bd9Sstevel@tonic-gate */ 37457c478bd9Sstevel@tonic-gate void 37467c478bd9Sstevel@tonic-gate vfs_hold(vfs_t *vfsp) 37477c478bd9Sstevel@tonic-gate { 37487c478bd9Sstevel@tonic-gate atomic_add_32(&vfsp->vfs_count, 1); 37497c478bd9Sstevel@tonic-gate ASSERT(vfsp->vfs_count != 0); 37507c478bd9Sstevel@tonic-gate } 37517c478bd9Sstevel@tonic-gate 37527c478bd9Sstevel@tonic-gate /* 37537c478bd9Sstevel@tonic-gate * Decrements the vfs reference count by one atomically. When 37547c478bd9Sstevel@tonic-gate * vfs reference count becomes zero, it calls the file system 37557c478bd9Sstevel@tonic-gate * specific vfs_freevfs() to free up the resources. 37567c478bd9Sstevel@tonic-gate */ 37577c478bd9Sstevel@tonic-gate void 37587c478bd9Sstevel@tonic-gate vfs_rele(vfs_t *vfsp) 37597c478bd9Sstevel@tonic-gate { 37607c478bd9Sstevel@tonic-gate ASSERT(vfsp->vfs_count != 0); 37617c478bd9Sstevel@tonic-gate if (atomic_add_32_nv(&vfsp->vfs_count, -1) == 0) { 37627c478bd9Sstevel@tonic-gate VFS_FREEVFS(vfsp); 37637c478bd9Sstevel@tonic-gate if (vfsp->vfs_zone) 37647c478bd9Sstevel@tonic-gate zone_rele(vfsp->vfs_zone); 37657c478bd9Sstevel@tonic-gate vfs_freemnttab(vfsp); 37667c478bd9Sstevel@tonic-gate sema_destroy(&vfsp->vfs_reflock); 37677c478bd9Sstevel@tonic-gate kmem_free(vfsp, sizeof (*vfsp)); 37687c478bd9Sstevel@tonic-gate } 37697c478bd9Sstevel@tonic-gate } 37707c478bd9Sstevel@tonic-gate 37717c478bd9Sstevel@tonic-gate /* 37727c478bd9Sstevel@tonic-gate * Generic operations vector support. 37737c478bd9Sstevel@tonic-gate * 37747c478bd9Sstevel@tonic-gate * This is used to build operations vectors for both the vfs and vnode. 37757c478bd9Sstevel@tonic-gate * It's normally called only when a file system is loaded. 37767c478bd9Sstevel@tonic-gate * 37777c478bd9Sstevel@tonic-gate * There are many possible algorithms for this, including the following: 37787c478bd9Sstevel@tonic-gate * 37797c478bd9Sstevel@tonic-gate * (1) scan the list of known operations; for each, see if the file system 37807c478bd9Sstevel@tonic-gate * includes an entry for it, and fill it in as appropriate. 37817c478bd9Sstevel@tonic-gate * 37827c478bd9Sstevel@tonic-gate * (2) set up defaults for all known operations. scan the list of ops 37837c478bd9Sstevel@tonic-gate * supplied by the file system; for each which is both supplied and 37847c478bd9Sstevel@tonic-gate * known, fill it in. 37857c478bd9Sstevel@tonic-gate * 37867c478bd9Sstevel@tonic-gate * (3) sort the lists of known ops & supplied ops; scan the list, filling 37877c478bd9Sstevel@tonic-gate * in entries as we go. 37887c478bd9Sstevel@tonic-gate * 37897c478bd9Sstevel@tonic-gate * we choose (1) for simplicity, and because performance isn't critical here. 37907c478bd9Sstevel@tonic-gate * note that (2) could be sped up using a precomputed hash table on known ops. 37917c478bd9Sstevel@tonic-gate * (3) could be faster than either, but only if the lists were very large or 37927c478bd9Sstevel@tonic-gate * supplied in sorted order. 37937c478bd9Sstevel@tonic-gate * 37947c478bd9Sstevel@tonic-gate */ 37957c478bd9Sstevel@tonic-gate 37967c478bd9Sstevel@tonic-gate int 37977c478bd9Sstevel@tonic-gate fs_build_vector(void *vector, int *unused_ops, 37987c478bd9Sstevel@tonic-gate const fs_operation_trans_def_t *translation, 37997c478bd9Sstevel@tonic-gate const fs_operation_def_t *operations) 38007c478bd9Sstevel@tonic-gate { 38017c478bd9Sstevel@tonic-gate int i, num_trans, num_ops, used; 38027c478bd9Sstevel@tonic-gate 38037c478bd9Sstevel@tonic-gate /* Count the number of translations and the number of supplied */ 38047c478bd9Sstevel@tonic-gate /* operations. */ 38057c478bd9Sstevel@tonic-gate 38067c478bd9Sstevel@tonic-gate { 38077c478bd9Sstevel@tonic-gate const fs_operation_trans_def_t *p; 38087c478bd9Sstevel@tonic-gate 38097c478bd9Sstevel@tonic-gate for (num_trans = 0, p = translation; 38107c478bd9Sstevel@tonic-gate p->name != NULL; 38117c478bd9Sstevel@tonic-gate num_trans++, p++) 38127c478bd9Sstevel@tonic-gate ; 38137c478bd9Sstevel@tonic-gate } 38147c478bd9Sstevel@tonic-gate 38157c478bd9Sstevel@tonic-gate { 38167c478bd9Sstevel@tonic-gate const fs_operation_def_t *p; 38177c478bd9Sstevel@tonic-gate 38187c478bd9Sstevel@tonic-gate for (num_ops = 0, p = operations; 38197c478bd9Sstevel@tonic-gate p->name != NULL; 38207c478bd9Sstevel@tonic-gate num_ops++, p++) 38217c478bd9Sstevel@tonic-gate ; 38227c478bd9Sstevel@tonic-gate } 38237c478bd9Sstevel@tonic-gate 38247c478bd9Sstevel@tonic-gate /* Walk through each operation known to our caller. There will be */ 38257c478bd9Sstevel@tonic-gate /* one entry in the supplied "translation table" for each. */ 38267c478bd9Sstevel@tonic-gate 38277c478bd9Sstevel@tonic-gate used = 0; 38287c478bd9Sstevel@tonic-gate 38297c478bd9Sstevel@tonic-gate for (i = 0; i < num_trans; i++) { 38307c478bd9Sstevel@tonic-gate int j, found; 38317c478bd9Sstevel@tonic-gate char *curname; 38327c478bd9Sstevel@tonic-gate fs_generic_func_p result; 38337c478bd9Sstevel@tonic-gate fs_generic_func_p *location; 38347c478bd9Sstevel@tonic-gate 38357c478bd9Sstevel@tonic-gate curname = translation[i].name; 38367c478bd9Sstevel@tonic-gate 38377c478bd9Sstevel@tonic-gate /* Look for a matching operation in the list supplied by the */ 38387c478bd9Sstevel@tonic-gate /* file system. */ 38397c478bd9Sstevel@tonic-gate 38407c478bd9Sstevel@tonic-gate found = 0; 38417c478bd9Sstevel@tonic-gate 38427c478bd9Sstevel@tonic-gate for (j = 0; j < num_ops; j++) { 38437c478bd9Sstevel@tonic-gate if (strcmp(operations[j].name, curname) == 0) { 38447c478bd9Sstevel@tonic-gate used++; 38457c478bd9Sstevel@tonic-gate found = 1; 38467c478bd9Sstevel@tonic-gate break; 38477c478bd9Sstevel@tonic-gate } 38487c478bd9Sstevel@tonic-gate } 38497c478bd9Sstevel@tonic-gate 38507c478bd9Sstevel@tonic-gate /* If the file system is using a "placeholder" for default */ 38517c478bd9Sstevel@tonic-gate /* or error functions, grab the appropriate function out of */ 38527c478bd9Sstevel@tonic-gate /* the translation table. If the file system didn't supply */ 38537c478bd9Sstevel@tonic-gate /* this operation at all, use the default function. */ 38547c478bd9Sstevel@tonic-gate 38557c478bd9Sstevel@tonic-gate if (found) { 38567c478bd9Sstevel@tonic-gate result = operations[j].func; 38577c478bd9Sstevel@tonic-gate if (result == fs_default) { 38587c478bd9Sstevel@tonic-gate result = translation[i].defaultFunc; 38597c478bd9Sstevel@tonic-gate } else if (result == fs_error) { 38607c478bd9Sstevel@tonic-gate result = translation[i].errorFunc; 38617c478bd9Sstevel@tonic-gate } else if (result == NULL) { 38627c478bd9Sstevel@tonic-gate /* Null values are PROHIBITED */ 38637c478bd9Sstevel@tonic-gate return (EINVAL); 38647c478bd9Sstevel@tonic-gate } 38657c478bd9Sstevel@tonic-gate } else { 38667c478bd9Sstevel@tonic-gate result = translation[i].defaultFunc; 38677c478bd9Sstevel@tonic-gate } 38687c478bd9Sstevel@tonic-gate 38697c478bd9Sstevel@tonic-gate /* Now store the function into the operations vector. */ 38707c478bd9Sstevel@tonic-gate 38717c478bd9Sstevel@tonic-gate location = (fs_generic_func_p *) 38727c478bd9Sstevel@tonic-gate (((char *)vector) + translation[i].offset); 38737c478bd9Sstevel@tonic-gate 38747c478bd9Sstevel@tonic-gate *location = result; 38757c478bd9Sstevel@tonic-gate } 38767c478bd9Sstevel@tonic-gate 38777c478bd9Sstevel@tonic-gate *unused_ops = num_ops - used; 38787c478bd9Sstevel@tonic-gate 38797c478bd9Sstevel@tonic-gate return (0); 38807c478bd9Sstevel@tonic-gate } 38817c478bd9Sstevel@tonic-gate 38827c478bd9Sstevel@tonic-gate /* Placeholder functions, should never be called. */ 38837c478bd9Sstevel@tonic-gate 38847c478bd9Sstevel@tonic-gate int 38857c478bd9Sstevel@tonic-gate fs_error(void) 38867c478bd9Sstevel@tonic-gate { 38877c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "fs_error called"); 38887c478bd9Sstevel@tonic-gate return (0); 38897c478bd9Sstevel@tonic-gate } 38907c478bd9Sstevel@tonic-gate 38917c478bd9Sstevel@tonic-gate int 38927c478bd9Sstevel@tonic-gate fs_default(void) 38937c478bd9Sstevel@tonic-gate { 38947c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "fs_default called"); 38957c478bd9Sstevel@tonic-gate return (0); 38967c478bd9Sstevel@tonic-gate } 38977c478bd9Sstevel@tonic-gate 38987c478bd9Sstevel@tonic-gate #ifdef __sparc 38997c478bd9Sstevel@tonic-gate 39007c478bd9Sstevel@tonic-gate /* 39017c478bd9Sstevel@tonic-gate * Part of the implementation of booting off a mirrored root 39027c478bd9Sstevel@tonic-gate * involves a change of dev_t for the root device. To 39037c478bd9Sstevel@tonic-gate * accomplish this, first remove the existing hash table 39047c478bd9Sstevel@tonic-gate * entry for the root device, convert to the new dev_t, 39057c478bd9Sstevel@tonic-gate * then re-insert in the hash table at the head of the list. 39067c478bd9Sstevel@tonic-gate */ 39077c478bd9Sstevel@tonic-gate void 39087c478bd9Sstevel@tonic-gate vfs_root_redev(vfs_t *vfsp, dev_t ndev, int fstype) 39097c478bd9Sstevel@tonic-gate { 39107c478bd9Sstevel@tonic-gate vfs_list_lock(); 39117c478bd9Sstevel@tonic-gate 39127c478bd9Sstevel@tonic-gate vfs_hash_remove(vfsp); 39137c478bd9Sstevel@tonic-gate 39147c478bd9Sstevel@tonic-gate vfsp->vfs_dev = ndev; 39157c478bd9Sstevel@tonic-gate vfs_make_fsid(&vfsp->vfs_fsid, ndev, fstype); 39167c478bd9Sstevel@tonic-gate 39177c478bd9Sstevel@tonic-gate vfs_hash_add(vfsp, 1); 39187c478bd9Sstevel@tonic-gate 39197c478bd9Sstevel@tonic-gate vfs_list_unlock(); 39207c478bd9Sstevel@tonic-gate } 39217c478bd9Sstevel@tonic-gate 39227c478bd9Sstevel@tonic-gate #else /* x86 NEWBOOT */ 39237c478bd9Sstevel@tonic-gate 39247c478bd9Sstevel@tonic-gate int 39257c478bd9Sstevel@tonic-gate rootconf() 39267c478bd9Sstevel@tonic-gate { 39277c478bd9Sstevel@tonic-gate int error; 39287c478bd9Sstevel@tonic-gate struct vfssw *vsw; 39297c478bd9Sstevel@tonic-gate extern void pm_init(); 39307c478bd9Sstevel@tonic-gate char *fstyp; 39317c478bd9Sstevel@tonic-gate 39327c478bd9Sstevel@tonic-gate fstyp = getrootfs(); 39337c478bd9Sstevel@tonic-gate 39347c478bd9Sstevel@tonic-gate if (error = clboot_rootconf()) 39357c478bd9Sstevel@tonic-gate return (error); 39367c478bd9Sstevel@tonic-gate 39377c478bd9Sstevel@tonic-gate if (modload("fs", fstyp) == -1) 39387c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "Cannot _init %s module\n", fstyp); 39397c478bd9Sstevel@tonic-gate 39407c478bd9Sstevel@tonic-gate RLOCK_VFSSW(); 39417c478bd9Sstevel@tonic-gate vsw = vfs_getvfsswbyname(fstyp); 39427c478bd9Sstevel@tonic-gate RUNLOCK_VFSSW(); 39437c478bd9Sstevel@tonic-gate VFS_INIT(rootvfs, &vsw->vsw_vfsops, 0); 39447c478bd9Sstevel@tonic-gate VFS_HOLD(rootvfs); 39457c478bd9Sstevel@tonic-gate 39467c478bd9Sstevel@tonic-gate /* always mount readonly first */ 39477c478bd9Sstevel@tonic-gate rootvfs->vfs_flag |= VFS_RDONLY; 39487c478bd9Sstevel@tonic-gate 39497c478bd9Sstevel@tonic-gate pm_init(); 39507c478bd9Sstevel@tonic-gate 39517c478bd9Sstevel@tonic-gate if (netboot) 39527c478bd9Sstevel@tonic-gate (void) strplumb(); 39537c478bd9Sstevel@tonic-gate 39547c478bd9Sstevel@tonic-gate error = VFS_MOUNTROOT(rootvfs, ROOT_INIT); 39557c478bd9Sstevel@tonic-gate vfs_unrefvfssw(vsw); 39567c478bd9Sstevel@tonic-gate rootdev = rootvfs->vfs_dev; 39577c478bd9Sstevel@tonic-gate 39587c478bd9Sstevel@tonic-gate if (error) 39597c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "cannot mount root path %s", svm_bootpath); 39607c478bd9Sstevel@tonic-gate return (error); 39617c478bd9Sstevel@tonic-gate } 39627c478bd9Sstevel@tonic-gate 39637c478bd9Sstevel@tonic-gate /* 39647c478bd9Sstevel@tonic-gate * XXX this is called by nfs only and should probably be removed 39657c478bd9Sstevel@tonic-gate * If booted with ASKNAME, prompt on the console for a filesystem 39667c478bd9Sstevel@tonic-gate * name and return it. 39677c478bd9Sstevel@tonic-gate */ 39687c478bd9Sstevel@tonic-gate void 39697c478bd9Sstevel@tonic-gate getfsname(char *askfor, char *name, size_t namelen) 39707c478bd9Sstevel@tonic-gate { 39717c478bd9Sstevel@tonic-gate if (boothowto & RB_ASKNAME) { 39727c478bd9Sstevel@tonic-gate printf("%s name: ", askfor); 39737c478bd9Sstevel@tonic-gate console_gets(name, namelen); 39747c478bd9Sstevel@tonic-gate } 39757c478bd9Sstevel@tonic-gate } 39767c478bd9Sstevel@tonic-gate 39777c478bd9Sstevel@tonic-gate /* 39787c478bd9Sstevel@tonic-gate * If server_path exists, then we are booting a diskless 39797c478bd9Sstevel@tonic-gate * client. Otherwise, we default to ufs. Zfs should perhaps be 39807c478bd9Sstevel@tonic-gate * another property. 39817c478bd9Sstevel@tonic-gate */ 39827c478bd9Sstevel@tonic-gate static char * 39837c478bd9Sstevel@tonic-gate getrootfs(void) 39847c478bd9Sstevel@tonic-gate { 39857c478bd9Sstevel@tonic-gate extern char *strplumb_get_netdev_path(void); 39867c478bd9Sstevel@tonic-gate char *propstr = NULL; 39877c478bd9Sstevel@tonic-gate 39887c478bd9Sstevel@tonic-gate /* check fstype property; it should be nfsdyn for diskless */ 39897c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 39907c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "fstype", &propstr) 39917c478bd9Sstevel@tonic-gate == DDI_SUCCESS) { 39927c478bd9Sstevel@tonic-gate (void) strncpy(rootfs.bo_fstype, propstr, BO_MAXFSNAME); 39937c478bd9Sstevel@tonic-gate ddi_prop_free(propstr); 39947c478bd9Sstevel@tonic-gate } 39957c478bd9Sstevel@tonic-gate 39967c478bd9Sstevel@tonic-gate if (strncmp(rootfs.bo_fstype, "nfs", 3) != 0) 39977c478bd9Sstevel@tonic-gate return (rootfs.bo_fstype); 39987c478bd9Sstevel@tonic-gate 39997c478bd9Sstevel@tonic-gate ++netboot; 40007c478bd9Sstevel@tonic-gate /* check if path to network interface is specified in bootpath */ 40017c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 40027c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "bootpath", &propstr) 40037c478bd9Sstevel@tonic-gate == DDI_SUCCESS) { 40047c478bd9Sstevel@tonic-gate (void) strncpy(rootfs.bo_name, propstr, BO_MAXOBJNAME); 40057c478bd9Sstevel@tonic-gate ddi_prop_free(propstr); 40067c478bd9Sstevel@tonic-gate } else { 40077c478bd9Sstevel@tonic-gate /* attempt to determine netdev_path via boot_mac address */ 40087c478bd9Sstevel@tonic-gate netdev_path = strplumb_get_netdev_path(); 40097c478bd9Sstevel@tonic-gate if (netdev_path == NULL) 40107c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 40117c478bd9Sstevel@tonic-gate "Cannot find boot network interface\n"); 40127c478bd9Sstevel@tonic-gate (void) strncpy(rootfs.bo_name, netdev_path, BO_MAXOBJNAME); 40137c478bd9Sstevel@tonic-gate } 40147c478bd9Sstevel@tonic-gate return ("nfs"); 40157c478bd9Sstevel@tonic-gate } 40167c478bd9Sstevel@tonic-gate #endif 4017