xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision 0fc6daa72d3513dbb7c5699a3eb9cee69ef4bd23)
1d167cf6fSWarner Losh /*-
2996c772fSJohn Dyson  * Copyright (c) 1992, 1993, 1995
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software donated to Berkeley by
6df8bae1dSRodney W. Grimes  * Jan-Simon Pendry.
7df8bae1dSRodney W. Grimes  *
8df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
9df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
10df8bae1dSRodney W. Grimes  * are met:
11df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
12df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
13df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
15df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
16df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
17df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
18df8bae1dSRodney W. Grimes  *    without specific prior written permission.
19df8bae1dSRodney W. Grimes  *
20df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
31df8bae1dSRodney W. Grimes  *
32df8bae1dSRodney W. Grimes  *	@(#)null_vfsops.c	8.2 (Berkeley) 1/21/94
33df8bae1dSRodney W. Grimes  *
34df8bae1dSRodney W. Grimes  * @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
35c3aac50fSPeter Wemm  * $FreeBSD$
36df8bae1dSRodney W. Grimes  */
37df8bae1dSRodney W. Grimes 
38df8bae1dSRodney W. Grimes /*
39df8bae1dSRodney W. Grimes  * Null Layer
40df8bae1dSRodney W. Grimes  * (See null_vnops.c for a description of what this does.)
41df8bae1dSRodney W. Grimes  */
42df8bae1dSRodney W. Grimes 
43df8bae1dSRodney W. Grimes #include <sys/param.h>
44df8bae1dSRodney W. Grimes #include <sys/systm.h>
4557b4252eSKonstantin Belousov #include <sys/fcntl.h>
46fdc0430eSMike Pritchard #include <sys/kernel.h>
47fb919e4dSMark Murray #include <sys/lock.h>
48a1c995b6SPoul-Henning Kamp #include <sys/malloc.h>
49df8bae1dSRodney W. Grimes #include <sys/mount.h>
50df8bae1dSRodney W. Grimes #include <sys/namei.h>
51fb919e4dSMark Murray #include <sys/proc.h>
52fb919e4dSMark Murray #include <sys/vnode.h>
53bf3db8aaSMartin Matuska #include <sys/jail.h>
54fb919e4dSMark Murray 
5599d300a1SRuslan Ermilov #include <fs/nullfs/null.h>
56df8bae1dSRodney W. Grimes 
575bb84bc8SRobert Watson static MALLOC_DEFINE(M_NULLFSMNT, "nullfs_mount", "NULLFS mount structure");
58a1c995b6SPoul-Henning Kamp 
597652131bSPoul-Henning Kamp static vfs_fhtovp_t	nullfs_fhtovp;
605e8c582aSPoul-Henning Kamp static vfs_mount_t	nullfs_mount;
617652131bSPoul-Henning Kamp static vfs_quotactl_t	nullfs_quotactl;
627652131bSPoul-Henning Kamp static vfs_root_t	nullfs_root;
637652131bSPoul-Henning Kamp static vfs_sync_t	nullfs_sync;
647652131bSPoul-Henning Kamp static vfs_statfs_t	nullfs_statfs;
657652131bSPoul-Henning Kamp static vfs_unmount_t	nullfs_unmount;
667652131bSPoul-Henning Kamp static vfs_vget_t	nullfs_vget;
677652131bSPoul-Henning Kamp static vfs_extattrctl_t	nullfs_extattrctl;
689b5e8b3aSBruce Evans 
69df8bae1dSRodney W. Grimes /*
70df8bae1dSRodney W. Grimes  * Mount null layer
71df8bae1dSRodney W. Grimes  */
72d4b7a369SPoul-Henning Kamp static int
73dfd233edSAttilio Rao nullfs_mount(struct mount *mp)
74df8bae1dSRodney W. Grimes {
75df8bae1dSRodney W. Grimes 	int error = 0;
76df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
77df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
78df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
79bf3db8aaSMartin Matuska 	struct thread *td = curthread;
809fcc512cSMaxime Henrion 	char *target;
819fcc512cSMaxime Henrion 	int isvnunlocked = 0, len;
825e8c582aSPoul-Henning Kamp 	struct nameidata nd, *ndp = &nd;
83df8bae1dSRodney W. Grimes 
848da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
85df8bae1dSRodney W. Grimes 
86bf3db8aaSMartin Matuska 	if (!prison_allow(td->td_ucred, PR_ALLOW_MOUNT_NULLFS))
87bf3db8aaSMartin Matuska 		return (EPERM);
8864042a76SPoul-Henning Kamp 	if (mp->mnt_flag & MNT_ROOTFS)
8964042a76SPoul-Henning Kamp 		return (EOPNOTSUPP);
909cf4c952SKonstantin Belousov 
91df8bae1dSRodney W. Grimes 	/*
92df8bae1dSRodney W. Grimes 	 * Update is a no-op
93df8bae1dSRodney W. Grimes 	 */
94df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
95ebbf93fdSCraig Rodrigues 		/*
96ebbf93fdSCraig Rodrigues 		 * Only support update mounts for NFS export.
97ebbf93fdSCraig Rodrigues 		 */
98ebbf93fdSCraig Rodrigues 		if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0))
99ebbf93fdSCraig Rodrigues 			return (0);
100ebbf93fdSCraig Rodrigues 		else
101df8bae1dSRodney W. Grimes 			return (EOPNOTSUPP);
102df8bae1dSRodney W. Grimes 	}
103df8bae1dSRodney W. Grimes 
104df8bae1dSRodney W. Grimes 	/*
105df8bae1dSRodney W. Grimes 	 * Get argument
106df8bae1dSRodney W. Grimes 	 */
1079fcc512cSMaxime Henrion 	error = vfs_getopt(mp->mnt_optnew, "target", (void **)&target, &len);
1089fcc512cSMaxime Henrion 	if (error || target[len - 1] != '\0')
1099fcc512cSMaxime Henrion 		return (EINVAL);
110df8bae1dSRodney W. Grimes 
111df8bae1dSRodney W. Grimes 	/*
1129ce73797SPeter Holm 	 * Unlock lower node to avoid possible deadlock.
113f85e8fc5SKATO Takenori 	 */
114aec0fb7bSPoul-Henning Kamp 	if ((mp->mnt_vnodecovered->v_op == &null_vnodeops) &&
1159ce73797SPeter Holm 	    VOP_ISLOCKED(mp->mnt_vnodecovered) == LK_EXCLUSIVE) {
11622db15c0SAttilio Rao 		VOP_UNLOCK(mp->mnt_vnodecovered, 0);
117f85e8fc5SKATO Takenori 		isvnunlocked = 1;
118f85e8fc5SKATO Takenori 	}
119f85e8fc5SKATO Takenori 	/*
120df8bae1dSRodney W. Grimes 	 * Find lower node
121df8bae1dSRodney W. Grimes 	 */
122dfd233edSAttilio Rao 	NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF, UIO_SYSSPACE, target, curthread);
1233a773ad0SPoul-Henning Kamp 	error = namei(ndp);
124d9e9650aSKonstantin Belousov 
125f85e8fc5SKATO Takenori 	/*
126f85e8fc5SKATO Takenori 	 * Re-lock vnode.
127d9e9650aSKonstantin Belousov 	 * XXXKIB This is deadlock-prone as well.
128f85e8fc5SKATO Takenori 	 */
129ffa43617SKonstantin Belousov 	if (isvnunlocked)
130cb05b60aSAttilio Rao 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY);
131f85e8fc5SKATO Takenori 
1323a773ad0SPoul-Henning Kamp 	if (error)
133df8bae1dSRodney W. Grimes 		return (error);
134762e6b85SEivind Eklund 	NDFREE(ndp, NDF_ONLY_PNBUF);
135df8bae1dSRodney W. Grimes 
136df8bae1dSRodney W. Grimes 	/*
137df8bae1dSRodney W. Grimes 	 * Sanity check on lower vnode
138df8bae1dSRodney W. Grimes 	 */
139df8bae1dSRodney W. Grimes 	lowerrootvp = ndp->ni_vp;
140df8bae1dSRodney W. Grimes 
141f85e8fc5SKATO Takenori 	/*
142f85e8fc5SKATO Takenori 	 * Check multi null mount to avoid `lock against myself' panic.
143f85e8fc5SKATO Takenori 	 */
144f85e8fc5SKATO Takenori 	if (lowerrootvp == VTONULL(mp->mnt_vnodecovered)->null_lowervp) {
1458da80660SBoris Popov 		NULLFSDEBUG("nullfs_mount: multi null mount?\n");
1466716c905SBoris Popov 		vput(lowerrootvp);
147747e9157SKATO Takenori 		return (EDEADLK);
148f85e8fc5SKATO Takenori 	}
149f85e8fc5SKATO Takenori 
150df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
1519cf4c952SKonstantin Belousov 	    M_NULLFSMNT, M_WAITOK | M_ZERO);
152df8bae1dSRodney W. Grimes 
153df8bae1dSRodney W. Grimes 	/*
154df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
155df8bae1dSRodney W. Grimes 	 */
156df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
157df8bae1dSRodney W. Grimes 
158df8bae1dSRodney W. Grimes 	/*
159df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
160df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
161df8bae1dSRodney W. Grimes 	 */
1621cfdefbbSSemen Ustimenko 	error = null_nodeget(mp, lowerrootvp, &vp);
163df8bae1dSRodney W. Grimes 	/*
164df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
165df8bae1dSRodney W. Grimes 	 */
166df8bae1dSRodney W. Grimes 	if (error) {
167dd0f9532SKonstantin Belousov 		free(xmp, M_NULLFSMNT);
168df8bae1dSRodney W. Grimes 		return (error);
169df8bae1dSRodney W. Grimes 	}
170df8bae1dSRodney W. Grimes 
171df8bae1dSRodney W. Grimes 	/*
172df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
173df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
174df8bae1dSRodney W. Grimes 	 */
175df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
176e6e370a7SJeff Roberson 	nullm_rootvp->v_vflag |= VV_ROOT;
177df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
17875cabb63SJeff Roberson 
17975cabb63SJeff Roberson 	/*
18075cabb63SJeff Roberson 	 * Unlock the node (either the lower or the alias)
18175cabb63SJeff Roberson 	 */
18222db15c0SAttilio Rao 	VOP_UNLOCK(vp, 0);
18375cabb63SJeff Roberson 
1845da56ddbSTor Egge 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL) {
1855da56ddbSTor Egge 		MNT_ILOCK(mp);
186df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
1875da56ddbSTor Egge 		MNT_IUNLOCK(mp);
1885da56ddbSTor Egge 	}
1899cf4c952SKonstantin Belousov 
1909cf4c952SKonstantin Belousov 	xmp->nullm_flags |= NULLM_CACHE;
1919cf4c952SKonstantin Belousov 	if (vfs_getopt(mp->mnt_optnew, "nocache", NULL, NULL) == 0)
1929cf4c952SKonstantin Belousov 		xmp->nullm_flags &= ~NULLM_CACHE;
1939cf4c952SKonstantin Belousov 
1945da56ddbSTor Egge 	MNT_ILOCK(mp);
1959cf4c952SKonstantin Belousov 	if ((xmp->nullm_flags & NULLM_CACHE) != 0) {
19637a1046eSKonstantin Belousov 		mp->mnt_kern_flag |= lowerrootvp->v_mount->mnt_kern_flag &
1979cf4c952SKonstantin Belousov 		    (MNTK_SHARED_WRITES | MNTK_LOOKUP_SHARED |
1989cf4c952SKonstantin Belousov 		    MNTK_EXTENDED_SHARED);
1999cf4c952SKonstantin Belousov 	}
200d9e9650aSKonstantin Belousov 	mp->mnt_kern_flag |= MNTK_LOOKUP_EXCL_DOTDOT;
2015da56ddbSTor Egge 	MNT_IUNLOCK(mp);
20277465d93SAlfred Perlstein 	mp->mnt_data = xmp;
203996c772fSJohn Dyson 	vfs_getnewfsid(mp);
2049cf4c952SKonstantin Belousov 	if ((xmp->nullm_flags & NULLM_CACHE) != 0) {
205d9e9650aSKonstantin Belousov 		MNT_ILOCK(xmp->nullm_vfs);
2069cf4c952SKonstantin Belousov 		TAILQ_INSERT_TAIL(&xmp->nullm_vfs->mnt_uppers, mp,
2079cf4c952SKonstantin Belousov 		    mnt_upper_link);
208d9e9650aSKonstantin Belousov 		MNT_IUNLOCK(xmp->nullm_vfs);
2099cf4c952SKonstantin Belousov 	}
210df8bae1dSRodney W. Grimes 
2117ab8c8c0SPoul-Henning Kamp 	vfs_mountedfrom(mp, target);
2127ab8c8c0SPoul-Henning Kamp 
2138da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount: lower %s, alias at %s\n",
214df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
215df8bae1dSRodney W. Grimes 	return (0);
216df8bae1dSRodney W. Grimes }
217df8bae1dSRodney W. Grimes 
218df8bae1dSRodney W. Grimes /*
219df8bae1dSRodney W. Grimes  * Free reference to null layer
220df8bae1dSRodney W. Grimes  */
221d4b7a369SPoul-Henning Kamp static int
222dfd233edSAttilio Rao nullfs_unmount(mp, mntflags)
223df8bae1dSRodney W. Grimes 	struct mount *mp;
224df8bae1dSRodney W. Grimes 	int mntflags;
225df8bae1dSRodney W. Grimes {
226d9e9650aSKonstantin Belousov 	struct null_mount *mntdata;
227d9e9650aSKonstantin Belousov 	struct mount *ump;
228d9e9650aSKonstantin Belousov 	int error, flags;
229df8bae1dSRodney W. Grimes 
2308da80660SBoris Popov 	NULLFSDEBUG("nullfs_unmount: mp = %p\n", (void *)mp);
231df8bae1dSRodney W. Grimes 
232996c772fSJohn Dyson 	if (mntflags & MNT_FORCE)
233d9e9650aSKonstantin Belousov 		flags = FORCECLOSE;
234d9e9650aSKonstantin Belousov 	else
235d9e9650aSKonstantin Belousov 		flags = 0;
236df8bae1dSRodney W. Grimes 
2370864ef1eSIan Dowse 	/* There is 1 extra root vnode reference (nullm_rootvp). */
238dfd233edSAttilio Rao 	error = vflush(mp, 1, flags, curthread);
2393a773ad0SPoul-Henning Kamp 	if (error)
240df8bae1dSRodney W. Grimes 		return (error);
241df8bae1dSRodney W. Grimes 
242df8bae1dSRodney W. Grimes 	/*
243df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
244df8bae1dSRodney W. Grimes 	 */
2458da80660SBoris Popov 	mntdata = mp->mnt_data;
246d9e9650aSKonstantin Belousov 	ump = mntdata->nullm_vfs;
2479cf4c952SKonstantin Belousov 	if ((mntdata->nullm_flags & NULLM_CACHE) != 0) {
248d9e9650aSKonstantin Belousov 		MNT_ILOCK(ump);
249d9e9650aSKonstantin Belousov 		while ((ump->mnt_kern_flag & MNTK_VGONE_UPPER) != 0) {
250d9e9650aSKonstantin Belousov 			ump->mnt_kern_flag |= MNTK_VGONE_WAITER;
251d9e9650aSKonstantin Belousov 			msleep(&ump->mnt_uppers, &ump->mnt_mtx, 0, "vgnupw", 0);
252d9e9650aSKonstantin Belousov 		}
253d9e9650aSKonstantin Belousov 		TAILQ_REMOVE(&ump->mnt_uppers, mp, mnt_upper_link);
254d9e9650aSKonstantin Belousov 		MNT_IUNLOCK(ump);
2559cf4c952SKonstantin Belousov 	}
25611753bd0SKevin Lo 	mp->mnt_data = NULL;
2574451405fSBoris Popov 	free(mntdata, M_NULLFSMNT);
258d9e9650aSKonstantin Belousov 	return (0);
259df8bae1dSRodney W. Grimes }
260df8bae1dSRodney W. Grimes 
261d4b7a369SPoul-Henning Kamp static int
262dfd233edSAttilio Rao nullfs_root(mp, flags, vpp)
263df8bae1dSRodney W. Grimes 	struct mount *mp;
264d9b2d9f7SJeff Roberson 	int flags;
265df8bae1dSRodney W. Grimes 	struct vnode **vpp;
266df8bae1dSRodney W. Grimes {
267df8bae1dSRodney W. Grimes 	struct vnode *vp;
268df8bae1dSRodney W. Grimes 
2698da80660SBoris Popov 	NULLFSDEBUG("nullfs_root(mp = %p, vp = %p->%p)\n", (void *)mp,
27089785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
27189785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
272df8bae1dSRodney W. Grimes 
273df8bae1dSRodney W. Grimes 	/*
274df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
275df8bae1dSRodney W. Grimes 	 */
276df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
277df8bae1dSRodney W. Grimes 	VREF(vp);
2784451405fSBoris Popov 
27917edcd76SKonstantin Belousov 	ASSERT_VOP_UNLOCKED(vp, "root vnode is locked");
280cb05b60aSAttilio Rao 	vn_lock(vp, flags | LK_RETRY);
281df8bae1dSRodney W. Grimes 	*vpp = vp;
282df8bae1dSRodney W. Grimes 	return 0;
283df8bae1dSRodney W. Grimes }
284df8bae1dSRodney W. Grimes 
285d4b7a369SPoul-Henning Kamp static int
286dfd233edSAttilio Rao nullfs_quotactl(mp, cmd, uid, arg)
287df8bae1dSRodney W. Grimes 	struct mount *mp;
288df8bae1dSRodney W. Grimes 	int cmd;
289df8bae1dSRodney W. Grimes 	uid_t uid;
2900430a5e2SDag-Erling Smørgrav 	void *arg;
291df8bae1dSRodney W. Grimes {
292dfd233edSAttilio Rao 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg);
293df8bae1dSRodney W. Grimes }
294df8bae1dSRodney W. Grimes 
295d4b7a369SPoul-Henning Kamp static int
296dfd233edSAttilio Rao nullfs_statfs(mp, sbp)
297df8bae1dSRodney W. Grimes 	struct mount *mp;
298df8bae1dSRodney W. Grimes 	struct statfs *sbp;
299df8bae1dSRodney W. Grimes {
300df8bae1dSRodney W. Grimes 	int error;
301df8bae1dSRodney W. Grimes 	struct statfs mstat;
302df8bae1dSRodney W. Grimes 
3038da80660SBoris Popov 	NULLFSDEBUG("nullfs_statfs(mp = %p, vp = %p->%p)\n", (void *)mp,
30489785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
30589785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
306df8bae1dSRodney W. Grimes 
307df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
308df8bae1dSRodney W. Grimes 
309dfd233edSAttilio Rao 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat);
310df8bae1dSRodney W. Grimes 	if (error)
311df8bae1dSRodney W. Grimes 		return (error);
312df8bae1dSRodney W. Grimes 
313df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
314df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
3156d6a91c5SJilles Tjoelker 	sbp->f_flags = (sbp->f_flags & (MNT_RDONLY | MNT_NOEXEC | MNT_NOSUID |
3166d6a91c5SJilles Tjoelker 	    MNT_UNION | MNT_NOSYMFOLLOW)) | (mstat.f_flags & ~MNT_ROOTFS);
317df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
318df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
319df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
320df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
321df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
322df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
323df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
324df8bae1dSRodney W. Grimes 	return (0);
325df8bae1dSRodney W. Grimes }
326df8bae1dSRodney W. Grimes 
327d4b7a369SPoul-Henning Kamp static int
328dfd233edSAttilio Rao nullfs_sync(mp, waitfor)
329df8bae1dSRodney W. Grimes 	struct mount *mp;
330df8bae1dSRodney W. Grimes 	int waitfor;
331df8bae1dSRodney W. Grimes {
332df8bae1dSRodney W. Grimes 	/*
333df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
334df8bae1dSRodney W. Grimes 	 */
335df8bae1dSRodney W. Grimes 	return (0);
336df8bae1dSRodney W. Grimes }
337df8bae1dSRodney W. Grimes 
338d4b7a369SPoul-Henning Kamp static int
339a0595d02SKirk McKusick nullfs_vget(mp, ino, flags, vpp)
340df8bae1dSRodney W. Grimes 	struct mount *mp;
341df8bae1dSRodney W. Grimes 	ino_t ino;
342a0595d02SKirk McKusick 	int flags;
343df8bae1dSRodney W. Grimes 	struct vnode **vpp;
344df8bae1dSRodney W. Grimes {
3454451405fSBoris Popov 	int error;
346e4e1d9f3SKonstantin Belousov 
347e4e1d9f3SKonstantin Belousov 	KASSERT((flags & LK_TYPE_MASK) != 0,
348e4e1d9f3SKonstantin Belousov 	    ("nullfs_vget: no lock requested"));
349e4e1d9f3SKonstantin Belousov 
350a0595d02SKirk McKusick 	error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, flags, vpp);
351d9e9650aSKonstantin Belousov 	if (error != 0)
3524451405fSBoris Popov 		return (error);
3531cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
354df8bae1dSRodney W. Grimes }
355df8bae1dSRodney W. Grimes 
356d4b7a369SPoul-Henning Kamp static int
357694a586aSRick Macklem nullfs_fhtovp(mp, fidp, flags, vpp)
358df8bae1dSRodney W. Grimes 	struct mount *mp;
359df8bae1dSRodney W. Grimes 	struct fid *fidp;
360694a586aSRick Macklem 	int flags;
361df8bae1dSRodney W. Grimes 	struct vnode **vpp;
362c24fda81SAlfred Perlstein {
3634451405fSBoris Popov 	int error;
364c24fda81SAlfred Perlstein 
365d9e9650aSKonstantin Belousov 	error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, flags,
366d9e9650aSKonstantin Belousov 	    vpp);
367d9e9650aSKonstantin Belousov 	if (error != 0)
368d9e9650aSKonstantin Belousov 		return (error);
3691cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
370c24fda81SAlfred Perlstein }
371c24fda81SAlfred Perlstein 
372c24fda81SAlfred Perlstein static int
373dfd233edSAttilio Rao nullfs_extattrctl(mp, cmd, filename_vp, namespace, attrname)
37491f37dcbSRobert Watson 	struct mount *mp;
37591f37dcbSRobert Watson 	int cmd;
37670f36851SRobert Watson 	struct vnode *filename_vp;
37770f36851SRobert Watson 	int namespace;
3788f073875SRobert Watson 	const char *attrname;
37991f37dcbSRobert Watson {
380d9e9650aSKonstantin Belousov 
381d9e9650aSKonstantin Belousov 	return (VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd,
382d9e9650aSKonstantin Belousov 	    filename_vp, namespace, attrname));
38391f37dcbSRobert Watson }
38491f37dcbSRobert Watson 
385d9e9650aSKonstantin Belousov static void
386d9e9650aSKonstantin Belousov nullfs_reclaim_lowervp(struct mount *mp, struct vnode *lowervp)
387d9e9650aSKonstantin Belousov {
388d9e9650aSKonstantin Belousov 	struct vnode *vp;
389d9e9650aSKonstantin Belousov 
390d9e9650aSKonstantin Belousov 	vp = null_hashget(mp, lowervp);
391d9e9650aSKonstantin Belousov 	if (vp == NULL)
392d9e9650aSKonstantin Belousov 		return;
393*0fc6daa7SKonstantin Belousov 	VTONULL(vp)->null_flags |= NULLV_NOUNLOCK;
394d9e9650aSKonstantin Belousov 	vgone(vp);
395*0fc6daa7SKonstantin Belousov 	vput(vp);
396*0fc6daa7SKonstantin Belousov }
397*0fc6daa7SKonstantin Belousov 
398*0fc6daa7SKonstantin Belousov static void
399*0fc6daa7SKonstantin Belousov nullfs_unlink_lowervp(struct mount *mp, struct vnode *lowervp)
400*0fc6daa7SKonstantin Belousov {
401*0fc6daa7SKonstantin Belousov 	struct vnode *vp;
402*0fc6daa7SKonstantin Belousov 	struct null_node *xp;
403*0fc6daa7SKonstantin Belousov 
404*0fc6daa7SKonstantin Belousov 	vp = null_hashget(mp, lowervp);
405*0fc6daa7SKonstantin Belousov 	if (vp == NULL)
406*0fc6daa7SKonstantin Belousov 		return;
407*0fc6daa7SKonstantin Belousov 	xp = VTONULL(vp);
408*0fc6daa7SKonstantin Belousov 	xp->null_flags |= NULLV_DROP | NULLV_NOUNLOCK;
409*0fc6daa7SKonstantin Belousov 	vhold(vp);
410*0fc6daa7SKonstantin Belousov 	vunref(vp);
411*0fc6daa7SKonstantin Belousov 
412*0fc6daa7SKonstantin Belousov 	/*
413*0fc6daa7SKonstantin Belousov 	 * If vunref() dropped the last use reference on the nullfs
414*0fc6daa7SKonstantin Belousov 	 * vnode, it must be reclaimed, and its lock was split from
415*0fc6daa7SKonstantin Belousov 	 * the lower vnode lock.  Need to do extra unlock before
416*0fc6daa7SKonstantin Belousov 	 * allowing the final vdrop() to free the vnode.
417*0fc6daa7SKonstantin Belousov 	 */
418*0fc6daa7SKonstantin Belousov 	if (vp->v_usecount == 0) {
419*0fc6daa7SKonstantin Belousov 		KASSERT((vp->v_iflag & VI_DOOMED) != 0,
420*0fc6daa7SKonstantin Belousov 		    ("not reclaimed %p", vp));
421*0fc6daa7SKonstantin Belousov 		VOP_UNLOCK(vp, 0);
422*0fc6daa7SKonstantin Belousov 	}
423*0fc6daa7SKonstantin Belousov 	vdrop(vp);
424d9e9650aSKonstantin Belousov }
42591f37dcbSRobert Watson 
426d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
4277652131bSPoul-Henning Kamp 	.vfs_extattrctl =	nullfs_extattrctl,
4287652131bSPoul-Henning Kamp 	.vfs_fhtovp =		nullfs_fhtovp,
4297652131bSPoul-Henning Kamp 	.vfs_init =		nullfs_init,
4305e8c582aSPoul-Henning Kamp 	.vfs_mount =		nullfs_mount,
4317652131bSPoul-Henning Kamp 	.vfs_quotactl =		nullfs_quotactl,
4327652131bSPoul-Henning Kamp 	.vfs_root =		nullfs_root,
4337652131bSPoul-Henning Kamp 	.vfs_statfs =		nullfs_statfs,
4347652131bSPoul-Henning Kamp 	.vfs_sync =		nullfs_sync,
4357652131bSPoul-Henning Kamp 	.vfs_uninit =		nullfs_uninit,
4367652131bSPoul-Henning Kamp 	.vfs_unmount =		nullfs_unmount,
4377652131bSPoul-Henning Kamp 	.vfs_vget =		nullfs_vget,
438d9e9650aSKonstantin Belousov 	.vfs_reclaim_lowervp =	nullfs_reclaim_lowervp,
439*0fc6daa7SKonstantin Belousov 	.vfs_unlink_lowervp =	nullfs_unlink_lowervp,
440df8bae1dSRodney W. Grimes };
441c901836cSGarrett Wollman 
44261f0e25aSMartin Matuska VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK | VFCF_JAIL);
443