xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision 9cf4c952caa443733ad3b44fa274a2018a94f5f5)
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;
68d9e9650aSKonstantin Belousov static vfs_reclaim_lowervp_t nullfs_reclaim_lowervp;
699b5e8b3aSBruce Evans 
70*9cf4c952SKonstantin Belousov /* Mount options that we support. */
71*9cf4c952SKonstantin Belousov static const char *nullfs_opts[] = {
72*9cf4c952SKonstantin Belousov 	"cache",
73*9cf4c952SKonstantin Belousov 	"export",
74*9cf4c952SKonstantin Belousov 	"from",
75*9cf4c952SKonstantin Belousov 	"target",
76*9cf4c952SKonstantin Belousov 	NULL
77*9cf4c952SKonstantin Belousov };
78*9cf4c952SKonstantin Belousov 
79df8bae1dSRodney W. Grimes /*
80df8bae1dSRodney W. Grimes  * Mount null layer
81df8bae1dSRodney W. Grimes  */
82d4b7a369SPoul-Henning Kamp static int
83dfd233edSAttilio Rao nullfs_mount(struct mount *mp)
84df8bae1dSRodney W. Grimes {
85df8bae1dSRodney W. Grimes 	int error = 0;
86df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
87df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
88df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
89bf3db8aaSMartin Matuska 	struct thread *td = curthread;
909fcc512cSMaxime Henrion 	char *target;
919fcc512cSMaxime Henrion 	int isvnunlocked = 0, len;
925e8c582aSPoul-Henning Kamp 	struct nameidata nd, *ndp = &nd;
93df8bae1dSRodney W. Grimes 
948da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
95df8bae1dSRodney W. Grimes 
96bf3db8aaSMartin Matuska 	if (!prison_allow(td->td_ucred, PR_ALLOW_MOUNT_NULLFS))
97bf3db8aaSMartin Matuska 		return (EPERM);
9864042a76SPoul-Henning Kamp 	if (mp->mnt_flag & MNT_ROOTFS)
9964042a76SPoul-Henning Kamp 		return (EOPNOTSUPP);
100*9cf4c952SKonstantin Belousov 	if (vfs_filteropt(mp->mnt_optnew, nullfs_opts))
101*9cf4c952SKonstantin Belousov 		return (EINVAL);
102*9cf4c952SKonstantin Belousov 
103df8bae1dSRodney W. Grimes 	/*
104df8bae1dSRodney W. Grimes 	 * Update is a no-op
105df8bae1dSRodney W. Grimes 	 */
106df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
107ebbf93fdSCraig Rodrigues 		/*
108ebbf93fdSCraig Rodrigues 		 * Only support update mounts for NFS export.
109ebbf93fdSCraig Rodrigues 		 */
110ebbf93fdSCraig Rodrigues 		if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0))
111ebbf93fdSCraig Rodrigues 			return (0);
112ebbf93fdSCraig Rodrigues 		else
113df8bae1dSRodney W. Grimes 			return (EOPNOTSUPP);
114df8bae1dSRodney W. Grimes 	}
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes 	/*
117df8bae1dSRodney W. Grimes 	 * Get argument
118df8bae1dSRodney W. Grimes 	 */
1199fcc512cSMaxime Henrion 	error = vfs_getopt(mp->mnt_optnew, "target", (void **)&target, &len);
1209fcc512cSMaxime Henrion 	if (error || target[len - 1] != '\0')
1219fcc512cSMaxime Henrion 		return (EINVAL);
122df8bae1dSRodney W. Grimes 
123df8bae1dSRodney W. Grimes 	/*
1249ce73797SPeter Holm 	 * Unlock lower node to avoid possible deadlock.
125f85e8fc5SKATO Takenori 	 */
126aec0fb7bSPoul-Henning Kamp 	if ((mp->mnt_vnodecovered->v_op == &null_vnodeops) &&
1279ce73797SPeter Holm 	    VOP_ISLOCKED(mp->mnt_vnodecovered) == LK_EXCLUSIVE) {
12822db15c0SAttilio Rao 		VOP_UNLOCK(mp->mnt_vnodecovered, 0);
129f85e8fc5SKATO Takenori 		isvnunlocked = 1;
130f85e8fc5SKATO Takenori 	}
131f85e8fc5SKATO Takenori 	/*
132df8bae1dSRodney W. Grimes 	 * Find lower node
133df8bae1dSRodney W. Grimes 	 */
134dfd233edSAttilio Rao 	NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF, UIO_SYSSPACE, target, curthread);
1353a773ad0SPoul-Henning Kamp 	error = namei(ndp);
136d9e9650aSKonstantin Belousov 
137f85e8fc5SKATO Takenori 	/*
138f85e8fc5SKATO Takenori 	 * Re-lock vnode.
139d9e9650aSKonstantin Belousov 	 * XXXKIB This is deadlock-prone as well.
140f85e8fc5SKATO Takenori 	 */
141ffa43617SKonstantin Belousov 	if (isvnunlocked)
142cb05b60aSAttilio Rao 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY);
143f85e8fc5SKATO Takenori 
1443a773ad0SPoul-Henning Kamp 	if (error)
145df8bae1dSRodney W. Grimes 		return (error);
146762e6b85SEivind Eklund 	NDFREE(ndp, NDF_ONLY_PNBUF);
147df8bae1dSRodney W. Grimes 
148df8bae1dSRodney W. Grimes 	/*
149df8bae1dSRodney W. Grimes 	 * Sanity check on lower vnode
150df8bae1dSRodney W. Grimes 	 */
151df8bae1dSRodney W. Grimes 	lowerrootvp = ndp->ni_vp;
152df8bae1dSRodney W. Grimes 
153f85e8fc5SKATO Takenori 	/*
154f85e8fc5SKATO Takenori 	 * Check multi null mount to avoid `lock against myself' panic.
155f85e8fc5SKATO Takenori 	 */
156f85e8fc5SKATO Takenori 	if (lowerrootvp == VTONULL(mp->mnt_vnodecovered)->null_lowervp) {
1578da80660SBoris Popov 		NULLFSDEBUG("nullfs_mount: multi null mount?\n");
1586716c905SBoris Popov 		vput(lowerrootvp);
159747e9157SKATO Takenori 		return (EDEADLK);
160f85e8fc5SKATO Takenori 	}
161f85e8fc5SKATO Takenori 
162df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
163*9cf4c952SKonstantin Belousov 	    M_NULLFSMNT, M_WAITOK | M_ZERO);
164df8bae1dSRodney W. Grimes 
165df8bae1dSRodney W. Grimes 	/*
166df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
167df8bae1dSRodney W. Grimes 	 */
168df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
169df8bae1dSRodney W. Grimes 
170df8bae1dSRodney W. Grimes 	/*
171df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
172df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
173df8bae1dSRodney W. Grimes 	 */
1741cfdefbbSSemen Ustimenko 	error = null_nodeget(mp, lowerrootvp, &vp);
175df8bae1dSRodney W. Grimes 	/*
176df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
177df8bae1dSRodney W. Grimes 	 */
178df8bae1dSRodney W. Grimes 	if (error) {
179dd0f9532SKonstantin Belousov 		free(xmp, M_NULLFSMNT);
180df8bae1dSRodney W. Grimes 		return (error);
181df8bae1dSRodney W. Grimes 	}
182df8bae1dSRodney W. Grimes 
183df8bae1dSRodney W. Grimes 	/*
184df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
185df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
186df8bae1dSRodney W. Grimes 	 */
187df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
188e6e370a7SJeff Roberson 	nullm_rootvp->v_vflag |= VV_ROOT;
189df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
19075cabb63SJeff Roberson 
19175cabb63SJeff Roberson 	/*
19275cabb63SJeff Roberson 	 * Unlock the node (either the lower or the alias)
19375cabb63SJeff Roberson 	 */
19422db15c0SAttilio Rao 	VOP_UNLOCK(vp, 0);
19575cabb63SJeff Roberson 
1965da56ddbSTor Egge 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL) {
1975da56ddbSTor Egge 		MNT_ILOCK(mp);
198df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
1995da56ddbSTor Egge 		MNT_IUNLOCK(mp);
2005da56ddbSTor Egge 	}
201*9cf4c952SKonstantin Belousov 
202*9cf4c952SKonstantin Belousov 	xmp->nullm_flags |= NULLM_CACHE;
203*9cf4c952SKonstantin Belousov 	if (vfs_getopt(mp->mnt_optnew, "nocache", NULL, NULL) == 0)
204*9cf4c952SKonstantin Belousov 		xmp->nullm_flags &= ~NULLM_CACHE;
205*9cf4c952SKonstantin Belousov 
2065da56ddbSTor Egge 	MNT_ILOCK(mp);
207*9cf4c952SKonstantin Belousov 	if ((xmp->nullm_flags & NULLM_CACHE) != 0) {
20837a1046eSKonstantin Belousov 		mp->mnt_kern_flag |= lowerrootvp->v_mount->mnt_kern_flag &
209*9cf4c952SKonstantin Belousov 		    (MNTK_SHARED_WRITES | MNTK_LOOKUP_SHARED |
210*9cf4c952SKonstantin Belousov 		    MNTK_EXTENDED_SHARED);
211*9cf4c952SKonstantin Belousov 	}
212d9e9650aSKonstantin Belousov 	mp->mnt_kern_flag |= MNTK_LOOKUP_EXCL_DOTDOT;
2135da56ddbSTor Egge 	MNT_IUNLOCK(mp);
21477465d93SAlfred Perlstein 	mp->mnt_data = xmp;
215996c772fSJohn Dyson 	vfs_getnewfsid(mp);
216*9cf4c952SKonstantin Belousov 	if ((xmp->nullm_flags & NULLM_CACHE) != 0) {
217d9e9650aSKonstantin Belousov 		MNT_ILOCK(xmp->nullm_vfs);
218*9cf4c952SKonstantin Belousov 		TAILQ_INSERT_TAIL(&xmp->nullm_vfs->mnt_uppers, mp,
219*9cf4c952SKonstantin Belousov 		    mnt_upper_link);
220d9e9650aSKonstantin Belousov 		MNT_IUNLOCK(xmp->nullm_vfs);
221*9cf4c952SKonstantin Belousov 	}
222df8bae1dSRodney W. Grimes 
2237ab8c8c0SPoul-Henning Kamp 	vfs_mountedfrom(mp, target);
2247ab8c8c0SPoul-Henning Kamp 
2258da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount: lower %s, alias at %s\n",
226df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
227df8bae1dSRodney W. Grimes 	return (0);
228df8bae1dSRodney W. Grimes }
229df8bae1dSRodney W. Grimes 
230df8bae1dSRodney W. Grimes /*
231df8bae1dSRodney W. Grimes  * Free reference to null layer
232df8bae1dSRodney W. Grimes  */
233d4b7a369SPoul-Henning Kamp static int
234dfd233edSAttilio Rao nullfs_unmount(mp, mntflags)
235df8bae1dSRodney W. Grimes 	struct mount *mp;
236df8bae1dSRodney W. Grimes 	int mntflags;
237df8bae1dSRodney W. Grimes {
238d9e9650aSKonstantin Belousov 	struct null_mount *mntdata;
239d9e9650aSKonstantin Belousov 	struct mount *ump;
240d9e9650aSKonstantin Belousov 	int error, flags;
241df8bae1dSRodney W. Grimes 
2428da80660SBoris Popov 	NULLFSDEBUG("nullfs_unmount: mp = %p\n", (void *)mp);
243df8bae1dSRodney W. Grimes 
244996c772fSJohn Dyson 	if (mntflags & MNT_FORCE)
245d9e9650aSKonstantin Belousov 		flags = FORCECLOSE;
246d9e9650aSKonstantin Belousov 	else
247d9e9650aSKonstantin Belousov 		flags = 0;
248df8bae1dSRodney W. Grimes 
2490864ef1eSIan Dowse 	/* There is 1 extra root vnode reference (nullm_rootvp). */
250dfd233edSAttilio Rao 	error = vflush(mp, 1, flags, curthread);
2513a773ad0SPoul-Henning Kamp 	if (error)
252df8bae1dSRodney W. Grimes 		return (error);
253df8bae1dSRodney W. Grimes 
254df8bae1dSRodney W. Grimes 	/*
255df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
256df8bae1dSRodney W. Grimes 	 */
2578da80660SBoris Popov 	mntdata = mp->mnt_data;
258d9e9650aSKonstantin Belousov 	ump = mntdata->nullm_vfs;
259*9cf4c952SKonstantin Belousov 	if ((mntdata->nullm_flags & NULLM_CACHE) != 0) {
260d9e9650aSKonstantin Belousov 		MNT_ILOCK(ump);
261d9e9650aSKonstantin Belousov 		while ((ump->mnt_kern_flag & MNTK_VGONE_UPPER) != 0) {
262d9e9650aSKonstantin Belousov 			ump->mnt_kern_flag |= MNTK_VGONE_WAITER;
263d9e9650aSKonstantin Belousov 			msleep(&ump->mnt_uppers, &ump->mnt_mtx, 0, "vgnupw", 0);
264d9e9650aSKonstantin Belousov 		}
265d9e9650aSKonstantin Belousov 		TAILQ_REMOVE(&ump->mnt_uppers, mp, mnt_upper_link);
266d9e9650aSKonstantin Belousov 		MNT_IUNLOCK(ump);
267*9cf4c952SKonstantin Belousov 	}
26811753bd0SKevin Lo 	mp->mnt_data = NULL;
2694451405fSBoris Popov 	free(mntdata, M_NULLFSMNT);
270d9e9650aSKonstantin Belousov 	return (0);
271df8bae1dSRodney W. Grimes }
272df8bae1dSRodney W. Grimes 
273d4b7a369SPoul-Henning Kamp static int
274dfd233edSAttilio Rao nullfs_root(mp, flags, vpp)
275df8bae1dSRodney W. Grimes 	struct mount *mp;
276d9b2d9f7SJeff Roberson 	int flags;
277df8bae1dSRodney W. Grimes 	struct vnode **vpp;
278df8bae1dSRodney W. Grimes {
279df8bae1dSRodney W. Grimes 	struct vnode *vp;
280df8bae1dSRodney W. Grimes 
2818da80660SBoris Popov 	NULLFSDEBUG("nullfs_root(mp = %p, vp = %p->%p)\n", (void *)mp,
28289785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
28389785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
284df8bae1dSRodney W. Grimes 
285df8bae1dSRodney W. Grimes 	/*
286df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
287df8bae1dSRodney W. Grimes 	 */
288df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
289df8bae1dSRodney W. Grimes 	VREF(vp);
2904451405fSBoris Popov 
29117edcd76SKonstantin Belousov 	ASSERT_VOP_UNLOCKED(vp, "root vnode is locked");
292cb05b60aSAttilio Rao 	vn_lock(vp, flags | LK_RETRY);
293df8bae1dSRodney W. Grimes 	*vpp = vp;
294df8bae1dSRodney W. Grimes 	return 0;
295df8bae1dSRodney W. Grimes }
296df8bae1dSRodney W. Grimes 
297d4b7a369SPoul-Henning Kamp static int
298dfd233edSAttilio Rao nullfs_quotactl(mp, cmd, uid, arg)
299df8bae1dSRodney W. Grimes 	struct mount *mp;
300df8bae1dSRodney W. Grimes 	int cmd;
301df8bae1dSRodney W. Grimes 	uid_t uid;
3020430a5e2SDag-Erling Smørgrav 	void *arg;
303df8bae1dSRodney W. Grimes {
304dfd233edSAttilio Rao 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg);
305df8bae1dSRodney W. Grimes }
306df8bae1dSRodney W. Grimes 
307d4b7a369SPoul-Henning Kamp static int
308dfd233edSAttilio Rao nullfs_statfs(mp, sbp)
309df8bae1dSRodney W. Grimes 	struct mount *mp;
310df8bae1dSRodney W. Grimes 	struct statfs *sbp;
311df8bae1dSRodney W. Grimes {
312df8bae1dSRodney W. Grimes 	int error;
313df8bae1dSRodney W. Grimes 	struct statfs mstat;
314df8bae1dSRodney W. Grimes 
3158da80660SBoris Popov 	NULLFSDEBUG("nullfs_statfs(mp = %p, vp = %p->%p)\n", (void *)mp,
31689785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
31789785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
318df8bae1dSRodney W. Grimes 
319df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
320df8bae1dSRodney W. Grimes 
321dfd233edSAttilio Rao 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat);
322df8bae1dSRodney W. Grimes 	if (error)
323df8bae1dSRodney W. Grimes 		return (error);
324df8bae1dSRodney W. Grimes 
325df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
326df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
327df8bae1dSRodney W. Grimes 	sbp->f_flags = mstat.f_flags;
328df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
329df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
330df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
331df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
332df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
333df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
334df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
335df8bae1dSRodney W. Grimes 	return (0);
336df8bae1dSRodney W. Grimes }
337df8bae1dSRodney W. Grimes 
338d4b7a369SPoul-Henning Kamp static int
339dfd233edSAttilio Rao nullfs_sync(mp, waitfor)
340df8bae1dSRodney W. Grimes 	struct mount *mp;
341df8bae1dSRodney W. Grimes 	int waitfor;
342df8bae1dSRodney W. Grimes {
343df8bae1dSRodney W. Grimes 	/*
344df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
345df8bae1dSRodney W. Grimes 	 */
346df8bae1dSRodney W. Grimes 	return (0);
347df8bae1dSRodney W. Grimes }
348df8bae1dSRodney W. Grimes 
349d4b7a369SPoul-Henning Kamp static int
350a0595d02SKirk McKusick nullfs_vget(mp, ino, flags, vpp)
351df8bae1dSRodney W. Grimes 	struct mount *mp;
352df8bae1dSRodney W. Grimes 	ino_t ino;
353a0595d02SKirk McKusick 	int flags;
354df8bae1dSRodney W. Grimes 	struct vnode **vpp;
355df8bae1dSRodney W. Grimes {
3564451405fSBoris Popov 	int error;
357e4e1d9f3SKonstantin Belousov 
358e4e1d9f3SKonstantin Belousov 	KASSERT((flags & LK_TYPE_MASK) != 0,
359e4e1d9f3SKonstantin Belousov 	    ("nullfs_vget: no lock requested"));
360e4e1d9f3SKonstantin Belousov 
361a0595d02SKirk McKusick 	error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, flags, vpp);
362d9e9650aSKonstantin Belousov 	if (error != 0)
3634451405fSBoris Popov 		return (error);
3641cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
365df8bae1dSRodney W. Grimes }
366df8bae1dSRodney W. Grimes 
367d4b7a369SPoul-Henning Kamp static int
368694a586aSRick Macklem nullfs_fhtovp(mp, fidp, flags, vpp)
369df8bae1dSRodney W. Grimes 	struct mount *mp;
370df8bae1dSRodney W. Grimes 	struct fid *fidp;
371694a586aSRick Macklem 	int flags;
372df8bae1dSRodney W. Grimes 	struct vnode **vpp;
373c24fda81SAlfred Perlstein {
3744451405fSBoris Popov 	int error;
375c24fda81SAlfred Perlstein 
376d9e9650aSKonstantin Belousov 	error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, flags,
377d9e9650aSKonstantin Belousov 	    vpp);
378d9e9650aSKonstantin Belousov 	if (error != 0)
379d9e9650aSKonstantin Belousov 		return (error);
3801cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
381c24fda81SAlfred Perlstein }
382c24fda81SAlfred Perlstein 
383c24fda81SAlfred Perlstein static int
384dfd233edSAttilio Rao nullfs_extattrctl(mp, cmd, filename_vp, namespace, attrname)
38591f37dcbSRobert Watson 	struct mount *mp;
38691f37dcbSRobert Watson 	int cmd;
38770f36851SRobert Watson 	struct vnode *filename_vp;
38870f36851SRobert Watson 	int namespace;
3898f073875SRobert Watson 	const char *attrname;
39091f37dcbSRobert Watson {
391d9e9650aSKonstantin Belousov 
392d9e9650aSKonstantin Belousov 	return (VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd,
393d9e9650aSKonstantin Belousov 	    filename_vp, namespace, attrname));
39491f37dcbSRobert Watson }
39591f37dcbSRobert Watson 
396d9e9650aSKonstantin Belousov static void
397d9e9650aSKonstantin Belousov nullfs_reclaim_lowervp(struct mount *mp, struct vnode *lowervp)
398d9e9650aSKonstantin Belousov {
399d9e9650aSKonstantin Belousov 	struct vnode *vp;
400d9e9650aSKonstantin Belousov 
401d9e9650aSKonstantin Belousov 	vp = null_hashget(mp, lowervp);
402d9e9650aSKonstantin Belousov 	if (vp == NULL)
403d9e9650aSKonstantin Belousov 		return;
404d9e9650aSKonstantin Belousov 	vgone(vp);
405d9e9650aSKonstantin Belousov 	vn_lock(lowervp, LK_EXCLUSIVE | LK_RETRY);
406d9e9650aSKonstantin Belousov }
40791f37dcbSRobert Watson 
408d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
4097652131bSPoul-Henning Kamp 	.vfs_extattrctl =	nullfs_extattrctl,
4107652131bSPoul-Henning Kamp 	.vfs_fhtovp =		nullfs_fhtovp,
4117652131bSPoul-Henning Kamp 	.vfs_init =		nullfs_init,
4125e8c582aSPoul-Henning Kamp 	.vfs_mount =		nullfs_mount,
4137652131bSPoul-Henning Kamp 	.vfs_quotactl =		nullfs_quotactl,
4147652131bSPoul-Henning Kamp 	.vfs_root =		nullfs_root,
4157652131bSPoul-Henning Kamp 	.vfs_statfs =		nullfs_statfs,
4167652131bSPoul-Henning Kamp 	.vfs_sync =		nullfs_sync,
4177652131bSPoul-Henning Kamp 	.vfs_uninit =		nullfs_uninit,
4187652131bSPoul-Henning Kamp 	.vfs_unmount =		nullfs_unmount,
4197652131bSPoul-Henning Kamp 	.vfs_vget =		nullfs_vget,
420d9e9650aSKonstantin Belousov 	.vfs_reclaim_lowervp =	nullfs_reclaim_lowervp,
421df8bae1dSRodney W. Grimes };
422c901836cSGarrett Wollman 
42361f0e25aSMartin Matuska VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK | VFCF_JAIL);
424