FBSD restore old syscall register logic for older kernels
[openafs.git] / src / afs / FBSD / osi_vfsops.c
index faa0fb7..23079f0 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
 
-#include <afs/sysincludes.h>            /* Standard vendor system headers */
-#include <afs/afsincludes.h>            /* Afs-based standard headers */
-#include <afs/afs_stats.h>              /* statistics */
+#include <afs/sysincludes.h>   /* Standard vendor system headers */
+#include <afsincludes.h>       /* Afs-based standard headers */
+#include <afs/afs_stats.h>     /* statistics */
 #include <sys/malloc.h>
 #include <sys/namei.h>
 #include <sys/conf.h>
+#include <sys/module.h>
+#include <sys/sysproto.h>
 #include <sys/syscall.h>
+#include <sys/sysent.h>
 
-struct vcache *afs_globalVp = 0;
-struct mount *afs_globalVFS = 0;
-int afs_pbuf_freecnt=-1;
-int
-afs_quotactl()
-{
-       return EOPNOTSUPP;
-}
+struct vcache *afs_globalVp = NULL;
+struct mount *afs_globalVFS = NULL;
+int afs_pbuf_freecnt = -1;
+
+extern int Afs_xsetgroups();
+extern int afs_xioctl();
+
+#if !defined(AFS_FBSD90_ENV)
+static sy_call_t *old_handler;
+#else
+static struct sysent old_sysent;
+
+static struct sysent afs_sysent = {
+    5,                 /* int sy_narg */
+    afs3_syscall,      /* sy_call_t *sy_call */
+#ifdef AFS_FBSD60_ENV
+    AUE_NULL,          /* au_event_t sy_auevent */
+#ifdef AFS_FBSD70_ENV
+    NULL,              /* systrace_args_funt_t sy_systrace_args_func */
+    0,                 /* u_int32_t sy_entry */
+    0,                 /* u_int32_t sy_return */
+#ifdef AFS_FBSD90_ENV
+    0,                 /* u_int32_t sy_flags */
+    0                  /* u_int32_t sy_thrcnt */
+#endif
+#endif
+#endif /* FBSD60 */
+};
+#endif /* FBSD90 */
 
 int
-afs_fhtovp(mp, fhp, vpp)
-struct mount *mp;
-struct fid *fhp;
-struct vnode **vpp;
+afs_init(struct vfsconf *vfc)
 {
-
-       return (EINVAL);
+    int code;
+    int offset = AFS_SYSCALL;
+#if defined(AFS_FBSD90_ENV)
+    code = syscall_register(&offset, &afs_sysent, &old_sysent);
+    if (code) {
+       printf("AFS_SYSCALL in use, error %i. aborting\n", code);
+       return code;
+    }
+#else
+    if (sysent[AFS_SYSCALL].sy_call != nosys
+        && sysent[AFS_SYSCALL].sy_call != lkmnosys) {
+        printf("AFS_SYSCALL in use. aborting\n");
+        return EBUSY;
+    }
+#endif
+    osi_Init();
+    afs_pbuf_freecnt = nswbuf / 2 + 1;
+#if !defined(AFS_FBSD90_ENV)
+    old_handler = sysent[AFS_SYSCALL].sy_call;
+    sysent[AFS_SYSCALL].sy_call = afs3_syscall;
+    sysent[AFS_SYSCALL].sy_narg = 5;
+#endif
+    return 0;
 }
 
 int
-afs_vptofh(vp, fhp)
-struct vnode *vp;
-struct fid *fhp;
+afs_uninit(struct vfsconf *vfc)
 {
+#if defined(AFS_FBSD90_ENV)
+    int offset = AFS_SYSCALL;
+#endif
 
-       return (EINVAL);
+    if (afs_globalVFS)
+       return EBUSY;
+#if defined(AFS_FBSD90_ENV)
+    syscall_deregister(&offset, &old_sysent);
+#else
+    sysent[AFS_SYSCALL].sy_narg = 0;
+    sysent[AFS_SYSCALL].sy_call = old_handler;
+#endif
+    return 0;
 }
 
 int
