Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[linux-2.6/openmoko-kernel/knife-kernel.git] / fs / afs / cache.c
blobde0d7de69edc4764b98f3d2ff098225e0e18e5fe
1 /* AFS caching stuff
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,
14 const void *entry);
15 static void afs_cell_cache_update(void *source, void *entry);
17 struct cachefs_index_def afs_cache_cell_index_def = {
18 .name = "cell_ix",
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,
24 #endif
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,
31 const void *entry)
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) {
39 _leave(" = SUCCESS");
40 return CACHEFS_MATCH_SUCCESS;
43 _leave(" = FAILED");
44 return CACHEFS_MATCH_FAILED;
46 #endif
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,
62 cell->vl_addrs,
63 min(sizeof(ccell->vl_servers), sizeof(cell->vl_addrs)));
66 #endif
68 #ifdef AFS_CACHING_SUPPORT
69 static cachefs_match_val_t afs_vlocation_cache_match(void *target,
70 const void *entry);
71 static void afs_vlocation_cache_update(void *source, void *entry);
73 struct cachefs_index_def afs_vlocation_cache_index_def = {
74 .name = "vldb",
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,
80 #endif
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,
88 const void *entry)
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
96 ) {
97 if (!vlocation->valid ||
98 vlocation->vldb.rtime == vldb->rtime
99 ) {
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,
107 &vldb->vid,
108 sizeof(vldb->vid)) != 0) {
109 _leave(" = DELETE");
110 return CACHEFS_MATCH_SUCCESS_DELETE;
113 _leave(" = UPDATE");
114 return CACHEFS_MATCH_SUCCESS_UPDATE;
115 } else {
116 _leave(" = SUCCESS");
117 return CACHEFS_MATCH_SUCCESS;
121 _leave(" = FAILED");
122 return CACHEFS_MATCH_FAILED;
124 #endif
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;
135 _enter("");
137 *vldb = vlocation->vldb;
139 #endif
141 #ifdef AFS_CACHING_SUPPORT
142 static cachefs_match_val_t afs_volume_cache_match(void *target,
143 const void *entry);
144 static void afs_volume_cache_update(void *source, void *entry);
146 struct cachefs_index_def afs_volume_cache_index_def = {
147 .name = "volume",
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,
154 #endif
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,
161 const void *entry)
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;
173 _leave(" = FAILED");
174 return CACHEFS_MATCH_FAILED;
176 #endif
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;
187 _enter("");
189 vhash->vtype = volume->type;
191 #endif
193 #ifdef AFS_CACHING_SUPPORT
194 static cachefs_match_val_t afs_vnode_cache_match(void *target,
195 const void *entry);
196 static void afs_vnode_cache_update(void *source, void *entry);
198 struct cachefs_index_def afs_vnode_cache_index_def = {
199 .name = "vnode",
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,
205 #endif
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,
212 const void *entry)
214 const struct afs_cache_vnode *cvnode = entry;
215 struct afs_vnode *vnode = target;
217 _enter("{%x,%x,%Lx},{%x,%x,%Lx}",
218 vnode->fid.vnode,
219 vnode->fid.unique,
220 vnode->status.version,
221 cvnode->vnode_id,
222 cvnode->vnode_unique,
223 cvnode->data_version);
225 if (vnode->fid.vnode != cvnode->vnode_id) {
226 _leave(" = FAILED");
227 return CACHEFS_MATCH_FAILED;
230 if (vnode->fid.unique != cvnode->vnode_unique ||
231 vnode->status.version != cvnode->data_version) {
232 _leave(" = DELETE");
233 return CACHEFS_MATCH_SUCCESS_DELETE;
236 _leave(" = SUCCESS");
237 return CACHEFS_MATCH_SUCCESS;
239 #endif
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;
250 _enter("");
252 cvnode->vnode_id = vnode->fid.vnode;
253 cvnode->vnode_unique = vnode->fid.unique;
254 cvnode->data_version = vnode->status.version;
256 #endif