Remove support for Solaris pre-8
[openafs.git] / src / afs / SOLARIS / osi_vfsops.c
index 2792397..7d69c34 100644 (file)
@@ -13,8 +13,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
@@ -26,12 +24,12 @@ RCSID
 #endif
 #include <sys/kobj.h>
 
-
+#include <sys/mount.h>
 
 struct vfs *afs_globalVFS = 0;
 struct vcache *afs_globalVp = 0;
 
-#if defined(AFS_SUN57_64BIT_ENV)
+#if defined(AFS_SUN5_64BIT_ENV)
 extern struct sysent sysent32[];
 #endif
 
@@ -39,7 +37,7 @@ int afsfstype = 0;
 
 int
 afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
-         struct AFS_UCRED *credp)
+         afs_ucred_t *credp)
 {
 
     AFS_GLOCK();
@@ -71,14 +69,23 @@ afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
     return 0;
 }
 
-#if defined(AFS_SUN58_ENV)
-int
-afs_unmount(struct vfs *afsp, int flag, struct AFS_UCRED *credp)
-#else
+static void
+afs_freevfs(void)
+{
+    int i;
+    struct vcache *vc, *nvc;
+    extern struct vcache *afs_vhashT[VCSIZE];
+
+    afs_globalVFS = 0;
+
+    afs_shutdown();
+}
+
 int
-afs_unmount(struct vfs *afsp, struct AFS_UCRED *credp)
-#endif
+afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
 {
+    struct vcache *rootvp = NULL;
+
     AFS_GLOCK();
     AFS_STATCNT(afs_unmount);
 
@@ -90,19 +97,54 @@ afs_unmount(struct vfs *afsp, struct AFS_UCRED *credp)
         AFS_GUNLOCK();
         return (EPERM);
     }
-    afs_globalVFS = 0;
-    afs_shutdown();
+
+    if (flag & MS_FORCE) {
+       AFS_GUNLOCK();
+       return ENOTSUP;
+    }
+
+    /* We should have one reference from the caller, and one reference for the
+     * root vnode; any more and someone is still referencing something */
+    if (afsp->vfs_count > 2) {
+       AFS_GUNLOCK();
+       return EBUSY;
+    }
+
+    /* The root vnode should have one ref for the mount; any more, and someone
+     * else is using the root vnode */
+    if (afs_globalVp && VREFCOUNT_GT(afs_globalVp, 1)) {
+       AFS_GUNLOCK();
+       return EBUSY;
+    }
+
+    afsp->vfs_flag |= VFS_UNMOUNTED;
+
+    /* release the root vnode, which should be the last reference to us
+     * besides the caller of afs_unmount */
+    rootvp = afs_globalVp;
+    afs_globalVp = NULL;
+    AFS_RELE(rootvp);
 
     AFS_GUNLOCK();
     return 0;
 }
 
+void
+gafs_freevfs(struct vfs *afsp)
+{
+    AFS_GLOCK();
+
+    afs_freevfs();
+
+    AFS_GUNLOCK();
+}
+
 int
 afs_root(struct vfs *afsp, struct vnode **avpp)
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
     struct vrequest treq;
-    register struct vcache *tvp = 0;
+    struct vcache *tvp = 0;
     struct vcache *gvp;
     struct proc *proc = ttoproc(curthread);
     struct vnode *vp = afsp->vfs_vnodecovered;
@@ -120,7 +162,7 @@ afs_root(struct vfs *afsp, struct vnode **avpp)
     AFS_STATCNT(afs_root);
 
 again:
-    if (afs_globalVp && (afs_globalVp->states & CStatd)) {
+    if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
        tvp = afs_globalVp;
     } else {
        if (MUTEX_HELD(&vp->v_lock)) {
@@ -152,7 +194,7 @@ again:
        }
     }
     if (tvp) {
-       VN_HOLD(AFSTOV(tvp));
+       AFS_FAST_HOLD(tvp);
        mutex_enter(&AFSTOV(tvp)->v_lock);
        AFSTOV(tvp)->v_flag |= VROOT;
        mutex_exit(&AFSTOV(tvp)->v_lock);
@@ -177,13 +219,8 @@ again:
     return code;
 }
 
