2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 /* osi_vm.c implements:
13 * osi_VM_FlushVCache(avc, slept)
14 * osi_ubc_flush_dirty_and_wait(vp, flags)
15 * osi_VM_StoreAllSegments(avc)
16 * osi_VM_TryToSmush(avc, acred, sync)
17 * osi_VM_FlushPages(avc, credp)
18 * osi_VM_Truncate(avc, alen, acred)
21 #include <afsconfig.h>
22 #include "afs/param.h"
27 #include "afs/sysincludes.h" /* Standard vendor system headers */
28 #include "afsincludes.h" /* Afs-based standard headers */
29 #include "afs/afs_stats.h" /* statistics */
30 #include <vm/vm_object.h>
31 #include <vm/vm_map.h>
35 /* Try to discard pages, in order to recycle a vcache entry.
37 * We also make some sanity checks: ref count, open count, held locks.
39 * We also do some non-VM-related chores, such as releasing the cred pointer
40 * (for AIX and Solaris) and releasing the gnode (for AIX).
42 * Locking: afs_xvcache lock is held. If it is dropped and re-acquired,
43 * *slept should be set to warn the caller.
45 * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
46 * is not dropped and re-acquired for any platform. It may be that *slept is
47 * therefore obsolescent.
49 * OSF/1 Locking: VN_LOCK has been called.
52 osi_VM_FlushVCache(struct vcache *avc, int *slept)
54 struct vm_object *obj;
56 if (VREFCOUNT(avc) > 1)
62 /* if a lock is held, give up */
63 if (CheckLock(&avc->lock) || afs_CheckBozonLock(&avc->pvnLock))
68 simple_lock(&vp->v_interlock);
69 if (VOP_GETVOBJECT(vp, &obj) == 0) {
70 vm_object_page_remove(obj, 0, 0, FALSE);
72 if (obj->ref_count == 0) {
74 simple_lock(&vp->v_interlock);
80 simple_unlock(&vp->v_interlock);
86 /* Try to store pages to cache, in order to store a file back to the server.
88 * Locking: the vcache entry's lock is held. It will usually be dropped and
92 osi_VM_StoreAllSegments(struct vcache *avc)
95 struct vm_object *obj;
98 ReleaseWriteLock(&avc->lock);
104 simple_lock(&vp->v_interlock);
105 if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) {
106 #ifdef AFS_FBSD50_ENV
107 if (!vget(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, curthread)) {
110 (vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ,
113 if (VOP_GETVOBJECT(vp, &obj) == 0) {
114 vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
120 simple_unlock(&vp->v_interlock);
121 } while (anyio && (--tries > 0));
123 ObtainWriteLock(&avc->lock, 94);
126 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
127 * try to free pages, when deleting a file.
129 * Locking: the vcache entry's lock is held. It may be dropped and
132 * Since we drop and re-obtain the lock, we can't guarantee that there won't
133 * be some pages around when we return, newly created by concurrent activity.
136 osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync)
139 struct vm_object *obj;
142 ReleaseWriteLock(&avc->lock);
148 simple_lock(&vp->v_interlock);
149 if (VOP_GETVOBJECT(vp, &obj) == 0 && (obj->flags & OBJ_MIGHTBEDIRTY)) {
150 #ifdef AFS_FBSD50_ENV
151 if (!vget(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, curthread)) {
154 (vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY | LK_NOOBJ,
157 if (VOP_GETVOBJECT(vp, &obj) == 0) {
158 vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
164 simple_unlock(&vp->v_interlock);
165 } while (anyio && (--tries > 0));
166 simple_lock(&vp->v_interlock);
167 if (VOP_GETVOBJECT(vp, &obj) == 0) {
168 vm_object_page_remove(obj, 0, 0, FALSE);
170 simple_unlock(&vp->v_interlock);
171 /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */
173 ObtainWriteLock(&avc->lock, 59);
176 /* Purge VM for a file when its callback is revoked.
178 * Locking: No lock is held, not even the global lock.
181 osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
184 struct vm_object *obj;
187 simple_lock(&vp->v_interlock);
188 if (VOP_GETVOBJECT(vp, &obj) == 0) {
189 vm_object_page_remove(obj, 0, 0, FALSE);
191 simple_unlock(&vp->v_interlock);
192 /*vinvalbuf(AFSTOV(avc),0, NOCRED, curproc, 0,0); */
195 /* Purge pages beyond end-of-file, when truncating a file.
197 * Locking: no lock is held, not even the global lock.
198 * activeV is raised. This is supposed to block pageins, but at present
199 * it only works on Solaris.
202 osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
204 vnode_pager_setsize(AFSTOV(avc), alen);