-afs_start(mp, flags, p)
-struct mount *mp;
-int flags;
-struct proc *p;
+afs_start(struct mount *mp, int flags, struct thread *p)
 {
-    afs_pbuf_freecnt = nswbuf / 2 + 1;
-    return (0);                         /* nothing to do. ? */
+    return (0);                        /* nothing to do. ? */
 }
 
 int
-afs_mount(mp, path, data, ndp, p)
-register struct mount *mp;
-char *path;
-caddr_t data;
-struct nameidata *ndp;
-struct proc *p;
+#if defined(AFS_FBSD80_ENV)
+afs_omount(struct mount *mp, char *path, caddr_t data)
+#elif defined(AFS_FBSD53_ENV)
+afs_omount(struct mount *mp, char *path, caddr_t data, struct thread *p)
+#else
+afs_omount(struct mount *mp, char *path, caddr_t data, struct nameidata *ndp,
+       struct thread *p)
+#endif
 {
     /* ndp contains the mounted-from device.  Just ignore it.
-       we also don't care about our proc struct. */
+     * we also don't care about our thread struct. */
     size_t size;
-    int error;
 
     if (mp->mnt_flag & MNT_UPDATE)
        return EINVAL;
@@ -68,118 +115,183 @@ struct proc *p;
     AFS_GLOCK();
     AFS_STATCNT(afs_mount);
 
-    if (afs_globalVFS) { /* Don't allow remounts. */
+    if (afs_globalVFS) {       /* Don't allow remounts. */
        AFS_GUNLOCK();
-       return (EBUSY);
+       return EBUSY;
     }
 
     afs_globalVFS = mp;
     mp->vfs_bsize = 8192;
     vfs_getnewfsid(mp);
-    mp->mnt_stat.f_iosize=8192;
-    
-    (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size);
+#ifdef AFS_FBSD70_ENV /* XXX 70? */
+    MNT_ILOCK(mp);
+    mp->mnt_flag &= ~MNT_LOCAL;
+    mp->mnt_kern_flag |= MNTK_MPSAFE; /* solid steel */
+#endif
+    mp->mnt_stat.f_iosize = 8192;
+
+    if (path != NULL)
+       copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
+    else
+       bcopy("/afs", mp->mnt_stat.f_mntonname, size = 4);
     memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
     memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
     strcpy(mp->mnt_stat.f_mntfromname, "AFS");
     /* null terminated string "AFS" will fit, just leave it be. */
     strcpy(mp->mnt_stat.f_fstypename, "afs");
+#ifdef AFS_FBSD70_ENV
+    MNT_IUNLOCK(mp);
+#endif
     AFS_GUNLOCK();
-    (void) afs_statfs(mp, &mp->mnt_stat, p);
+#ifdef AFS_FBSD80_ENV
+    afs_statfs(mp, &mp->mnt_stat);
+#else
+    afs_statfs(mp, &mp->mnt_stat, p);
+#endif
+
     return 0;
 }
 
+#ifdef AFS_FBSD53_ENV
 int
-afs_unmount(mp, flags, p)
-struct mount *mp;
-int flags;
-struct proc *p;
+#ifdef AFS_FBSD80_ENV
+afs_mount(struct mount *mp)
+#else
+afs_mount(struct mount *mp, struct thread *td)
+#endif
 {
-    
+#ifdef AFS_FBSD80_ENV
+    return afs_omount(mp, NULL, NULL);
+#else
+    return afs_omount(mp, NULL, NULL, td);
+#endif
+}
+#endif
+
+#ifdef AFS_FBSD60_ENV
+static int
+#ifdef AFS_FBSD80_ENV
+afs_cmount(struct mntarg *ma, void *data, int flags)
+#else
+afs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
+#endif
+{
+    return kernel_mount(ma, flags);
+}
+#endif
+
+int
+#ifdef AFS_FBSD80_ENV
+afs_unmount(struct mount *mp, int flags)
+#else
+afs_unmount(struct mount *mp, int flags, struct thread *p)
+#endif
+{
+    int error = 0;
+
+    /*
+     * Release any remaining vnodes on this mount point.
+     * The `1' means that we hold one extra reference on
+     * the root vnode (this is just a guess right now).
+     * This has to be done outside the global lock.
+     */
+#if defined(AFS_FBSD80_ENV)
+    error = vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0, curthread);
+#elif defined(AFS_FBSD53_ENV)
+    error = vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0, p);
+#else
+    error = vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0);
+#endif
+    if (error)
+       goto out;
     AFS_GLOCK();
     AFS_STATCNT(afs_unmount);
     afs_globalVFS = 0;
     afs_shutdown();
     AFS_GUNLOCK();
 
