From 297c776822954dd524fc2ffd18df2023134fae4a Mon Sep 17 00:00:00 2001 From: ad Date: Mon, 7 Jan 2008 12:34:12 +0000 Subject: [PATCH] Make VFS_SYNC() and friends functions, and have them acquire kernel_lock if the FS is not marked MPSAFE. --- sys/kern/vfs_subr2.c | 186 ++++++++++++++++++++++++++++++++++++++++++- sys/sys/mount.h | 34 ++++---- 2 files changed, 203 insertions(+), 17 deletions(-) diff --git a/sys/kern/vfs_subr2.c b/sys/kern/vfs_subr2.c index d66b502417f5..602e2af99648 100644 --- a/sys/kern/vfs_subr2.c +++ b/sys/kern/vfs_subr2.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr2.c,v 1.9 2008/01/02 11:48:56 ad Exp $ */ +/* $NetBSD: vfs_subr2.c,v 1.10 2008/01/07 12:34:12 ad Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.9 2008/01/02 11:48:56 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.10 2008/01/07 12:34:12 ad Exp $"); #include "opt_ddb.h" @@ -170,6 +170,8 @@ vntblinit(void) /* * Lookup a mount point by filesystem identifier. + * + * XXX Needs to add a reference to the mount point. */ struct mount * vfs_getvfs(fsid_t *fsid) @@ -991,6 +993,186 @@ mount_setspecific(struct mount *mp, specificdata_key_t key, void *data) &mp->mnt_specdataref, key, data); } +int +VFS_MOUNT(struct mount *mp, const char *a, void *b, size_t *c) +{ + int error; + + KERNEL_LOCK(1, NULL); + error = (*(mp->mnt_op->vfs_mount))(mp, a, b, c); + KERNEL_UNLOCK_ONE(NULL); + + return error; +} + +int +VFS_START(struct mount *mp, int a) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_start))(mp, a); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_UNMOUNT(struct mount *mp, int a) +{ + int error; + + KERNEL_LOCK(1, NULL); + error = (*(mp->mnt_op->vfs_unmount))(mp, a); + KERNEL_UNLOCK_ONE(NULL); + + return error; +} + +int +VFS_ROOT(struct mount *mp, struct vnode **a) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_root))(mp, a); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_QUOTACTL(struct mount *mp, int a, uid_t b, void *c) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_quotactl))(mp, a, b, c); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_STATVFS(struct mount *mp, struct statvfs *a) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_statvfs))(mp, a); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_SYNC(struct mount *mp, int a, struct kauth_cred *b) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_sync))(mp, a, b); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_FHTOVP(struct mount *mp, struct fid *a, struct vnode **b) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_fhtovp))(mp, a, b); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_VPTOFH(struct vnode *vp, struct fid *a, size_t *b) +{ + int error; + + if ((vp->v_vflag & VV_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(vp->v_mount->mnt_op->vfs_vptofh))(vp, a, b); + if ((vp->v_vflag & VV_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_SNAPSHOT(struct mount *mp, struct vnode *a, struct timespec *b) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_snapshot))(mp, a, b); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + +int +VFS_EXTATTRCTL(struct mount *mp, int a, struct vnode *b, int c, const char *d) +{ + int error; + + KERNEL_LOCK(1, NULL); /* XXXSMP check ffs */ + error = (*(mp->mnt_op->vfs_extattrctl))(mp, a, b, c, d); + KERNEL_UNLOCK_ONE(NULL); /* XXX */ + + return error; +} + +int +VFS_SUSPENDCTL(struct mount *mp, int a) +{ + int error; + + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_LOCK(1, NULL); + } + error = (*(mp->mnt_op->vfs_suspendctl))(mp, a); + if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) { + KERNEL_UNLOCK_ONE(NULL); + } + + return error; +} + #ifdef DDB static const char buf_flagbits[] = BUF_FLAGBITS; diff --git a/sys/sys/mount.h b/sys/sys/mount.h index b8a17691a843..6371118c318c 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $NetBSD: mount.h,v 1.169 2008/01/02 11:49:07 ad Exp $ */ +/* $NetBSD: mount.h,v 1.170 2008/01/07 12:34:12 ad Exp $ */ /* * Copyright (c) 1989, 1991, 1993 @@ -215,21 +215,25 @@ struct vfsops { LIST_ENTRY(vfsops) vfs_list; }; -#define VFS_MOUNT(MP, PATH, DATA, DATA_LEN) \ - (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, DATA_LEN) -#define VFS_START(MP, FLAGS) (*(MP)->mnt_op->vfs_start)(MP, FLAGS) -#define VFS_UNMOUNT(MP, FORCE) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE) -#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) -#define VFS_QUOTACTL(MP,C,U,A) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A) -#define VFS_STATVFS(MP, SBP) (*(MP)->mnt_op->vfs_statvfs)(MP, SBP) -#define VFS_SYNC(MP, WAIT, C) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C) +/* XXX Actually file system internal. */ #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) -#define VFS_FHTOVP(MP, FIDP, VPP) (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP) -#define VFS_VPTOFH(VP, FIDP, FIDSZP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP, FIDSZP) -#define VFS_SNAPSHOT(MP, VP, TS) (*(MP)->mnt_op->vfs_snapshot)(MP, VP, TS) -#define VFS_EXTATTRCTL(MP, C, VP, AS, AN) \ - (*(MP)->mnt_op->vfs_extattrctl)(MP, C, VP, AS, AN) -#define VFS_SUSPENDCTL(MP, C) (*(MP)->mnt_op->vfs_suspendctl)(MP, C) + +int VFS_MOUNT(struct mount *, const char *, void *, size_t *); +int VFS_START(struct mount *, int); +int VFS_UNMOUNT(struct mount *, int); +int VFS_ROOT(struct mount *, struct vnode **); +int VFS_QUOTACTL(struct mount *, int, uid_t, void *); +int VFS_STATVFS(struct mount *, struct statvfs *); +int VFS_SYNC(struct mount *, int, struct kauth_cred *); +int VFS_FHTOVP(struct mount *, struct fid *, struct vnode **); +int VFS_VPTOFH(struct vnode *, struct fid *, size_t *); +void VFS_INIT(void); +void VFS_REINIT(void); +void VFS_DONE(void); +int VFS_MOUNTROOT(void); +int VFS_SNAPSHOT(struct mount *, struct vnode *, struct timespec *); +int VFS_EXTATTRCTL(struct mount *, int, struct vnode *, int, const char *); +int VFS_SUSPENDCTL(struct mount *, int); #endif /* _KERNEL || __VFSOPS_EXPOSE */