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)
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"
24 #include "afs/sysincludes.h" /* Standard vendor system headers */
25 #include "afs/afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* statistics */
28 /* Try to discard pages, in order to recycle a vcache entry.
30 * We also make some sanity checks: ref count, open count, held locks.
32 * We also do some non-VM-related chores, such as releasing the cred pointer
33 * (for AIX and Solaris) and releasing the gnode (for AIX).
35 * Locking: afs_xvcache lock is held. It must not be dropped.
37 * OSF/1 Locking: VN_LOCK has been called.
40 osi_VM_FlushVCache(struct vcache
*avc
)
42 struct vnode
*vp
= AFSTOV(avc
);
44 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
45 printf("%s enter\n", __func__
);
49 printf("%s NULL vp\n", __func__
);
58 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
59 printf("%s exit\n", __func__
);
65 /* Try to store pages to cache, in order to store a file back to the server.
67 * Locking: the vcache entry's lock is held. It will usually be dropped and
71 osi_VM_StoreAllSegments(struct vcache
*avc
)
75 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
76 printf("%s enter\n", __func__
);
79 ReleaseWriteLock(&avc
->lock
);
82 mutex_enter(&vp
->v_interlock
);
83 VOP_PUTPAGES(vp
, 0, 0, PGO_ALLPAGES
|PGO_CLEANIT
|PGO_SYNCIO
);
85 ObtainWriteLock(&avc
->lock
, 94);
86 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
87 printf("%s exit\n", __func__
);
91 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
92 * try to free pages, when deleting a file.
94 * Locking: the vcache entry's lock is held. It may be dropped and
97 * Since we drop and re-obtain the lock, we can't guarantee that there won't
98 * be some pages around when we return, newly created by concurrent activity.
101 osi_VM_TryToSmush(struct vcache
*avc
, afs_ucred_t
*acred
, int sync
)
103 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
104 printf("%s enter\n", __func__
);
107 ReleaseWriteLock(&avc
->lock
);
108 osi_VM_FlushVCache(avc
);
109 ObtainWriteLock(&avc
->lock
, 59);
111 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
112 printf("%s exit\n", __func__
);
116 /* Purge VM for a file when its callback is revoked.
118 * Locking: No lock is held, not even the global lock.
121 osi_VM_FlushPages(struct vcache
*avc
, afs_ucred_t
*credp
)
123 struct vnode
*vp
= AFSTOV(avc
);
125 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
126 printf("%s enter\n", __func__
);
130 printf("%s NULL vp\n", __func__
);
135 vinvalbuf(vp
, 0, credp
, curlwp
, false, 1);
137 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
138 printf("%s exit\n", __func__
);
142 /* Purge pages beyond end-of-file, when truncating a file.
144 * Locking: no lock is held, not even the global lock.
145 * activeV is raised. This is supposed to block pageins, but at present
146 * it only works on Solaris.
149 osi_VM_Truncate(struct vcache
*avc
, voff_t alen
, afs_ucred_t
*acred
)
151 struct vnode
*vp
= AFSTOV(avc
);
153 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
154 printf("%s enter\n", __func__
);
157 vtruncbuf(vp
, alen
, false, 0);
159 if ((afs_debug
& AFSDEB_VNLAYER
) != 0) {
160 printf("%s exit\n", __func__
);