-    return 0;
+out:
+    return error;
 }
 
 int
-afs_root(struct mount *mp,
-             struct vnode **vpp)
+#if defined(AFS_FBSD80_ENV)
+afs_root(struct mount *mp, int flags, struct vnode **vpp)
+#elif defined(AFS_FBSD60_ENV)
+afs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
+#elif defined(AFS_FBSD53_ENV)
+afs_root(struct mount *mp, struct vnode **vpp, struct thread *td)
+#else
+afs_root(struct mount *mp, struct vnode **vpp)
+#endif
 {
     int error;
     struct vrequest treq;
-    register struct vcache *tvp=0;
-    struct proc *p=curproc;
-    struct ucred cr;
+    struct vcache *tvp = 0;
+#if !defined(AFS_FBSD53_ENV) || defined(AFS_FBSD80_ENV)
+    struct thread *td = curthread;
+#endif
+    struct ucred *cr = osi_curcred();
 
-    cr=*p->p_cred->pc_ucred;
     AFS_GLOCK();
     AFS_STATCNT(afs_root);
-    if (afs_globalVp && (afs_globalVp->states & CStatd)) {
+    crhold(cr);
+    if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
        tvp = afs_globalVp;
-        error=0;
+       error = 0;
     } else {
+tryagain:
        if (afs_globalVp) {
            afs_PutVCache(afs_globalVp);
+           /* vrele() needed here or not? */
            afs_globalVp = NULL;
        }
-
-       if (!(error = afs_InitReq(&treq, &cr)) &&
-           !(error = afs_CheckInit())) {
-           tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
-                               (struct vcache*)0, WRITE_LOCK);
+       if (!(error = afs_InitReq(&treq, cr)) && !(error = afs_CheckInit())) {
+           tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
            /* we really want this to stay around */
-           if (tvp) {
-               afs_globalVp = tvp;
-           } else
-               error = ENOENT;
+           if (tvp)
+               afs_globalVp = tvp;
+           else
+               error = ENOENT;
        }
     }
     if (tvp) {
-        osi_vnhold(tvp,0);
-    AFS_GUNLOCK();
-        vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
-    AFS_GLOCK();
+       struct vnode *vp = AFSTOV(tvp);
+
+       ASSERT_VI_UNLOCKED(vp, "afs_root");
+       AFS_GUNLOCK();
+       /*
+        * I'm uncomfortable about this.  Shouldn't this happen at a
+        * higher level, and shouldn't we busy the top-level directory
+        * to prevent recycling?
+        */
+       error = vget(vp, LK_EXCLUSIVE | LK_RETRY, td);
+       vp->v_vflag |= VV_ROOT;
+       AFS_GLOCK();
+       if (error != 0)
+               goto tryagain;
+
        afs_globalVFS = mp;
-       *vpp = AFSTOV(tvp);
-        tvp->v.v_flag |= VROOT;
+       *vpp = vp;
     }
 
-    afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
+    afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, tvp ? AFSTOV(tvp) : NULL,
               ICL_TYPE_INT32, error);
     AFS_GUNLOCK();
+    crfree(cr);
     return error;
 }
 
 int
