Use afsd code in libuafs
[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 typedef struct uio uio_t;
75 #ifndef PAGE_SIZE
76 #define PAGE_SIZE 1024 * sizeof(long) / 8
77 #endif
78 #endif
79
80 /* A ptr to an object of the following type is expected to be passed
81  * as the ab->parm[0] to afs_BQueue */
82 struct nocache_read_request {
83     /* Why can't we all get along? */
84 #if defined(AFS_SUN5_ENV)
85     /* SOLARIS */
86     u_offset_t offset;
87     struct seg *segment;
88     caddr_t address;
89 #elif defined(AFS_SGI_ENV)
90     /* SGI (of some vintage) */
91     int32 offset;
92     int32 rem;
93     int32 pmp; /* mmm */
94     int32 length;
95 #elif defined(AFS_LINUX24_ENV) || defined(AFS_USR_LINUX24_ENV)
96     /* The tested platform, as CITI impl. just packs ab->parms */
97     uio_t * auio;
98     struct vrequest *areq;
99     afs_size_t offset;
100     afs_size_t length;
101 #endif
102 };
103
104 enum cache_bypass_strategies
105 {
106     ALWAYS_BYPASS_CACHE,
107     NEVER_BYPASS_CACHE,
108     LARGE_FILES_BYPASS_CACHE
109 };
110
111 extern int cache_bypass_prefetch;
112 extern int cache_bypass_strategy;
113 extern int cache_bypass_threshold;
114
115 void afs_TransitionToBypass(register struct vcache *, register afs_ucred_t *, int);
116 void afs_TransitionToCaching(register struct vcache *, register afs_ucred_t *, int);
117
118 /* Cache strategy permits vnode transition between caching and no-cache--
119  * currently, this means LARGE_FILES_BYPASS_CACHE.  Currently, no pioctl permits
120  * setting FCSBypass manually for a vnode */
121 #define variable_cache_strategy                                 \
122     (! ((cache_bypass_strategy == ALWAYS_BYPASS_CACHE) ||       \
123         (cache_bypass_strategy == NEVER_BYPASS_CACHE)) )
124
125 /* Cache-coherently toggle cache/no-cache for a vnode */
126 #define trydo_cache_transition(avc, credp, bypasscache)                 \
127     do {                                                                \
128         if(variable_cache_strategy) {                                   \
129             if(bypasscache) {                                           \
130                 if(!(avc->cachingStates & FCSBypass))                   \
131                     afs_TransitionToBypass(avc, credp, TRANSChangeDesiredBit); \
132             } else {                                                    \
133                 if(avc->cachingStates & FCSBypass)                      \
134                     afs_TransitionToCaching(avc, credp, TRANSChangeDesiredBit); \
135             }                                                           \
136         }                                                               \
137     }                                                                   \
138     while(0);
139
140 /* dispatch a no-cache read request */
141 afs_int32
142 afs_ReadNoCache(register struct vcache *avc, register struct nocache_read_request *bparms, 
143                 afs_ucred_t *acred);
144
145 /* no-cache prefetch routine */
146 afs_int32
147 afs_PrefetchNoCache(register struct vcache *avc, register afs_ucred_t *acred,
148                         struct nocache_read_request *bparms);
149
150
151 #endif /* AFS_CACHE_BYPASS */
152 #endif /* _AFS_BYPASSCACHE_H */
153