xref: /dragonfly/sys/kern/vfs_vfsops.c (revision 8e11cefe)
1 /*
2  * Copyright (c) 2009 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 /*
35  * Implement mp->mnt_ops function call wrappers.
36  *
37  * These wrappers are responsible for handling all MPSAFE issues related to
38  * a mount.
39  */
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/buf.h>
44 #include <sys/conf.h>
45 #include <sys/dirent.h>
46 #include <sys/domain.h>
47 #include <sys/eventhandler.h>
48 #include <sys/fcntl.h>
49 #include <sys/kernel.h>
50 #include <sys/kthread.h>
51 #include <sys/malloc.h>
52 #include <sys/mbuf.h>
53 #include <sys/mount.h>
54 #include <sys/proc.h>
55 #include <sys/namei.h>
56 #include <sys/reboot.h>
57 #include <sys/socket.h>
58 #include <sys/stat.h>
59 #include <sys/sysctl.h>
60 #include <sys/syslog.h>
61 #include <sys/vmmeter.h>
62 #include <sys/vnode.h>
63 #include <sys/vfsops.h>
64 #include <sys/sysmsg.h>
65 
66 #include <machine/limits.h>
67 
68 #include <vm/vm.h>
69 #include <vm/vm_object.h>
70 #include <vm/vm_extern.h>
71 #include <vm/vm_kern.h>
72 #include <vm/pmap.h>
73 #include <vm/vm_map.h>
74 #include <vm/vm_page.h>
75 #include <vm/vm_pager.h>
76 #include <vm/vnode_pager.h>
77 #include <vm/vm_zone.h>
78 
79 #include <sys/buf2.h>
80 #include <sys/mplock2.h>
81 
82 /*
83  * MPSAFE
84  */
85 int
86 vfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
87 {
88 	VFS_MPLOCK_DECLARE;
89 	int error;
90 
91 	VFS_MPLOCK(mp);
92 	if (!mp->mnt_cred)
93 		mp->mnt_cred = crhold(cred);	/* For cr_prison */
94 	error = (mp->mnt_op->vfs_mount)(mp, path, data, cred);
95 	VFS_MPUNLOCK();
96 
97 	return (error);
98 }
99 
100 /*
101  * MPSAFE
102  */
103 int
104 vfs_start(struct mount *mp, int flags)
105 {
106 	VFS_MPLOCK_DECLARE;
107 	int error;
108 
109 	VFS_MPLOCK_FLAG(mp, MNTK_ST_MPSAFE);
110 	error = (mp->mnt_op->vfs_start)(mp, flags);
111 	if (error == 0) {
112 		/* do not call vfs_acinit on mount updates */
113 		if ((mp->mnt_flag & MNT_UPDATE) == 0)
114 			VFS_ACINIT(mp,error);
115 	}
116 	VFS_MPUNLOCK();
117 	if (error == EMOUNTEXIT)
118 		error = 0;
119 	return (error);
120 }
121 
122 /*
123  * MPSAFE
124  */
125 int
126 vfs_unmount(struct mount *mp, int mntflags)
127 {
128 	VFS_MPLOCK_DECLARE;
129 	int error;
130 	int flags;
131 
132 	VFS_MPLOCK(mp);
133 	VFS_ACDONE(mp);
134 	flags = mp->mnt_kern_flag;
135 	error = (mp->mnt_op->vfs_unmount)(mp, mntflags);
136 	if (error == 0)
137 		vn_syncer_thr_stop(mp);
138 	VFS_MPUNLOCK();
139 	return (error);
140 }
141 
142 /*
143  * MPSAFE
144  */
145 int
146 vfs_root(struct mount *mp, struct vnode **vpp)
147 {
148 	VFS_MPLOCK_DECLARE;
149 	int error;
150 
151 	VFS_MPLOCK(mp);
152 	error = (mp->mnt_op->vfs_root)(mp, vpp);
153 	VFS_MPUNLOCK();
154 	return (error);
155 }
156 
157 /*
158  * MPSAFE
159  */
160 int
161 vfs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
162 	     struct ucred *cred)
163 {
164 	VFS_MPLOCK_DECLARE;
165 	int error;
166 
167 	VFS_MPLOCK(mp);
168 	error = (mp->mnt_op->vfs_quotactl)(mp, cmds, uid, arg, cred);
169 	VFS_MPUNLOCK();
170 	return (error);
171 }
172 
173 /*
174  * MPSAFE
175  */
176 int
177 vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
178 {
179 	VFS_MPLOCK_DECLARE;
180 	int error;
181 
182 	VFS_MPLOCK(mp);
183 	error = (mp->mnt_op->vfs_statfs)(mp, sbp, cred);
184 	VFS_MPUNLOCK();
185 	return (error);
186 }
187 
188 /*
189  * MPSAFE
190  */
191 int
192 vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
193 {
194 	VFS_MPLOCK_DECLARE;
195 	int error;
196 
197 	VFS_MPLOCK(mp);
198 	error = (mp->mnt_op->vfs_statvfs)(mp, sbp, cred);
199 	VFS_MPUNLOCK();
200 	return (error);
201 }
202 
203 /*
204  * MPSAFE
205  */
206 int
207 vfs_sync(struct mount *mp, int waitfor)
208 {
209 	VFS_MPLOCK_DECLARE;
210 	int error;
211 
212 	VFS_MPLOCK(mp);
213 	error = (mp->mnt_op->vfs_sync)(mp, waitfor);
214 	VFS_MPUNLOCK();
215 	return (error);
216 }
217 
218 /*
219  * MPSAFE
220  */
221 int
222 vfs_vget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
223 {
224 	VFS_MPLOCK_DECLARE;
225 	int error;
226 
227 	VFS_MPLOCK(mp);
228 	error = (mp->mnt_op->vfs_vget)(mp, dvp, ino, vpp);
229 	VFS_MPUNLOCK();
230 	return (error);
231 }
232 
233 /*
234  * MPSAFE
235  */
236 int
237 vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
238 	   struct fid *fhp, struct vnode **vpp)
239 {
240 	VFS_MPLOCK_DECLARE;
241 	int error;
242 
243 	VFS_MPLOCK(mp);
244 	error = (mp->mnt_op->vfs_fhtovp)(mp, rootvp, fhp, vpp);
245 	VFS_MPUNLOCK();
246 	return (error);
247 }
248 
249 /*
250  * MPSAFE
251  */
252 int
253 vfs_checkexp(struct mount *mp, struct sockaddr *nam,
254 	     int *extflagsp, struct ucred **credanonp)
255 {
256 	VFS_MPLOCK_DECLARE;
257 	int error;
258 
259 	VFS_MPLOCK(mp);
260 	error = (mp->mnt_op->vfs_checkexp)(mp, nam, extflagsp, credanonp);
261 	VFS_MPUNLOCK();
262 	return (error);
263 }
264 
265 /*
266  * MPSAFE
267  */
268 int
269 vfs_vptofh(struct vnode *vp, struct fid *fhp)
270 {
271 	VFS_MPLOCK_DECLARE;
272 	int error;
273 
274 	VFS_MPLOCK(vp->v_mount);
275 	error = (vp->v_mount->mnt_op->vfs_vptofh)(vp, fhp);
276 	VFS_MPUNLOCK();
277 	return (error);
278 }
279 
280 /*
281  * MPSAFE
282  */
283 int
284 vfs_init(struct vfsconf *vfc)
285 {
286 	int error;
287 
288 	error = (vfc->vfc_vfsops->vfs_init)(vfc);
289 
290 	return (error);
291 }
292 
293 /*
294  * MPSAFE
295  */
296 int
297 vfs_uninit(struct vfsconf *vfc, struct vfsconf *vfsp)
298 {
299 	int error;
300 
301 	error = (vfc->vfc_vfsops->vfs_uninit)(vfsp);
302 
303 	return (error);
304 }
305 
306 /*
307  * MPSAFE
308  */
309 int
310 vfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
311 		 int attrnamespace, const char *attrname,
312 		 struct ucred *cred)
313 {
314 	VFS_MPLOCK_DECLARE;
315 	int error;
316 
317 	VFS_MPLOCK(mp);
318 	error = (mp->mnt_op->vfs_extattrctl)(mp, cmd, vp,
319 					     attrnamespace, attrname,
320 					     cred);
321 	VFS_MPUNLOCK();
322 	return (error);
323 }
324