-#ifdef AFS_SUN56_ENV
 int
 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
-#else
-int
-afs_statvfs(struct vfs *afsp, struct statvfs *abp)
-#endif
 {
     AFS_GLOCK();
 
@@ -201,7 +238,7 @@ afs_statvfs(struct vfs *afsp, struct statvfs *abp)
 }
 
 int
-afs_sync(struct vfs *afsp, short flags, struct AFS_UCRED *credp)
+afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
 {
     return 0;
 }
@@ -267,7 +304,7 @@ static const fs_operation_def_t afs_vfsops_template[] = {
     VFSNAME_SYNC,              { .vfs_sync = afs_sync },
     VFSNAME_VGET,              { .vfs_vget = afs_vget },
     VFSNAME_MOUNTROOT,         { .vfs_mountroot = afs_mountroot },
-    VFSNAME_FREEVFS,           { .vfs_freevfs = fs_freevfs },
+    VFSNAME_FREEVFS,           { .vfs_freevfs = gafs_freevfs },
     NULL,                      NULL
 };
 struct vfsops *afs_vfsopsp;
@@ -281,7 +318,7 @@ const fs_operation_def_t afs_vfsops_template[] = {
     VFSNAME_SYNC,              afs_sync,
     VFSNAME_VGET,              afs_vget,
     VFSNAME_MOUNTROOT,         afs_mountroot,
-    VFSNAME_FREEVFS,           fs_freevfs,
+    VFSNAME_FREEVFS,           gafs_freevfs,
     NULL,                      NULL
 };
 struct vfsops *afs_vfsopsp;
@@ -295,9 +332,7 @@ struct vfsops Afs_vfsops = {
     afs_vget,
     afs_mountroot,
     afs_swapvp,
-#if defined(AFS_SUN58_ENV)
-    fs_freevfs,
-#endif
+    gafs_freevfs,
 };
 #endif
 
@@ -362,12 +397,12 @@ afsinit(struct vfssw *vfsswp, int fstype)
     sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
     sysent[SYS_ioctl].sy_call = afs_xioctl;
 
-#if defined(AFS_SUN57_64BIT_ENV)
+#if defined(AFS_SUN5_64BIT_ENV)
     afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
     afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
     sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
     sysent32[SYS_ioctl].sy_call = afs_xioctl;
-#endif /* AFS_SUN57_64BIT_ENV */
+#endif /* AFS_SUN5_64BIT_ENV */
 
 #ifdef AFS_SUN510_ENV
     vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
@@ -442,11 +477,13 @@ static struct vfssw afs_vfw = {
 };
 #endif
 
+#ifndef AFS_SUN511_ENV
 static struct sysent afssysent = {
     6,
     0,
     Afs_syscall
 };
+#endif /* AFS_SUN511_ENV */
 
 /* inter-module dependencies */
 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
@@ -455,7 +492,6 @@ char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
  * Info/Structs to link the afs module into the kernel
  */
 extern struct mod_ops mod_fsops;