-afs_vget(mp, lfl, vp)
-struct mount *mp;
-struct vnode *vp;
-int lfl;
-{
-    int error;
-    printf("vget called. help!\n");
-    if (vp->v_usecount < 0) {
-       vprint("bad usecount", vp);
-       panic("afs_vget");
-    }
-    error = vget(vp, lfl, curproc);
-    if (!error)
-       insmntque(vp, afs_globalVFS);   /* take off free list */
-    return error;
-}
-
-int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
+#ifdef AFS_FBSD80_ENV
+afs_statfs(struct mount *mp, struct statfs *abp)
+#else
+afs_statfs(struct mount *mp, struct statfs *abp, struct thread *p)
+#endif
 {
     AFS_GLOCK();
     AFS_STATCNT(afs_statfs);
 
-#if 0
-    abp->f_type = MOUNT_AFS;
-#endif
     abp->f_bsize = mp->vfs_bsize;
     abp->f_iosize = mp->vfs_bsize;
 
@@ -188,49 +300,65 @@ int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
      * storing something there.
      */
     abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
-       abp->f_ffree  = 2000000;
+       abp->f_ffree = 2000000;
 
     abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
     abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
     if (abp != &mp->mnt_stat) {
        abp->f_type = mp->mnt_vfc->vfc_typenum;
-       memcpy((caddr_t)&abp->f_mntonname[0], (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN);
-       memcpy((caddr_t)&abp->f_mntfromname[0], (caddr_t)mp->mnt_stat.f_mntfromname, MNAMELEN);
+       memcpy((caddr_t) & abp->f_mntonname[0],
+              (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN);
+       memcpy((caddr_t) & abp->f_mntfromname[0],
+              (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN);
     }
 
     AFS_GUNLOCK();
     return 0;
 }
 
-int afs_sync(mp, waitfor, cred, p) 
-struct mount *mp;
-int waitfor;
-struct ucred *cred;
-struct prioc *p;
+int
+#if defined(AFS_FBSD80_ENV)
+afs_sync(struct mount *mp, int waitfor)
+#elif defined(AFS_FBSD60_ENV)
+afs_sync(struct mount *mp, int waitfor, struct thread *td)
+#else
+afs_sync(struct mount *mp, int waitfor, struct ucred *cred, struct thread *p)
+#endif
 {
-return 0;
-}
-
-int afs_sysctl() {
-   return EOPNOTSUPP;
-}
-
-
-int afs_init(struct vfsconf *vfc) {
-   return 0;
+    return 0;
 }
 
+#ifdef AFS_FBSD60_ENV
 struct vfsops afs_vfsops = {
-  afs_mount,
-  afs_start,
-  afs_unmount,
-  afs_root,
-  afs_quotactl,
-  afs_statfs,
-  afs_sync,
-  afs_vget,
-  afs_fhtovp,
-  afs_vptofh,
-  afs_init,
-  afs_sysctl
+       .vfs_init =             afs_init,
+       .vfs_mount =            afs_mount,
+       .vfs_cmount =           afs_cmount,
+       .vfs_root =             afs_root,
+       .vfs_statfs =           afs_statfs,
+       .vfs_sync =             afs_sync,
+       .vfs_uninit =           afs_uninit,
+       .vfs_unmount =          afs_unmount,
+       .vfs_sysctl =           vfs_stdsysctl,
 };
+#else
+struct vfsops afs_vfsops = {
+#ifdef AFS_FBSD53_ENV
+    afs_mount,
+#endif
+    afs_omount,
+    afs_start,
+    afs_unmount,
+    afs_root,
+    vfs_stdquotactl,
+    afs_statfs,
+    afs_sync,
+    vfs_stdvget,
+    vfs_stdfhtovp,
+    vfs_stdcheckexp,
+    vfs_stdvptofh,
+    afs_init,
+    afs_uninit,
+    vfs_stdextattrctl,
+    vfs_stdsysctl,
+};
+#endif