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