Lines Matching refs:cache

2 /* FS-Cache cache handling
22 * Allocate a cache cookie.
26 struct fscache_cache *cache;
28 cache = kzalloc(sizeof(*cache), GFP_KERNEL);
29 if (cache) {
31 cache->name = kstrdup(name, GFP_KERNEL);
32 if (!cache->name) {
33 kfree(cache);
37 refcount_set(&cache->ref, 1);
38 INIT_LIST_HEAD(&cache->cache_link);
39 cache->debug_id = atomic_inc_return(&fscache_cache_debug_id);
41 return cache;
44 static bool fscache_get_cache_maybe(struct fscache_cache *cache,
50 success = __refcount_inc_not_zero(&cache->ref, &ref);
52 trace_fscache_cache(cache->debug_id, ref + 1, where);
57 * Look up a cache cookie.
61 struct fscache_cache *candidate, *cache, *unnamed = NULL;
63 /* firstly check for the existence of the cache under read lock */
66 list_for_each_entry(cache, &fscache_caches, cache_link) {
67 if (cache->name && name && strcmp(cache->name, name) == 0 &&
68 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
70 if (!cache->name && !name &&
71 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
76 list_for_each_entry(cache, &fscache_caches, cache_link) {
77 if (cache->name &&
78 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
85 /* the cache does not exist - create a candidate */
93 list_for_each_entry(cache, &fscache_caches, cache_link) {
94 if (cache->name && name && strcmp(cache->name, name) == 0 &&
95 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
97 if (!cache->name) {
98 unnamed = cache;
100 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
110 list_for_each_entry(cache, &fscache_caches, cache_link) {
111 if (cache->name &&
112 fscache_get_cache_maybe(cache, fscache_cache_get_acquire))
126 return cache;
128 cache = unnamed;
129 cache->name = candidate->name;
135 return cache;
139 * fscache_acquire_cache - Acquire a cache-level cookie.
140 * @name: The name of the cache.
142 * Get a cookie to represent an actual cache. If a name is given and there is
143 * a nameless cache record available, this will acquire that and set its name,
144 * directing all the volumes using it to this cache.
146 * The cache will be switched over to the preparing state if not currently in
151 struct fscache_cache *cache;
154 cache = fscache_lookup_cache(name, true);
155 if (IS_ERR(cache))
156 return cache;
158 if (!fscache_set_cache_state_maybe(cache,
162 fscache_put_cache(cache, fscache_cache_put_cache);
166 return cache;
171 * fscache_put_cache - Release a cache-level cookie.
172 * @cache: The cache cookie to be released
175 * Release the caller's reference on a cache-level cookie. The @where
179 void fscache_put_cache(struct fscache_cache *cache,
186 if (IS_ERR_OR_NULL(cache))
189 debug_id = cache->debug_id;
190 zero = __refcount_dec_and_test(&cache->ref, &ref);
195 list_del_init(&cache->cache_link);
197 kfree(cache->name);
198 kfree(cache);
203 * fscache_relinquish_cache - Reset cache state and release cookie
204 * @cache: The cache cookie to be released
206 * Reset the state of a cache and release the caller's reference on a cache
209 void fscache_relinquish_cache(struct fscache_cache *cache)
212 (cache->state == FSCACHE_CACHE_IS_PREPARING) ?
216 cache->ops = NULL;
217 cache->cache_priv = NULL;
218 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_NOT_PRESENT);
219 fscache_put_cache(cache, where);
224 * fscache_add_cache - Declare a cache as being open for business
225 * @cache: The cache-level cookie representing the cache
226 * @ops: Table of cache operations to use
227 * @cache_priv: Private data for the cache record
229 * Add a cache to the system, making it available for netfs's to use.
234 int fscache_add_cache(struct fscache_cache *cache,
240 _enter("{%s,%s}", ops->name, cache->name);
242 BUG_ON(fscache_cache_state(cache) != FSCACHE_CACHE_IS_PREPARING);
244 /* Get a ref on the cache cookie and keep its n_accesses counter raised
248 n_accesses = atomic_inc_return(&cache->n_accesses);
249 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref),
254 cache->ops = ops;
255 cache->cache_priv = cache_priv;
256 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_ACTIVE);
259 pr_notice("Cache \"%s\" added (type %s)\n", cache->name, ops->name);
260 _leave(" = 0 [%s]", cache->name);
266 * fscache_begin_cache_access - Pin a cache so it can be accessed
267 * @cache: The cache-level cookie
270 * Attempt to pin the cache to prevent it from going away whilst we're
273 * (1) If the cache tests as not live (state is not FSCACHE_CACHE_IS_ACTIVE),
276 * (2) If the cache tests as live, then we increment the n_accesses count and
282 * (4) Whilst the cache is caching, n_accesses is kept artificially
285 * (5) When the cache is taken offline, the state is changed to prevent new
289 bool fscache_begin_cache_access(struct fscache_cache *cache, enum fscache_access_trace why)
293 if (!fscache_cache_is_live(cache))
296 n_accesses = atomic_inc_return(&cache->n_accesses);
298 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref),
300 if (!fscache_cache_is_live(cache)) {
301 fscache_end_cache_access(cache, fscache_access_unlive);
308 * fscache_end_cache_access - Unpin a cache at the end of an access.
309 * @cache: The cache-level cookie
312 * Unpin a cache after we've accessed it. The @why indicator is merely
315 void fscache_end_cache_access(struct fscache_cache *cache, enum fscache_access_trace why)
320 n_accesses = atomic_dec_return(&cache->n_accesses);
321 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref),
324 wake_up_var(&cache->n_accesses);
328 * fscache_io_error - Note a cache I/O error
329 * @cache: The record describing the cache
331 * Note that an I/O error occurred in a cache and that it should no longer be
337 void fscache_io_error(struct fscache_cache *cache)
339 if (fscache_set_cache_state_maybe(cache,
343 cache->name);
348 * fscache_withdraw_cache - Withdraw a cache from the active service
349 * @cache: The cache cookie
351 * Begin the process of withdrawing a cache from service. This stops new
352 * cache-level and volume-level accesses from taking place and waits for
353 * currently ongoing cache-level accesses to end.
355 void fscache_withdraw_cache(struct fscache_cache *cache)
359 pr_notice("Withdrawing cache \"%s\" (%u objs)\n",
360 cache->name, atomic_read(&cache->object_count));
362 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_WITHDRAWN);
365 n_accesses = atomic_dec_return(&cache->n_accesses);
366 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref),
369 wait_var_event(&cache->n_accesses,
370 atomic_read(&cache->n_accesses) == 0);
382 struct fscache_cache *cache;
392 cache = list_entry(v, struct fscache_cache, cache_link);
395 cache->debug_id,
396 refcount_read(&cache->ref),
397 atomic_read(&cache->n_volumes),
398 atomic_read(&cache->object_count),
399 atomic_read(&cache->n_accesses),
400 fscache_cache_states[cache->state],
401 cache->name ?: "-");