FBSD try-relax child vnode locking (recurse only)
[openafs.git] / src / afs / FBSD / osi_vnodeops.c
index 0e7a6d1..cbd94d7 100644 (file)
@@ -478,7 +478,7 @@ afs_vop_lookup(ap)
     int error;
     struct vcache *vcp;
     struct vnode *vp, *dvp;
-    register int flags = ap->a_cnp->cn_flags;
+    int flags = ap->a_cnp->cn_flags;
     int lockparent;            /* 1 => lockparent flag is set */
     int wantparent;            /* 1 => wantparent or lockparent flag */
     struct thread *p = ap->a_cnp->cn_thread;
@@ -548,7 +548,7 @@ afs_vop_lookup(ap)
            MA_VOP_UNLOCK(dvp, 0, p);   /* done with parent. */
 #endif
        }
-       ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
+       ma_vn_lock(vp, LK_EXCLUSIVE | LK_CANRECURSE | LK_RETRY, p);
        /* always return the child locked */
     }
     *ap->a_vpp = vp;
@@ -572,7 +572,7 @@ afs_vop_create(ap)
 {
     int error = 0;
     struct vcache *vcp;
-    register struct vnode *dvp = ap->a_dvp;
+    struct vnode *dvp = ap->a_dvp;
     struct thread *p = ap->a_cnp->cn_thread;
     GETNAME();
 
@@ -666,8 +666,24 @@ afs_vop_close(ap)
                                 * struct thread *a_td;
                                 * } */ *ap;
 {
-    int code;
-    struct vcache *avc = VTOAFS(ap->a_vp);
+    int code, iflag;
+    struct vnode *vp = ap->a_vp;
+    struct vcache *avc = VTOAFS(vp);
+
+#if defined(AFS_FBSD80_ENV)
+    VI_LOCK(vp);
+    iflag = vp->v_iflag & VI_DOOMED;
+    VI_UNLOCK(vp);
+    if (iflag & VI_DOOMED) {
+        /* osi_FlushVCache (correctly) calls vgone() on recycled vnodes, we don't
+         * have an afs_close to process, in that case */
+        if (avc->opens != 0)
+            panic("afs_vop_close: doomed vnode %p has vcache %p with non-zero opens %d\n",
+                  vp, avc, avc->opens);
+        return 0;
+    }
+#endif
+
     AFS_GLOCK();
     if (ap->a_cred)
        code = afs_close(avc, ap->a_fflag, ap->a_cred);
@@ -707,9 +723,11 @@ afs_vop_getattr(ap)
                                 * } */ *ap;
 {
     int code;
+
     AFS_GLOCK();
     code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
     AFS_GUNLOCK();
+
     return code;
 }
 
@@ -1085,7 +1103,7 @@ afs_vop_fsync(ap)
                                 * } */ *ap;
 {
     int error;
-    register struct vnode *vp = ap->a_vp;
+    struct vnode *vp = ap->a_vp;
 
     AFS_GLOCK();
     /*vflushbuf(vp, wait); */
@@ -1110,8 +1128,8 @@ afs_vop_remove(ap)
                                 * } */ *ap;
 {
     int error = 0;
-    register struct vnode *vp = ap->a_vp;
-    register struct vnode *dvp = ap->a_dvp;
+    struct vnode *vp = ap->a_vp;
+    struct vnode *dvp = ap->a_dvp;
 
     GETNAME();
     AFS_GLOCK();
@@ -1131,8 +1149,8 @@ afs_vop_link(ap)
                                 * } */ *ap;
 {
     int error = 0;
-    register struct vnode *dvp = ap->a_tdvp;
-    register struct vnode *vp = ap->a_vp;
+    struct vnode *dvp = ap->a_tdvp;
+    struct vnode *vp = ap->a_vp;
     struct thread *p = ap->a_cnp->cn_thread;
 
     GETNAME();
@@ -1144,7 +1162,7 @@ afs_vop_link(ap)
        error = EISDIR;
        goto out;
     }
