3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #ifdef AFS_CACHING_SUPPORT
13 static cachefs_match_val_t
afs_cell_cache_match(void *target
,
15 static void afs_cell_cache_update(void *source
, void *entry
);
17 struct cachefs_index_def afs_cache_cell_index_def
= {
19 .data_size
= sizeof(struct afs_cache_cell
),
20 .keys
[0] = { CACHEFS_INDEX_KEYS_ASCIIZ
, 64 },
21 .match
= afs_cell_cache_match
,
22 .update
= afs_cell_cache_update
,
27 * match a cell record obtained from the cache
29 #ifdef AFS_CACHING_SUPPORT
30 static cachefs_match_val_t
afs_cell_cache_match(void *target
,
33 const struct afs_cache_cell
*ccell
= entry
;
34 struct afs_cell
*cell
= target
;
36 _enter("{%s},{%s}", ccell
->name
, cell
->name
);
38 if (strncmp(ccell
->name
, cell
->name
, sizeof(ccell
->name
)) == 0) {
40 return CACHEFS_MATCH_SUCCESS
;
44 return CACHEFS_MATCH_FAILED
;
49 * update a cell record in the cache
51 #ifdef AFS_CACHING_SUPPORT
52 static void afs_cell_cache_update(void *source
, void *entry
)
54 struct afs_cache_cell
*ccell
= entry
;
55 struct afs_cell
*cell
= source
;
57 _enter("%p,%p", source
, entry
);
59 strncpy(ccell
->name
, cell
->name
, sizeof(ccell
->name
));
61 memcpy(ccell
->vl_servers
,
63 min(sizeof(ccell
->vl_servers
), sizeof(cell
->vl_addrs
)));
68 #ifdef AFS_CACHING_SUPPORT
69 static cachefs_match_val_t
afs_vlocation_cache_match(void *target
,
71 static void afs_vlocation_cache_update(void *source
, void *entry
);
73 struct cachefs_index_def afs_vlocation_cache_index_def
= {
75 .data_size
= sizeof(struct afs_cache_vlocation
),
76 .keys
[0] = { CACHEFS_INDEX_KEYS_ASCIIZ
, 64 },
77 .match
= afs_vlocation_cache_match
,
78 .update
= afs_vlocation_cache_update
,
83 * match a VLDB record stored in the cache
84 * - may also load target from entry
86 #ifdef AFS_CACHING_SUPPORT
87 static cachefs_match_val_t
afs_vlocation_cache_match(void *target
,
90 const struct afs_cache_vlocation
*vldb
= entry
;
91 struct afs_vlocation
*vlocation
= target
;
93 _enter("{%s},{%s}", vlocation
->vldb
.name
, vldb
->name
);
95 if (strncmp(vlocation
->vldb
.name
, vldb
->name
, sizeof(vldb
->name
)) == 0
97 if (!vlocation
->valid
||
98 vlocation
->vldb
.rtime
== vldb
->rtime
100 vlocation
->vldb
= *vldb
;
101 vlocation
->valid
= 1;
102 _leave(" = SUCCESS [c->m]");
103 return CACHEFS_MATCH_SUCCESS
;
104 } else if (memcmp(&vlocation
->vldb
, vldb
, sizeof(*vldb
)) != 0) {
105 /* delete if VIDs for this name differ */
106 if (memcmp(&vlocation
->vldb
.vid
,
108 sizeof(vldb
->vid
)) != 0) {
110 return CACHEFS_MATCH_SUCCESS_DELETE
;
114 return CACHEFS_MATCH_SUCCESS_UPDATE
;
116 _leave(" = SUCCESS");
117 return CACHEFS_MATCH_SUCCESS
;
122 return CACHEFS_MATCH_FAILED
;
127 * update a VLDB record stored in the cache
129 #ifdef AFS_CACHING_SUPPORT
130 static void afs_vlocation_cache_update(void *source
, void *entry
)
132 struct afs_cache_vlocation
*vldb
= entry
;
133 struct afs_vlocation
*vlocation
= source
;
137 *vldb
= vlocation
->vldb
;
141 #ifdef AFS_CACHING_SUPPORT
142 static cachefs_match_val_t
afs_volume_cache_match(void *target
,
144 static void afs_volume_cache_update(void *source
, void *entry
);
146 struct cachefs_index_def afs_volume_cache_index_def
= {
148 .data_size
= sizeof(struct afs_cache_vhash
),
149 .keys
[0] = { CACHEFS_INDEX_KEYS_BIN
, 1 },
150 .keys
[1] = { CACHEFS_INDEX_KEYS_BIN
, 1 },
151 .match
= afs_volume_cache_match
,
152 .update
= afs_volume_cache_update
,
157 * match a volume hash record stored in the cache
159 #ifdef AFS_CACHING_SUPPORT
160 static cachefs_match_val_t
afs_volume_cache_match(void *target
,
163 const struct afs_cache_vhash
*vhash
= entry
;
164 struct afs_volume
*volume
= target
;
166 _enter("{%u},{%u}", volume
->type
, vhash
->vtype
);
168 if (volume
->type
== vhash
->vtype
) {
169 _leave(" = SUCCESS");
170 return CACHEFS_MATCH_SUCCESS
;
174 return CACHEFS_MATCH_FAILED
;
179 * update a volume hash record stored in the cache
181 #ifdef AFS_CACHING_SUPPORT
182 static void afs_volume_cache_update(void *source
, void *entry
)
184 struct afs_cache_vhash
*vhash
= entry
;
185 struct afs_volume
*volume
= source
;
189 vhash
->vtype
= volume
->type
;
193 #ifdef AFS_CACHING_SUPPORT
194 static cachefs_match_val_t
afs_vnode_cache_match(void *target
,
196 static void afs_vnode_cache_update(void *source
, void *entry
);
198 struct cachefs_index_def afs_vnode_cache_index_def
= {
200 .data_size
= sizeof(struct afs_cache_vnode
),
201 .keys
[0] = { CACHEFS_INDEX_KEYS_BIN
, 4 },
202 .match
= afs_vnode_cache_match
,
203 .update
= afs_vnode_cache_update
,
208 * match a vnode record stored in the cache
210 #ifdef AFS_CACHING_SUPPORT
211 static cachefs_match_val_t
afs_vnode_cache_match(void *target
,
214 const struct afs_cache_vnode
*cvnode
= entry
;
215 struct afs_vnode
*vnode
= target
;
217 _enter("{%x,%x,%Lx},{%x,%x,%Lx}",
220 vnode
->status
.version
,
222 cvnode
->vnode_unique
,
223 cvnode
->data_version
);
225 if (vnode
->fid
.vnode
!= cvnode
->vnode_id
) {
227 return CACHEFS_MATCH_FAILED
;
230 if (vnode
->fid
.unique
!= cvnode
->vnode_unique
||
231 vnode
->status
.version
!= cvnode
->data_version
) {
233 return CACHEFS_MATCH_SUCCESS_DELETE
;
236 _leave(" = SUCCESS");
237 return CACHEFS_MATCH_SUCCESS
;
242 * update a vnode record stored in the cache
244 #ifdef AFS_CACHING_SUPPORT
245 static void afs_vnode_cache_update(void *source
, void *entry
)
247 struct afs_cache_vnode
*cvnode
= entry
;
248 struct afs_vnode
*vnode
= source
;
252 cvnode
->vnode_id
= vnode
->fid
.vnode
;
253 cvnode
->vnode_unique
= vnode
->fid
.unique
;
254 cvnode
->data_version
= vnode
->status
.version
;