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
10 #include <afsconfig.h>
11 #include "afs/param.h"
15 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "afsincludes.h" /* Afs-based standard headers */
17 #include "afs/afs_stats.h" /* statistics */
19 /* Try to discard pages, in order to recycle a vcache entry.
21 * We also make some sanity checks: ref count, open count, held locks.
23 * We also do some non-VM-related chores, such as releasing the cred pointer
24 * (for AIX and Solaris) and releasing the gnode (for AIX).
26 * Locking: afs_xvcache lock is held. If it is dropped and re-acquired,
27 * *slept should be set to warn the caller.
29 * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
30 * is not dropped and re-acquired for any platform. It may be that *slept is
31 * therefore obsolescent.
33 int osi_VM_FlushVCache(struct vcache *avc, int *slept)
35 if (avc->vrefCount != 0)
41 /* Just in case someone is still referring to the vnode we
42 * give up trying to get rid of this guy */
43 if (avc->vrefCount || CheckLock(&avc->lock) || LockWaiters(&avc->lock))
48 vms_delete(avc->segid);
50 avc->segid = avc->vmh = NULL;
58 /* Free the alloced gnode that was accompanying the vcache's vnode */
59 aix_gnode_rele(AFSTOV(avc));
64 /* Try to store pages to cache, in order to store a file back to the server.
66 * Locking: the vcache entry's lock is held. It will usually be dropped and
69 void osi_VM_StoreAllSegments(struct vcache *avc)
73 * The execsOrWriters test is done so that we don't thrash on
74 * the vm_writep call below. We only initiate a pageout of the
75 * dirty vm pages on the last store...
76 * this is strictly a pragmatic decision, and _does_ break the
77 * advertised AFS consistency semantics. Without this hack,
78 * AIX systems panic under heavy load. I consider the current
79 * behavior a bug introduced to hack around a worse bug. XXX
81 * Removed do_writep governing sync'ing behavior.
83 ReleaseWriteLock(&avc->lock); /* XXX */
85 vm_writep(avc->vmh, 0, MAXFSIZE/PAGESIZE -1 );
88 ObtainWriteLock(&avc->lock,93); /* XXX */
90 * The following is necessary because of the following
91 * asynchronicity: We open a file, write to it and
93 * if CCore flag is set, we clear it and do the extra
94 * decrement ourselves now.
95 * If we're called by the CCore clearer, the CCore flag
96 * will already be clear, so we don't have to worry about
98 * avc was "VN_HELD" and "crheld" when CCore was set in
101 if (avc->states & CCore) {
102 avc->states &= ~CCore;
104 avc->execsOrWriters--;
105 AFS_RELE(AFSTOV(avc));
106 crfree((struct ucred *)avc->linkData);
107 avc->linkData = NULL;
112 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
113 * try to free pages, when deleting a file.
115 * Locking: the vcache entry's lock is held. It may be dropped and
118 * Since we drop and re-obtain the lock, we can't guarantee that there won't
119 * be some pages around when we return, newly created by concurrent activity.
121 void osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred,
125 ReleaseWriteLock(&avc->lock);
127 vm_flushp(avc->segid, 0, MAXFSIZE/PAGESIZE - 1);
128 vms_iowait(avc->vmh); /* XXX Wait?? XXX */
130 ObtainWriteLock(&avc->lock,60);
134 /* Purge VM for a file when its callback is revoked.
136 * Locking: No lock is held, not even the global lock.
138 void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
141 vm_flushp(avc->segid, 0, MAXFSIZE/PAGESIZE - 1);
143 * XXX We probably don't need to wait but better be safe XXX
145 vms_iowait(avc->vmh);
149 /* Purge pages beyond end-of-file, when truncating a file.
151 * Locking: no lock is held, not even the global lock.
152 * activeV is raised. This is supposed to block pageins, but at present
153 * it only works on Solaris.
155 void osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
158 int firstpage = (alen + PAGESIZE-1)/PAGESIZE;
159 vm_releasep(avc->segid, firstpage, MAXFSIZE/PAGESIZE - firstpage);
160 vms_iowait(avc->vmh); /* Do we need this? */