FBSD: use better casts in vop_advlock
[openafs.git] / src / afs / afs_bypasscache.h
1 /*
2  * COPYRIGHT  ©  2000
3  * THE REGENTS OF THE UNIVERSITY OF MICHIGAN
4  * ALL RIGHTS RESERVED
5  *
6  * Permission is granted to use, copy, create derivative works
7  * and redistribute this software and such derivative works
8  * for any purpose, so long as the name of The University of
9  * Michigan is not used in any advertising or publicity
10  * pertaining to the use of distribution of this software
11  * without specific, written prior authorization.  If the
12  * above copyright notice or any other identification of the
13  * University of Michigan is included in any copy of any
14  * portion of this software, then the disclaimer below must
15  * also be included.
16  *
17  * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
18  * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
19  * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY O
20  * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
21  * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
23  * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
24  * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
25  * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
26  * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
27  * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGES.
29  */
30
31  /*
32  * Portions Copyright (c) 2008
33  * The Linux Box Corporation
34  * ALL RIGHTS RESERVED
35  *
36  * Permission is granted to use, copy, create derivative works
37  * and redistribute this software and such derivative works
38  * for any purpose, so long as the name of the Linux Box
39  * Corporation is not used in any advertising or publicity
40  * pertaining to the use or distribution of this software
41  * without specific, written prior authorization.  If the
42  * above copyright notice or any other identification of the
43  * Linux Box Corporation is included in any copy of any
44  * portion of this software, then the disclaimer below must
45  * also be included.
46  *
47  * This software is provided as is, without representation
48  * from the Linux Box Corporation as to its fitness for any
49  * purpose, and without warranty by the Linux Box Corporation
50  * of any kind, either express or implied, including
51  * without limitation the implied warranties of
52  * merchantability and fitness for a particular purpose.  The
53  * Linux Box Corporation shall not be liable for any damages,
54  * including special, indirect, incidental, or consequential
55  * damages, with respect to any claim arising out of or in
56  * connection with the use of the software, even if it has been
57  * or is hereafter advised of the possibility of such damages.
58  */
59
60
61 #ifndef _AFS_BYPASSCACHE_H
62 #define _AFS_BYPASSCACHE_H
63
64 #if defined(AFS_CACHE_BYPASS)
65
66 #include <afsconfig.h>
67 #include "afs/param.h"
68 #include "afs/sysincludes.h"
69 #include "afsincludes.h"
70
71 #define AFS_CACHE_BYPASS_DISABLED -1
72
73 #ifdef UKERNEL
74 #ifndef PAGE_SIZE
75 #define PAGE_SIZE 1024 * sizeof(long) / 8
76 #endif
77 #endif
78
79 /* A ptr to an object of the following type is expected to be passed
80  * as the ab->parm[0] to afs_BQueue */
81 struct nocache_read_request {
82     /* Why can't we all get along? */
83 #if defined(AFS_SUN5_ENV)
84     /* SOLARIS */
85     u_offset_t offset;
86     struct seg *segment;
87     caddr_t address;
88 #elif defined(AFS_SGI_ENV)
89     /* SGI (of some vintage) */
90     int32 offset;
91     int32 rem;
92     int32 pmp; /* mmm */
93     int32 length;
94 #elif defined(AFS_LINUX24_ENV) || defined(AFS_USR_LINUX24_ENV)
95     /* The tested platform, as CITI impl. just packs ab->parms */
96     struct uio *auio;
97     struct vrequest *areq;
98     afs_size_t offset;
99     afs_size_t length;
100 #endif
101 };
102
103 enum cache_bypass_strategies
104 {
105     ALWAYS_BYPASS_CACHE,
106     NEVER_BYPASS_CACHE,
107     LARGE_FILES_BYPASS_CACHE
108 };
109
110 extern int cache_bypass_prefetch;
111 extern int cache_bypass_strategy;
112 extern int cache_bypass_threshold;
113
114 void afs_TransitionToBypass(struct vcache *, afs_ucred_t *, int);
115 void afs_TransitionToCaching(struct vcache *, afs_ucred_t *, int);
116
117 /* Cache strategy permits vnode transition between caching and no-cache--
118  * currently, this means LARGE_FILES_BYPASS_CACHE.  Currently, no pioctl permits
119  * setting FCSBypass manually for a vnode */
120 #define variable_cache_strategy                                 \
121     (! ((cache_bypass_strategy == ALWAYS_BYPASS_CACHE) ||       \
122         (cache_bypass_strategy == NEVER_BYPASS_CACHE)) )
123
124 /* Cache-coherently toggle cache/no-cache for a vnode */
125 #define trydo_cache_transition(avc, credp, bypasscache)                 \
126     do {                                                                \
127         if(variable_cache_strategy) {                                   \
128             if(bypasscache) {                                           \
129                 if(!(avc->cachingStates & FCSBypass))                   \
130                     afs_TransitionToBypass(avc, credp, TRANSChangeDesiredBit); \
131             } else {                                                    \
132                 if(avc->cachingStates & FCSBypass)                      \
133                     afs_TransitionToCaching(avc, credp, TRANSChangeDesiredBit); \
134             }                                                           \
135         }                                                               \
136     }                                                                   \
137     while(0);
138
139 /* dispatch a no-cache read request */
140 afs_int32
141 afs_ReadNoCache(struct vcache *avc, struct nocache_read_request *bparms,
142                 afs_ucred_t *acred);
143
144 /* no-cache prefetch routine */
145 afs_int32
146 afs_PrefetchNoCache(struct vcache *avc, afs_ucred_t *acred,
147                         struct nocache_read_request *bparms);
148
149
150 #endif /* AFS_CACHE_BYPASS */
151 #endif /* _AFS_BYPASSCACHE_H */
152