Port cache manager to NetBSD-5 and NetBSD-current
[openafs.git] / src / afs / NBSD / osi_vm.c
index 39f8921..5cc2beb 100644 (file)
@@ -24,9 +24,6 @@
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afs/afsincludes.h"   /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* statistics */
-/* #include <vm/vm_ubc.h> */
-#include <limits.h>
-#include <float.h>
 
 /* Try to discard pages, in order to recycle a vcache entry.
  *
 int
 osi_VM_FlushVCache(struct vcache *avc, int *slept)
 {
+    struct vnode *vp = AFSTOV(avc);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s enter\n", __func__);
+    }
+
+    if (vp == NULL) {
+       printf("%s NULL vp\n", __func__);
+       return 0;
+    }
+
+    AFS_GUNLOCK();
+    cache_purge(vp);
+    vflushbuf(vp, 1);
+    AFS_GLOCK();
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s exit\n", __func__);
+    }
+
     return 0;
 }
 
@@ -58,6 +75,22 @@ osi_VM_FlushVCache(struct vcache *avc, int *slept)
 void
 osi_VM_StoreAllSegments(struct vcache *avc)
 {
+    struct vnode *vp;
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s enter\n", __func__);
+    }
+
+    ReleaseWriteLock(&avc->lock);
+    AFS_GUNLOCK();
+    vp = AFSTOV(avc);
+    mutex_enter(&vp->v_interlock);
+    VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES|PGO_CLEANIT|PGO_SYNCIO);
+    AFS_GLOCK();
+    ObtainWriteLock(&avc->lock, 94);
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s exit\n", __func__);
+    }
 }
 
 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
@@ -72,6 +105,17 @@ osi_VM_StoreAllSegments(struct vcache *avc)
 void
 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
 {
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s enter\n", __func__);
+    }
+
+    ReleaseWriteLock(&avc->lock);
+    osi_VM_FlushVCache(avc, NULL);
+    ObtainWriteLock(&avc->lock, 59);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s exit\n", __func__);
+    }
 }
 
 /* Purge VM for a file when its callback is revoked.
@@ -81,6 +125,23 @@ osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
 void
 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
 {
+    struct vnode *vp = AFSTOV(avc);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s enter\n", __func__);
+    }
+
+    if (!vp) {
+       printf("%s NULL vp\n", __func__);
+       return;
+    }
+
+    cache_purge(vp);
+    vinvalbuf(vp, 0, credp, curlwp, false, 1);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s exit\n", __func__);
+    }
 }
 
 /* Purge pages beyond end-of-file, when truncating a file.
@@ -90,6 +151,17 @@ osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
  * it only works on Solaris.
  */
 void
-osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
+osi_VM_Truncate(struct vcache *avc, voff_t alen, afs_ucred_t *acred)
 {
+    struct vnode *vp = AFSTOV(avc);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s enter\n", __func__);
+    }
+
+    vtruncbuf(vp, alen, false, 0);
+
+    if ((afs_debug & AFSDEB_VNLAYER) != 0) {
+       printf("%s exit\n", __func__);
+    }
 }