openbsd-shutdown-panic-20040311
[openafs.git] / src / afs / OBSD / osi_vfsops.c
index 5dcabf1..5b34edb 100644 (file)
@@ -43,7 +43,7 @@ Reserved.
 You are hereby granted a worldwide, irrevocable, paid-up, right and
 license to use, execute, display, modify, copy and distribute MIT's
 Modifications, provided that (i) you abide by the terms and conditions
-of your Transarc AFS License Agreement, and (ii) you do not use the name
+of the OpenAFS License Agreement, and (ii) you do not use the name
 of MIT in any advertising or publicity without the prior written consent
 of MIT.  MIT disclaims all liability for your use of MIT's
 Modifications.  MIT's Modifications are provided "AS IS" WITHOUT
@@ -93,11 +93,12 @@ NONINFRINGEMENT.
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID("$Header$");
+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/afs_stats.h"     /* statistics */
 
 #include <sys/conf.h>
 #include <sys/exec.h>
@@ -109,11 +110,11 @@ RCSID("$Header$");
 /* from /usr/src/sys/kern/vfs_subr.c */
 extern void insmntque(struct vnode *, struct mount *);
 
-#define NBSD_DONTFOLLOW_LINK 0
-#define NBSD_FOLLOW_LINK 1
+extern int sys_lkmnosys(), afs3_syscall(), afs_xioctl(), Afs_xsetgroups();
 
 static int lkmid = -1;
-static int afs_badcall(struct proc *p, void *xx, register_t *yy);
+static int afs_badcall(struct proc *p, void *xx, register_t * yy);
+static struct sysent old_sysent;
 
 char afs_NetBSD_osname[] = "OpenBSD";
 struct osi_vfs *afs_globalVFS;
@@ -150,11 +151,8 @@ struct vfsops afs_vfsops = {
 };
 
 int
