Lines Matching full:cache

2 /* FS-Cache cache handling
8 #define FSCACHE_DEBUG_LEVEL CACHE
22 * Allocate a cache cookie.
26 struct fscache_cache *cache; in fscache_alloc_cache() local
28 cache = kzalloc(sizeof(*cache), GFP_KERNEL); in fscache_alloc_cache()
29 if (cache) { in fscache_alloc_cache()
31 cache->name = kstrdup(name, GFP_KERNEL); in fscache_alloc_cache()
32 if (!cache->name) { in fscache_alloc_cache()
33 kfree(cache); in fscache_alloc_cache()
37 refcount_set(&cache->ref, 1); in fscache_alloc_cache()
38 INIT_LIST_HEAD(&cache->cache_link); in fscache_alloc_cache()
39 cache->debug_id = atomic_inc_return(&fscache_cache_debug_id); in fscache_alloc_cache()
41 return cache; in fscache_alloc_cache()
44 static bool fscache_get_cache_maybe(struct fscache_cache *cache, in fscache_get_cache_maybe() argument
50 success = __refcount_inc_not_zero(&cache->ref, &ref); in fscache_get_cache_maybe()
52 trace_fscache_cache(cache->debug_id, ref + 1, where); in fscache_get_cache_maybe()
57 * Look up a cache cookie.
61 struct fscache_cache *candidate, *cache, *unnamed = NULL; in fscache_lookup_cache() local
63 /* firstly check for the existence of the cache under read lock */ in fscache_lookup_cache()
66 list_for_each_entry(cache, &fscache_caches, cache_link) { in fscache_lookup_cache()
67 if (cache->name && name && strcmp(cache->name, name) == 0 && in fscache_lookup_cache()
68 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
70 if (!cache->name && !name && in fscache_lookup_cache()
71 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
76 list_for_each_entry(cache, &fscache_caches, cache_link) { in fscache_lookup_cache()
77 if (cache->name && in fscache_lookup_cache()
78 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
85 /* the cache does not exist - create a candidate */ in fscache_lookup_cache()
93 list_for_each_entry(cache, &fscache_caches, cache_link) { in fscache_lookup_cache()
94 if (cache->name && name && strcmp(cache->name, name) == 0 && in fscache_lookup_cache()
95 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
97 if (!cache->name) { in fscache_lookup_cache()
98 unnamed = cache; in fscache_lookup_cache()
100 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
110 list_for_each_entry(cache, &fscache_caches, cache_link) { in fscache_lookup_cache()
111 if (cache->name && in fscache_lookup_cache()
112 fscache_get_cache_maybe(cache, fscache_cache_get_acquire)) in fscache_lookup_cache()
126 return cache; in fscache_lookup_cache()
128 cache = unnamed; in fscache_lookup_cache()
129 cache->name = candidate->name; in fscache_lookup_cache()
135 return cache; in fscache_lookup_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; in fscache_acquire_cache() local
154 cache = fscache_lookup_cache(name, true); in fscache_acquire_cache()
155 if (IS_ERR(cache)) in fscache_acquire_cache()
156 return cache; in fscache_acquire_cache()
158 if (!fscache_set_cache_state_maybe(cache, in fscache_acquire_cache()
161 pr_warn("Cache tag %s in use\n", name); in fscache_acquire_cache()
162 fscache_put_cache(cache, fscache_cache_put_cache); in fscache_acquire_cache()
166 return cache; in fscache_acquire_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, in fscache_put_cache() argument
182 unsigned int debug_id = cache->debug_id; in fscache_put_cache()
186 if (IS_ERR_OR_NULL(cache)) in fscache_put_cache()
189 zero = __refcount_dec_and_test(&cache->ref, &ref); in fscache_put_cache()
194 list_del_init(&cache->cache_link); in fscache_put_cache()
196 kfree(cache->name); in fscache_put_cache()
197 kfree(cache); in fscache_put_cache()
202 * fscache_relinquish_cache - Reset cache state and release cookie
203 * @cache: The cache cookie to be released
205 * Reset the state of a cache and release the caller's reference on a cache
208 void fscache_relinquish_cache(struct fscache_cache *cache) in fscache_relinquish_cache() argument
211 (cache->state == FSCACHE_CACHE_IS_PREPARING) ? in fscache_relinquish_cache()
215 cache->ops = NULL; in fscache_relinquish_cache()
216 cache->cache_priv = NULL; in fscache_relinquish_cache()
217 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_NOT_PRESENT); in fscache_relinquish_cache()
218 fscache_put_cache(cache, where); in fscache_relinquish_cache()
223 * fscache_add_cache - Declare a cache as being open for business
224 * @cache: The cache-level cookie representing the cache
225 * @ops: Table of cache operations to use
226 * @cache_priv: Private data for the cache record
228 * Add a cache to the system, making it available for netfs's to use.
233 int fscache_add_cache(struct fscache_cache *cache, in fscache_add_cache() argument
239 _enter("{%s,%s}", ops->name, cache->name); in fscache_add_cache()
241 BUG_ON(fscache_cache_state(cache) != FSCACHE_CACHE_IS_PREPARING); in fscache_add_cache()
243 /* Get a ref on the cache cookie and keep its n_accesses counter raised in fscache_add_cache()
247 n_accesses = atomic_inc_return(&cache->n_accesses); in fscache_add_cache()
248 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_add_cache()
253 cache->ops = ops; in fscache_add_cache()
254 cache->cache_priv = cache_priv; in fscache_add_cache()
255 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_ACTIVE); in fscache_add_cache()
258 pr_notice("Cache \"%s\" added (type %s)\n", cache->name, ops->name); in fscache_add_cache()
259 _leave(" = 0 [%s]", cache->name); in fscache_add_cache()
265 * fscache_begin_cache_access - Pin a cache so it can be accessed
266 * @cache: The cache-level cookie
269 * Attempt to pin the cache to prevent it from going away whilst we're
272 * (1) If the cache tests as not live (state is not FSCACHE_CACHE_IS_ACTIVE),
275 * (2) If the cache tests as live, then we increment the n_accesses count and
281 * (4) Whilst the cache is caching, n_accesses is kept artificially
284 * (5) When the cache is taken offline, the state is changed to prevent new
288 bool fscache_begin_cache_access(struct fscache_cache *cache, enum fscache_access_trace why) in fscache_begin_cache_access() argument
292 if (!fscache_cache_is_live(cache)) in fscache_begin_cache_access()
295 n_accesses = atomic_inc_return(&cache->n_accesses); in fscache_begin_cache_access()
297 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_begin_cache_access()
299 if (!fscache_cache_is_live(cache)) { in fscache_begin_cache_access()
300 fscache_end_cache_access(cache, fscache_access_unlive); in fscache_begin_cache_access()
307 * fscache_end_cache_access - Unpin a cache at the end of an access.
308 * @cache: The cache-level cookie
311 * Unpin a cache after we've accessed it. The @why indicator is merely
314 void fscache_end_cache_access(struct fscache_cache *cache, enum fscache_access_trace why) in fscache_end_cache_access() argument
319 n_accesses = atomic_dec_return(&cache->n_accesses); in fscache_end_cache_access()
320 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_end_cache_access()
323 wake_up_var(&cache->n_accesses); in fscache_end_cache_access()
327 * fscache_io_error - Note a cache I/O error
328 * @cache: The record describing the cache
330 * Note that an I/O error occurred in a cache and that it should no longer be
336 void fscache_io_error(struct fscache_cache *cache) in fscache_io_error() argument
338 if (fscache_set_cache_state_maybe(cache, in fscache_io_error()
341 pr_err("Cache '%s' stopped due to I/O error\n", in fscache_io_error()
342 cache->name); in fscache_io_error()
347 * fscache_withdraw_cache - Withdraw a cache from the active service
348 * @cache: The cache cookie
350 * Begin the process of withdrawing a cache from service. This stops new
351 * cache-level and volume-level accesses from taking place and waits for
352 * currently ongoing cache-level accesses to end.
354 void fscache_withdraw_cache(struct fscache_cache *cache) in fscache_withdraw_cache() argument
358 pr_notice("Withdrawing cache \"%s\" (%u objs)\n", in fscache_withdraw_cache()
359 cache->name, atomic_read(&cache->object_count)); in fscache_withdraw_cache()
361 fscache_set_cache_state(cache, FSCACHE_CACHE_IS_WITHDRAWN); in fscache_withdraw_cache()
364 n_accesses = atomic_dec_return(&cache->n_accesses); in fscache_withdraw_cache()
365 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_withdraw_cache()
368 wait_var_event(&cache->n_accesses, in fscache_withdraw_cache()
369 atomic_read(&cache->n_accesses) == 0); in fscache_withdraw_cache()
381 struct fscache_cache *cache; in fscache_caches_seq_show() local
385 "CACHE REF VOLS OBJS ACCES S NAME\n" in fscache_caches_seq_show()
391 cache = list_entry(v, struct fscache_cache, cache_link); in fscache_caches_seq_show()
394 cache->debug_id, in fscache_caches_seq_show()
395 refcount_read(&cache->ref), in fscache_caches_seq_show()
396 atomic_read(&cache->n_volumes), in fscache_caches_seq_show()
397 atomic_read(&cache->object_count), in fscache_caches_seq_show()
398 atomic_read(&cache->n_accesses), in fscache_caches_seq_show()
399 fscache_cache_states[cache->state], in fscache_caches_seq_show()
400 cache->name ?: "-"); in fscache_caches_seq_show()