4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2016 Joyent, Inc.
25 * Copyright 2016 Toomas Soome <tsoome@me.com>
26 * Copyright 2016 Nexenta Systems, Inc.
27 * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
28 * Copyright 2017 RackTop Systems.
31 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
35 * University Copyright- Copyright (c) 1982, 1986, 1988
36 * The Regents of the University of California
39 * University Acknowledgment- Portions of this document are derived from
40 * software developed by the University of California, Berkeley, and its
44 #include <sys/types.h>
45 #include <sys/t_lock.h>
46 #include <sys/param.h>
47 #include <sys/errno.h>
49 #include <sys/fstyp.h>
51 #include <sys/systm.h>
53 #include <sys/mount.h>
55 #include <sys/vfs_dispatch.h>
57 #include <sys/mntent.h>
59 #include <sys/statvfs.h>
60 #include <sys/statfs.h>
62 #include <sys/vnode.h>
63 #include <sys/rwstlock.h>
67 #include <sys/atomic.h>
68 #include <sys/cmn_err.h>
71 #include <sys/debug.h>
72 #include <sys/vnode.h>
73 #include <sys/modctl.h>
75 #include <sys/pathname.h>
76 #include <sys/bootconf.h>
77 #include <sys/dumphdr.h>
79 #include <sys/sunddi.h>
80 #include <sys/sysmacros.h>
82 #include <sys/policy.h>
84 #include <sys/objfs.h>
85 #include <sys/console.h>
86 #include <sys/reboot.h>
91 #include <sys/bootprops.h>
95 #include <sys/fs_subr.h>
96 /* Private interfaces to create vopstats-related data structures */
97 extern void initialize_vopstats(vopstats_t
*);
98 extern vopstats_t
*get_fstype_vopstats(struct vfs
*, struct vfssw
*);
99 extern vsk_anchor_t
*get_vskstat_anchor(struct vfs
*);
101 static void vfs_clearmntopt_nolock(mntopts_t
*, const char *, int);
102 static void vfs_setmntopt_nolock(mntopts_t
*, const char *,
103 const char *, int, int);
104 static int vfs_optionisset_nolock(const mntopts_t
*, const char *, char **);
105 static void vfs_freemnttab(struct vfs
*);
106 static void vfs_freeopt(mntopt_t
*);
107 static void vfs_swapopttbl_nolock(mntopts_t
*, mntopts_t
*);
108 static void vfs_swapopttbl(mntopts_t
*, mntopts_t
*);
109 static void vfs_copyopttbl_extend(const mntopts_t
*, mntopts_t
*, int);
110 static void vfs_createopttbl_extend(mntopts_t
*, const char *,
112 static char **vfs_copycancelopt_extend(char **const, int);
113 static void vfs_freecancelopt(char **);
114 static void getrootfs(char **, char **);
115 static int getmacpath(dev_info_t
*, void *);
116 static void vfs_mnttabvp_setup(void);
119 struct ipmnt
*mip_next
;
121 struct vfs
*mip_vfsp
;
124 static kmutex_t vfs_miplist_mutex
;
125 static struct ipmnt
*vfs_miplist
= NULL
;
126 static struct ipmnt
*vfs_miplist_end
= NULL
;
128 static kmem_cache_t
*vfs_cache
; /* Pointer to VFS kmem cache */
133 vnode_t
*rootdir
; /* pointer to root inode vnode. */
134 vnode_t
*devicesdir
; /* pointer to inode of devices root */
135 vnode_t
*devdir
; /* pointer to inode of dev root */
137 char *server_rootpath
; /* root path for diskless clients */
138 char *server_hostname
; /* hostname of diskless server */
140 static struct vfs root
;
141 static struct vfs devices
;
142 static struct vfs dev
;
143 struct vfs
*rootvfs
= &root
; /* pointer to root vfs; head of VFS list. */
144 rvfs_t
*rvfs_list
; /* array of vfs ptrs for vfs hash list */
145 int vfshsz
= 512; /* # of heads/locks in vfs hash arrays */
146 /* must be power of 2! */
147 timespec_t vfs_mnttab_ctime
; /* mnttab created time */
148 timespec_t vfs_mnttab_mtime
; /* mnttab last modified time */
149 char *vfs_dummyfstype
= "\0";
150 struct pollhead vfs_pollhd
; /* for mnttab pollers */
151 struct vnode
*vfs_mntdummyvp
; /* to fake mnttab read/write for file events */
152 int mntfstype
; /* will be set once mnt fs is mounted */
155 * Table for generic options recognized in the VFS layer and acted
156 * on at this level before parsing file system specific options.
157 * The nosuid option is stronger than any of the devices and setuid
158 * options, so those are canceled when nosuid is seen.
160 * All options which are added here need to be added to the
161 * list of standard options in usr/src/cmd/fs.d/fslib.c as well.
164 * VFS Mount options table
166 static char *ro_cancel
[] = { MNTOPT_RW
, NULL
};
167 static char *rw_cancel
[] = { MNTOPT_RO
, NULL
};
168 static char *suid_cancel
[] = { MNTOPT_NOSUID
, NULL
};
169 static char *nosuid_cancel
[] = { MNTOPT_SUID
, MNTOPT_DEVICES
, MNTOPT_NODEVICES
,
170 MNTOPT_NOSETUID
, MNTOPT_SETUID
, NULL
};
171 static char *devices_cancel
[] = { MNTOPT_NODEVICES
, NULL
};
172 static char *nodevices_cancel
[] = { MNTOPT_DEVICES
, NULL
};
173 static char *setuid_cancel
[] = { MNTOPT_NOSETUID
, NULL
};
174 static char *nosetuid_cancel
[] = { MNTOPT_SETUID
, NULL
};
175 static char *nbmand_cancel
[] = { MNTOPT_NONBMAND
, NULL
};
176 static char *nonbmand_cancel
[] = { MNTOPT_NBMAND
, NULL
};
177 static char *exec_cancel
[] = { MNTOPT_NOEXEC
, NULL
};
178 static char *noexec_cancel
[] = { MNTOPT_EXEC
, NULL
};
180 static const mntopt_t mntopts
[] = {
182 * option name cancel options default arg flags
184 { MNTOPT_REMOUNT
, NULL
, NULL
,
185 MO_NODISPLAY
, NULL
},
186 { MNTOPT_RO
, ro_cancel
, NULL
, 0,
188 { MNTOPT_RW
, rw_cancel
, NULL
, 0,
190 { MNTOPT_SUID
, suid_cancel
, NULL
, 0,
192 { MNTOPT_NOSUID
, nosuid_cancel
, NULL
, 0,
194 { MNTOPT_DEVICES
, devices_cancel
, NULL
, 0,
196 { MNTOPT_NODEVICES
, nodevices_cancel
, NULL
, 0,
198 { MNTOPT_SETUID
, setuid_cancel
, NULL
, 0,
200 { MNTOPT_NOSETUID
, nosetuid_cancel
, NULL
, 0,
202 { MNTOPT_NBMAND
, nbmand_cancel
, NULL
, 0,
204 { MNTOPT_NONBMAND
, nonbmand_cancel
, NULL
, 0,
206 { MNTOPT_EXEC
, exec_cancel
, NULL
, 0,
208 { MNTOPT_NOEXEC
, noexec_cancel
, NULL
, 0,
212 const mntopts_t vfs_mntopts
= {
213 sizeof (mntopts
) / sizeof (mntopt_t
),
214 (mntopt_t
*)&mntopts
[0]
218 * File system operation dispatch functions.
222 fsop_mount(vfs_t
*vfsp
, vnode_t
*mvp
, struct mounta
*uap
, cred_t
*cr
)
224 return fsop_mount_dispatch(vfsp
, mvp
, uap
, cr
, true);
228 fsop_unmount(vfs_t
*vfsp
, int flag
, cred_t
*cr
)
230 return fsop_unmount_dispatch(vfsp
, flag
, cr
, true);
234 fsop_root(vfs_t
*vfsp
, vnode_t
**vpp
)
239 ret
= fsop_root_dispatch(vfsp
, vpp
, true);
242 * Make sure this root has a path. With lofs, it is possible to have
245 if (ret
== 0 && vfsp
->vfs_mntpt
!= NULL
&&
246 (*vpp
)->v_path
== vn_vpath_empty
) {
249 mntpt
= vfs_getmntpoint(vfsp
);
250 path
= refstr_value(mntpt
);
251 vn_setpath_str(*vpp
, path
, strlen(path
));
259 fsop_statfs(vfs_t
*vfsp
, statvfs64_t
*sp
)
261 return fsop_statfs_dispatch(vfsp
, sp
, true);
265 fsop_sync(vfs_t
*vfsp
, short flag
, cred_t
*cr
)
267 return fsop_sync_dispatch(vfsp
, flag
, cr
, true);
271 fsop_vget(vfs_t
*vfsp
, vnode_t
**vpp
, fid_t
*fidp
)
274 * In order to handle system attribute fids in a manner
275 * transparent to the underlying fs, we embed the fid for
276 * the sysattr parent object in the sysattr fid and tack on
277 * some extra bytes that only the sysattr layer knows about.
279 * This guarantees that sysattr fids are larger than other fids
280 * for this vfs. If the vfs supports the sysattr view interface
281 * (as indicated by VFSFT_SYSATTR_VIEWS), we cannot have a size
282 * collision with XATTR_FIDSZ.
284 if (vfs_has_feature(vfsp
, VFSFT_SYSATTR_VIEWS
) &&
285 fidp
->fid_len
== XATTR_FIDSZ
)
286 return (xattr_dir_vget(vfsp
, vpp
, fidp
));
288 return fsop_vget_dispatch(vfsp
, vpp
, fidp
, true);
292 fsop_mountroot(vfs_t
*vfsp
, enum whymountroot reason
)
294 return fsop_mountroot_dispatch(vfsp
, reason
, true);
298 fsop_freefs(vfs_t
*vfsp
)
300 fsop_freefs_dispatch(vfsp
, true);
304 fsop_vnstate(vfs_t
*vfsp
, vnode_t
*vp
, vntrans_t nstate
)
306 return fsop_vnstate_dispatch(vfsp
, vp
, nstate
, true);
310 fsop_sync_by_kind(int fstype
, short flag
, cred_t
*cr
)
312 ASSERT((fstype
>= 0) && (fstype
< nfstype
));
314 if (!ALLOCATED_VFSSW(&vfssw
[fstype
]) || !VFS_INSTALLED(&vfssw
[fstype
]))
317 if (vfssw
[fstype
].vsw_vfsops
.vfs_sync
== NULL
)
320 return vfssw
[fstype
].vsw_vfsops
.vfs_sync(NULL
, flag
, cr
);
324 * File system initialization. vfs_setfsops() must be called from a file
325 * system's init routine.
331 if (strcmp(rootfs
.bo_fstype
, MNTTYPE_ZFS
) == 0)
336 vfs_setfsops(int fstype
, const struct vfsops
*ops
)
339 * Verify that fstype refers to a valid fs. Note that
340 * 0 is valid since it's used to set "stray" ops.
342 if ((fstype
< 0) || (fstype
>= nfstype
))
345 if (!ALLOCATED_VFSSW(&vfssw
[fstype
]))
348 vfssw
[fstype
].vsw_vfsops
= *ops
;
349 vfssw
[fstype
].vsw_flag
|= VSW_INSTALLED
;
355 * Since the vfsops structure is part of the vfssw table and wasn't
356 * really allocated, we're not really freeing anything. However, we need to
357 * take care of a little bookkeeping.
360 vfs_freevfsops_by_type(int fstype
)
363 /* Verify that fstype refers to a loaded fs (and not fsid 0). */
364 if ((fstype
<= 0) || (fstype
>= nfstype
))
368 if ((vfssw
[fstype
].vsw_flag
& VSW_INSTALLED
) == 0) {
373 vfssw
[fstype
].vsw_flag
&= ~VSW_INSTALLED
;
379 /* Support routines used to reference vfs_op */
381 /* Set the operations vector for a vfs */
383 vfs_setops(struct vfs
*vfs
, const struct vfsops
*ops
)
388 /* Retrieve the operations vector for a vfs */
389 const struct vfsops
*
390 vfs_getops(struct vfs
*vfs
)
396 * Returns non-zero (1) if the vfsops matches that of the vfs.
397 * Returns zero (0) if not.
400 vfs_matchops(struct vfs
*vfs
, const struct vfsops
*ops
)
402 return (vfs_getops(vfs
) == ops
);
406 * Returns non-zero (1) if the file system has installed a non-default,
407 * non-error vfs_sync routine. Returns zero (0) otherwise.
410 vfs_can_sync(vfs_t
*vfsp
)
412 /* vfs_sync() routine is not the default */
413 return vfs_getops(vfsp
)->vfs_sync
!= NULL
;
417 * Initialize a vfs structure.
420 vfs_init(struct vfs
*vfs
, const struct vfsops
*ops
, void *data
)
422 /* Other initialization has been moved to vfs_alloc() */
426 vfs
->vfs_zone_next
= vfs
;
427 vfs
->vfs_zone_prev
= vfs
;
428 vfs
->vfs_lofi_id
= 0;
429 sema_init(&vfs
->vfs_reflock
, 1, NULL
, SEMA_DEFAULT
, NULL
);
431 vfs
->vfs_data
= data
;
432 vfs_setops(vfs
, ops
);
436 * Allocate and initialize the vfs implementation private data
437 * structure, vfs_impl_t.
440 vfsimpl_setup(vfs_t
*vfsp
)
444 if (vfsp
->vfs_implp
!= NULL
) {
448 vfsp
->vfs_implp
= kmem_alloc(sizeof (vfs_impl_t
), KM_SLEEP
);
449 /* Note that these are #define'd in vfs.h */
450 vfsp
->vfs_vskap
= NULL
;
451 vfsp
->vfs_fstypevsp
= NULL
;
453 /* Set size of counted array, then zero the array */
454 vfsp
->vfs_featureset
[0] = VFS_FEATURE_MAXSZ
- 1;
455 for (i
= 1; i
< VFS_FEATURE_MAXSZ
; i
++) {
456 vfsp
->vfs_featureset
[i
] = 0;
461 * Release the vfs_impl_t structure, if it exists. Some unbundled
462 * filesystems may not use the newer version of vfs and thus
463 * would not contain this implementation private data structure.
466 vfsimpl_teardown(vfs_t
*vfsp
)
468 vfs_impl_t
*vip
= vfsp
->vfs_implp
;
473 kmem_free(vfsp
->vfs_implp
, sizeof (vfs_impl_t
));
474 vfsp
->vfs_implp
= NULL
;
478 * VFS system calls: mount, umount, syssync, statfs, fstatfs, statvfs,
479 * fstatvfs, and sysfs are in kernel/syscall.
483 * Update every mounted file system. We call the vfs_sync operation of
484 * each file system type, passing it a NULL vfsp to indicate that all
485 * mounted file systems of that type should be updated.
492 for (vswp
= &vfssw
[1]; vswp
< &vfssw
[nfstype
]; vswp
++) {
493 if (ALLOCATED_VFSSW(vswp
) && VFS_INSTALLED(vswp
)) {
496 if (vswp
->vsw_vfsops
.vfs_sync
!= NULL
)
497 vswp
->vsw_vfsops
.vfs_sync(NULL
, flag
, CRED());
498 vfs_unrefvfssw(vswp
);
515 krwlock_t vfssw_lock
; /* lock accesses to vfssw */
518 * Lock for accessing the vfs linked list. Initialized in vfs_mountroot(),
519 * but otherwise should be accessed only via vfs_list_lock() and
520 * vfs_list_unlock(). Also used to protect the timestamp for mods to the list.
522 static krwlock_t vfslist
;
525 * Mount devfs on /devices. This is done right after root is mounted
526 * to provide device access support for the system
529 vfs_mountdevices(void)
533 struct mounta mounta
= { /* fake mounta for devfs_mount() */
545 * _init devfs module to fill in the vfssw
547 if (modload("fs", "devfs") == -1)
548 panic("Cannot _init devfs module");
554 vsw
= vfs_getvfsswbyname("devfs");
555 VFS_INIT(&devices
, &vsw
->vsw_vfsops
, NULL
);
561 if (lookupname("/devices", UIO_SYSSPACE
, FOLLOW
, NULLVPP
, &mvp
))
562 panic("Cannot find /devices");
565 * Perform the mount of /devices
567 if (VFS_MOUNT(&devices
, mvp
, &mounta
, CRED()))
568 panic("Cannot mount /devices");
573 * Set appropriate members and add to vfs list for mnttab display
575 vfs_setresource(&devices
, "/devices", 0);
576 vfs_setmntpoint(&devices
, "/devices", 0);
579 * Hold the root of /devices so it won't go away
581 if (VFS_ROOT(&devices
, &devicesdir
))
582 panic("vfs_mountdevices: not devices root");
584 if (vfs_lock(&devices
) != 0) {
586 cmn_err(CE_NOTE
, "Cannot acquire vfs_lock of /devices");
590 if (vn_vfswlock(mvp
) != 0) {
591 vfs_unlock(&devices
);
593 cmn_err(CE_NOTE
, "Cannot acquire vfswlock of /devices");
597 vfs_add(mvp
, &devices
, 0);
599 vfs_unlock(&devices
);
604 * mount the first instance of /dev to root and remain mounted
611 struct mounta mounta
= { /* fake mounta for sdev_mount() */
614 MS_SYSSPACE
| MS_OVERLAY
,
623 * _init dev module to fill in the vfssw
625 if (modload("fs", "dev") == -1)
626 cmn_err(CE_PANIC
, "Cannot _init dev module\n");
632 vsw
= vfs_getvfsswbyname("dev");
633 VFS_INIT(&dev
, &vsw
->vsw_vfsops
, NULL
);
639 if (lookupname("/dev", UIO_SYSSPACE
, FOLLOW
, NULLVPP
, &mvp
))
640 cmn_err(CE_PANIC
, "Cannot find /dev\n");
643 * Perform the mount of /dev
645 if (VFS_MOUNT(&dev
, mvp
, &mounta
, CRED()))
646 cmn_err(CE_PANIC
, "Cannot mount /dev 1\n");
651 * Set appropriate members and add to vfs list for mnttab display
653 vfs_setresource(&dev
, "/dev", 0);
654 vfs_setmntpoint(&dev
, "/dev", 0);
657 * Hold the root of /dev so it won't go away
659 if (VFS_ROOT(&dev
, &devdir
))
660 cmn_err(CE_PANIC
, "vfs_mountdev1: not dev root");
662 if (vfs_lock(&dev
) != 0) {
664 cmn_err(CE_NOTE
, "Cannot acquire vfs_lock of /dev");
668 if (vn_vfswlock(mvp
) != 0) {
671 cmn_err(CE_NOTE
, "Cannot acquire vfswlock of /dev");
675 vfs_add(mvp
, &dev
, 0);
682 * Mount required filesystem. This is done right after root is mounted.
685 vfs_mountfs(char *module
, char *spec
, char *path
)
688 struct mounta mounta
;
691 bzero(&mounta
, sizeof (mounta
));
692 mounta
.flags
= MS_SYSSPACE
| MS_DATA
;
693 mounta
.fstype
= module
;
696 if (lookupname(path
, UIO_SYSSPACE
, FOLLOW
, NULLVPP
, &mvp
)) {
697 cmn_err(CE_WARN
, "Cannot find %s", path
);
700 if (domount(NULL
, &mounta
, mvp
, CRED(), &vfsp
))
701 cmn_err(CE_WARN
, "Cannot mount %s", path
);
708 * vfs_mountroot is called by main() to mount the root filesystem.
713 struct vnode
*rvp
= NULL
;
719 rw_init(&vfssw_lock
, NULL
, RW_DEFAULT
, NULL
);
720 rw_init(&vfslist
, NULL
, RW_DEFAULT
, NULL
);
723 * Alloc the vfs hash bucket array and locks
725 rvfs_list
= kmem_zalloc(vfshsz
* sizeof (rvfs_t
), KM_SLEEP
);
728 * Call machine-dependent routine "rootconf" to choose a root
732 panic("vfs_mountroot: cannot mount root");
734 * Get vnode for '/'. Set up rootdir, u.u_rdir and u.u_cdir
735 * to point to it. These are used by lookuppn() so that it
736 * knows where to start from ('/' or '.').
738 vfs_setmntpoint(rootvfs
, "/", 0);
739 if (VFS_ROOT(rootvfs
, &rootdir
))
740 panic("vfs_mountroot: no root vnode");
743 * At this point, the process tree consists of p0 and possibly some
744 * direct children of p0. (i.e. there are no grandchildren)
746 * Walk through them all, setting their current directory.
748 mutex_enter(&pidlock
);
749 for (p
= practive
; p
!= NULL
; p
= p
->p_next
) {
750 ASSERT(p
== &p0
|| p
->p_parent
== &p0
);
752 PTOU(p
)->u_cdir
= rootdir
;
753 VN_HOLD(PTOU(p
)->u_cdir
);
754 PTOU(p
)->u_rdir
= NULL
;
756 mutex_exit(&pidlock
);
759 * Setup the global zone's rootvp, now that it exists.
761 global_zone
->zone_rootvp
= rootdir
;
762 VN_HOLD(global_zone
->zone_rootvp
);
765 * Notify the module code that it can begin using the
766 * root filesystem instead of the boot program's services.
771 * Special handling for a ZFS root file system.
776 * Set up mnttab information for root
778 vfs_setresource(rootvfs
, rootfs
.bo_name
, 0);
780 /* Now that we're all done with the root FS, set up its vopstats */
781 if ((vswp
= vfs_getvfsswbyvfsops(vfs_getops(rootvfs
))) != NULL
) {
782 /* Set flag for statistics collection */
783 if (vswp
->vsw_flag
& VSW_STATS
) {
784 initialize_vopstats(&rootvfs
->vfs_vopstats
);
785 rootvfs
->vfs_flag
|= VFS_STATS
;
786 rootvfs
->vfs_fstypevsp
=
787 get_fstype_vopstats(rootvfs
, vswp
);
788 rootvfs
->vfs_vskap
= get_vskstat_anchor(rootvfs
);
790 vfs_unrefvfssw(vswp
);
794 * Mount /devices, /dev instance 1, /system/contract, /etc/mnttab,
795 * /etc/svc/volatile, /etc/dfs/sharetab, /system/object, and /proc.
800 vfs_mountfs("ctfs", "ctfs", CTFS_ROOT
);
801 vfs_mountfs("proc", "/proc", "/proc");
802 vfs_mountfs("mntfs", "/etc/mnttab", "/etc/mnttab");
803 vfs_mountfs("tmpfs", "/etc/svc/volatile", "/etc/svc/volatile");
804 vfs_mountfs("objfs", "objfs", OBJFS_ROOT
);
805 vfs_mountfs("bootfs", "bootfs", "/system/boot");
807 if (getzoneid() == GLOBAL_ZONEID
) {
808 vfs_mountfs("sharefs", "sharefs", "/etc/dfs/sharetab");
811 if (strcmp(rootfs
.bo_fstype
, "zfs") != 0) {
813 * Look up the root device via devfs so that a dv_node is
814 * created for it. The vnode is never VN_RELE()ed.
815 * We allocate more than MAXPATHLEN so that the
816 * buffer passed to i_ddi_prompath_to_devfspath() is
817 * exactly MAXPATHLEN (the function expects a buffer
820 plen
= strlen("/devices");
821 path
= kmem_alloc(plen
+ MAXPATHLEN
, KM_SLEEP
);
822 (void) strcpy(path
, "/devices");
824 if (i_ddi_prompath_to_devfspath(rootfs
.bo_name
, path
+ plen
)
826 lookupname(path
, UIO_SYSSPACE
, FOLLOW
, NULLVPP
, &rvp
)) {
828 /* NUL terminate in case "path" has garbage */
829 path
[plen
+ MAXPATHLEN
- 1] = '\0';
831 cmn_err(CE_WARN
, "!Cannot lookup root device: %s",
835 kmem_free(path
, plen
+ MAXPATHLEN
);
838 vfs_mnttabvp_setup();
842 * Check to see if our "block device" is actually a file. If so,
843 * automatically add a lofi device, and keep track of this fact.
846 lofi_add(const char *fsname
, struct vfs
*vfsp
,
847 mntopts_t
*mntopts
, struct mounta
*uap
)
849 int fromspace
= (uap
->flags
& MS_SYSSPACE
) ?
850 UIO_SYSSPACE
: UIO_USERSPACE
;
851 struct lofi_ioctl
*li
= NULL
;
852 struct vnode
*vp
= NULL
;
853 struct pathname pn
= { NULL
};
855 ldi_handle_t ldi_hdl
;
860 if ((vfssw
= vfs_getvfssw(fsname
)) == NULL
)
863 if (!(vfssw
->vsw_flag
& VSW_CANLOFI
)) {
864 vfs_unrefvfssw(vfssw
);
868 vfs_unrefvfssw(vfssw
);
871 if (pn_get(uap
->spec
, fromspace
, &pn
) != 0)
874 if (lookupname(uap
->spec
, fromspace
, FOLLOW
, NULL
, &vp
) != 0)
877 if (vp
->v_type
!= VREG
)
880 /* OK, this is a lofi mount. */
882 if ((uap
->flags
& MS_REMOUNT
) ||
883 vfs_optionisset_nolock(mntopts
, MNTOPT_SUID
, NULL
) ||
884 vfs_optionisset_nolock(mntopts
, MNTOPT_SETUID
, NULL
) ||
885 vfs_optionisset_nolock(mntopts
, MNTOPT_DEVICES
, NULL
)) {
890 ldi_id
= ldi_ident_from_anon();
891 li
= kmem_zalloc(sizeof (*li
), KM_SLEEP
);
892 (void) strlcpy(li
->li_filename
, pn
.pn_path
, MAXPATHLEN
);
894 err
= ldi_open_by_name("/dev/lofictl", FREAD
| FWRITE
, kcred
,
900 err
= ldi_ioctl(ldi_hdl
, LOFI_MAP_FILE
, (intptr_t)li
,
901 FREAD
| FWRITE
| FKIOCTL
, kcred
, &id
);
903 (void) ldi_close(ldi_hdl
, FREAD
| FWRITE
, kcred
);
906 vfsp
->vfs_lofi_id
= id
;
909 ldi_ident_release(ldi_id
);
912 kmem_free(li
, sizeof (*li
));
920 lofi_remove(struct vfs
*vfsp
)
922 struct lofi_ioctl
*li
= NULL
;
924 ldi_handle_t ldi_hdl
;
927 if (vfsp
->vfs_lofi_id
== 0)
930 ldi_id
= ldi_ident_from_anon();
932 li
= kmem_zalloc(sizeof (*li
), KM_SLEEP
);
933 li
->li_id
= vfsp
->vfs_lofi_id
;
934 li
->li_cleanup
= B_TRUE
;
936 err
= ldi_open_by_name("/dev/lofictl", FREAD
| FWRITE
, kcred
,
942 err
= ldi_ioctl(ldi_hdl
, LOFI_UNMAP_FILE_MINOR
, (intptr_t)li
,
943 FREAD
| FWRITE
| FKIOCTL
, kcred
, NULL
);
945 (void) ldi_close(ldi_hdl
, FREAD
| FWRITE
, kcred
);
948 vfsp
->vfs_lofi_id
= 0;
951 ldi_ident_release(ldi_id
);
953 kmem_free(li
, sizeof (*li
));
957 * Common mount code. Called from the system call entry point, from autofs,
958 * nfsv4 trigger mounts, and from pxfs.
960 * Takes the effective file system type, mount arguments, the mount point
961 * vnode, flags specifying whether the mount is a remount and whether it
962 * should be entered into the vfs list, and credentials. Fills in its vfspp
963 * parameter with the mounted file system instance's vfs.
965 * Note that the effective file system type is specified as a string. It may
966 * be null, in which case it's determined from the mount arguments, and may
967 * differ from the type specified in the mount arguments; this is a hook to
968 * allow interposition when instantiating file system instances.
970 * The caller is responsible for releasing its own hold on the mount point
971 * vp (this routine does its own hold when necessary).
972 * Also note that for remounts, the mount point vp should be the vnode for
973 * the root of the file system rather than the vnode that the file system
974 * is mounted on top of.
977 domount(char *fsname
, struct mounta
*uap
, vnode_t
*vp
, struct cred
*credp
,
985 mntopts_t mnt_mntopts
;
987 int copyout_error
= 0;
989 char *opts
= uap
->optptr
;
991 int optlen
= uap
->optlen
;
997 int splice
= ((uap
->flags
& MS_NOSPLICE
) == 0);
998 int fromspace
= (uap
->flags
& MS_SYSSPACE
) ?
999 UIO_SYSSPACE
: UIO_USERSPACE
;
1000 char *resource
= NULL
, *mountpt
= NULL
;
1001 refstr_t
*oldresource
, *oldmntpt
;
1002 struct pathname pn
, rpn
;
1003 vsk_anchor_t
*vskap
;
1004 char fstname
[FSTYPSZ
];
1008 * The v_flag value for the mount point vp is permanently set
1009 * to VVFSLOCK so that no one bypasses the vn_vfs*locks routine
1010 * for mount point locking.
1012 mutex_enter(&vp
->v_lock
);
1013 vp
->v_flag
|= VVFSLOCK
;
1014 mutex_exit(&vp
->v_lock
);
1016 mnt_mntopts
.mo_count
= 0;
1018 * Find the ops vector to use to invoke the file system-specific mount
1019 * method. If the fsname argument is non-NULL, use it directly.
1020 * Otherwise, dig the file system type information out of the mount
1023 * A side effect is to hold the vfssw entry.
1025 * Mount arguments can be specified in several ways, which are
1026 * distinguished by flag bit settings. The preferred way is to set
1027 * MS_OPTIONSTR, indicating an 8 argument mount with the file system
1028 * type supplied as a character string and the last two arguments
1029 * being a pointer to a character buffer and the size of the buffer.
1030 * On entry, the buffer holds a null terminated list of options; on
1031 * return, the string is the list of options the file system
1032 * recognized. If MS_DATA is set arguments five and six point to a
1033 * block of binary data which the file system interprets.
1034 * A further wrinkle is that some callers don't set MS_FSS and MS_DATA
1035 * consistently with these conventions. To handle them, we check to
1036 * see whether the pointer to the file system name has a numeric value
1037 * less than 256. If so, we treat it as an index.
1039 if (fsname
!= NULL
) {
1040 if ((vswp
= vfs_getvfssw(fsname
)) == NULL
) {
1043 } else if (uap
->flags
& (MS_OPTIONSTR
| MS_DATA
| MS_FSS
)) {
1049 if ((fstype
= (uintptr_t)uap
->fstype
) < 256) {
1051 if (fstype
== 0 || fstype
>= nfstype
||
1052 !ALLOCATED_VFSSW(&vfssw
[fstype
])) {
1056 (void) strcpy(fsname
, vfssw
[fstype
].vsw_name
);
1058 if ((vswp
= vfs_getvfssw(fsname
)) == NULL
)
1062 * Handle either kernel or user address space.
1064 if (uap
->flags
& MS_SYSSPACE
) {
1065 error
= copystr(uap
->fstype
, fsname
,
1068 error
= copyinstr(uap
->fstype
, fsname
,
1072 if (error
== ENAMETOOLONG
)
1076 if ((vswp
= vfs_getvfssw(fsname
)) == NULL
)
1080 if ((vswp
= vfs_getvfsswbyvfsops(vfs_getops(rootvfs
))) == NULL
)
1082 fsname
= vswp
->vsw_name
;
1084 if (!VFS_INSTALLED(vswp
))
1087 if ((error
= secpolicy_fs_allowed_mount(fsname
)) != 0) {
1088 vfs_unrefvfssw(vswp
);
1092 vfsops
= &vswp
->vsw_vfsops
;
1094 vfs_copyopttbl(&vswp
->vsw_optproto
, &mnt_mntopts
);
1096 * Fetch mount options and parse them for generic vfs options
1098 if (uap
->flags
& MS_OPTIONSTR
) {
1100 * Limit the buffer size
1102 if (optlen
< 0 || optlen
> MAX_MNTOPT_STR
) {
1106 if ((uap
->flags
& MS_SYSSPACE
) == 0) {
1107 inargs
= kmem_alloc(MAX_MNTOPT_STR
, KM_SLEEP
);
1110 error
= copyinstr(opts
, inargs
, (size_t)optlen
,
1117 vfs_parsemntopts(&mnt_mntopts
, inargs
, 0);
1120 * Flag bits override the options string.
1122 if (uap
->flags
& MS_REMOUNT
)
1123 vfs_setmntopt_nolock(&mnt_mntopts
, MNTOPT_REMOUNT
, NULL
, 0, 0);
1124 if (uap
->flags
& MS_RDONLY
)
1125 vfs_setmntopt_nolock(&mnt_mntopts
, MNTOPT_RO
, NULL
, 0, 0);
1126 if (uap
->flags
& MS_NOSUID
)
1127 vfs_setmntopt_nolock(&mnt_mntopts
, MNTOPT_NOSUID
, NULL
, 0, 0);
1130 * Check if this is a remount; must be set in the option string and
1131 * the file system must support a remount option.
1133 if (remount
= vfs_optionisset_nolock(&mnt_mntopts
,
1134 MNTOPT_REMOUNT
, NULL
)) {
1135 if (!(vswp
->vsw_flag
& VSW_CANREMOUNT
)) {
1139 uap
->flags
|= MS_REMOUNT
;
1143 * uap->flags and vfs_optionisset() should agree.
1145 if (rdonly
= vfs_optionisset_nolock(&mnt_mntopts
, MNTOPT_RO
, NULL
)) {
1146 uap
->flags
|= MS_RDONLY
;
1148 if (vfs_optionisset_nolock(&mnt_mntopts
, MNTOPT_NOSUID
, NULL
)) {
1149 uap
->flags
|= MS_NOSUID
;
1151 nbmand
= vfs_optionisset_nolock(&mnt_mntopts
, MNTOPT_NBMAND
, NULL
);
1152 ASSERT(splice
|| !remount
);
1154 * If we are splicing the fs into the namespace,
1155 * perform mount point checks.
1157 * We want to resolve the path for the mount point to eliminate
1158 * '.' and ".." and symlinks in mount points; we can't do the
1159 * same for the resource string, since it would turn
1160 * "/dev/dsk/c0t0d0s0" into "/devices/pci@...". We need to do
1161 * this before grabbing vn_vfswlock(), because otherwise we
1162 * would deadlock with lookuppn().
1165 ASSERT(vp
->v_count
> 0);
1168 * Pick up mount point and device from appropriate space.
1170 if (pn_get(uap
->spec
, fromspace
, &pn
) == 0) {
1171 resource
= kmem_alloc(pn
.pn_pathlen
+ 1,
1173 (void) strcpy(resource
, pn
.pn_path
);
1177 * Do a lookupname prior to taking the
1178 * writelock. Mark this as completed if
1179 * successful for later cleanup and addition to
1180 * the mount in progress table.
1182 if ((vswp
->vsw_flag
& VSW_MOUNTDEV
) &&
1183 lookupname(uap
->spec
, fromspace
,
1184 FOLLOW
, NULL
, &bvp
) == 0) {
1188 if ((error
= pn_get(uap
->dir
, fromspace
, &pn
)) == 0) {
1191 if (*pn
.pn_path
!= '/') {
1198 * Kludge to prevent autofs from deadlocking with
1199 * itself when it calls domount().
1201 * If autofs is calling, it is because it is doing
1202 * (autofs) mounts in the process of an NFS mount. A
1203 * lookuppn() here would cause us to block waiting for
1204 * said NFS mount to complete, which can't since this
1205 * is the thread that was supposed to doing it.
1207 if (fromspace
== UIO_USERSPACE
) {
1208 if ((error
= lookuppn(&pn
, &rpn
, FOLLOW
, NULL
,
1213 * The file disappeared or otherwise
1214 * became inaccessible since we opened
1215 * it; might as well fail the mount
1216 * since the mount point is no longer
1226 mountpt
= kmem_alloc(pnp
->pn_pathlen
+ 1, KM_SLEEP
);
1227 (void) strcpy(mountpt
, pnp
->pn_path
);
1230 * If the addition of the zone's rootpath
1231 * would push us over a total path length
1232 * of MAXPATHLEN, we fail the mount with
1233 * ENAMETOOLONG, which is what we would have
1234 * gotten if we were trying to perform the same
1235 * mount in the global zone.
1237 * strlen() doesn't count the trailing
1238 * '\0', but zone_rootpathlen counts both a
1239 * trailing '/' and the terminating '\0'.
1241 if ((curproc
->p_zone
->zone_rootpathlen
- 1 +
1242 strlen(mountpt
)) > MAXPATHLEN
||
1243 (resource
!= NULL
&&
1244 (curproc
->p_zone
->zone_rootpathlen
- 1 +
1245 strlen(resource
)) > MAXPATHLEN
)) {
1246 error
= ENAMETOOLONG
;
1257 * Prevent path name resolution from proceeding past
1260 if (vn_vfswlock(vp
) != 0) {
1266 * Verify that it's legitimate to establish a mount on
1267 * the prospective mount point.
1269 if (vn_mountedvfs(vp
) != NULL
) {
1271 * The mount point lock was obtained after some
1272 * other thread raced through and established a mount.
1278 if (vp
->v_flag
& VNOMOUNT
) {
1284 if ((uap
->flags
& (MS_DATA
| MS_OPTIONSTR
)) == 0) {
1285 uap
->dataptr
= NULL
;
1290 * If this is a remount, we don't want to create a new VFS.
1291 * Instead, we pass the existing one with a remount flag.
1295 * Confirm that the mount point is the root vnode of the
1296 * file system that is being remounted.
1297 * This can happen if the user specifies a different
1298 * mount point directory pathname in the (re)mount command.
1300 * Code below can only be reached if splice is true, so it's
1301 * safe to do vn_vfsunlock() here.
1303 if ((vp
->v_flag
& VROOT
) == 0) {
1309 * Disallow making file systems read-only unless file system
1310 * explicitly allows it in its vfssw. Ignore other flags.
1312 if (rdonly
&& vn_is_readonly(vp
) == 0 &&
1313 (vswp
->vsw_flag
& VSW_CANRWRO
) == 0) {
1319 * Disallow changing the NBMAND disposition of the file
1320 * system on remounts.
1322 if ((nbmand
&& ((vp
->v_vfsp
->vfs_flag
& VFS_NBMAND
) == 0)) ||
1323 (!nbmand
&& (vp
->v_vfsp
->vfs_flag
& VFS_NBMAND
))) {
1329 ovflags
= vfsp
->vfs_flag
;
1330 vfsp
->vfs_flag
|= VFS_REMOUNT
;
1331 vfsp
->vfs_flag
&= ~VFS_RDONLY
;
1333 vfsp
= vfs_alloc(KM_SLEEP
);
1334 VFS_INIT(vfsp
, vfsops
, NULL
);
1339 if ((error
= lofi_add(fsname
, vfsp
, &mnt_mntopts
, uap
)) != 0) {
1352 * PRIV_SYS_MOUNT doesn't mean you can become root.
1354 if (vfsp
->vfs_lofi_id
!= 0) {
1355 uap
->flags
|= MS_NOSUID
;
1356 vfs_setmntopt_nolock(&mnt_mntopts
, MNTOPT_NOSUID
, NULL
, 0, 0);
1360 * The vfs_reflock is not used anymore the code below explicitly
1361 * holds it preventing others accesing it directly.
1363 if ((sema_tryp(&vfsp
->vfs_reflock
) == 0) &&
1364 !(vfsp
->vfs_flag
& VFS_REMOUNT
))
1366 "mount type %s couldn't get vfs_reflock", vswp
->vsw_name
);
1369 * Lock the vfs. If this is a remount we want to avoid spurious umount
1370 * failures that happen as a side-effect of fsflush() and other mount
1371 * and unmount operations that might be going on simultaneously and
1372 * may have locked the vfs currently. To not return EBUSY immediately
1373 * here we use vfs_lock_wait() instead vfs_lock() for the remount case.
1376 if (error
= vfs_lock(vfsp
)) {
1377 vfsp
->vfs_flag
= ovflags
;
1387 vfs_lock_wait(vfsp
);
1391 * Add device to mount in progress table, global mounts require special
1392 * handling. It is possible that we have already done the lookupname
1393 * on a spliced, non-global fs. If so, we don't want to do it again
1394 * since we cannot do a lookupname after taking the
1395 * wlock above. This case is for a non-spliced, non-global filesystem.
1398 if ((vswp
->vsw_flag
& VSW_MOUNTDEV
) &&
1399 lookupname(uap
->spec
, fromspace
, FOLLOW
, NULL
, &bvp
) == 0) {
1405 vnode_t
*lvp
= NULL
;
1407 error
= vfs_get_lofi(vfsp
, &lvp
);
1422 } else if (error
== -1) {
1431 vfs_addmip(bdev
, vfsp
);
1436 * Invalidate cached entry for the mount point.
1442 * If have an option string but the filesystem doesn't supply a
1443 * prototype options table, create a table with the global
1444 * options and sufficient room to accept all the options in the
1445 * string. Then parse the passed in option string
1446 * accepting all the options in the string. This gives us an
1447 * option table with all the proper cancel properties for the
1450 * Filesystems that supply a prototype options table are handled
1451 * earlier in this function.
1453 if (uap
->flags
& MS_OPTIONSTR
) {
1454 if (!(vswp
->vsw_flag
& VSW_HASPROTO
)) {
1455 mntopts_t tmp_mntopts
;
1457 tmp_mntopts
.mo_count
= 0;
1458 vfs_createopttbl_extend(&tmp_mntopts
, inargs
,
1460 vfs_parsemntopts(&tmp_mntopts
, inargs
, 1);
1461 vfs_swapopttbl_nolock(&mnt_mntopts
, &tmp_mntopts
);
1462 vfs_freeopttbl(&tmp_mntopts
);
1467 * Serialize with zone state transitions.
1468 * See vfs_list_add; zone mounted into is:
1469 * zone_find_by_path(refstr_value(vfsp->vfs_mntpt))
1470 * not the zone doing the mount (curproc->p_zone), but if we're already
1471 * inside a NGZ, then we know what zone we are.
1473 if (INGLOBALZONE(curproc
)) {
1474 zone
= zone_find_by_path(mountpt
);
1475 ASSERT(zone
!= NULL
);
1477 zone
= curproc
->p_zone
;
1479 * zone_find_by_path does a hold, so do one here too so that
1480 * we can do a zone_rele after mount_completed.
1484 mount_in_progress(zone
);
1486 * Instantiate (or reinstantiate) the file system. If appropriate,
1487 * splice it into the file system name space.
1489 * We want VFS_MOUNT() to be able to override the vfs_resource
1490 * string if necessary (ie, mntfs), and also for a remount to
1491 * change the same (necessary when remounting '/' during boot).
1492 * So we set up vfs_mntpt and vfs_resource to what we think they
1493 * should be, then hand off control to VFS_MOUNT() which can
1496 * For safety's sake, when changing vfs_resource or vfs_mntpt of
1497 * a vfs which is on the vfs list (i.e. during a remount), we must
1498 * never set those fields to NULL. Several bits of code make
1499 * assumptions that the fields are always valid.
1501 vfs_swapopttbl(&mnt_mntopts
, &vfsp
->vfs_mntopts
);
1503 if ((oldresource
= vfsp
->vfs_resource
) != NULL
)
1504 refstr_hold(oldresource
);
1505 if ((oldmntpt
= vfsp
->vfs_mntpt
) != NULL
)
1506 refstr_hold(oldmntpt
);
1508 vfs_setresource(vfsp
, resource
, 0);
1509 vfs_setmntpoint(vfsp
, mountpt
, 0);
1512 * going to mount on this vnode, so notify.
1514 vnevent_mountedover(vp
, NULL
);
1515 error
= VFS_MOUNT(vfsp
, vp
, uap
, credp
);
1517 if (uap
->flags
& MS_RDONLY
)
1518 vfs_setmntopt(vfsp
, MNTOPT_RO
, NULL
, 0);
1519 if (uap
->flags
& MS_NOSUID
)
1520 vfs_setmntopt(vfsp
, MNTOPT_NOSUID
, NULL
, 0);
1526 /* put back pre-remount options */
1527 vfs_swapopttbl(&mnt_mntopts
, &vfsp
->vfs_mntopts
);
1528 vfs_setmntpoint(vfsp
, refstr_value(oldmntpt
),
1531 refstr_rele(oldmntpt
);
1532 vfs_setresource(vfsp
, refstr_value(oldresource
),
1535 refstr_rele(oldresource
);
1536 vfsp
->vfs_flag
= ovflags
;
1541 vfs_freemnttab(vfsp
);
1546 * Set the mount time to now
1548 vfsp
->vfs_mtime
= ddi_get_time();
1550 vfsp
->vfs_flag
&= ~VFS_REMOUNT
;
1552 refstr_rele(oldresource
);
1554 refstr_rele(oldmntpt
);
1555 } else if (splice
) {
1557 * Link vfsp into the name space at the mount
1558 * point. Vfs_add() is responsible for
1559 * holding the mount point which will be
1560 * released when vfs_remove() is called.
1562 vfs_add(vp
, vfsp
, uap
->flags
);
1565 * Hold the reference to file system which is
1566 * not linked into the name space.
1568 vfsp
->vfs_zone
= NULL
;
1570 vfsp
->vfs_vnodecovered
= NULL
;
1573 * Set flags for global options encountered
1575 if (vfs_optionisset(vfsp
, MNTOPT_RO
, NULL
))
1576 vfsp
->vfs_flag
|= VFS_RDONLY
;
1578 vfsp
->vfs_flag
&= ~VFS_RDONLY
;
1579 if (vfs_optionisset(vfsp
, MNTOPT_NOSUID
, NULL
)) {
1580 vfsp
->vfs_flag
|= (VFS_NOSETUID
|VFS_NODEVICES
);
1582 if (vfs_optionisset(vfsp
, MNTOPT_NODEVICES
, NULL
))
1583 vfsp
->vfs_flag
|= VFS_NODEVICES
;
1585 vfsp
->vfs_flag
&= ~VFS_NODEVICES
;
1586 if (vfs_optionisset(vfsp
, MNTOPT_NOSETUID
, NULL
))
1587 vfsp
->vfs_flag
|= VFS_NOSETUID
;
1589 vfsp
->vfs_flag
&= ~VFS_NOSETUID
;
1591 if (vfs_optionisset(vfsp
, MNTOPT_NBMAND
, NULL
))
1592 vfsp
->vfs_flag
|= VFS_NBMAND
;
1594 vfsp
->vfs_flag
&= ~VFS_NBMAND
;
1596 if (vfs_optionisset(vfsp
, MNTOPT_XATTR
, NULL
))
1597 vfsp
->vfs_flag
|= VFS_XATTR
;
1599 vfsp
->vfs_flag
&= ~VFS_XATTR
;
1601 if (vfs_optionisset(vfsp
, MNTOPT_NOEXEC
, NULL
))
1602 vfsp
->vfs_flag
|= VFS_NOEXEC
;
1604 vfsp
->vfs_flag
&= ~VFS_NOEXEC
;
1607 * Now construct the output option string of options
1610 if (uap
->flags
& MS_OPTIONSTR
) {
1611 vfs_list_read_lock();
1612 copyout_error
= vfs_buildoptionstr(
1613 &vfsp
->vfs_mntopts
, inargs
, optlen
);
1615 if (copyout_error
== 0 &&
1616 (uap
->flags
& MS_SYSSPACE
) == 0) {
1617 copyout_error
= copyoutstr(inargs
, opts
,
1623 * If this isn't a remount, set up the vopstats before
1624 * anyone can touch this. We only allow spliced file
1625 * systems (file systems which are in the namespace) to
1626 * have the VFS_STATS flag set.
1627 * NOTE: PxFS mounts the underlying file system with
1628 * MS_NOSPLICE set and copies those vfs_flags to its private
1629 * vfs structure. As a result, PxFS should never have
1630 * the VFS_STATS flag or else we might access the vfs
1631 * statistics-related fields prior to them being
1632 * properly initialized.
1634 if (!remount
&& (vswp
->vsw_flag
& VSW_STATS
) && splice
) {
1635 initialize_vopstats(&vfsp
->vfs_vopstats
);
1637 * We need to set vfs_vskap to NULL because there's
1638 * a chance it won't be set below. This is checked
1639 * in teardown_vopstats() so we can't have garbage.
1641 vfsp
->vfs_vskap
= NULL
;
1642 vfsp
->vfs_flag
|= VFS_STATS
;
1643 vfsp
->vfs_fstypevsp
= get_fstype_vopstats(vfsp
, vswp
);
1646 if (vswp
->vsw_flag
& VSW_XID
)
1647 vfsp
->vfs_flag
|= VFS_XID
;
1651 mount_completed(zone
);
1656 if ((error
== 0) && (copyout_error
== 0)) {
1659 * Don't call get_vskstat_anchor() while holding
1660 * locks since it allocates memory and calls
1661 * VFS_STATVFS(). For NFS, the latter can generate
1662 * an over-the-wire call.
1664 vskap
= get_vskstat_anchor(vfsp
);
1665 /* Only take the lock if we have something to do */
1666 if (vskap
!= NULL
) {
1667 vfs_lock_wait(vfsp
);
1668 if (vfsp
->vfs_flag
& VFS_STATS
) {
1669 vfsp
->vfs_vskap
= vskap
;
1674 /* Return vfsp to caller. */
1678 vfs_freeopttbl(&mnt_mntopts
);
1679 if (resource
!= NULL
)
1680 kmem_free(resource
, strlen(resource
) + 1);
1681 if (mountpt
!= NULL
)
1682 kmem_free(mountpt
, strlen(mountpt
) + 1);
1684 * It is possible we errored prior to adding to mount in progress
1685 * table. Must free vnode we acquired with successful lookupname.
1691 ASSERT(vswp
!= NULL
);
1692 vfs_unrefvfssw(vswp
);
1694 kmem_free(inargs
, MAX_MNTOPT_STR
);
1695 if (copyout_error
) {
1698 error
= copyout_error
;
1705 struct vfs
*vfsp
, /* vfs being updated */
1706 refstr_t
**refp
, /* Ref-count string to contain the new path */
1707 const char *newpath
, /* Path to add to refp (above) */
1708 uint32_t flag
) /* flag */
1712 zone_t
*zone
= curproc
->p_zone
;
1714 int have_list_lock
= 0;
1716 ASSERT(!VFS_ON_LIST(vfsp
) || vfs_lock_held(vfsp
));
1719 * New path must be less than MAXPATHLEN because mntfs
1720 * will only display up to MAXPATHLEN bytes. This is currently
1721 * safe, because domount() uses pn_get(), and other callers
1722 * similarly cap the size to fewer than MAXPATHLEN bytes.
1725 ASSERT(strlen(newpath
) < MAXPATHLEN
);
1727 /* mntfs requires consistency while vfs list lock is held */
1729 if (VFS_ON_LIST(vfsp
)) {
1738 * If we are in a non-global zone then we prefix the supplied path,
1739 * newpath, with the zone's root path, with two exceptions. The first
1740 * is where we have been explicitly directed to avoid doing so; this
1741 * will be the case following a failed remount, where the path supplied
1742 * will be a saved version which must now be restored. The second
1743 * exception is where newpath is not a pathname but a descriptive name,
1746 if (zone
== global_zone
|| (flag
& VFSSP_VERBATIM
) || *newpath
!= '/') {
1747 ref
= refstr_alloc(newpath
);
1752 * Truncate the trailing '/' in the zoneroot, and merge
1753 * in the zone's rootpath with the "newpath" (resource
1754 * or mountpoint) passed in.
1756 * The size of the required buffer is thus the size of
1757 * the buffer required for the passed-in newpath
1758 * (strlen(newpath) + 1), plus the size of the buffer
1759 * required to hold zone_rootpath (zone_rootpathlen)
1760 * minus one for one of the now-superfluous NUL
1761 * terminations, minus one for the trailing '/'.
1765 * (strlen(newpath) + 1) + zone_rootpathlen - 1 - 1
1767 * Which is what we have below.
1770 len
= strlen(newpath
) + zone
->zone_rootpathlen
- 1;
1771 sp
= kmem_alloc(len
, KM_SLEEP
);
1774 * Copy everything including the trailing slash, which
1775 * we then overwrite with the NUL character.
1778 (void) strcpy(sp
, zone
->zone_rootpath
);
1779 sp
[zone
->zone_rootpathlen
- 2] = '\0';
1780 (void) strcat(sp
, newpath
);
1782 ref
= refstr_alloc(sp
);
1787 if (have_list_lock
) {
1788 vfs_mnttab_modtimeupd();
1794 * Record a mounted resource name in a vfs structure.
1795 * If vfsp is already mounted, caller must hold the vfs lock.
1798 vfs_setresource(struct vfs
*vfsp
, const char *resource
, uint32_t flag
)
1800 if (resource
== NULL
|| resource
[0] == '\0')
1801 resource
= VFS_NORESOURCE
;
1802 vfs_setpath(vfsp
, &vfsp
->vfs_resource
, resource
, flag
);
1806 * Record a mount point name in a vfs structure.
1807 * If vfsp is already mounted, caller must hold the vfs lock.
1810 vfs_setmntpoint(struct vfs
*vfsp
, const char *mntpt
, uint32_t flag
)
1812 if (mntpt
== NULL
|| mntpt
[0] == '\0')
1813 mntpt
= VFS_NOMNTPT
;
1814 vfs_setpath(vfsp
, &vfsp
->vfs_mntpt
, mntpt
, flag
);
1817 /* Returns the vfs_resource. Caller must call refstr_rele() when finished. */
1820 vfs_getresource(const struct vfs
*vfsp
)
1824 vfs_list_read_lock();
1825 resource
= vfsp
->vfs_resource
;
1826 refstr_hold(resource
);
1832 /* Returns the vfs_mntpt. Caller must call refstr_rele() when finished. */
1835 vfs_getmntpoint(const struct vfs
*vfsp
)
1839 vfs_list_read_lock();
1840 mntpt
= vfsp
->vfs_mntpt
;
1848 * Create an empty options table with enough empty slots to hold all
1849 * The options in the options string passed as an argument.
1850 * Potentially prepend another options table.
1852 * Note: caller is responsible for locking the vfs list, if needed,
1856 vfs_createopttbl_extend(mntopts_t
*mops
, const char *opts
,
1857 const mntopts_t
*mtmpl
)
1859 const char *s
= opts
;
1862 if (opts
== NULL
|| *opts
== '\0') {
1868 * Count number of options in the string
1870 for (s
= strchr(s
, ','); s
!= NULL
; s
= strchr(s
, ',')) {
1875 vfs_copyopttbl_extend(mtmpl
, mops
, count
);
1879 * Create an empty options table with enough empty slots to hold all
1880 * The options in the options string passed as an argument.
1882 * This function is *not* for general use by filesystems.
1884 * Note: caller is responsible for locking the vfs list, if needed,
1888 vfs_createopttbl(mntopts_t
*mops
, const char *opts
)
1890 vfs_createopttbl_extend(mops
, opts
, NULL
);
1895 * Swap two mount options tables
1898 vfs_swapopttbl_nolock(mntopts_t
*optbl1
, mntopts_t
*optbl2
)
1903 tmpcnt
= optbl2
->mo_count
;
1904 tmplist
= optbl2
->mo_list
;
1905 optbl2
->mo_count
= optbl1
->mo_count
;
1906 optbl2
->mo_list
= optbl1
->mo_list
;
1907 optbl1
->mo_count
= tmpcnt
;
1908 optbl1
->mo_list
= tmplist
;
1912 vfs_swapopttbl(mntopts_t
*optbl1
, mntopts_t
*optbl2
)
1915 vfs_swapopttbl_nolock(optbl1
, optbl2
);
1916 vfs_mnttab_modtimeupd();
1921 vfs_copycancelopt_extend(char **const moc
, int extend
)
1928 for (; moc
[i
] != NULL
; i
++)
1929 /* count number of options to cancel */;
1932 if (i
+ extend
== 0)
1935 result
= kmem_alloc((i
+ extend
+ 1) * sizeof (char *), KM_SLEEP
);
1937 for (j
= 0; j
< i
; j
++) {
1938 result
[j
] = kmem_alloc(strlen(moc
[j
]) + 1, KM_SLEEP
);
1939 (void) strcpy(result
[j
], moc
[j
]);
1941 for (; j
<= i
+ extend
; j
++)
1948 vfs_copyopt(const mntopt_t
*s
, mntopt_t
*d
)
1952 d
->mo_flags
= s
->mo_flags
;
1953 d
->mo_data
= s
->mo_data
;
1956 dp
= kmem_alloc(strlen(sp
) + 1, KM_SLEEP
);
1957 (void) strcpy(dp
, sp
);
1960 d
->mo_name
= NULL
; /* should never happen */
1963 d
->mo_cancel
= vfs_copycancelopt_extend(s
->mo_cancel
, 0);
1967 dp
= kmem_alloc(strlen(sp
) + 1, KM_SLEEP
);
1968 (void) strcpy(dp
, sp
);
1976 * Copy a mount options table, possibly allocating some spare
1977 * slots at the end. It is permissible to copy_extend the NULL table.
1980 vfs_copyopttbl_extend(const mntopts_t
*smo
, mntopts_t
*dmo
, int extra
)
1986 * Clear out any existing stuff in the options table being initialized
1988 vfs_freeopttbl(dmo
);
1989 count
= (smo
== NULL
) ? 0 : smo
->mo_count
;
1990 if ((count
+ extra
) == 0) /* nothing to do */
1992 dmo
->mo_count
= count
+ extra
;
1993 motbl
= kmem_zalloc((count
+ extra
) * sizeof (mntopt_t
), KM_SLEEP
);
1994 dmo
->mo_list
= motbl
;
1995 for (i
= 0; i
< count
; i
++) {
1996 vfs_copyopt(&smo
->mo_list
[i
], &motbl
[i
]);
1998 for (i
= count
; i
< count
+ extra
; i
++) {
1999 motbl
[i
].mo_flags
= MO_EMPTY
;
2004 * Copy a mount options table.
2006 * This function is *not* for general use by filesystems.
2008 * Note: caller is responsible for locking the vfs list, if needed,
2009 * to protect smo and dmo.
2012 vfs_copyopttbl(const mntopts_t
*smo
, mntopts_t
*dmo
)
2014 vfs_copyopttbl_extend(smo
, dmo
, 0);
2018 vfs_mergecancelopts(const mntopt_t
*mop1
, const mntopt_t
*mop2
)
2023 char **sp1
, **sp2
, **dp
;
2026 * First we count both lists of cancel options.
2027 * If either is NULL or has no elements, we return a copy of
2030 if (mop1
->mo_cancel
!= NULL
) {
2031 for (; mop1
->mo_cancel
[c1
] != NULL
; c1
++)
2032 /* count cancel options in mop1 */;
2036 return (vfs_copycancelopt_extend(mop2
->mo_cancel
, 0));
2038 if (mop2
->mo_cancel
!= NULL
) {
2039 for (; mop2
->mo_cancel
[c2
] != NULL
; c2
++)
2040 /* count cancel options in mop2 */;
2043 result
= vfs_copycancelopt_extend(mop1
->mo_cancel
, c2
);
2049 * When we get here, we've got two sets of cancel options;
2050 * we need to merge the two sets. We know that the result
2051 * array has "c1+c2+1" entries and in the end we might shrink
2053 * Result now has a copy of the c1 entries from mop1; we'll
2054 * now lookup all the entries of mop2 in mop1 and copy it if
2056 * This operation is O(n^2) but it's only called once per
2057 * filesystem per duplicate option. This is a situation
2058 * which doesn't arise with the filesystems in ON and
2063 for (sp2
= mop2
->mo_cancel
; *sp2
!= NULL
; sp2
++) {
2064 for (sp1
= mop1
->mo_cancel
; *sp1
!= NULL
; sp1
++) {
2065 if (strcmp(*sp1
, *sp2
) == 0)
2070 * Option *sp2 not found in mop1, so copy it.
2071 * The calls to vfs_copycancelopt_extend()
2072 * guarantee that there's enough room.
2074 *dp
= kmem_alloc(strlen(*sp2
) + 1, KM_SLEEP
);
2075 (void) strcpy(*dp
++, *sp2
);
2078 if (dp
!= &result
[c1
+c2
]) {
2079 size_t bytes
= (dp
- result
+ 1) * sizeof (char *);
2080 char **nres
= kmem_alloc(bytes
, KM_SLEEP
);
2082 bcopy(result
, nres
, bytes
);
2083 kmem_free(result
, (c1
+ c2
+ 1) * sizeof (char *));
2090 * Merge two mount option tables (outer and inner) into one. This is very
2091 * similar to "merging" global variables and automatic variables in C.
2093 * This isn't (and doesn't have to be) fast.
2095 * This function is *not* for general use by filesystems.
2097 * Note: caller is responsible for locking the vfs list, if needed,
2098 * to protect omo, imo & dmo.
2101 vfs_mergeopttbl(const mntopts_t
*omo
, const mntopts_t
*imo
, mntopts_t
*dmo
)
2104 mntopt_t
*mop
, *motbl
;
2108 * First determine how much space we need to allocate.
2110 count
= omo
->mo_count
;
2111 for (i
= 0; i
< imo
->mo_count
; i
++) {
2112 if (imo
->mo_list
[i
].mo_flags
& MO_EMPTY
)
2114 if (vfs_hasopt(omo
, imo
->mo_list
[i
].mo_name
) == NULL
)
2117 ASSERT(count
>= omo
->mo_count
&&
2118 count
<= omo
->mo_count
+ imo
->mo_count
);
2119 motbl
= kmem_alloc(count
* sizeof (mntopt_t
), KM_SLEEP
);
2120 for (i
= 0; i
< omo
->mo_count
; i
++)
2121 vfs_copyopt(&omo
->mo_list
[i
], &motbl
[i
]);
2122 freeidx
= omo
->mo_count
;
2123 for (i
= 0; i
< imo
->mo_count
; i
++) {
2124 if (imo
->mo_list
[i
].mo_flags
& MO_EMPTY
)
2126 if ((mop
= vfs_hasopt(omo
, imo
->mo_list
[i
].mo_name
)) != NULL
) {
2128 uint_t index
= mop
- omo
->mo_list
;
2130 newcanp
= vfs_mergecancelopts(mop
, &motbl
[index
]);
2132 vfs_freeopt(&motbl
[index
]);
2133 vfs_copyopt(&imo
->mo_list
[i
], &motbl
[index
]);
2135 vfs_freecancelopt(motbl
[index
].mo_cancel
);
2136 motbl
[index
].mo_cancel
= newcanp
;
2139 * If it's a new option, just copy it over to the first
2142 vfs_copyopt(&imo
->mo_list
[i
], &motbl
[freeidx
++]);
2145 dmo
->mo_count
= count
;
2146 dmo
->mo_list
= motbl
;
2150 * Functions to set and clear mount options in a mount options table.
2154 * Clear a mount option, if it exists.
2156 * The update_mnttab arg indicates whether mops is part of a vfs that is on
2160 vfs_clearmntopt_nolock(mntopts_t
*mops
, const char *opt
, int update_mnttab
)
2165 ASSERT(!update_mnttab
|| RW_WRITE_HELD(&vfslist
));
2167 count
= mops
->mo_count
;
2168 for (i
= 0; i
< count
; i
++) {
2169 mop
= &mops
->mo_list
[i
];
2171 if (mop
->mo_flags
& MO_EMPTY
)
2173 if (strcmp(opt
, mop
->mo_name
))
2175 mop
->mo_flags
&= ~MO_SET
;
2176 if (mop
->mo_arg
!= NULL
) {
2177 kmem_free(mop
->mo_arg
, strlen(mop
->mo_arg
) + 1);
2181 vfs_mnttab_modtimeupd();
2187 vfs_clearmntopt(struct vfs
*vfsp
, const char *opt
)
2191 if (VFS_ON_LIST(vfsp
)) {
2195 vfs_clearmntopt_nolock(&vfsp
->vfs_mntopts
, opt
, gotlock
);
2202 * Set a mount option on. If it's not found in the table, it's silently
2203 * ignored. If the option has MO_IGNORE set, it is still set unless the
2204 * VFS_NOFORCEOPT bit is set in the flags. Also, VFS_DISPLAY/VFS_NODISPLAY flag
2205 * bits can be used to toggle the MO_NODISPLAY bit for the option.
2206 * If the VFS_CREATEOPT flag bit is set then the first option slot with
2207 * MO_EMPTY set is created as the option passed in.
2209 * The update_mnttab arg indicates whether mops is part of a vfs that is on
2213 vfs_setmntopt_nolock(mntopts_t
*mops
, const char *opt
,
2214 const char *arg
, int flags
, int update_mnttab
)
2220 ASSERT(!update_mnttab
|| RW_WRITE_HELD(&vfslist
));
2222 if (flags
& VFS_CREATEOPT
) {
2223 if (vfs_hasopt(mops
, opt
) != NULL
) {
2224 flags
&= ~VFS_CREATEOPT
;
2227 count
= mops
->mo_count
;
2228 for (i
= 0; i
< count
; i
++) {
2229 mop
= &mops
->mo_list
[i
];
2231 if (mop
->mo_flags
& MO_EMPTY
) {
2232 if ((flags
& VFS_CREATEOPT
) == 0)
2234 sp
= kmem_alloc(strlen(opt
) + 1, KM_SLEEP
);
2235 (void) strcpy(sp
, opt
);
2238 mop
->mo_flags
= MO_HASVALUE
;
2241 } else if (strcmp(opt
, mop
->mo_name
)) {
2244 if ((mop
->mo_flags
& MO_IGNORE
) && (flags
& VFS_NOFORCEOPT
))
2246 if (arg
!= NULL
&& (mop
->mo_flags
& MO_HASVALUE
) != 0) {
2247 sp
= kmem_alloc(strlen(arg
) + 1, KM_SLEEP
);
2248 (void) strcpy(sp
, arg
);
2252 if (mop
->mo_arg
!= NULL
)
2253 kmem_free(mop
->mo_arg
, strlen(mop
->mo_arg
) + 1);
2255 if (flags
& VFS_DISPLAY
)
2256 mop
->mo_flags
&= ~MO_NODISPLAY
;
2257 if (flags
& VFS_NODISPLAY
)
2258 mop
->mo_flags
|= MO_NODISPLAY
;
2259 mop
->mo_flags
|= MO_SET
;
2260 if (mop
->mo_cancel
!= NULL
) {
2263 for (cp
= mop
->mo_cancel
; *cp
!= NULL
; cp
++)
2264 vfs_clearmntopt_nolock(mops
, *cp
, 0);
2267 vfs_mnttab_modtimeupd();
2273 vfs_setmntopt(struct vfs
*vfsp
, const char *opt
, const char *arg
, int flags
)
2277 if (VFS_ON_LIST(vfsp
)) {
2281 vfs_setmntopt_nolock(&vfsp
->vfs_mntopts
, opt
, arg
, flags
, gotlock
);
2288 * Add a "tag" option to a mounted file system's options list.
2290 * Note: caller is responsible for locking the vfs list, if needed,
2294 vfs_addtag(mntopts_t
*mops
, const char *tag
)
2297 mntopt_t
*mop
, *motbl
;
2299 count
= mops
->mo_count
+ 1;
2300 motbl
= kmem_zalloc(count
* sizeof (mntopt_t
), KM_SLEEP
);
2301 if (mops
->mo_count
) {
2302 size_t len
= (count
- 1) * sizeof (mntopt_t
);
2304 bcopy(mops
->mo_list
, motbl
, len
);
2305 kmem_free(mops
->mo_list
, len
);
2307 mops
->mo_count
= count
;
2308 mops
->mo_list
= motbl
;
2309 mop
= &motbl
[count
- 1];
2310 mop
->mo_flags
= MO_TAG
;
2311 mop
->mo_name
= kmem_alloc(strlen(tag
) + 1, KM_SLEEP
);
2312 (void) strcpy(mop
->mo_name
, tag
);
2317 * Allow users to set arbitrary "tags" in a vfs's mount options.
2318 * Broader use within the kernel is discouraged.
2321 vfs_settag(uint_t major
, uint_t minor
, const char *mntpt
, const char *tag
,
2328 dev_t dev
= makedevice(major
, minor
);
2330 char *buf
= kmem_alloc(MAX_MNTOPT_STR
, KM_SLEEP
);
2333 * Find the desired mounted file system
2338 if (vfsp
->vfs_dev
== dev
&&
2339 strcmp(mntpt
, refstr_value(vfsp
->vfs_mntpt
)) == 0) {
2343 vfsp
= vfsp
->vfs_next
;
2344 } while (vfsp
!= rootvfs
);
2350 err
= secpolicy_fs_config(cr
, vfsp
);
2354 mops
= &vfsp
->vfs_mntopts
;
2356 * Add tag if it doesn't already exist
2358 if ((mop
= vfs_hasopt(mops
, tag
)) == NULL
) {
2361 (void) vfs_buildoptionstr(mops
, buf
, MAX_MNTOPT_STR
);
2363 if (len
+ strlen(tag
) + 2 > MAX_MNTOPT_STR
) {
2367 mop
= vfs_addtag(mops
, tag
);
2369 if ((mop
->mo_flags
& MO_TAG
) == 0) {
2373 vfs_setmntopt_nolock(mops
, tag
, NULL
, 0, 1);
2376 kmem_free(buf
, MAX_MNTOPT_STR
);
2381 * Allow users to remove arbitrary "tags" in a vfs's mount options.
2382 * Broader use within the kernel is discouraged.
2385 vfs_clrtag(uint_t major
, uint_t minor
, const char *mntpt
, const char *tag
,
2391 dev_t dev
= makedevice(major
, minor
);
2395 * Find the desired mounted file system
2400 if (vfsp
->vfs_dev
== dev
&&
2401 strcmp(mntpt
, refstr_value(vfsp
->vfs_mntpt
)) == 0) {
2405 vfsp
= vfsp
->vfs_next
;
2406 } while (vfsp
!= rootvfs
);
2412 err
= secpolicy_fs_config(cr
, vfsp
);
2416 if ((mop
= vfs_hasopt(&vfsp
->vfs_mntopts
, tag
)) == NULL
) {
2420 if ((mop
->mo_flags
& MO_TAG
) == 0) {
2424 vfs_clearmntopt_nolock(&vfsp
->vfs_mntopts
, tag
, 1);
2431 * Function to parse an option string and fill in a mount options table.
2432 * Unknown options are silently ignored. The input option string is modified
2433 * by replacing separators with nulls. If the create flag is set, options
2434 * not found in the table are just added on the fly. The table must have
2435 * an option slot marked MO_EMPTY to add an option on the fly.
2437 * This function is *not* for general use by filesystems.
2439 * Note: caller is responsible for locking the vfs list, if needed,
2443 vfs_parsemntopts(mntopts_t
*mops
, char *osp
, int create
)
2445 char *s
= osp
, *p
, *nextop
, *valp
, *cp
, *ep
;
2446 int setflg
= VFS_NOFORCEOPT
;
2450 while (*s
!= '\0') {
2451 p
= strchr(s
, ','); /* find next option */
2456 cp
= p
; /* save location of comma */
2457 *p
++ = '\0'; /* mark end and point to next option */
2460 p
= strchr(s
, '='); /* look for value */
2462 valp
= NULL
; /* no value supplied */
2464 ep
= p
; /* save location of equals */
2465 *p
++ = '\0'; /* end option and point to value */
2469 * set option into options table
2472 setflg
|= VFS_CREATEOPT
;
2473 vfs_setmntopt_nolock(mops
, s
, valp
, setflg
, 0);
2475 *cp
= ','; /* restore the comma */
2477 *ep
= '='; /* restore the equals */
2483 * Function to inquire if an option exists in a mount options table.
2484 * Returns a pointer to the option if it exists, else NULL.
2486 * This function is *not* for general use by filesystems.
2488 * Note: caller is responsible for locking the vfs list, if needed,
2492 vfs_hasopt(const mntopts_t
*mops
, const char *opt
)
2497 count
= mops
->mo_count
;
2498 for (i
= 0; i
< count
; i
++) {
2499 mop
= &mops
->mo_list
[i
];
2501 if (mop
->mo_flags
& MO_EMPTY
)
2503 if (strcmp(opt
, mop
->mo_name
) == 0)
2510 * Function to inquire if an option is set in a mount options table.
2511 * Returns non-zero if set and fills in the arg pointer with a pointer to
2512 * the argument string or NULL if there is no argument string.
2515 vfs_optionisset_nolock(const mntopts_t
*mops
, const char *opt
, char **argp
)
2520 count
= mops
->mo_count
;
2521 for (i
= 0; i
< count
; i
++) {
2522 mop
= &mops
->mo_list
[i
];
2524 if (mop
->mo_flags
& MO_EMPTY
)
2526 if (strcmp(opt
, mop
->mo_name
))
2528 if ((mop
->mo_flags
& MO_SET
) == 0)
2530 if (argp
!= NULL
&& (mop
->mo_flags
& MO_HASVALUE
) != 0)
2531 *argp
= mop
->mo_arg
;
2539 vfs_optionisset(const struct vfs
*vfsp
, const char *opt
, char **argp
)
2543 vfs_list_read_lock();
2544 ret
= vfs_optionisset_nolock(&vfsp
->vfs_mntopts
, opt
, argp
);
2551 * Construct a comma separated string of the options set in the given
2552 * mount table, return the string in the given buffer. Return non-zero if
2553 * the buffer would overflow.
2555 * This function is *not* for general use by filesystems.
2557 * Note: caller is responsible for locking the vfs list, if needed,
2561 vfs_buildoptionstr(const mntopts_t
*mp
, char *buf
, int len
)
2568 for (i
= 0; i
< mp
->mo_count
; i
++) {
2571 mop
= &mp
->mo_list
[i
];
2572 if (mop
->mo_flags
& MO_SET
) {
2573 int optlen
, comma
= 0;
2577 optlen
= strlen(mop
->mo_name
);
2578 if (strlen(buf
) + comma
+ optlen
+ 1 > len
)
2582 (void) strcpy(cp
, mop
->mo_name
);
2585 * Append option value if there is one
2587 if (mop
->mo_arg
!= NULL
) {
2590 arglen
= strlen(mop
->mo_arg
);
2591 if (strlen(buf
) + arglen
+ 2 > len
)
2594 (void) strcpy(cp
, mop
->mo_arg
);
2605 vfs_freecancelopt(char **moc
)
2611 for (cp
= moc
; *cp
!= NULL
; cp
++) {
2612 kmem_free(*cp
, strlen(*cp
) + 1);
2615 kmem_free(moc
, (ccnt
+ 1) * sizeof (char *));
2620 vfs_freeopt(mntopt_t
*mop
)
2622 if (mop
->mo_name
!= NULL
)
2623 kmem_free(mop
->mo_name
, strlen(mop
->mo_name
) + 1);
2625 vfs_freecancelopt(mop
->mo_cancel
);
2627 if (mop
->mo_arg
!= NULL
)
2628 kmem_free(mop
->mo_arg
, strlen(mop
->mo_arg
) + 1);
2632 * Free a mount options table
2634 * This function is *not* for general use by filesystems.
2636 * Note: caller is responsible for locking the vfs list, if needed,
2640 vfs_freeopttbl(mntopts_t
*mp
)
2644 count
= mp
->mo_count
;
2645 for (i
= 0; i
< count
; i
++) {
2646 vfs_freeopt(&mp
->mo_list
[i
]);
2649 kmem_free(mp
->mo_list
, sizeof (mntopt_t
) * count
);
2658 vfs_mntdummyread(vnode_t
*vp
, uio_t
*uio
, int ioflag
, cred_t
*cred
,
2659 caller_context_t
*ct
)
2666 vfs_mntdummywrite(vnode_t
*vp
, uio_t
*uio
, int ioflag
, cred_t
*cred
,
2667 caller_context_t
*ct
)
2673 * The dummy vnode is currently used only by file events notification
2674 * module which is just interested in the timestamps.
2678 vfs_mntdummygetattr(vnode_t
*vp
, vattr_t
*vap
, int flags
, cred_t
*cr
,
2679 caller_context_t
*ct
)
2681 bzero(vap
, sizeof (vattr_t
));
2682 vap
->va_type
= VREG
;
2684 vap
->va_ctime
= vfs_mnttab_ctime
;
2686 * it is ok to just copy mtime as the time will be monotonically
2689 vap
->va_mtime
= vfs_mnttab_mtime
;
2690 vap
->va_atime
= vap
->va_mtime
;
2695 vfs_mnttabvp_setup(void)
2697 static const struct vnodeops dummyops
= {
2698 .vnop_name
= "mnttab",
2699 .vop_read
= vfs_mntdummyread
,
2700 .vop_write
= vfs_mntdummywrite
,
2701 .vop_getattr
= vfs_mntdummygetattr
,
2702 .vop_vnevent
= fs_vnevent_support
,
2707 * A global dummy vnode is allocated to represent mntfs files.
2708 * The mntfs file (/etc/mnttab) can be monitored for file events
2709 * and receive an event when mnttab changes. Dummy VOP calls
2710 * will be made on this vnode. The file events notification module
2711 * intercepts this vnode and delivers relevant events.
2713 tvp
= vn_alloc(KM_SLEEP
);
2714 tvp
->v_flag
= VNOMOUNT
|VNOMAP
|VNOSWAP
|VNOCACHE
;
2715 vn_setops(tvp
, &dummyops
);
2718 * The mnt dummy ops do not reference v_data.
2719 * No other module intercepting this vnode should either.
2720 * Just set it to point to itself.
2722 tvp
->v_data
= (caddr_t
)tvp
;
2723 tvp
->v_vfsp
= rootvfs
;
2724 vfs_mntdummyvp
= tvp
;
2728 * performs fake read/write ops
2731 vfs_mnttab_rwop(int rw
)
2737 if (vfs_mntdummyvp
== NULL
)
2740 bzero(&uio
, sizeof (uio
));
2741 bzero(&iov
, sizeof (iov
));
2746 uio
.uio_loffset
= 0;
2747 uio
.uio_segflg
= UIO_SYSSPACE
;
2750 (void) fop_write(vfs_mntdummyvp
, &uio
, 0, kcred
, NULL
);
2752 (void) fop_read(vfs_mntdummyvp
, &uio
, 0, kcred
, NULL
);
2757 * Generate a write operation.
2760 vfs_mnttab_writeop(void)
2766 * Generate a read operation.
2769 vfs_mnttab_readop(void)
2775 * Free any mnttab information recorded in the vfs struct.
2776 * The vfs must not be on the vfs list.
2779 vfs_freemnttab(struct vfs
*vfsp
)
2781 ASSERT(!VFS_ON_LIST(vfsp
));
2784 * Free device and mount point information
2786 if (vfsp
->vfs_mntpt
!= NULL
) {
2787 refstr_rele(vfsp
->vfs_mntpt
);
2788 vfsp
->vfs_mntpt
= NULL
;
2790 if (vfsp
->vfs_resource
!= NULL
) {
2791 refstr_rele(vfsp
->vfs_resource
);
2792 vfsp
->vfs_resource
= NULL
;
2795 * Now free mount options information
2797 vfs_freeopttbl(&vfsp
->vfs_mntopts
);
2801 * Return the last mnttab modification time
2804 vfs_mnttab_modtime(timespec_t
*ts
)
2806 ASSERT(RW_LOCK_HELD(&vfslist
));
2807 *ts
= vfs_mnttab_mtime
;
2811 * See if mnttab is changed
2814 vfs_mnttab_poll(timespec_t
*old
, struct pollhead
**phpp
)
2821 * Note: don't grab vfs list lock before accessing vfs_mnttab_mtime.
2822 * Can lead to deadlock against vfs_mnttab_modtimeupd(). It is safe
2823 * to not grab the vfs list lock because tv_sec is monotonically
2827 changed
= (old
->tv_nsec
!= vfs_mnttab_mtime
.tv_nsec
) ||
2828 (old
->tv_sec
!= vfs_mnttab_mtime
.tv_sec
);
2830 *phpp
= &vfs_pollhd
;
2834 /* Provide a unique and monotonically-increasing timestamp. */
2836 vfs_mono_time(timespec_t
*ts
)
2838 static volatile hrtime_t hrt
; /* The saved time. */
2839 hrtime_t newhrt
, oldhrt
; /* For effecting the CAS. */
2843 * Try gethrestime() first, but be prepared to fabricate a sensible
2844 * answer at the first sign of any trouble.
2846 gethrestime(&newts
);
2847 newhrt
= ts2hrt(&newts
);
2852 if (atomic_cas_64((uint64_t *)&hrt
, oldhrt
, newhrt
) == oldhrt
)
2859 * Update the mnttab modification time and wake up any waiters for
2863 vfs_mnttab_modtimeupd()
2865 hrtime_t oldhrt
, newhrt
;
2867 ASSERT(RW_WRITE_HELD(&vfslist
));
2868 oldhrt
= ts2hrt(&vfs_mnttab_mtime
);
2869 gethrestime(&vfs_mnttab_mtime
);
2870 newhrt
= ts2hrt(&vfs_mnttab_mtime
);
2871 if (oldhrt
== (hrtime_t
)0)
2872 vfs_mnttab_ctime
= vfs_mnttab_mtime
;
2874 * Attempt to provide unique mtime (like uniqtime but not).
2876 if (newhrt
== oldhrt
) {
2878 hrt2ts(newhrt
, &vfs_mnttab_mtime
);
2880 pollwakeup(&vfs_pollhd
, (short)POLLRDBAND
);
2881 vfs_mnttab_writeop();
2885 dounmount(struct vfs
*vfsp
, int flag
, cred_t
*cr
)
2889 extern void teardown_vopstats(vfs_t
*);
2892 * Get covered vnode. This will be NULL if the vfs is not linked
2893 * into the file system name space (i.e., domount() with MNT_NOSPICE).
2895 coveredvp
= vfsp
->vfs_vnodecovered
;
2896 ASSERT(coveredvp
== NULL
|| vn_vfswlock_held(coveredvp
));
2899 * Purge all dnlc entries for this vfs.
2901 (void) dnlc_purge_vfsp(vfsp
, 0);
2903 /* For forcible umount, skip VFS_SYNC() since it may hang */
2904 if ((flag
& MS_FORCE
) == 0)
2905 (void) VFS_SYNC(vfsp
, 0, cr
);
2908 * Lock the vfs to maintain fs status quo during unmount. This
2909 * has to be done after the sync because ufs_update tries to acquire
2912 vfs_lock_wait(vfsp
);
2914 if (error
= VFS_UNMOUNT(vfsp
, flag
, cr
)) {
2916 if (coveredvp
!= NULL
)
2917 vn_vfsunlock(coveredvp
);
2918 } else if (coveredvp
!= NULL
) {
2919 teardown_vopstats(vfsp
);
2921 * vfs_remove() will do a VN_RELE(vfsp->vfs_vnodecovered)
2922 * when it frees vfsp so we do a VN_HOLD() so we can
2923 * continue to use coveredvp afterwards.
2927 vn_vfsunlock(coveredvp
);
2930 teardown_vopstats(vfsp
);
2932 * Release the reference to vfs that is not linked
2933 * into the name space.
2943 * Vfs_unmountall() is called by uadmin() to unmount all
2944 * mounted file systems (except the root file system) during shutdown.
2945 * It follows the existing locking protocol when traversing the vfs list
2946 * to sync and unmount vfses. Even though there should be no
2947 * other thread running while the system is shutting down, it is prudent
2948 * to still follow the locking protocol.
2951 vfs_unmountall(void)
2954 struct vfs
*prev_vfsp
= NULL
;
2958 * Toss all dnlc entries now so that the per-vfs sync
2959 * and unmount operations don't have to slog through
2960 * a bunch of uninteresting vnodes over and over again.
2965 for (vfsp
= rootvfs
->vfs_prev
; vfsp
!= rootvfs
; vfsp
= prev_vfsp
) {
2966 prev_vfsp
= vfsp
->vfs_prev
;
2968 if (vfs_lock(vfsp
) != 0)
2970 error
= vn_vfswlock(vfsp
->vfs_vnodecovered
);
2977 (void) VFS_SYNC(vfsp
, SYNC_CLOSE
, CRED());
2978 (void) dounmount(vfsp
, 0, CRED());
2981 * Since we dropped the vfslist lock above we must
2982 * verify that next_vfsp still exists, else start over.
2985 for (vfsp
= rootvfs
->vfs_prev
;
2986 vfsp
!= rootvfs
; vfsp
= vfsp
->vfs_prev
)
2987 if (vfsp
== prev_vfsp
)
2989 if (vfsp
== rootvfs
&& prev_vfsp
!= rootvfs
)
2990 prev_vfsp
= rootvfs
->vfs_prev
;
2996 * Called to add an entry to the end of the vfs mount in progress list
2999 vfs_addmip(dev_t dev
, struct vfs
*vfsp
)
3003 mipp
= kmem_alloc(sizeof (struct ipmnt
), KM_SLEEP
);
3004 mipp
->mip_next
= NULL
;
3005 mipp
->mip_dev
= dev
;
3006 mipp
->mip_vfsp
= vfsp
;
3007 mutex_enter(&vfs_miplist_mutex
);
3008 if (vfs_miplist_end
!= NULL
)
3009 vfs_miplist_end
->mip_next
= mipp
;
3012 vfs_miplist_end
= mipp
;
3013 mutex_exit(&vfs_miplist_mutex
);
3017 * Called to remove an entry from the mount in progress list
3018 * Either because the mount completed or it failed.
3021 vfs_delmip(struct vfs
*vfsp
)
3023 struct ipmnt
*mipp
, *mipprev
;
3025 mutex_enter(&vfs_miplist_mutex
);
3027 for (mipp
= vfs_miplist
;
3028 mipp
&& mipp
->mip_vfsp
!= vfsp
; mipp
= mipp
->mip_next
) {
3032 return; /* shouldn't happen */
3033 if (mipp
== vfs_miplist_end
)
3034 vfs_miplist_end
= mipprev
;
3035 if (mipprev
== NULL
)
3036 vfs_miplist
= mipp
->mip_next
;
3038 mipprev
->mip_next
= mipp
->mip_next
;
3039 mutex_exit(&vfs_miplist_mutex
);
3040 kmem_free(mipp
, sizeof (struct ipmnt
));
3044 * vfs_add is called by a specific filesystem's mount routine to add
3045 * the new vfs into the vfs list/hash and to cover the mounted-on vnode.
3046 * The vfs should already have been locked by the caller.
3048 * coveredvp is NULL if this is the root.
3051 vfs_add(vnode_t
*coveredvp
, struct vfs
*vfsp
, int mflag
)
3055 ASSERT(vfs_lock_held(vfsp
));
3057 newflag
= vfsp
->vfs_flag
;
3058 if (mflag
& MS_RDONLY
)
3059 newflag
|= VFS_RDONLY
;
3061 newflag
&= ~VFS_RDONLY
;
3062 if (mflag
& MS_NOSUID
)
3063 newflag
|= (VFS_NOSETUID
|VFS_NODEVICES
);
3065 newflag
&= ~(VFS_NOSETUID
|VFS_NODEVICES
);
3066 if (mflag
& MS_NOMNTTAB
)
3067 newflag
|= VFS_NOMNTTAB
;
3069 newflag
&= ~VFS_NOMNTTAB
;
3071 if (coveredvp
!= NULL
) {
3072 ASSERT(vn_vfswlock_held(coveredvp
));
3073 coveredvp
->v_vfsmountedhere
= vfsp
;
3076 vfsp
->vfs_vnodecovered
= coveredvp
;
3077 vfsp
->vfs_flag
= newflag
;
3083 * Remove a vfs from the vfs list, null out the pointer from the
3084 * covered vnode to the vfs (v_vfsmountedhere), and null out the pointer
3085 * from the vfs to the covered vnode (vfs_vnodecovered). Release the
3086 * reference to the vfs and to the covered vnode.
3088 * Called from dounmount after it's confirmed with the file system
3089 * that the unmount is legal.
3092 vfs_remove(struct vfs
*vfsp
)
3096 ASSERT(vfs_lock_held(vfsp
));
3099 * Can't unmount root. Should never happen because fs will
3102 if (vfsp
== rootvfs
)
3103 panic("vfs_remove: unmounting root");
3105 vfs_list_remove(vfsp
);
3108 * Unhook from the file system name space.
3110 vp
= vfsp
->vfs_vnodecovered
;
3111 ASSERT(vn_vfswlock_held(vp
));
3112 vp
->v_vfsmountedhere
= NULL
;
3113 vfsp
->vfs_vnodecovered
= NULL
;
3117 * Release lock and wakeup anybody waiting.
3124 * Lock a filesystem to prevent access to it while mounting,
3125 * unmounting and syncing. Return EBUSY immediately if lock
3126 * can't be acquired.
3129 vfs_lock(vfs_t
*vfsp
)
3131 vn_vfslocks_entry_t
*vpvfsentry
;
3133 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3134 if (rwst_tryenter(&vpvfsentry
->ve_lock
, RW_WRITER
))
3137 vn_vfslocks_rele(vpvfsentry
);
3142 vfs_rlock(vfs_t
*vfsp
)
3144 vn_vfslocks_entry_t
*vpvfsentry
;
3146 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3148 if (rwst_tryenter(&vpvfsentry
->ve_lock
, RW_READER
))
3151 vn_vfslocks_rele(vpvfsentry
);
3156 vfs_lock_wait(vfs_t
*vfsp
)
3158 vn_vfslocks_entry_t
*vpvfsentry
;
3160 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3161 rwst_enter(&vpvfsentry
->ve_lock
, RW_WRITER
);
3165 vfs_rlock_wait(vfs_t
*vfsp
)
3167 vn_vfslocks_entry_t
*vpvfsentry
;
3169 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3170 rwst_enter(&vpvfsentry
->ve_lock
, RW_READER
);
3174 * Unlock a locked filesystem.
3177 vfs_unlock(vfs_t
*vfsp
)
3179 vn_vfslocks_entry_t
*vpvfsentry
;
3182 * vfs_unlock will mimic sema_v behaviour to fix 4748018.
3183 * And these changes should remain for the patch changes as it is.
3189 * ve_refcount needs to be dropped twice here.
3190 * 1. To release refernce after a call to vfs_locks_getlock()
3191 * 2. To release the reference from the locking routines like
3192 * vfs_rlock_wait/vfs_wlock_wait/vfs_wlock etc,.
3195 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3196 vn_vfslocks_rele(vpvfsentry
);
3198 rwst_exit(&vpvfsentry
->ve_lock
);
3199 vn_vfslocks_rele(vpvfsentry
);
3203 * Utility routine that allows a filesystem to construct its
3204 * fsid in "the usual way" - by munging some underlying dev_t and
3205 * the filesystem type number into the 64-bit fsid. Note that
3206 * this implicitly relies on dev_t persistence to make filesystem
3209 * There's nothing to prevent an individual fs from constructing its
3210 * fsid in a different way, and indeed they should.
3212 * Since we want fsids to be 32-bit quantities (so that they can be
3213 * exported identically by either 32-bit or 64-bit APIs, as well as
3214 * the fact that fsid's are "known" to NFS), we compress the device
3215 * number given down to 32-bits, and panic if that isn't possible.
3218 vfs_make_fsid(fsid_t
*fsi
, dev_t dev
, int val
)
3220 if (!cmpldev((dev32_t
*)&fsi
->val
[0], dev
))
3221 panic("device number too big for fsid!");
3226 vfs_lock_held(vfs_t
*vfsp
)
3229 vn_vfslocks_entry_t
*vpvfsentry
;
3232 * vfs_lock_held will mimic sema_held behaviour
3233 * if panicstr is set. And these changes should remain
3234 * for the patch changes as it is.
3239 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3240 held
= rwst_lock_held(&vpvfsentry
->ve_lock
, RW_WRITER
);
3242 vn_vfslocks_rele(vpvfsentry
);
3247 vfs_lock_owner(vfs_t
*vfsp
)
3249 struct _kthread
*owner
;
3250 vn_vfslocks_entry_t
*vpvfsentry
;
3253 * vfs_wlock_held will mimic sema_held behaviour
3254 * if panicstr is set. And these changes should remain
3255 * for the patch changes as it is.
3260 vpvfsentry
= vn_vfslocks_getlock(vfsp
);
3261 owner
= rwst_owner(&vpvfsentry
->ve_lock
);
3263 vn_vfslocks_rele(vpvfsentry
);
3270 * Rather than manipulate the vfslist lock directly, we abstract into lock
3271 * and unlock routines to allow the locking implementation to be changed for
3274 * Whenever the vfs list is modified through its hash links, the overall list
3275 * lock must be obtained before locking the relevant hash bucket. But to see
3276 * whether a given vfs is on the list, it suffices to obtain the lock for the
3277 * hash bucket without getting the overall list lock. (See getvfs() below.)
3283 rw_enter(&vfslist
, RW_WRITER
);
3287 vfs_list_read_lock()
3289 rw_enter(&vfslist
, RW_READER
);
3299 * Low level worker routines for adding entries to and removing entries from
3304 vfs_hash_add(struct vfs
*vfsp
, int insert_at_head
)
3310 ASSERT(RW_WRITE_HELD(&vfslist
));
3312 dev
= expldev(vfsp
->vfs_fsid
.val
[0]);
3313 vhno
= VFSHASH(getmajor(dev
), getminor(dev
));
3315 mutex_enter(&rvfs_list
[vhno
].rvfs_lock
);
3318 * Link into the hash table, inserting it at the end, so that LOFS
3319 * with the same fsid as UFS (or other) file systems will not hide the
3322 if (insert_at_head
) {
3323 vfsp
->vfs_hash
= rvfs_list
[vhno
].rvfs_head
;
3324 rvfs_list
[vhno
].rvfs_head
= vfsp
;
3326 for (hp
= &rvfs_list
[vhno
].rvfs_head
; *hp
!= NULL
;
3327 hp
= &(*hp
)->vfs_hash
)
3330 * hp now contains the address of the pointer to update
3331 * to effect the insertion.
3333 vfsp
->vfs_hash
= NULL
;
3337 rvfs_list
[vhno
].rvfs_len
++;
3338 mutex_exit(&rvfs_list
[vhno
].rvfs_lock
);
3343 vfs_hash_remove(struct vfs
*vfsp
)
3349 ASSERT(RW_WRITE_HELD(&vfslist
));
3351 dev
= expldev(vfsp
->vfs_fsid
.val
[0]);
3352 vhno
= VFSHASH(getmajor(dev
), getminor(dev
));
3354 mutex_enter(&rvfs_list
[vhno
].rvfs_lock
);
3359 if (rvfs_list
[vhno
].rvfs_head
== vfsp
) {
3360 rvfs_list
[vhno
].rvfs_head
= vfsp
->vfs_hash
;
3361 rvfs_list
[vhno
].rvfs_len
--;
3364 for (tvfsp
= rvfs_list
[vhno
].rvfs_head
; tvfsp
!= NULL
;
3365 tvfsp
= tvfsp
->vfs_hash
) {
3366 if (tvfsp
->vfs_hash
== vfsp
) {
3367 tvfsp
->vfs_hash
= vfsp
->vfs_hash
;
3368 rvfs_list
[vhno
].rvfs_len
--;
3372 cmn_err(CE_WARN
, "vfs_list_remove: vfs not found in hash");
3376 mutex_exit(&rvfs_list
[vhno
].rvfs_lock
);
3381 vfs_list_add(struct vfs
*vfsp
)
3386 * Typically, the vfs_t will have been created on behalf of the file
3387 * system in vfs_init, where it will have been provided with a
3388 * vfs_impl_t. This, however, might be lacking if the vfs_t was created
3389 * by an unbundled file system. We therefore check for such an example
3390 * before stamping the vfs_t with its creation time for the benefit of
3393 if (vfsp
->vfs_implp
== NULL
)
3394 vfsimpl_setup(vfsp
);
3395 vfs_mono_time(&vfsp
->vfs_hrctime
);
3398 * The zone that owns the mount is the one that performed the mount.
3399 * Note that this isn't necessarily the same as the zone mounted into.
3400 * The corresponding zone_rele_ref() will be done when the vfs_t
3403 vfsp
->vfs_zone
= curproc
->p_zone
;
3404 zone_init_ref(&vfsp
->vfs_implp
->vi_zone_ref
);
3405 zone_hold_ref(vfsp
->vfs_zone
, &vfsp
->vfs_implp
->vi_zone_ref
,
3409 * Find the zone mounted into, and put this mount on its vfs list.
3411 zone
= zone_find_by_path(refstr_value(vfsp
->vfs_mntpt
));
3412 ASSERT(zone
!= NULL
);
3414 * Special casing for the root vfs. This structure is allocated
3415 * statically and hooked onto rootvfs at link time. During the
3416 * vfs_mountroot call at system startup time, the root file system's
3417 * VFS_MOUNTROOT routine will call vfs_add with this root vfs struct
3418 * as argument. The code below must detect and handle this special
3419 * case. The only apparent justification for this special casing is
3420 * to ensure that the root file system appears at the head of the
3423 * XXX: I'm assuming that it's ok to do normal list locking when
3424 * adding the entry for the root file system (this used to be
3425 * done with no locks held).
3429 * Link into the vfs list proper.
3431 if (vfsp
== &root
) {
3433 * Assert: This vfs is already on the list as its first entry.
3434 * Thus, there's nothing to do.
3436 ASSERT(rootvfs
== vfsp
);
3438 * Add it to the head of the global zone's vfslist.
3440 ASSERT(zone
== global_zone
);
3441 ASSERT(zone
->zone_vfslist
== NULL
);
3442 zone
->zone_vfslist
= vfsp
;
3445 * Link to end of list using vfs_prev (as rootvfs is now a
3446 * doubly linked circular list) so list is in mount order for
3449 rootvfs
->vfs_prev
->vfs_next
= vfsp
;
3450 vfsp
->vfs_prev
= rootvfs
->vfs_prev
;
3451 rootvfs
->vfs_prev
= vfsp
;
3452 vfsp
->vfs_next
= rootvfs
;
3455 * Do it again for the zone-private list (which may be NULL).
3457 if (zone
->zone_vfslist
== NULL
) {
3458 ASSERT(zone
!= global_zone
);
3459 zone
->zone_vfslist
= vfsp
;
3461 zone
->zone_vfslist
->vfs_zone_prev
->vfs_zone_next
= vfsp
;
3462 vfsp
->vfs_zone_prev
= zone
->zone_vfslist
->vfs_zone_prev
;
3463 zone
->zone_vfslist
->vfs_zone_prev
= vfsp
;
3464 vfsp
->vfs_zone_next
= zone
->zone_vfslist
;
3469 * Link into the hash table, inserting it at the end, so that LOFS
3470 * with the same fsid as UFS (or other) file systems will not hide
3473 vfs_hash_add(vfsp
, 0);
3476 * update the mnttab modification time
3478 vfs_mnttab_modtimeupd();
3484 vfs_list_remove(struct vfs
*vfsp
)
3488 zone
= zone_find_by_path(refstr_value(vfsp
->vfs_mntpt
));
3489 ASSERT(zone
!= NULL
);
3491 * Callers are responsible for preventing attempts to unmount the
3494 ASSERT(vfsp
!= rootvfs
);
3501 vfs_hash_remove(vfsp
);
3504 * Remove from vfs list.
3506 vfsp
->vfs_prev
->vfs_next
= vfsp
->vfs_next
;
3507 vfsp
->vfs_next
->vfs_prev
= vfsp
->vfs_prev
;
3508 vfsp
->vfs_next
= vfsp
->vfs_prev
= NULL
;
3511 * Remove from zone-specific vfs list.
3513 if (zone
->zone_vfslist
== vfsp
)
3514 zone
->zone_vfslist
= vfsp
->vfs_zone_next
;
3516 if (vfsp
->vfs_zone_next
== vfsp
) {
3517 ASSERT(vfsp
->vfs_zone_prev
== vfsp
);
3518 ASSERT(zone
->zone_vfslist
== vfsp
);
3519 zone
->zone_vfslist
= NULL
;
3522 vfsp
->vfs_zone_prev
->vfs_zone_next
= vfsp
->vfs_zone_next
;
3523 vfsp
->vfs_zone_next
->vfs_zone_prev
= vfsp
->vfs_zone_prev
;
3524 vfsp
->vfs_zone_next
= vfsp
->vfs_zone_prev
= NULL
;
3527 * update the mnttab modification time
3529 vfs_mnttab_modtimeupd();
3535 getvfs(fsid_t
*fsid
)
3538 int val0
= fsid
->val
[0];
3539 int val1
= fsid
->val
[1];
3540 dev_t dev
= expldev(val0
);
3541 int vhno
= VFSHASH(getmajor(dev
), getminor(dev
));
3542 kmutex_t
*hmp
= &rvfs_list
[vhno
].rvfs_lock
;
3545 for (vfsp
= rvfs_list
[vhno
].rvfs_head
; vfsp
; vfsp
= vfsp
->vfs_hash
) {
3546 if (vfsp
->vfs_fsid
.val
[0] == val0
&&
3547 vfsp
->vfs_fsid
.val
[1] == val1
) {
3558 * Search the vfs mount in progress list for a specified device/vfs entry.
3559 * Returns 0 if the first entry in the list that the device matches has the
3560 * given vfs pointer as well. If the device matches but a different vfs
3561 * pointer is encountered in the list before the given vfs pointer then
3566 vfs_devmounting(dev_t dev
, struct vfs
*vfsp
)
3571 mutex_enter(&vfs_miplist_mutex
);
3572 for (mipp
= vfs_miplist
; mipp
!= NULL
; mipp
= mipp
->mip_next
) {
3573 if (mipp
->mip_dev
== dev
) {
3574 if (mipp
->mip_vfsp
!= vfsp
)
3579 mutex_exit(&vfs_miplist_mutex
);
3584 * Search the vfs list for a specified device. Returns 1, if entry is found
3585 * or 0 if no suitable entry is found.
3589 vfs_devismounted(dev_t dev
)
3594 vfs_list_read_lock();
3598 if (vfsp
->vfs_dev
== dev
) {
3602 vfsp
= vfsp
->vfs_next
;
3603 } while (vfsp
!= rootvfs
);
3610 * Search the vfs list for a specified device. Returns a pointer to it
3611 * or NULL if no suitable entry is found. The caller of this routine
3612 * is responsible for releasing the returned vfs pointer.
3615 vfs_dev2vfsp(dev_t dev
)
3620 vfs_list_read_lock();
3625 * The following could be made more efficient by making
3626 * the entire loop use vfs_zone_next if the call is from
3627 * a zone. The only callers, however, ustat(2) and
3628 * umount2(2), don't seem to justify the added
3629 * complexity at present.
3631 if (vfsp
->vfs_dev
== dev
&&
3632 ZONE_PATH_VISIBLE(refstr_value(vfsp
->vfs_mntpt
),
3638 vfsp
= vfsp
->vfs_next
;
3639 } while (vfsp
!= rootvfs
);
3641 return (found
? vfsp
: NULL
);
3645 * Search the vfs list for a specified mntpoint. Returns a pointer to it
3646 * or NULL if no suitable entry is found. The caller of this routine
3647 * is responsible for releasing the returned vfs pointer.
3649 * Note that if multiple mntpoints match, the last one matching is
3650 * returned in an attempt to return the "top" mount when overlay
3651 * mounts are covering the same mount point. This is accomplished by starting
3652 * at the end of the list and working our way backwards, stopping at the first
3656 vfs_mntpoint2vfsp(const char *mp
)
3659 struct vfs
*retvfsp
= NULL
;
3660 zone_t
*zone
= curproc
->p_zone
;
3663 vfs_list_read_lock();
3664 if (getzoneid() == GLOBAL_ZONEID
) {
3666 * The global zone may see filesystems in any zone.
3668 vfsp
= rootvfs
->vfs_prev
;
3670 if (strcmp(refstr_value(vfsp
->vfs_mntpt
), mp
) == 0) {
3674 vfsp
= vfsp
->vfs_prev
;
3675 } while (vfsp
!= rootvfs
->vfs_prev
);
3676 } else if ((list
= zone
->zone_vfslist
) != NULL
) {
3679 vfsp
= list
->vfs_zone_prev
;
3681 mntpt
= refstr_value(vfsp
->vfs_mntpt
);
3682 mntpt
= ZONE_PATH_TRANSLATE(mntpt
, zone
);
3683 if (strcmp(mntpt
, mp
) == 0) {
3687 vfsp
= vfsp
->vfs_zone_prev
;
3688 } while (vfsp
!= list
->vfs_zone_prev
);
3697 * Search the vfs list for a specified vfsops.
3698 * if vfs entry is found then return 1, else 0.
3701 vfs_opsinuse(const struct vfsops
*ops
)
3706 vfs_list_read_lock();
3710 if (vfs_getops(vfsp
) == ops
) {
3714 vfsp
= vfsp
->vfs_next
;
3715 } while (vfsp
!= rootvfs
);
3721 * Allocate an entry in vfssw for a file system type
3724 allocate_vfssw(const char *type
)
3728 if (type
[0] == '\0' || strlen(type
) + 1 > _ST_FSTYPSZ
) {
3730 * The vfssw table uses the empty string to identify an
3731 * available entry; we cannot add any type which has
3732 * a leading NUL. The string length is limited to
3733 * the size of the st_fstype array in struct stat.
3738 ASSERT(VFSSW_WRITE_LOCKED());
3739 for (vswp
= &vfssw
[1]; vswp
< &vfssw
[nfstype
]; vswp
++)
3740 if (!ALLOCATED_VFSSW(vswp
)) {
3741 vswp
->vsw_name
= kmem_alloc(strlen(type
) + 1, KM_SLEEP
);
3742 (void) strcpy(vswp
->vsw_name
, type
);
3743 ASSERT(vswp
->vsw_count
== 0);
3744 vswp
->vsw_count
= 1;
3745 mutex_init(&vswp
->vsw_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
3752 * Impose additional layer of translation between vfstype names
3753 * and module names in the filesystem.
3756 vfs_to_modname(const char *vfstype
)
3758 if (strcmp(vfstype
, "proc") == 0) {
3760 } else if (strcmp(vfstype
, "fd") == 0) {
3762 } else if (strncmp(vfstype
, "nfs", 3) == 0) {
3770 * Find a vfssw entry given a file system type name.
3771 * Try to autoload the filesystem if it's not found.
3772 * If it's installed, return the vfssw locked to prevent unloading.
3775 vfs_getvfssw(const char *type
)
3778 const char *modname
;
3781 vswp
= vfs_getvfsswbyname(type
);
3782 modname
= vfs_to_modname(type
);
3784 if (rootdir
== NULL
) {
3786 * If we haven't yet loaded the root file system, then our
3787 * _init won't be called until later. Allocate vfssw entry,
3788 * because mod_installfs won't be called.
3793 if ((vswp
= vfs_getvfsswbyname(type
)) == NULL
) {
3794 if ((vswp
= allocate_vfssw(type
)) == NULL
) {
3802 if (!VFS_INSTALLED(vswp
)) {
3804 (void) modloadonly("fs", modname
);
3811 * Try to load the filesystem. Before calling modload(), we drop
3812 * our lock on the VFS switch table, and pick it up after the
3813 * module is loaded. However, there is a potential race: the
3814 * module could be unloaded after the call to modload() completes
3815 * but before we pick up the lock and drive on. Therefore,
3816 * we keep reloading the module until we've loaded the module
3817 * _and_ we have the lock on the VFS switch table.
3819 while (vswp
== NULL
|| !VFS_INSTALLED(vswp
)) {
3821 if (modload("fs", modname
) == -1)
3825 if ((vswp
= vfs_getvfsswbyname(type
)) == NULL
)
3834 * Find a vfssw entry given a file system type name.
3837 vfs_getvfsswbyname(const char *type
)
3841 ASSERT(VFSSW_LOCKED());
3842 if (type
== NULL
|| *type
== '\0')
3845 for (vswp
= &vfssw
[1]; vswp
< &vfssw
[nfstype
]; vswp
++) {
3846 if (strcmp(type
, vswp
->vsw_name
) == 0) {
3856 * Find a vfssw entry given a set of vfsops.
3859 vfs_getvfsswbyvfsops(const struct vfsops
*ops
)
3864 for (vswp
= &vfssw
[1]; vswp
< &vfssw
[nfstype
]; vswp
++) {
3865 if (ALLOCATED_VFSSW(vswp
) && &vswp
->vsw_vfsops
== ops
) {
3877 * Reference a vfssw entry.
3880 vfs_refvfssw(struct vfssw
*vswp
)
3883 mutex_enter(&vswp
->vsw_lock
);
3885 mutex_exit(&vswp
->vsw_lock
);
3889 * Unreference a vfssw entry.
3892 vfs_unrefvfssw(struct vfssw
*vswp
)
3895 mutex_enter(&vswp
->vsw_lock
);
3897 mutex_exit(&vswp
->vsw_lock
);
3900 static int sync_retries
= 20; /* number of retries when not making progress */
3901 static int sync_triesleft
; /* portion of sync_retries remaining */
3903 static pgcnt_t old_pgcnt
, new_pgcnt
;
3904 static int new_bufcnt
, old_bufcnt
;
3907 * Sync all of the mounted filesystems, and then wait for the actual i/o to
3908 * complete. We wait by counting the number of dirty pages and buffers,
3909 * pushing them out using bio_busy() and page_busy(), and then counting again.
3910 * This routine is used during the uadmin A_SHUTDOWN code. It should only
3911 * be used after some higher-level mechanism has quiesced the system so that
3912 * new writes are not being initiated while we are waiting for completion.
3914 * To ensure finite running time, our algorithm uses sync_triesleft (a progress
3915 * counter used by the vfs_syncall() loop below). It is declared above so
3916 * it can be found easily in the debugger.
3918 * The sync_triesleft counter is updated by vfs_syncall() itself. If we make
3919 * sync_retries consecutive calls to bio_busy() and page_busy() without
3920 * decreasing either the number of dirty buffers or dirty pages below the
3921 * lowest count we have seen so far, we give up and return from vfs_syncall().
3923 * Each loop iteration ends with a call to delay() one second to allow time for
3924 * i/o completion and to permit the user time to read our progress messages.
3929 if (rootdir
== NULL
&& !modrootloaded
)
3930 return; /* no filesystems have been loaded yet */
3932 printf("syncing file systems...");
3935 sync_triesleft
= sync_retries
;
3937 old_bufcnt
= new_bufcnt
= INT_MAX
;
3938 old_pgcnt
= new_pgcnt
= ULONG_MAX
;
3940 while (sync_triesleft
> 0) {
3941 old_bufcnt
= MIN(old_bufcnt
, new_bufcnt
);
3942 old_pgcnt
= MIN(old_pgcnt
, new_pgcnt
);
3944 new_bufcnt
= bio_busy(B_TRUE
);
3945 new_pgcnt
= page_busy(B_TRUE
);
3947 if (new_bufcnt
== 0 && new_pgcnt
== 0)
3950 if (new_bufcnt
< old_bufcnt
|| new_pgcnt
< old_pgcnt
)
3951 sync_triesleft
= sync_retries
;
3956 printf(" [%d]", new_bufcnt
);
3958 printf(" %lu", new_pgcnt
);
3963 if (new_bufcnt
!= 0 || new_pgcnt
!= 0)
3964 printf(" done (not all i/o completed)\n");
3972 * Map VFS flags to statvfs flags. These shouldn't really be separate
3976 vf_to_stf(uint_t vf
)
3980 if (vf
& VFS_RDONLY
)
3982 if (vf
& VFS_NOSETUID
)
3984 if (vf
& VFS_NOTRUNC
)
3991 * Entries for (illegal) fstype 0.
3995 vfsstray_sync(struct vfs
*vfsp
, short arg
, struct cred
*cr
)
3997 cmn_err(CE_PANIC
, "stray vfs operation");
4002 * Entries for (illegal) fstype 0.
4007 cmn_err(CE_PANIC
, "stray vfs operation");
4012 * Support for dealing with forced UFS unmount and its interaction with
4013 * LOFS. Could be used by any filesystem.
4023 * We've gotta define the op for sync separately, since the compiler gets
4024 * confused if we mix and match ANSI and normal style prototypes when
4025 * a "short" argument is present and spits out a warning.
4029 vfs_EIO_sync(struct vfs
*vfsp
, short arg
, struct cred
*cr
)
4036 const struct vfsops EIO_vfsops
= {
4037 .vfs_mount
= (void *) vfs_EIO
,
4038 .vfs_unmount
= (void *) vfs_EIO
,
4039 .vfs_root
= (void *) vfs_EIO
,
4040 .vfs_statvfs
= (void *) vfs_EIO
,
4041 .vfs_sync
= (void *) vfs_EIO_sync
,
4042 .vfs_vget
= (void *) vfs_EIO
,
4043 .vfs_mountroot
= (void *) vfs_EIO
,
4044 .vfs_freevfs
= (void *) vfs_EIO
,
4045 .vfs_vnstate
= (void *) vfs_EIO
,
4048 static const struct vfsops stray_vfsops
= {
4049 .vfs_mount
= (void *) vfsstray
,
4050 .vfs_unmount
= (void *) vfsstray
,
4051 .vfs_root
= (void *) vfsstray
,
4052 .vfs_statvfs
= (void *) vfsstray
,
4053 .vfs_sync
= (void *) vfsstray_sync
,
4054 .vfs_vget
= (void *) vfsstray
,
4055 .vfs_mountroot
= (void *) vfsstray
,
4056 .vfs_freevfs
= (void *) vfsstray
,
4057 .vfs_vnstate
= (void *) vfsstray
,
4061 * Called from startup() to initialize all loaded vfs's
4068 extern int vopstats_enabled
;
4069 extern void vopstats_startup();
4071 /* Create vfs cache */
4072 vfs_cache
= kmem_cache_create("vfs_cache", sizeof (struct vfs
),
4073 sizeof (uintptr_t), NULL
, NULL
, NULL
, NULL
, NULL
, 0);
4075 /* Initialize the vnode cache (file systems may use it during init). */
4078 /* Setup event monitor framework */
4081 /* Initialize the dummy stray file system type. */
4082 error
= vfs_setfsops(0, &stray_vfsops
);
4084 VFS_INIT(&EIO_vfs
, &EIO_vfsops
, NULL
);
4087 * Default EIO_vfs.vfs_flag to VFS_UNMOUNTED so a lookup
4088 * on this vfs can immediately notice it's invalid.
4090 EIO_vfs
.vfs_flag
|= VFS_UNMOUNTED
;
4093 * Call the init routines of non-loadable filesystems only.
4094 * Filesystems which are loaded as separate modules will be
4095 * initialized by the module loading code instead.
4098 for (vswp
= &vfssw
[1]; vswp
< &vfssw
[nfstype
]; vswp
++) {
4100 if (vswp
->vsw_init
!= NULL
)
4101 (*vswp
->vsw_init
)(vswp
- vfssw
, vswp
->vsw_name
);
4107 if (vopstats_enabled
) {
4108 /* EIO_vfs can collect stats, but we don't retrieve them */
4109 initialize_vopstats(&EIO_vfs
.vfs_vopstats
);
4110 EIO_vfs
.vfs_fstypevsp
= NULL
;
4111 EIO_vfs
.vfs_vskap
= NULL
;
4112 EIO_vfs
.vfs_flag
|= VFS_STATS
;
4117 reparse_point_init();
4121 vfs_alloc(int kmflag
)
4125 vfsp
= kmem_cache_alloc(vfs_cache
, kmflag
);
4128 * Do the simplest initialization here.
4129 * Everything else gets done in vfs_init()
4131 bzero(vfsp
, sizeof (vfs_t
));
4136 vfs_free(vfs_t
*vfsp
)
4139 * One would be tempted to assert that "vfsp->vfs_count == 0".
4140 * The problem is that this gets called out of domount() with
4141 * a partially initialized vfs and a vfs_count of 1. This is
4142 * also called from vfs_rele() with a vfs_count of 0. We can't
4143 * call VFS_RELE() from domount() if VFS_MOUNT() hasn't successfully
4144 * returned. This is because VFS_MOUNT() fully initializes the
4145 * vfs structure and its associated data. VFS_RELE() will call
4146 * VFS_FREEVFS() which may panic the system if the data structures
4147 * aren't fully initialized from a successful VFS_MOUNT()).
4150 /* If FEM was in use, make sure everything gets cleaned up */
4151 if (vfsp
->vfs_femhead
) {
4152 ASSERT(vfsp
->vfs_femhead
->femh_list
== NULL
);
4153 mutex_destroy(&vfsp
->vfs_femhead
->femh_lock
);
4154 kmem_free(vfsp
->vfs_femhead
, sizeof (*(vfsp
->vfs_femhead
)));
4155 vfsp
->vfs_femhead
= NULL
;
4158 if (vfsp
->vfs_implp
)
4159 vfsimpl_teardown(vfsp
);
4160 sema_destroy(&vfsp
->vfs_reflock
);
4161 kmem_cache_free(vfs_cache
, vfsp
);
4165 * Increments the vfs reference count by one atomically.
4168 vfs_hold(vfs_t
*vfsp
)
4170 atomic_inc_32(&vfsp
->vfs_count
);
4171 ASSERT(vfsp
->vfs_count
!= 0);
4175 * Decrements the vfs reference count by one atomically. When
4176 * vfs reference count becomes zero, it calls the file system
4177 * specific vfs_freevfs() to free up the resources.
4180 vfs_rele(vfs_t
*vfsp
)
4182 ASSERT(vfsp
->vfs_count
!= 0);
4183 if (atomic_dec_32_nv(&vfsp
->vfs_count
) == 0) {
4187 zone_rele_ref(&vfsp
->vfs_implp
->vi_zone_ref
,
4189 vfs_freemnttab(vfsp
);
4196 extern int hvmboot_rootconf();
4199 extern ib_boot_prop_t
*iscsiboot_prop
;
4206 extern void pm_init();
4207 char *fstyp
, *fsmod
;
4210 getrootfs(&fstyp
, &fsmod
);
4214 * hvmboot_rootconf() is defined in the hvm_bootstrap misc module,
4215 * which lives in /platform/i86hvm, and hence is only available when
4216 * booted in an x86 hvm environment. If the hvm_bootstrap misc module
4217 * is not available then the modstub for this function will return 0.
4218 * If the hvm_bootstrap misc module is available it will be loaded
4219 * and hvmboot_rootconf() will be invoked.
4221 if (error
= hvmboot_rootconf())
4225 if (modload("fs", fsmod
) == -1)
4226 panic("Cannot _init %s module", fsmod
);
4229 vsw
= vfs_getvfsswbyname(fstyp
);
4232 cmn_err(CE_CONT
, "Cannot find %s filesystem\n", fstyp
);
4235 VFS_INIT(rootvfs
, &vsw
->vsw_vfsops
, 0);
4238 /* always mount readonly first */
4239 rootvfs
->vfs_flag
|= VFS_RDONLY
;
4243 if (netboot
&& iscsiboot_prop
) {
4244 cmn_err(CE_WARN
, "NFS boot and iSCSI boot"
4245 " shouldn't happen in the same time");
4249 if (netboot
|| iscsiboot_prop
) {
4252 cmn_err(CE_WARN
, "Cannot plumb network device %d", ret
);
4257 if ((ret
== 0) && iscsiboot_prop
) {
4258 ret
= modload("drv", "iscsi");
4259 /* -1 indicates fail */
4261 cmn_err(CE_WARN
, "Failed to load iscsi module");
4262 iscsi_boot_prop_free();
4265 if (!i_ddi_attach_pseudo_node("iscsi")) {
4267 "Failed to attach iscsi driver");
4268 iscsi_boot_prop_free();
4274 error
= VFS_MOUNTROOT(rootvfs
, ROOT_INIT
);
4275 vfs_unrefvfssw(vsw
);
4276 rootdev
= rootvfs
->vfs_dev
;
4279 cmn_err(CE_CONT
, "Cannot mount root on %s fstype %s\n",
4280 rootfs
.bo_name
, fstyp
);
4282 cmn_err(CE_CONT
, "?root on %s fstype %s\n",
4283 rootfs
.bo_name
, fstyp
);
4288 * XXX this is called by nfs only and should probably be removed
4289 * If booted with ASKNAME, prompt on the console for a filesystem
4290 * name and return it.
4293 getfsname(char *askfor
, char *name
, size_t namelen
)
4295 if (boothowto
& RB_ASKNAME
) {
4296 printf("%s name: ", askfor
);
4297 console_gets(name
, namelen
);
4302 * Init the root filesystem type (rootfs.bo_fstype) from the "fstype"
4305 * Filesystem types starting with the prefix "nfs" are diskless clients;
4306 * init the root filename name (rootfs.bo_name), too.
4308 * If we are booting via NFS we currently have these options:
4309 * nfs - dynamically choose NFS V2, V3, or V4 (default)
4310 * nfs2 - force NFS V2
4311 * nfs3 - force NFS V3
4312 * nfs4 - force NFS V4
4313 * Because we need to maintain backward compatibility with the naming
4314 * convention that the NFS V2 filesystem name is "nfs" (see vfs_conf.c)
4315 * we need to map "nfs" => "nfsdyn" and "nfs2" => "nfs". The dynamic
4316 * nfs module will map the type back to either "nfs", "nfs3", or "nfs4".
4317 * This is only for root filesystems, all other uses will expect
4318 * that "nfs" == NFS V2.
4321 getrootfs(char **fstypp
, char **fsmodp
)
4323 char *propstr
= NULL
;
4326 * Check fstype property; for diskless it should be one of "nfs",
4327 * "nfs2", "nfs3" or "nfs4".
4329 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, ddi_root_node(),
4330 DDI_PROP_DONTPASS
, "fstype", &propstr
)
4332 (void) strncpy(rootfs
.bo_fstype
, propstr
, BO_MAXFSNAME
);
4333 ddi_prop_free(propstr
);
4336 * if the boot property 'fstype' is not set, but 'zfs-bootfs' is set,
4337 * assume the type of this root filesystem is 'zfs'.
4339 } else if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, ddi_root_node(),
4340 DDI_PROP_DONTPASS
, "zfs-bootfs", &propstr
)
4342 (void) strncpy(rootfs
.bo_fstype
, "zfs", BO_MAXFSNAME
);
4343 ddi_prop_free(propstr
);
4346 if (strncmp(rootfs
.bo_fstype
, "nfs", 3) != 0) {
4347 *fstypp
= *fsmodp
= rootfs
.bo_fstype
;
4353 if (strcmp(rootfs
.bo_fstype
, "nfs2") == 0)
4354 (void) strcpy(rootfs
.bo_fstype
, "nfs");
4355 else if (strcmp(rootfs
.bo_fstype
, "nfs") == 0)
4356 (void) strcpy(rootfs
.bo_fstype
, "nfsdyn");
4359 * check if path to network interface is specified in bootpath
4360 * or by a hypervisor domain configuration file.
4361 * XXPV - enable strlumb_get_netdev_path()
4363 if (ddi_prop_exists(DDI_DEV_T_ANY
, ddi_root_node(), DDI_PROP_DONTPASS
,
4365 (void) strcpy(rootfs
.bo_name
, "/xpvd/xnf@0");
4366 } else if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, ddi_root_node(),
4367 DDI_PROP_DONTPASS
, "bootpath", &propstr
)
4369 (void) strncpy(rootfs
.bo_name
, propstr
, BO_MAXOBJNAME
);
4370 ddi_prop_free(propstr
);
4372 rootfs
.bo_name
[0] = '\0';
4374 *fstypp
= rootfs
.bo_fstype
;
4379 * VFS feature routines
4382 #define VFTINDEX(feature) (((feature) >> 32) & 0xFFFFFFFF)
4383 #define VFTBITS(feature) ((feature) & 0xFFFFFFFFLL)
4385 /* Register a feature in the vfs */
4387 vfs_set_feature(vfs_t
*vfsp
, vfs_feature_t feature
)
4389 /* Note that vfs_featureset[] is found in *vfsp->vfs_implp */
4390 if (vfsp
->vfs_implp
== NULL
)
4393 vfsp
->vfs_featureset
[VFTINDEX(feature
)] |= VFTBITS(feature
);
4397 vfs_clear_feature(vfs_t
*vfsp
, vfs_feature_t feature
)
4399 /* Note that vfs_featureset[] is found in *vfsp->vfs_implp */
4400 if (vfsp
->vfs_implp
== NULL
)
4402 vfsp
->vfs_featureset
[VFTINDEX(feature
)] &= VFTBITS(~feature
);
4406 * Query a vfs for a feature.
4407 * Returns 1 if feature is present, 0 if not
4410 vfs_has_feature(vfs_t
*vfsp
, vfs_feature_t feature
)
4414 /* Note that vfs_featureset[] is found in *vfsp->vfs_implp */
4415 if (vfsp
->vfs_implp
== NULL
)
4418 if (vfsp
->vfs_featureset
[VFTINDEX(feature
)] & VFTBITS(feature
))
4425 * Propagate feature set from one vfs to another
4428 vfs_propagate_features(vfs_t
*from
, vfs_t
*to
)
4432 if (to
->vfs_implp
== NULL
|| from
->vfs_implp
== NULL
)
4435 for (i
= 1; i
<= to
->vfs_featureset
[0]; i
++) {
4436 to
->vfs_featureset
[i
] = from
->vfs_featureset
[i
];
4440 #define LOFINODE_PATH "/dev/lofi/%d"
4443 * Return the vnode for the lofi node if there's a lofi mount in place.
4444 * Returns -1 when there's no lofi node, 0 on success, and > 0 on
4448 vfs_get_lofi(vfs_t
*vfsp
, vnode_t
**vpp
)
4454 if (vfsp
->vfs_lofi_id
== 0) {
4459 strsize
= snprintf(NULL
, 0, LOFINODE_PATH
, vfsp
->vfs_lofi_id
);
4460 path
= kmem_alloc(strsize
+ 1, KM_SLEEP
);
4461 (void) snprintf(path
, strsize
+ 1, LOFINODE_PATH
, vfsp
->vfs_lofi_id
);
4464 * We may be inside a zone, so we need to use the /dev path, but
4465 * it's created asynchronously, so we wait here.
4468 err
= lookupname(path
, UIO_SYSSPACE
, FOLLOW
, NULLVPP
, vpp
);
4473 if ((err
= delay_sig(hz
/ 8)) == EINTR
)
4480 kmem_free(path
, strsize
+ 1);