FreeBSD/Linux Kernel Cross Reference
sys/kern/vfs_vfsops.c
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/thread2.h>
81 #include <sys/mplock2.h>
82
83 /*
84 * MPSAFE
85 */
86 int
87 vfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
88 {
89 VFS_MPLOCK_DECLARE;
90 int error;
91
92 VFS_MPLOCK1(mp);
93 error = (mp->mnt_op->vfs_mount)(mp, path, data, cred);
94 VFS_MPUNLOCK(mp);
95
96 return (error);
97 }
98
99 /*
100 * MPSAFE
101 */
102 int
103 vfs_start(struct mount *mp, int flags)
104 {
105 VFS_MPLOCK_DECLARE;
106 int error;
107
108 VFS_MPLOCK_FLAG(mp, MNTK_ST_MPSAFE);
109 error = (mp->mnt_op->vfs_start)(mp, flags);
110 if (error == 0) {
111 /* do not call vfs_acinit on mount updates */
112 if ((mp->mnt_flag & MNT_UPDATE) == 0)
113 VFS_ACINIT(mp,error);
114 }
115 VFS_MPUNLOCK(mp);
116 if (error == EMOUNTEXIT)
117 error = 0;
118 return (error);
119 }
120
121 /*
122 * MPSAFE
123 */
124 int
125 vfs_unmount(struct mount *mp, int mntflags)
126 {
127 VFS_MPLOCK_DECLARE;
128 int error;
129 int flags;
130
131 VFS_MPLOCK1(mp);
132 VFS_ACDONE(mp);
133 flags = mp->mnt_kern_flag;
134 error = (mp->mnt_op->vfs_unmount)(mp, mntflags);
135 if (error == 0)
136 vn_syncer_thr_stop(mp);
137 VFS_MPUNLOCK(mp);
138 return (error);
139 }
140
141 /*
142 * MPSAFE
143 */
144 int
145 vfs_root(struct mount *mp, struct vnode **vpp)
146 {
147 VFS_MPLOCK_DECLARE;
148 int error;
149
150 VFS_MPLOCK1(mp);
151 error = (mp->mnt_op->vfs_root)(mp, vpp);
152 VFS_MPUNLOCK(mp);
153 return (error);
154 }
155
156 /*
157 * MPSAFE
158 */
159 int
160 vfs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
161 struct ucred *cred)
162 {
163 VFS_MPLOCK_DECLARE;
164 int error;
165
166 VFS_MPLOCK1(mp);
167 error = (mp->mnt_op->vfs_quotactl)(mp, cmds, uid, arg, cred);
168 VFS_MPUNLOCK(mp);
169 return (error);
170 }
171
172 /*
173 * MPSAFE
174 */
175 int
176 vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
177 {
178 VFS_MPLOCK_DECLARE;
179 int error;
180
181 VFS_MPLOCK1(mp);
182 error = (mp->mnt_op->vfs_statfs)(mp, sbp, cred);
183 VFS_MPUNLOCK(mp);
184 return (error);
185 }
186
187 int
188 vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
189 {
190 VFS_MPLOCK_DECLARE;
191 int error;
192
193 VFS_MPLOCK1(mp);
194 error = (mp->mnt_op->vfs_statvfs)(mp, sbp, cred);
195 VFS_MPUNLOCK(mp);
196 return (error);
197 }
198
199 /*
200 * MPSAFE
201 */
202 int
203 vfs_sync(struct mount *mp, int waitfor)
204 {
205 VFS_MPLOCK_DECLARE;
206 int error;
207
208 VFS_MPLOCK1(mp);
209 error = (mp->mnt_op->vfs_sync)(mp, waitfor);
210 VFS_MPUNLOCK(mp);
211 return (error);
212 }
213
214 /*
215 * MPSAFE
216 */
217 int
218 vfs_vget(struct mount *mp, struct vnode *dvp, ino_t ino, struct vnode **vpp)
219 {
220 VFS_MPLOCK_DECLARE;
221 int error;
222
223 VFS_MPLOCK1(mp);
224 error = (mp->mnt_op->vfs_vget)(mp, dvp, ino, vpp);
225 VFS_MPUNLOCK(mp);
226 return (error);
227 }
228
229 /*
230 * MPSAFE
231 */
232 int
233 vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
234 struct fid *fhp, struct vnode **vpp)
235 {
236 VFS_MPLOCK_DECLARE;
237 int error;
238
239 VFS_MPLOCK1(mp);
240 error = (mp->mnt_op->vfs_fhtovp)(mp, rootvp, fhp, vpp);
241 VFS_MPUNLOCK(mp);
242 return (error);
243 }
244
245 /*
246 * MPSAFE
247 */
248 int
249 vfs_checkexp(struct mount *mp, struct sockaddr *nam,
250 int *extflagsp, struct ucred **credanonp)
251 {
252 VFS_MPLOCK_DECLARE;
253 int error;
254
255 VFS_MPLOCK1(mp);
256 error = (mp->mnt_op->vfs_checkexp)(mp, nam, extflagsp, credanonp);
257 VFS_MPUNLOCK(mp);
258 return (error);
259 }
260
261 /*
262 * MPSAFE
263 */
264 int
265 vfs_vptofh(struct vnode *vp, struct fid *fhp)
266 {
267 VFS_MPLOCK_DECLARE;
268 int error;
269
270 VFS_MPLOCK1(vp->v_mount);
271 error = (vp->v_mount->mnt_op->vfs_vptofh)(vp, fhp);
272 VFS_MPUNLOCK(vp->v_mount);
273 return (error);
274 }
275
276 /*
277 * MPSAFE
278 */
279 int
280 vfs_init(struct vfsconf *vfc)
281 {
282 int error;
283
284 get_mplock();
285 error = (vfc->vfc_vfsops->vfs_init)(vfc);
286 rel_mplock();
287
288 return (error);
289 }
290
291 /*
292 * MPSAFE
293 */
294 int
295 vfs_uninit(struct vfsconf *vfc, struct vfsconf *vfsp)
296 {
297 int error;
298
299 get_mplock();
300 error = (vfc->vfc_vfsops->vfs_uninit)(vfsp);
301 rel_mplock();
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_MPLOCK1(mp);
318 error = (mp->mnt_op->vfs_extattrctl)(mp, cmd, vp,
319 attrnamespace, attrname,
320 cred);
321 VFS_MPUNLOCK(mp);
322 return (error);
323 }
Cache object: 10e885c12241f320fc62450fad0097fb
|