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