-extern struct mod_ops mod_syscallops;
 
 static struct modlfs afsmodlfs = {
     &mod_fsops,
@@ -467,6 +503,13 @@ static struct modlfs afsmodlfs = {
 #endif
 };
 
+#ifdef AFS_SUN511_ENV
+
+extern struct modldrv afs_modldrv;
+
+#else /* AFS_SUN511_ENV */
+
+extern struct mod_ops mod_syscallops;
 static struct modlsys afsmodlsys = {
     &mod_syscallops,
     "afs syscall interface",
@@ -482,7 +525,7 @@ static struct modlsys afsmodlsys = {
   * land here from sysent or sysent32
   */
 
-#if defined(AFS_SUN57_64BIT_ENV)
+# if defined(AFS_SUN5_64BIT_ENV)
 extern struct mod_ops mod_syscallops32;
 
 static struct modlsys afsmodlsys32 = {
@@ -490,19 +533,37 @@ static struct modlsys afsmodlsys32 = {
     "afs syscall interface(32 bit)",
     &afssysent
 };
-#endif
+# endif
+#endif /* !AFS_SUN511_ENV */
 
 
 static struct modlinkage afs_modlinkage = {
     MODREV_1,
+    (void *)&afsmodlfs,
+#ifdef AFS_SUN511_ENV
+    (void *)&afs_modldrv,
+#else
     (void *)&afsmodlsys,
-#ifdef AFS_SUN57_64BIT_ENV
+# ifdef AFS_SUN5_64BIT_ENV
     (void *)&afsmodlsys32,
-#endif
-    (void *)&afsmodlfs,
+# endif
+#endif /* !AFS_SUN511_ENV */
     NULL
 };
 
+static void
+reset_sysent(void)
+{
+    if (afs_sinited) {
+       sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
+       sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
+#if defined(AFS_SUN5_64BIT_ENV)
+       sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
+       sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
+#endif
+    }
+}
+
 /** This is the function that modload calls when loading the afs kernel
   * extensions. The solaris modload program searches for the _init
   * function in a module and calls it when modloading
@@ -530,10 +591,10 @@ _init()
        return (ENOSYS);
     }
 #ifndef        AFS_NONFSTRANS
-#if     defined(AFS_SUN55_ENV)
     if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
         && !(mp = mod_find_by_filename(NULL, NFSSRV))
-        && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || (mp
+        && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))
+        && !(mp = mod_find_by_filename(NULL, NFSSRV_AMD64))) || (mp
                                                               && !mp->
                                                               mod_installed))
     {
@@ -541,58 +602,17 @@ _init()
            ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
        return (ENOSYS);
     }
-#else /* !AFS_SUN55_ENV */
-#if    defined(AFS_SUN52_ENV)
-    if ((!(mp = mod_find_by_filename("fs", "nfs"))
-        && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
-        && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
-                                                              && !mp->
-                                                              mod_installed))
-    {
-       printf
-           ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
-       return (ENOSYS);
-    }
-#endif /* AFS_SUN52_ENV */
-#endif /* AFS_SUN55_ENV */
 #endif /* !AFS_NONFSTRANS */
-#if !defined(AFS_SUN58_ENV)
-    /* 
-     * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
-     * reboot.  Ideally we would like to call modctl_read_sysbinding_file() but
-     * unfortunately in Solaris 2.2 it became a local function so we have to do
-     * the read_binding_file() direct call with the appropriate text file and
-     * system call hashtable.  make_syscallname actually copies "afs" to the
-     * proper slot entry and we also actually have to properly initialize the
-     * global sysent[AFS_SYSCALL] entry!
-     */
-#ifdef AFS_SUN53_ENV
-#ifndef        SYSBINDFILE
-#define        SYSBINDFILE     "/etc/name_to_sysnum"
-#endif /* SYSBINDFILE */
-    read_binding_file(SYSBINDFILE, sb_hashtab);
-#else /* !AFS_SUN53_ENV */
-    read_binding_file(sysbind, sb_hashtab);
-#endif /* AFS_SUN53_ENV */
-    make_syscallname("afs", AFS_SYSCALL);
-
-    if (sysent[AFS_SYSCALL].sy_call == nosys) {
-       if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
-           sysent[AFS_SYSCALL].sy_lock =
-               (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
-           rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
-#ifdef AFS_SUN57_ENV
-                   RW_DEFAULT, NULL);
-#else /* !AFS_SUN57_ENV */
-                   RW_DEFAULT, DEFAULT_WT);
-#endif /* AFS_SUN57_ENV */
-       }
-    }
-#endif /* !AFS_SUN58_ENV */
+
 
     osi_Init();                        /* initialize global lock, etc */
 
     code = mod_install(&afs_modlinkage);
+    if (code) {
+       /* we failed to load, so make sure we don't leave behind any
+        * references to our syscall handlers */
+       reset_sysent();
+    }
     return code;
 }
 
@@ -612,14 +632,7 @@ _fini()
     if (afs_globalVFS)
        return EBUSY;
 
-    if (afs_sinited) {
-       sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
-       sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
-#if defined(AFS_SUN57_64BIT_ENV)
-       sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
-       sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
-#endif
-    }
+    reset_sysent();
     code = mod_remove(&afs_modlinkage);
     return code;
 }