xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision 5e8c582ac2973e6389d6f9ae62021546bef75705)
1df8bae1dSRodney W. Grimes /*
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>
454ea4f1f9SMarcel Moolenaar #include <sys/kdb.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>
53fb919e4dSMark Murray 
5499d300a1SRuslan Ermilov #include <fs/nullfs/null.h>
55df8bae1dSRodney W. Grimes 
56a1c995b6SPoul-Henning Kamp static MALLOC_DEFINE(M_NULLFSMNT, "NULLFS mount", "NULLFS mount structure");
57a1c995b6SPoul-Henning Kamp 
587652131bSPoul-Henning Kamp static vfs_fhtovp_t	nullfs_fhtovp;
597652131bSPoul-Henning Kamp static vfs_checkexp_t	nullfs_checkexp;
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_start_t	nullfs_start;
647652131bSPoul-Henning Kamp static vfs_sync_t	nullfs_sync;
657652131bSPoul-Henning Kamp static vfs_statfs_t	nullfs_statfs;
667652131bSPoul-Henning Kamp static vfs_unmount_t	nullfs_unmount;
677652131bSPoul-Henning Kamp static vfs_vget_t	nullfs_vget;
687652131bSPoul-Henning Kamp static vfs_vptofh_t	nullfs_vptofh;
697652131bSPoul-Henning Kamp static vfs_extattrctl_t	nullfs_extattrctl;
709b5e8b3aSBruce Evans 
71df8bae1dSRodney W. Grimes /*
72df8bae1dSRodney W. Grimes  * Mount null layer
73df8bae1dSRodney W. Grimes  */
74d4b7a369SPoul-Henning Kamp static int
755e8c582aSPoul-Henning Kamp nullfs_mount(struct mount *mp, struct thread *td)
76df8bae1dSRodney W. Grimes {
77df8bae1dSRodney W. Grimes 	int error = 0;
78df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
79df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
80df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
819fcc512cSMaxime Henrion 	char *target;
82aa56d911SMatt Jacob 	size_t size;
839fcc512cSMaxime Henrion 	int isvnunlocked = 0, len;
845e8c582aSPoul-Henning Kamp 	struct nameidata nd, *ndp = &nd;
85df8bae1dSRodney W. Grimes 
868da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
87df8bae1dSRodney W. Grimes 
88df8bae1dSRodney W. Grimes 	/*
89df8bae1dSRodney W. Grimes 	 * Update is a no-op
90df8bae1dSRodney W. Grimes 	 */
91df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
92df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
93b40ce416SJulian Elischer 		/* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, td);*/
94df8bae1dSRodney W. Grimes 	}
95df8bae1dSRodney W. Grimes 
96df8bae1dSRodney W. Grimes 	/*
97df8bae1dSRodney W. Grimes 	 * Get argument
98df8bae1dSRodney W. Grimes 	 */
999fcc512cSMaxime Henrion 	error = vfs_getopt(mp->mnt_optnew, "target", (void **)&target, &len);
1009fcc512cSMaxime Henrion 	if (error || target[len - 1] != '\0')
1019fcc512cSMaxime Henrion 		return (EINVAL);
102df8bae1dSRodney W. Grimes 
103df8bae1dSRodney W. Grimes 	/*
104f85e8fc5SKATO Takenori 	 * Unlock lower node to avoid deadlock.
105f85e8fc5SKATO Takenori 	 * (XXX) VOP_ISLOCKED is needed?
106f85e8fc5SKATO Takenori 	 */
107f85e8fc5SKATO Takenori 	if ((mp->mnt_vnodecovered->v_op == null_vnodeop_p) &&
1086bdfe06aSEivind Eklund 		VOP_ISLOCKED(mp->mnt_vnodecovered, NULL)) {
109b40ce416SJulian Elischer 		VOP_UNLOCK(mp->mnt_vnodecovered, 0, td);
110f85e8fc5SKATO Takenori 		isvnunlocked = 1;
111f85e8fc5SKATO Takenori 	}
112f85e8fc5SKATO Takenori 	/*
113df8bae1dSRodney W. Grimes 	 * Find lower node
114df8bae1dSRodney W. Grimes 	 */
115df8bae1dSRodney W. Grimes 	NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
1169fcc512cSMaxime Henrion 		UIO_SYSSPACE, target, td);
1173a773ad0SPoul-Henning Kamp 	error = namei(ndp);
118f85e8fc5SKATO Takenori 	/*
119f85e8fc5SKATO Takenori 	 * Re-lock vnode.
120f85e8fc5SKATO Takenori 	 */
1216bdfe06aSEivind Eklund 	if (isvnunlocked && !VOP_ISLOCKED(mp->mnt_vnodecovered, NULL))
122b40ce416SJulian Elischer 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY, td);
123f85e8fc5SKATO Takenori 
1243a773ad0SPoul-Henning Kamp 	if (error)
125df8bae1dSRodney W. Grimes 		return (error);
126762e6b85SEivind Eklund 	NDFREE(ndp, NDF_ONLY_PNBUF);
127df8bae1dSRodney W. Grimes 
128df8bae1dSRodney W. Grimes 	/*
129df8bae1dSRodney W. Grimes 	 * Sanity check on lower vnode
130df8bae1dSRodney W. Grimes 	 */
131df8bae1dSRodney W. Grimes 	lowerrootvp = ndp->ni_vp;
132df8bae1dSRodney W. Grimes 
133df8bae1dSRodney W. Grimes 	vrele(ndp->ni_dvp);
134c5e17d9eSKATO Takenori 	ndp->ni_dvp = NULLVP;
135df8bae1dSRodney W. Grimes 
136f85e8fc5SKATO Takenori 	/*
137f85e8fc5SKATO Takenori 	 * Check multi null mount to avoid `lock against myself' panic.
138f85e8fc5SKATO Takenori 	 */
139f85e8fc5SKATO Takenori 	if (lowerrootvp == VTONULL(mp->mnt_vnodecovered)->null_lowervp) {
1408da80660SBoris Popov 		NULLFSDEBUG("nullfs_mount: multi null mount?\n");
1416716c905SBoris Popov 		vput(lowerrootvp);
142747e9157SKATO Takenori 		return (EDEADLK);
143f85e8fc5SKATO Takenori 	}
144f85e8fc5SKATO Takenori 
145df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
146a163d034SWarner Losh 				M_NULLFSMNT, M_WAITOK);	/* XXX */
147df8bae1dSRodney W. Grimes 
148df8bae1dSRodney W. Grimes 	/*
149df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
150df8bae1dSRodney W. Grimes 	 */
151df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
152df8bae1dSRodney W. Grimes 
153df8bae1dSRodney W. Grimes 	/*
154df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
155df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
156df8bae1dSRodney W. Grimes 	 */
1571cfdefbbSSemen Ustimenko 	error = null_nodeget(mp, lowerrootvp, &vp);
158df8bae1dSRodney W. Grimes 	/*
159df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
160df8bae1dSRodney W. Grimes 	 */
161df8bae1dSRodney W. Grimes 	if (error) {
16275cabb63SJeff Roberson 		VOP_UNLOCK(vp, 0, td);
163df8bae1dSRodney W. Grimes 		vrele(lowerrootvp);
164a1c995b6SPoul-Henning Kamp 		free(xmp, M_NULLFSMNT);	/* XXX */
165df8bae1dSRodney W. Grimes 		return (error);
166df8bae1dSRodney W. Grimes 	}
167df8bae1dSRodney W. Grimes 
168df8bae1dSRodney W. Grimes 	/*
169df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
170df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
171df8bae1dSRodney W. Grimes 	 */
172df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
173e6e370a7SJeff Roberson 	nullm_rootvp->v_vflag |= VV_ROOT;
174df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
17575cabb63SJeff Roberson 
17675cabb63SJeff Roberson 	/*
17775cabb63SJeff Roberson 	 * Unlock the node (either the lower or the alias)
17875cabb63SJeff Roberson 	 */
17975cabb63SJeff Roberson 	VOP_UNLOCK(vp, 0, td);
18075cabb63SJeff Roberson 
181df8bae1dSRodney W. Grimes 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
182df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
183df8bae1dSRodney W. Grimes 	mp->mnt_data = (qaddr_t) xmp;
184996c772fSJohn Dyson 	vfs_getnewfsid(mp);
185df8bae1dSRodney W. Grimes 
1869fcc512cSMaxime Henrion 	(void) copystr(target, mp->mnt_stat.f_mntfromname,
187aa56d911SMatt Jacob 	    MNAMELEN - 1, &size);
188df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
189b40ce416SJulian Elischer 	(void)nullfs_statfs(mp, &mp->mnt_stat, td);
1908da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount: lower %s, alias at %s\n",
191df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
192df8bae1dSRodney W. Grimes 	return (0);
193df8bae1dSRodney W. Grimes }
194df8bae1dSRodney W. Grimes 
195df8bae1dSRodney W. Grimes /*
196df8bae1dSRodney W. Grimes  * VFS start.  Nothing needed here - the start routine
197df8bae1dSRodney W. Grimes  * on the underlying filesystem will have been called
198df8bae1dSRodney W. Grimes  * when that filesystem was mounted.
199df8bae1dSRodney W. Grimes  */
200d4b7a369SPoul-Henning Kamp static int
201b40ce416SJulian Elischer nullfs_start(mp, flags, td)
202df8bae1dSRodney W. Grimes 	struct mount *mp;
203df8bae1dSRodney W. Grimes 	int flags;
204b40ce416SJulian Elischer 	struct thread *td;
205df8bae1dSRodney W. Grimes {
206df8bae1dSRodney W. Grimes 	return (0);
207b40ce416SJulian Elischer 	/* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, td); */
208df8bae1dSRodney W. Grimes }
209df8bae1dSRodney W. Grimes 
210df8bae1dSRodney W. Grimes /*
211df8bae1dSRodney W. Grimes  * Free reference to null layer
212df8bae1dSRodney W. Grimes  */
213d4b7a369SPoul-Henning Kamp static int
214b40ce416SJulian Elischer nullfs_unmount(mp, mntflags, td)
215df8bae1dSRodney W. Grimes 	struct mount *mp;
216df8bae1dSRodney W. Grimes 	int mntflags;
217b40ce416SJulian Elischer 	struct thread *td;
218df8bae1dSRodney W. Grimes {
2198da80660SBoris Popov 	void *mntdata;
220df8bae1dSRodney W. Grimes 	int error;
221df8bae1dSRodney W. Grimes 	int flags = 0;
222df8bae1dSRodney W. Grimes 
2238da80660SBoris Popov 	NULLFSDEBUG("nullfs_unmount: mp = %p\n", (void *)mp);
224df8bae1dSRodney W. Grimes 
225996c772fSJohn Dyson 	if (mntflags & MNT_FORCE)
226df8bae1dSRodney W. Grimes 		flags |= FORCECLOSE;
227df8bae1dSRodney W. Grimes 
2280864ef1eSIan Dowse 	/* There is 1 extra root vnode reference (nullm_rootvp). */
229f257b7a5SAlfred Perlstein 	error = vflush(mp, 1, flags, td);
2303a773ad0SPoul-Henning Kamp 	if (error)
231df8bae1dSRodney W. Grimes 		return (error);
232df8bae1dSRodney W. Grimes 
233df8bae1dSRodney W. Grimes 	/*
234df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
235df8bae1dSRodney W. Grimes 	 */
2368da80660SBoris Popov 	mntdata = mp->mnt_data;
237df8bae1dSRodney W. Grimes 	mp->mnt_data = 0;
2384451405fSBoris Popov 	free(mntdata, M_NULLFSMNT);
239df8bae1dSRodney W. Grimes 	return 0;
240df8bae1dSRodney W. Grimes }
241df8bae1dSRodney W. Grimes 
242d4b7a369SPoul-Henning Kamp static int
243f257b7a5SAlfred Perlstein nullfs_root(mp, vpp, td)
244df8bae1dSRodney W. Grimes 	struct mount *mp;
245df8bae1dSRodney W. Grimes 	struct vnode **vpp;
246f257b7a5SAlfred Perlstein 	struct thread *td;
247df8bae1dSRodney W. Grimes {
248df8bae1dSRodney W. Grimes 	struct vnode *vp;
249df8bae1dSRodney W. Grimes 
2508da80660SBoris Popov 	NULLFSDEBUG("nullfs_root(mp = %p, vp = %p->%p)\n", (void *)mp,
25189785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
25289785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
253df8bae1dSRodney W. Grimes 
254df8bae1dSRodney W. Grimes 	/*
255df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
256df8bae1dSRodney W. Grimes 	 */
257df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
258df8bae1dSRodney W. Grimes 	VREF(vp);
2594451405fSBoris Popov 
2608da80660SBoris Popov #ifdef NULLFS_DEBUG
2616bdfe06aSEivind Eklund 	if (VOP_ISLOCKED(vp, NULL)) {
2624ea4f1f9SMarcel Moolenaar 		kdb_enter("root vnode is locked.\n");
263747e9157SKATO Takenori 		vrele(vp);
264747e9157SKATO Takenori 		return (EDEADLK);
2658da80660SBoris Popov 	}
2668da80660SBoris Popov #endif
267b40ce416SJulian Elischer 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
268df8bae1dSRodney W. Grimes 	*vpp = vp;
269df8bae1dSRodney W. Grimes 	return 0;
270df8bae1dSRodney W. Grimes }
271df8bae1dSRodney W. Grimes 
272d4b7a369SPoul-Henning Kamp static int
273b40ce416SJulian Elischer nullfs_quotactl(mp, cmd, uid, arg, td)
274df8bae1dSRodney W. Grimes 	struct mount *mp;
275df8bae1dSRodney W. Grimes 	int cmd;
276df8bae1dSRodney W. Grimes 	uid_t uid;
277df8bae1dSRodney W. Grimes 	caddr_t arg;
278b40ce416SJulian Elischer 	struct thread *td;
279df8bae1dSRodney W. Grimes {
280b40ce416SJulian Elischer 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, td);
281df8bae1dSRodney W. Grimes }
282df8bae1dSRodney W. Grimes 
283d4b7a369SPoul-Henning Kamp static int
284b40ce416SJulian Elischer nullfs_statfs(mp, sbp, td)
285df8bae1dSRodney W. Grimes 	struct mount *mp;
286df8bae1dSRodney W. Grimes 	struct statfs *sbp;
287b40ce416SJulian Elischer 	struct thread *td;
288df8bae1dSRodney W. Grimes {
289df8bae1dSRodney W. Grimes 	int error;
290df8bae1dSRodney W. Grimes 	struct statfs mstat;
291df8bae1dSRodney W. Grimes 
2928da80660SBoris Popov 	NULLFSDEBUG("nullfs_statfs(mp = %p, vp = %p->%p)\n", (void *)mp,
29389785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
29489785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
295df8bae1dSRodney W. Grimes 
296df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
297df8bae1dSRodney W. Grimes 
298b40ce416SJulian Elischer 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, td);
299df8bae1dSRodney W. Grimes 	if (error)
300df8bae1dSRodney W. Grimes 		return (error);
301df8bae1dSRodney W. Grimes 
302df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
303df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
304df8bae1dSRodney W. Grimes 	sbp->f_flags = mstat.f_flags;
305df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
306df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
307df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
308df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
309df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
310df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
311df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
312df8bae1dSRodney W. Grimes 	if (sbp != &mp->mnt_stat) {
313df8bae1dSRodney W. Grimes 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
314df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
315df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
316df8bae1dSRodney W. Grimes 	}
317df8bae1dSRodney W. Grimes 	return (0);
318df8bae1dSRodney W. Grimes }
319df8bae1dSRodney W. Grimes 
320d4b7a369SPoul-Henning Kamp static int
321b40ce416SJulian Elischer nullfs_sync(mp, waitfor, cred, td)
322df8bae1dSRodney W. Grimes 	struct mount *mp;
323df8bae1dSRodney W. Grimes 	int waitfor;
324df8bae1dSRodney W. Grimes 	struct ucred *cred;
325b40ce416SJulian Elischer 	struct thread *td;
326df8bae1dSRodney W. Grimes {
327df8bae1dSRodney W. Grimes 	/*
328df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
329df8bae1dSRodney W. Grimes 	 */
330df8bae1dSRodney W. Grimes 	return (0);
331df8bae1dSRodney W. Grimes }
332df8bae1dSRodney W. Grimes 
333d4b7a369SPoul-Henning Kamp static int
334a0595d02SKirk McKusick nullfs_vget(mp, ino, flags, vpp)
335df8bae1dSRodney W. Grimes 	struct mount *mp;
336df8bae1dSRodney W. Grimes 	ino_t ino;
337a0595d02SKirk McKusick 	int flags;
338df8bae1dSRodney W. Grimes 	struct vnode **vpp;
339df8bae1dSRodney W. Grimes {
3404451405fSBoris Popov 	int error;
341a0595d02SKirk McKusick 	error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, flags, vpp);
3424451405fSBoris Popov 	if (error)
3434451405fSBoris Popov 		return (error);
344df8bae1dSRodney W. Grimes 
3451cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
346df8bae1dSRodney W. Grimes }
347df8bae1dSRodney W. Grimes 
348d4b7a369SPoul-Henning Kamp static int
349c24fda81SAlfred Perlstein nullfs_fhtovp(mp, fidp, vpp)
350df8bae1dSRodney W. Grimes 	struct mount *mp;
351df8bae1dSRodney W. Grimes 	struct fid *fidp;
352df8bae1dSRodney W. Grimes 	struct vnode **vpp;
353c24fda81SAlfred Perlstein {
3544451405fSBoris Popov 	int error;
3554451405fSBoris Popov 	error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, vpp);
3564451405fSBoris Popov 	if (error)
3574451405fSBoris Popov 		return (error);
358c24fda81SAlfred Perlstein 
3591cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
360c24fda81SAlfred Perlstein }
361c24fda81SAlfred Perlstein 
362c24fda81SAlfred Perlstein static int
363c24fda81SAlfred Perlstein nullfs_checkexp(mp, nam, extflagsp, credanonp)
364c24fda81SAlfred Perlstein 	struct mount *mp;
365c24fda81SAlfred Perlstein 	struct sockaddr *nam;
366c24fda81SAlfred Perlstein 	int *extflagsp;
367df8bae1dSRodney W. Grimes 	struct ucred **credanonp;
368df8bae1dSRodney W. Grimes {
369df8bae1dSRodney W. Grimes 
370c24fda81SAlfred Perlstein 	return VFS_CHECKEXP(MOUNTTONULLMOUNT(mp)->nullm_vfs, nam,
371c24fda81SAlfred Perlstein 		extflagsp, credanonp);
372df8bae1dSRodney W. Grimes }
373df8bae1dSRodney W. Grimes 
374d4b7a369SPoul-Henning Kamp static int
375df8bae1dSRodney W. Grimes nullfs_vptofh(vp, fhp)
376df8bae1dSRodney W. Grimes 	struct vnode *vp;
377df8bae1dSRodney W. Grimes 	struct fid *fhp;
378df8bae1dSRodney W. Grimes {
379ff81e317SPoul-Henning Kamp 	struct vnode *lvp;
380ff81e317SPoul-Henning Kamp 
381ff81e317SPoul-Henning Kamp 	lvp = NULLVPTOLOWERVP(vp);
382ff81e317SPoul-Henning Kamp 	return VFS_VPTOFH(lvp, fhp);
383df8bae1dSRodney W. Grimes }
384df8bae1dSRodney W. Grimes 
38591f37dcbSRobert Watson static int
386b40ce416SJulian Elischer nullfs_extattrctl(mp, cmd, filename_vp, namespace, attrname, td)
38791f37dcbSRobert Watson 	struct mount *mp;
38891f37dcbSRobert Watson 	int cmd;
38970f36851SRobert Watson 	struct vnode *filename_vp;
39070f36851SRobert Watson 	int namespace;
3918f073875SRobert Watson 	const char *attrname;
392b40ce416SJulian Elischer 	struct thread *td;
39391f37dcbSRobert Watson {
39470f36851SRobert Watson 	return VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, filename_vp,
395b40ce416SJulian Elischer 	    namespace, attrname, td);
39691f37dcbSRobert Watson }
39791f37dcbSRobert Watson 
39891f37dcbSRobert Watson 
399d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
4007652131bSPoul-Henning Kamp 	.vfs_checkexp =		nullfs_checkexp,
4017652131bSPoul-Henning Kamp 	.vfs_extattrctl =	nullfs_extattrctl,
4027652131bSPoul-Henning Kamp 	.vfs_fhtovp =		nullfs_fhtovp,
4037652131bSPoul-Henning Kamp 	.vfs_init =		nullfs_init,
4045e8c582aSPoul-Henning Kamp 	.vfs_mount =		nullfs_mount,
4057652131bSPoul-Henning Kamp 	.vfs_quotactl =		nullfs_quotactl,
4067652131bSPoul-Henning Kamp 	.vfs_root =		nullfs_root,
4077652131bSPoul-Henning Kamp 	.vfs_start =		nullfs_start,
4087652131bSPoul-Henning Kamp 	.vfs_statfs =		nullfs_statfs,
4097652131bSPoul-Henning Kamp 	.vfs_sync =		nullfs_sync,
4107652131bSPoul-Henning Kamp 	.vfs_uninit =		nullfs_uninit,
4117652131bSPoul-Henning Kamp 	.vfs_unmount =		nullfs_unmount,
4127652131bSPoul-Henning Kamp 	.vfs_vget =		nullfs_vget,
4137652131bSPoul-Henning Kamp 	.vfs_vptofh =		nullfs_vptofh,
414df8bae1dSRodney W. Grimes };
415c901836cSGarrett Wollman 
4161b2fbe6fSSheldon Hearn VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK);
417