-afs_nbsd_lookupname(char *fnamep,
-                   enum uio_seg segflg,
-                   int followlink,
-                   struct vnode **dirvpp,
-                   struct vnode **compvpp)
+afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg, int followlink,
+                   struct vnode **dirvpp, struct vnode **compvpp)
 {
     struct nameidata nd;
     int niflag;
@@ -166,13 +164,10 @@ afs_nbsd_lookupname(char *fnamep,
      * pathname is user or system space.
      */
     /* XXX LOCKLEAF ? */
-    niflag =  (followlink == NBSD_FOLLOW_LINK) ? FOLLOW : NOFOLLOW;
+    niflag = followlink ? FOLLOW : NOFOLLOW;
     if (dirvpp)
-       niflag |= WANTPARENT;           /* XXX LOCKPARENT? */
-    NDINIT(&nd, LOOKUP,
-          niflag,
-          segflg,
-          fnamep, osi_curproc());
+       niflag |= WANTPARENT;   /* XXX LOCKPARENT? */
+    NDINIT(&nd, LOOKUP, niflag, segflg, fnamep, osi_curproc());
     if ((error = namei(&nd)))
        return error;
     *compvpp = nd.ni_vp;
@@ -196,14 +191,14 @@ afs_sysctl()
 int
 afs_checkexp()
 {
-       return EOPNOTSUPP;
+    return EOPNOTSUPP;
 }
 
 int
 afs_fhtovp(mp, fhp, vpp)
-struct mount *mp;
-struct fid *fhp;
-struct vnode **vpp;
+     struct mount *mp;
+     struct fid *fhp;
+     struct vnode **vpp;
 {
 
     return (EINVAL);
@@ -211,8 +206,8 @@ struct vnode **vpp;
 
 int
 afs_vptofh(vp, fhp)
-struct vnode *vp;
-struct fid *fhp;
+     struct vnode *vp;
+     struct fid *fhp;
 {
 
     return (EINVAL);
@@ -220,23 +215,23 @@ struct fid *fhp;
 
 int
 afs_start(mp, flags, p)
-struct mount *mp;
-int flags;
-struct proc *p;
+     struct mount *mp;
+     int flags;
+     struct proc *p;
 {
-    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;
+     register struct mount *mp;
+     char *path;
+     caddr_t data;
+     struct nameidata *ndp;
+     struct proc *p;
 {
     /* 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 proc struct. */
     int size;
 
     if (mp->mnt_flag & MNT_UPDATE)
@@ -248,6 +243,7 @@ struct proc *p;
     }
 
     AFS_STATCNT(afs_mount);
+    AFS_GLOCK();
 
 #ifdef AFS_DISCON_ENV
     /* initialize the vcache entries before we start using them */
@@ -257,25 +253,26 @@ struct proc *p;
 #endif
     afs_globalVFS = mp;
     mp->osi_vfs_bsize = 8192;
-    mp->osi_vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
-    mp->osi_vfs_fsid.val[1] = (int) AFS_VFSFSID; 
+    mp->osi_vfs_fsid.val[0] = AFS_VFSMAGIC;    /* magic */
+    mp->osi_vfs_fsid.val[1] = (int)AFS_VFSFSID;
 
-    (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size);
+    (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
     bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
     bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
     strcpy(mp->mnt_stat.f_mntfromname, "AFS");
     /* null terminated string "AFS" will fit, just leave it be. */
     strcpy(mp->mnt_stat.f_fstypename, MOUNT_AFS);
-    (void) afs_statfs(mp, &mp->mnt_stat);
+    AFS_GUNLOCK();
+    (void)afs_statfs(mp, &mp->mnt_stat);
 
     return 0;
 }
 
 int
 afs_unmount(afsp, flags, p)
-struct mount *afsp;
-int flags;
-struct proc *p;
+     struct mount *afsp;
+     int flags;
+     struct proc *p;
 {
     extern int sys_ioctl(), sys_setgroups();
 
@@ -283,20 +280,20 @@ struct proc *p;
 #ifdef AFS_DISCON_ENV
     give_up_cbs();
 #endif
-    if (!afs_globalVFS) {
+    if (afs_globalVFS == NULL) {
        printf("afs already unmounted\n");
        return 0;
     }
     if (afs_globalVp)
-       AFS_RELE(AFSTOV(afs_globalVp));
+       vrele(AFSTOV(afs_globalVp));
     afs_globalVp = NULL;
 
-    vflush(afsp, NULLVP, 0); /* don't support forced */
+    vflush(afsp, NULLVP, 0);   /* don't support forced */
     afsp->mnt_data = NULL;
     AFS_GLOCK();
     afs_globalVFS = 0;
     afs_cold_shutdown = 1;
-    afs_shutdown();                    /* XXX */
+    afs_shutdown();            /* XXX */
     AFS_GUNLOCK();
 
     /* give up syscall entries for ioctl & setgroups, which we've stolen */
@@ -307,12 +304,14 @@ struct proc *p;
     sysent[AFS_SYSCALL].sy_narg = 0;
     sysent[AFS_SYSCALL].sy_argsize = 0;
     sysent[AFS_SYSCALL].sy_call = afs_badcall;
-    printf("AFS unmounted--use `/sbin/modunload -i %d' to unload before restarting AFS\n", lkmid);
+    printf
+       ("AFS unmounted--use `/sbin/modunload -i %d' to unload before restarting AFS\n",
+        lkmid);
     return 0;
 }
 
 static int
-afs_badcall(struct proc *p, void *xx, register_t *yy)
+afs_badcall(struct proc *p, void *xx, register_t * yy)
 {
     return ENOSYS;
 }
@@ -328,8 +327,7 @@ afs_nbsd_getnewvnode(struct vcache *tvc)
 }
 
 int
-afs_root(struct mount *mp,
-             struct vnode **vpp)
+afs_root(struct mount *mp, struct vnode **vpp)
 {
     struct vrequest treq;
     struct vcache *tvp;
@@ -338,19 +336,19 @@ afs_root(struct mount *mp,
     AFS_STATCNT(afs_root);
 
     AFS_GLOCK();
-    if (!(code = afs_InitReq(&treq, osi_curcred())) &&
-       !(code = afs_CheckInit())) {
+    if (!(code = afs_InitReq(&treq, osi_curcred()))
+       && !(code = afs_CheckInit())) {
        tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
        if (tvp) {
            /* There is really no reason to over-hold this bugger--it's held
-              by the root filesystem reference. */
+            * by the root filesystem reference. */
            if (afs_globalVp != tvp) {
 #ifdef AFS_DONT_OVERHOLD_GLOBALVP
                if (afs_globalVp)
                    AFS_RELE(AFSTOV(afs_globalVp));
 #endif
                afs_globalVp = tvp;
-               AFS_HOLD(AFSTOV(afs_globalVp));
+               VREF(AFSTOV(afs_globalVp));
            }
            AFSTOV(tvp)->v_flag |= VROOT;
            afs_globalVFS = mp;
@@ -361,7 +359,7 @@ afs_root(struct mount *mp,
     AFS_GUNLOCK();
 
     if (!code)
-       vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curproc); /* return it locked */
+       vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curproc);        /* return it locked */
     return code;
 }
 
@@ -377,9 +375,10 @@ afs_statfs(struct osi_vfs *afsp, struct statfs *abp)
      * enough * space in the device partition before storing something there
      * (like * ed(1))
      */
-    abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = abp->f_ffree  = 9000000;
-    abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */
-    abp->f_fsid.val[1] = (int) AFS_VFSFSID;
+    abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
+       abp->f_ffree = 9000000;
+    abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */
+    abp->f_fsid.val[1] = (int)AFS_VFSFSID;
     return 0;
 }
 
@@ -394,30 +393,10 @@ afs_sync(struct osi_vfs *afsp)
     return 0;
 }
 
-void
-afs_nbsd_ref(struct vnode *vp)
-{
-    if (vp->v_usecount == 0) {
-       vprint("holding unheld node", vp);
-       panic("afs_ref");
-    }
-    VREF(vp);
-}
-
-void
-afs_nbsd_rele(struct vnode *vp)
-{
-    if (vp->v_usecount <= 0) {
-       vprint("rele'ing unheld node", vp);
-       panic("afs_rele");
-    }
-    vrele(vp);
-}
-
 int
 afs_vget(vp, lfl)
-struct vnode *vp;
-int lfl;
+     struct vnode *vp;
+     int lfl;
 {
     int error;
 
@@ -454,20 +433,20 @@ static char afsbfrmem[] = "afsbfrmem";
 int
 afsinit()
 {
-    extern int afs3_syscall(), afs_xioctl(), Afs_xsetgroups(), afs_xflock();
+    old_sysent = sysent[AFS_SYSCALL];
 
     sysent[AFS_SYSCALL].sy_call = afs3_syscall;
     sysent[AFS_SYSCALL].sy_narg = 6;
     sysent[AFS_SYSCALL].sy_argsize = 6 * sizeof(long);
-    sysent[54].sy_call = afs_xioctl;
-    sysent[80].sy_call = Afs_xsetgroups;
+    sysent[SYS_ioctl].sy_call = afs_xioctl;
+    sysent[SYS_setgroups].sy_call = Afs_xsetgroups;
+    osi_Init();
 
     return 0;
 }
 
 int
-afs_vfs_load(struct lkm_table *lkmtp,
-            int cmd)
+afs_vfs_load(struct lkm_table *lkmtp, int cmd)
 {
     extern char *memname[];
 
@@ -487,11 +466,9 @@ afs_vfs_load(struct lkm_table *lkmtp,
 }
 
 int
-afs_vfs_unload(struct lkm_table *lktmp,
-            int cmd)
+afs_vfs_unload(struct lkm_table *lktmp, int cmd)
 {
     extern char *memname[];
-    extern int sys_lkmnosys();
 
     if (afs_globalVp)
        return EBUSY;
@@ -507,32 +484,25 @@ afs_vfs_unload(struct lkm_table *lktmp,
     if (memname[M_AFSBUFFER] == afsbfrmem)
        memname[M_AFSBUFFER] = NULL;
 
-    sysent[AFS_SYSCALL].sy_call = sys_lkmnosys;
+    sysent[AFS_SYSCALL] = old_sysent;
     printf("OpenAFS unloaded\n");
     return 0;
 }
 
-
-
 int
-afsmodload(struct lkm_table *lkmtp,
-          int cmd,
-          int ver)
+libafs_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
 {
-    extern int sys_lkmnosys();
-
     if (cmd == LKM_E_LOAD) {
-       if (strcmp(ostype,afs_NetBSD_osname)) {
+       if (strcmp(ostype, afs_NetBSD_osname)) {
            printf("This is %s version %s\n", ostype, osrelease);
-           printf("This version of AFS is only for %s\n",
-                  afs_NetBSD_osname);
-/*         return EPROGMISMATCH;*/
+           printf("This version of AFS is only for %s\n", afs_NetBSD_osname);
+           return EPROGMISMATCH;
        }
-       if (sysent[AFS_SYSCALL].sy_call != sys_lkmnosys) {
-           printf("AFS must be loaded with syscall %d assigned to sys_lkmnosys\nIs AFS already loaded?\n",
-                  AFS_SYSCALL);
+       if (sysent[AFS_SYSCALL].sy_call == afs3_syscall
+           || sysent[AFS_SYSCALL].sy_call == afs_badcall) {
+           printf("AFS already loaded\n");
            return EINVAL;
        }
     }
-    DISPATCH(lkmtp,cmd,ver,afs_vfs_load,afs_vfs_unload,lkm_nofunc);
+    DISPATCH(lkmtp, cmd, ver, afs_vfs_load, afs_vfs_unload, lkm_nofunc);
 }