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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #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 * OSF/1 Locking: VN_LOCK has been called.
36 osi_VM_FlushVCache(struct vcache *avc, int *slept)
38 struct vnode *vp = AFSTOV(avc);
46 if (!(UBCINFOMISSING(vp) || UBCINFORECLAIMED(vp))) {
48 kret=ubc_invalidate(vp,0,size);
58 /* Try to store pages to cache, in order to store a file back to the server.
60 * Locking: the vcache entry's lock is held. It will usually be dropped and
64 osi_VM_StoreAllSegments(struct vcache *avc)
66 struct vnode *vp = AFSTOV(avc);
67 ReleaseWriteLock(&avc->lock);
69 #ifdef AFS_DARWIN80_ENV
70 ubc_sync_range(vp, 0, ubc_getsize(vp), UBC_SYNC|UBC_PUSHDIRTY);
72 if (UBCINFOEXISTS(vp)) {
77 ObtainWriteLock(&avc->lock, 94);
80 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
81 * try to free pages, when deleting a file.
83 * Locking: the vcache entry's lock is held. It may be dropped and
86 * Since we drop and re-obtain the lock, we can't guarantee that there won't
87 * be some pages around when we return, newly created by concurrent activity.
90 osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync)
92 struct vnode *vp = AFSTOV(avc);
97 ReleaseWriteLock(&avc->lock);
99 #ifdef AFS_DARWIN80_ENV
100 ubc_sync_range(vp, 0, ubc_getsize(vp), UBC_INVALIDATE);
102 if (UBCINFOEXISTS(vp)) {
103 size = ubc_getsize(vp);
104 kret = ubc_invalidate(vp, 0, size);
105 if (kret != 1) /* should be KERN_SUCCESS */
106 printf("TryToSmush: invalidate failed (error = %d)\n", kret);
110 ObtainWriteLock(&avc->lock, 59);
113 /* Purge VM for a file when its callback is revoked.
115 * Locking: No lock is held, not even the global lock.
117 /* XXX this seems to not be referenced anywhere. *somebody* ought to be calling
118 this, and also making sure that ubc's idea of the filesize is right more
121 osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
123 struct vnode *vp = AFSTOV(avc);
127 #ifdef AFS_DARWIN80_ENV
128 size = ubc_getsize(vp);
129 ubc_sync_range(vp, 0, size, UBC_INVALIDATE);
130 /* XXX what about when not CStatd */
131 if (avc->f.states & CStatd && size != avc->f.m.Length)
132 ubc_setsize(vp, avc->f.m.Length);
134 if (UBCINFOEXISTS(vp)) {
135 size = ubc_getsize(vp);
136 kret = ubc_invalidate(vp, 0, size);
137 if (kret != 1) /* Should be KERN_SUCCESS */
138 printf("VMFlushPages: invalidate failed (error = %d)\n", kret);
139 /* XXX what about when not CStatd */
140 if (avc->f.states & CStatd && size != avc->f.m.Length)
142 ubc_setsize(vp, avc->f.m.Length);
147 /* Purge pages beyond end-of-file, when truncating a file.
149 * Locking: no lock is held, not even the global lock.
150 * activeV is raised. This is supposed to block pageins, but at present
151 * it only works on Solaris.
154 osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
156 struct vnode *vp = AFSTOV(avc);
157 #ifdef AFS_DARWIN80_ENV
158 ubc_setsize(vp, alen);
160 if (UBCINFOEXISTS(vp) && UBCISVALID(vp)) {
161 ubc_setsize(vp, alen);
167 osi_VM_NukePages(struct vnode *vp, off_t offset, off_t size)
171 struct vcache *avc = VTOAFS(vp);
173 offset = trunc_page(offset);
174 size = round_page(size + 1);
176 ubc_page_op(vp, (vm_offset_t) offset,
177 UPL_POP_SET | UPL_POP_BUSY | UPL_POP_DUMP, 0, 0);
185 osi_VM_Setup(struct vcache *avc, int force)
188 struct vnode *vp = AFSTOV(avc);
190 #ifndef AFS_DARWIN80_ENV
191 if (UBCISVALID(vp) && ((avc->f.states & CStatd) || force)) {
192 if (!UBCINFOEXISTS(vp)) {
194 avc->f.states |= CUBCinit;
196 if ((error = ubc_info_init(vp))) {
198 avc->f.states &= ~CUBCinit;
203 avc->f.states &= ~CUBCinit;
206 if (UBCINFOEXISTS(vp) && UBCISVALID(vp)) {
207 ubc_setsize(vp, avc->f.m.Length);