SOLARIS: let xlator load if amd64/nfssrv is loaded
[openafs.git] / src / afs / SOLARIS / osi_vfsops.c
index 482e210..9a3e08b 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,7 +24,9 @@ RCSID
 #endif
 #include <sys/kobj.h>
 
-
+#ifdef AFS_SUN58_ENV
+# include <sys/mount.h>
+#endif
 
 struct vfs *afs_globalVFS = 0;
 struct vcache *afs_globalVp = 0;
@@ -39,7 +39,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();
@@ -73,12 +73,14 @@ afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
 
 #if defined(AFS_SUN58_ENV)
 int
-afs_unmount(struct vfs *afsp, int flag, struct AFS_UCRED *credp)
+afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
 #else
 int
-afs_unmount(struct vfs *afsp, struct AFS_UCRED *credp)
+afs_unmount(struct vfs *afsp, afs_ucred_t *credp)
 #endif
 {
+    struct vcache *rootvp = NULL;
+
     AFS_GLOCK();
     AFS_STATCNT(afs_unmount);
 
@@ -90,19 +92,66 @@ afs_unmount(struct vfs *afsp, struct AFS_UCRED *credp)
         AFS_GUNLOCK();
         return (EPERM);
     }
+
+#ifdef AFS_SUN58_ENV
+    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;
+#endif /* AFS_SUN58_ENV */
+
+    /* 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);
+
+#ifndef AFS_SUN58_ENV
+    /* shutdown now, since afs_freevfs() will not be called */
     afs_globalVFS = 0;
     afs_shutdown();
+#endif /* !AFS_SUN58_ENV */
 
     AFS_GUNLOCK();
     return 0;
 }
 
+#ifdef AFS_SUN58_ENV
+void
+afs_freevfs(struct vfs *afsp)
+{
+    AFS_GLOCK();
+
+    afs_globalVFS = 0;
+    afs_shutdown();
+
+    AFS_GUNLOCK();
+}
+#endif /* AFS_SUN58_ENV */
+
 int
 afs_root(struct vfs *afsp, struct vnode **avpp)
 {
     register afs_int32 code = 0;
     struct vrequest treq;
     register struct vcache *tvp = 0;
+    struct vcache *gvp;
     struct proc *proc = ttoproc(curthread);
     struct vnode *vp = afsp->vfs_vnodecovered;
     int locked = 0;
@@ -118,7 +167,8 @@ afs_root(struct vfs *afsp, struct vnode **avpp)
 
     AFS_STATCNT(afs_root);
 
-    if (afs_globalVp && (afs_globalVp->states & CStatd)) {
+again:
+    if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
        tvp = afs_globalVp;
     } else {
        if (MUTEX_HELD(&vp->v_lock)) {
@@ -128,8 +178,9 @@ afs_root(struct vfs *afsp, struct vnode **avpp)
        }
 
        if (afs_globalVp) {
-           afs_PutVCache(afs_globalVp);
+           gvp = afs_globalVp;
            afs_globalVp = NULL;
+           afs_PutVCache(gvp);
        }
 
        if (!(code = afs_InitReq(&treq, proc->p_cred))
@@ -137,13 +188,19 @@ afs_root(struct vfs *afsp, struct vnode **avpp)
            tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
            /* we really want this to stay around */
            if (tvp) {
+               if (afs_globalVp) {
+                   /* someone else got there before us! */
+                   afs_PutVCache(tvp);
+                   tvp = 0;
+                   goto again;
+               }
                afs_globalVp = tvp;
            } else
                code = ENOENT;
        }
     }
     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);
@@ -192,7 +249,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;
 }
@@ -258,7 +315,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 = afs_freevfs },
     NULL,                      NULL
 };
 struct vfsops *afs_vfsopsp;
@@ -272,7 +329,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,           afs_freevfs,
     NULL,                      NULL
 };
 struct vfsops *afs_vfsopsp;
@@ -287,7 +344,7 @@ struct vfsops Afs_vfsops = {
     afs_mountroot,
     afs_swapvp,
 #if defined(AFS_SUN58_ENV)
-    fs_freevfs,
+    afs_freevfs,
 #endif
 };
 #endif
@@ -408,12 +465,22 @@ afsinit(struct vfssw *vfsswp, int fstype)
 }
 
 #ifdef AFS_SUN510_ENV
+#ifdef AFS_SUN511_ENV
+static vfsdef_t afs_vfsdef = {
+    VFSDEF_VERSION,
+    "afs",
+    afsinit,
+    0,
+    NULL
+};
+#else
 static struct vfsdef_v3 afs_vfsdef = {
     VFSDEF_VERSION,
     "afs",
     afsinit,
     0
 };
+#endif
 #else
 static struct vfssw afs_vfw = {
     "afs",
@@ -514,7 +581,8 @@ _init()
 #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))
     {