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 "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h" /* statistics */
18 #include "../afs/nfsclient.h"
20 #if defined(AFS_SUN5_ENV)
21 /* This file contains Solaris VM-related code for the cache manager. */
29 #include <vm/seg_map.h>
30 #include <vm/seg_vn.h>
32 #include <sys/modctl.h>
33 #include <sys/syscall.h>
34 #include <sys/debug.h>
35 #include <sys/fs_subr.h>
37 /* Try to invalidate pages, in order to recycle a dcache entry.
39 * This function only exists for Solaris. For other platforms, it's OK to
40 * recycle a dcache entry without invalidating pages, because the strategy
41 * function can call afs_GetDCache().
43 * Locking: only the global lock is held on entry.
46 osi_VM_GetDownD(avc, adc)
53 code = afs_putpage(AFSTOV(avc),
54 (offset_t) AFS_CHUNKTOBASE(adc->f.chunk),
55 AFS_CHUNKTOSIZE(adc->f.chunk),
62 /* Try to discard pages, in order to recycle a vcache entry.
64 * We also make some sanity checks: ref count, open count, held locks.
66 * We also do some non-VM-related chores, such as releasing the cred pointer
67 * (for AIX and Solaris) and releasing the gnode (for AIX).
69 * Locking: afs_xvcache lock is held. If it is dropped and re-acquired,
70 * *slept should be set to warn the caller.
72 * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
73 * is not dropped and re-acquired for any platform. It may be that *slept is
74 * therefore obsolescent.
77 osi_VM_FlushVCache(avc, slept)
81 if (avc->vrefCount != 0)
87 /* if a lock is held, give up */
88 if (CheckLock(&avc->lock))
90 if (afs_CheckBozonLock(&avc->pvnLock))
94 pvn_vplist_dirty(AFSTOV(avc), 0, NULL, B_TRUNC|B_INVAL, CRED());
97 /* Might as well make the obvious check */
98 if (AFSTOV(avc)->v_pages)
99 return EBUSY; /* should be all gone still */
101 rw_destroy(&avc->rwlock);
111 /* Try to store pages to cache, in order to store a file back to the server.
113 * Locking: the vcache entry's lock is held. It will usually be dropped and
117 osi_VM_StoreAllSegments(avc)
121 #if defined(AFS_SUN56_ENV)
122 (void) pvn_vplist_dirty(AFSTOV(avc), (u_offset_t)0, afs_putapage,
125 (void) pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage, 0, CRED());
130 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
131 * try to free pages, when deleting a file.
133 * Locking: the vcache entry's lock is held. It may be dropped and
137 osi_VM_TryToSmush(avc, acred, sync)
139 struct AFS_UCRED *acred;
143 #if defined(AFS_SUN56_ENV)
144 (void) pvn_vplist_dirty(AFSTOV(avc), (u_offset_t)0, afs_putapage,
145 (sync ? B_INVAL : B_FREE), acred);
147 (void) pvn_vplist_dirty(AFSTOV(avc), 0, afs_putapage,
148 (sync ? B_INVAL : B_FREE), acred);
153 /* Purge VM for a file when its callback is revoked.
155 * Locking: No lock is held, not even the global lock.
158 osi_VM_FlushPages(avc, credp)
160 struct AFS_UCRED *credp;
162 extern int afs_pvn_vptrunc;
165 (void) afs_putpage(AFSTOV(avc), (offset_t)0, 0,
166 B_TRUNC|B_INVAL, credp);
169 /* Zero no-longer-used part of last page, when truncating a file
171 * This function only exists for Solaris. Other platforms do not support it.
173 * Locking: the vcache entry lock is held. It is released and re-obtained.
174 * The caller will raise activeV (to prevent pageins), but this function must
175 * be called first, since it causes a pagein.
178 osi_VM_PreTruncate(avc, alen, acred)
181 struct AFS_UCRED *acred;
184 int pageOffset = (alen & PAGEOFFSET);
186 if (pageOffset == 0) {
190 ReleaseWriteLock(&avc->lock);
192 pp = page_lookup(AFSTOV(avc), alen - pageOffset, SE_EXCL);
194 pagezero(pp, pageOffset, PAGESIZE - pageOffset);
198 ObtainWriteLock(&avc->lock,563);
201 /* Purge pages beyond end-of-file, when truncating a file.
203 * Locking: no lock is held, not even the global lock.
204 * Pageins are blocked (activeV is raised).
207 osi_VM_Truncate(avc, alen, acred)
210 struct AFS_UCRED *acred;
213 * It's OK to specify afs_putapage here, even though we aren't holding
214 * the vcache entry lock, because it isn't going to get called.
216 pvn_vplist_dirty(AFSTOV(avc), alen, afs_putapage, B_TRUNC|B_INVAL,
220 #endif /* SUN5 && !NCR */