-    if ((error = ma_vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
+    if ((error = ma_vn_lock(vp, LK_CANRECURSE | LK_EXCLUSIVE, p)) != 0) {
        goto out;
     }
     AFS_GLOCK();
@@ -1174,9 +1192,9 @@ afs_vop_rename(ap)
     struct componentname *tcnp = ap->a_tcnp;
     char *tname;
     struct vnode *tvp = ap->a_tvp;
-    register struct vnode *tdvp = ap->a_tdvp;
+    struct vnode *tdvp = ap->a_tdvp;
     struct vnode *fvp = ap->a_fvp;
-    register struct vnode *fdvp = ap->a_fdvp;
+    struct vnode *fdvp = ap->a_fdvp;
     struct thread *p = fcnp->cn_thread;
 
     /*
@@ -1275,8 +1293,8 @@ afs_vop_mkdir(ap)
                                 * struct vattr *a_vap;
                                 * } */ *ap;
 {
-    register struct vnode *dvp = ap->a_dvp;
-    register struct vattr *vap = ap->a_vap;
+    struct vnode *dvp = ap->a_dvp;
+    struct vattr *vap = ap->a_vap;
     int error = 0;
     struct vcache *vcp;
     struct thread *p = ap->a_cnp->cn_thread;
@@ -1311,7 +1329,7 @@ afs_vop_rmdir(ap)
                                 * } */ *ap;
 {
     int error = 0;
-    register struct vnode *dvp = ap->a_dvp;
+    struct vnode *dvp = ap->a_dvp;
 
     GETNAME();
     AFS_GLOCK();
@@ -1433,7 +1451,7 @@ afs_vop_inactive(ap)
                                 * struct thread *td;
                                 * } */ *ap;
 {
-    register struct vnode *vp = ap->a_vp;
+    struct vnode *vp = ap->a_vp;
 
     if (prtactive && vp->v_usecount != 0)
        vprint("afs_vop_inactive(): pushing active", vp);
@@ -1467,18 +1485,14 @@ afs_vop_reclaim(struct vop_reclaim_args *ap)
     if (!haveVlock)
        ObtainWriteLock(&afs_xvcache, 901);
     /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
-    code = afs_FlushVS(avc);
+    code = afs_FlushVCache(avc, &slept);
     if (!haveVlock)
        ReleaseWriteLock(&afs_xvcache);
     if (!haveGlock)
        AFS_GUNLOCK();
 
-    /*
-     * XXX Pretend it worked, to prevent panic on shutdown
-     * Garrett, please fix - Jim Rees
-     */
     if (code) {
-       printf("afs_vop_reclaim: afs_FlushVCache failed code %d vnode\n", code);
+       afs_warn("afs_vop_reclaim: afs_FlushVCache failed code %d vnode\n", code);
        VOP_PRINT(vp);
     }
 
@@ -1535,11 +1549,11 @@ afs_vop_print(ap)
                                 * struct vnode *a_vp;
                                 * } */ *ap;
 {
-    register struct vnode *vp = ap->a_vp;
-    register struct vcache *vc = VTOAFS(ap->a_vp);
+    struct vnode *vp = ap->a_vp;
+    struct vcache *vc = VTOAFS(ap->a_vp);
     int s = vc->f.states;
 
-    printf("tag %s, fid: %d.%d.%d.%d, opens %d, writers %d", vp->v_tag,
+    printf("vc %p vp %p tag %s, fid: %d.%d.%d.%d, opens %d, writers %d", vc, vp, vp->v_tag,
           (int)vc->f.fid.Cell, (u_int) vc->f.fid.Fid.Volume,
           (u_int) vc->f.fid.Fid.Vnode, (u_int) vc->f.fid.Fid.Unique, vc->opens,
           vc->execsOrWriters);