Remove nonsensical bozon-lock defines
[openafs.git] / src / afs / SOLARIS / 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 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* statistics */
17 #include "afs/nfsclient.h"
18
19 /* This file contains Solaris VM-related code for the cache manager. */
20
21 #include <sys/mman.h>
22 #include <vm/hat.h>
23 #include <vm/as.h>
24 #include <vm/page.h>
25 #include <vm/pvn.h>
26 #include <vm/seg.h>
27 #include <vm/seg_map.h>
28 #include <vm/seg_vn.h>
29 #include <vm/rm.h>
30 #include <sys/modctl.h>
31 #include <sys/syscall.h>
32 #include <sys/debug.h>
33 #include <sys/fs_subr.h>
34
35 /* Try to invalidate pages, in order to recycle a dcache entry.
36  *
37  * This function only exists for Solaris.  For other platforms, it's OK to
38  * recycle a dcache entry without invalidating pages, because the strategy
39  * function can call afs_GetDCache().
40  *
41  * Locking:  only the global lock is held on entry.
42  */
43 int
44 osi_VM_GetDownD(struct vcache *avc, struct dcache *adc)
45 {
46     int code;
47
48     AFS_GUNLOCK();
49     code =
50         afs_putpage(AFSTOV(avc), (offset_t) AFS_CHUNKTOBASE(adc->f.chunk),
51                     AFS_CHUNKTOSIZE(adc->f.chunk), B_INVAL, CRED());
52     AFS_GLOCK();
53
54     return code;
55 }
56
57 /* Try to discard pages, in order to recycle a vcache entry.
58  *
59  * We also make some sanity checks:  ref count, open count, held locks.
60  *
61  * We also do some non-VM-related chores, such as releasing the cred pointer
62  * (for AIX and Solaris) and releasing the gnode (for AIX).
63  *
64  * Locking:  afs_xvcache lock is held.  If it is dropped and re-acquired,
65  *   *slept should be set to warn the caller.
66  *
67  * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
68  * is not dropped and re-acquired for any platform.  It may be that *slept is
69  * therefore obsolescent.
70  */
71 int
72 osi_VM_FlushVCache(struct vcache *avc, int *slept)
73 {
74     if (avc->vrefCount != 0)
75         return EBUSY;
76
77     if (avc->opens)
78         return EBUSY;
79
80     /* if a lock is held, give up */
81     if (CheckLock(&avc->lock))
82         return EBUSY;
83
84     AFS_GUNLOCK();
85     pvn_vplist_dirty(AFSTOV(avc), 0, NULL, B_TRUNC | B_INVAL, CRED());
86     AFS_GLOCK();
87
88     /* Might as well make the obvious check */
89     if (AFSTOV(avc)->v_pages)
90         return EBUSY;           /* should be all gone still */
91
92     rw_destroy(&avc->rwlock);
93     if (avc->credp) {
94         crfree(avc->credp);
95         avc->credp = NULL;
96     }
97
98
99     return 0;
100 }
101
102 /* Try to store pages to cache, in order to store a file back to the server.
103  *
104  * Locking:  the vcache entry's lock is held.  It will usually be dropped and
105  * re-obtained.
106  */
107 void
108 osi_VM_StoreAllSegments(struct vcache *avc)
109 {
110     AFS_GUNLOCK();
111     (void)pvn_vplist_dirty(AFSTOV(avc), (u_offset_t) 0, afs_putapage, 0,
112                            CRED());
113     AFS_GLOCK();
114 }
115
116 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
117  * try to free pages, when deleting a file.
118  *
119  * Locking:  the vcache entry's lock is held.  It may be dropped and
120  * re-obtained.
121  */
122 void
123 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
124 {
125     AFS_GUNLOCK();
126     (void)pvn_vplist_dirty(AFSTOV(avc), (u_offset_t) 0, afs_putapage,
127                            (sync ? B_INVAL : B_FREE), acred);
128     AFS_GLOCK();
129 }
130
131 /* Purge VM for a file when its callback is revoked.
132  *
133  * Locking:  No lock is held, not even the global lock.
134  */
135 void
136 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
137 {
138     extern int afs_pvn_vptrunc;
139
140     afs_pvn_vptrunc++;
141     (void)afs_putpage(AFSTOV(avc), (offset_t) 0, 0, B_TRUNC | B_INVAL, credp);
142 }
143
144 /* Zero no-longer-used part of last page, when truncating a file
145  *
146  * This function only exists for Solaris.  Other platforms do not support it.
147  *
148  * Locking:  the vcache entry lock is held.  It is released and re-obtained.
149  * The caller will raise activeV (to prevent pageins), but this function must
150  * be called first, since it causes a pagein.
151  */
152 void
153 osi_VM_PreTruncate(struct vcache *avc, int alen, afs_ucred_t *acred)
154 {
155     page_t *pp;
156     int pageOffset = (alen & PAGEOFFSET);
157
158     if (pageOffset == 0) {
159         return;
160     }
161
162     ReleaseWriteLock(&avc->lock);
163     AFS_GUNLOCK();
164     pp = page_lookup(AFSTOV(avc), alen - pageOffset, SE_EXCL);
165     if (pp) {
166         pagezero(pp, pageOffset, PAGESIZE - pageOffset);
167         page_unlock(pp);
168     }
169     AFS_GLOCK();
170     ObtainWriteLock(&avc->lock, 563);
171 }
172
173 /* Purge pages beyond end-of-file, when truncating a file.
174  *
175  * Locking:  no lock is held, not even the global lock.
176  * Pageins are blocked (activeV is raised).
177  */
178 void
179 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
180 {
181     /*
182      * It's OK to specify afs_putapage here, even though we aren't holding
183      * the vcache entry lock, because it isn't going to get called.
184      */
185     pvn_vplist_dirty(AFSTOV(avc), alen, afs_putapage, B_TRUNC | B_INVAL,
186                      acred);
187 }