Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / OBSD / osi_vm.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
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
8 */
9
10
11 /* osi_vm.c implements:
12 *
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)
19 */
20
21 #include <afsconfig.h>
22 #include "afs/param.h"
23
24
25 #include "afs/sysincludes.h" /* Standard vendor system headers */
26 #include "afs/afsincludes.h" /* Afs-based standard headers */
27 #include "afs/afs_stats.h" /* statistics */
28 #include <sys/namei.h>
29 #include <limits.h>
30 #include <float.h>
31
32 /* Try to discard pages, in order to recycle a vcache entry.
33 *
34 * We also make some sanity checks: ref count, open count, held locks.
35 *
36 * We also do some non-VM-related chores, such as releasing the cred pointer
37 * (for AIX and Solaris) and releasing the gnode (for AIX).
38 *
39 * Locking: afs_xvcache lock is held. It must not be dropped.
40 *
41 * OSF/1 Locking: VN_LOCK has been called.
42 */
43 int
44 osi_VM_FlushVCache(struct vcache *avc)
45 {
46 struct vnode *vp = AFSTOV(avc);
47
48 if (!vp)
49 return 0;
50 AFS_GUNLOCK();
51
52 cache_purge(vp);
53 uvm_vnp_uncache(vp);
54
55 AFS_GLOCK();
56 return 0;
57 }
58
59 /* Try to store pages to cache, in order to store a file back to the server.
60 *
61 * Locking: the vcache entry's lock is held. It will usually be dropped and
62 * re-obtained.
63 *
64 */
65 void
66 osi_VM_StoreAllSegments(struct vcache *avc)
67 {
68 }
69
70 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
71 * try to free pages, when deleting a file.
72 *
73 * Locking: the vcache entry's lock is held. It may be dropped and
74 * re-obtained.
75 *
76 * Since we drop and re-obtain the lock, we can't guarantee that there won't
77 * be some pages around when we return, newly created by concurrent activity.
78 */
79 void
80 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
81 {
82 ReleaseWriteLock(&avc->lock);
83 osi_VM_FlushVCache(avc);
84 ObtainWriteLock(&avc->lock, 59);
85 }
86
87 /* Purge VM for a file when its callback is revoked.
88 *
89 * Locking: No lock is held, not even the global lock.
90 */
91 void
92 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
93 {
94 struct vnode *vp = AFSTOV(avc);
95
96 if (!vp)
97 return;
98 cache_purge(vp);
99 uvm_vnp_uncache(vp);
100 uvm_vnp_setsize(vp, avc->f.m.Length);
101 }
102
103 /* Purge pages beyond end-of-file, when truncating a file.
104 *
105 * Locking: no lock is held, not even the global lock.
106 * activeV is raised. This is supposed to block pageins, but at present
107 * it only works on Solaris.
108 */
109 void
110 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
111 {
112 uvm_vnp_setsize(AFSTOV(avc), alen);
113 }