Lines Matching +full:keep +full:- +full:a +full:- +full:live

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* FS-Cache cache handling
22 * Allocate a cache cookie.
31 cache->name = kstrdup(name, GFP_KERNEL); in fscache_alloc_cache()
32 if (!cache->name) { 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()
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.
67 if (cache->name && name && strcmp(cache->name, name) == 0 && in fscache_lookup_cache()
70 if (!cache->name && !name && in fscache_lookup_cache()
77 if (cache->name && in fscache_lookup_cache()
85 /* the cache does not exist - create a candidate */ in fscache_lookup_cache()
88 return ERR_PTR(-ENOMEM); in fscache_lookup_cache()
94 if (cache->name && name && strcmp(cache->name, name) == 0 && in fscache_lookup_cache()
97 if (!cache->name) { in fscache_lookup_cache()
111 if (cache->name && in fscache_lookup_cache()
117 list_add_tail(&candidate->cache_link, &fscache_caches); in fscache_lookup_cache()
118 trace_fscache_cache(candidate->debug_id, in fscache_lookup_cache()
119 refcount_read(&candidate->ref), in fscache_lookup_cache()
129 cache->name = candidate->name; in fscache_lookup_cache()
130 candidate->name = NULL; in fscache_lookup_cache()
133 kfree(candidate->name); in fscache_lookup_cache()
139 * fscache_acquire_cache - Acquire a cache-level cookie.
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,
147 * use, otherwise -EBUSY will be returned.
163 return ERR_PTR(-EBUSY); in fscache_acquire_cache()
171 * fscache_put_cache - Release a cache-level cookie.
175 * Release the caller's reference on a cache-level cookie. The @where
177 * occurs and will be logged through a tracepoint.
189 debug_id = cache->debug_id; in fscache_put_cache()
190 zero = __refcount_dec_and_test(&cache->ref, &ref); in fscache_put_cache()
191 trace_fscache_cache(debug_id, ref - 1, where); in fscache_put_cache()
195 list_del_init(&cache->cache_link); in fscache_put_cache()
197 kfree(cache->name); in fscache_put_cache()
203 * fscache_relinquish_cache - Reset cache state and release cookie
206 * Reset the state of a cache and release the caller's reference on a cache
212 (cache->state == FSCACHE_CACHE_IS_PREPARING) ? in fscache_relinquish_cache()
216 cache->ops = NULL; in fscache_relinquish_cache()
217 cache->cache_priv = NULL; in fscache_relinquish_cache()
224 * fscache_add_cache - Declare a cache as being open for business
225 * @cache: The cache-level cookie representing the cache
229 * Add a cache to the system, making it available for netfs's to use.
231 * See Documentation/filesystems/caching/backend-api.rst for a complete
240 _enter("{%s,%s}", ops->name, cache->name); in fscache_add_cache()
244 /* Get a ref on the cache cookie and keep its n_accesses counter raised in fscache_add_cache()
248 n_accesses = atomic_inc_return(&cache->n_accesses); in fscache_add_cache()
249 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_add_cache()
254 cache->ops = ops; in fscache_add_cache()
255 cache->cache_priv = cache_priv; in fscache_add_cache()
259 pr_notice("Cache \"%s\" added (type %s)\n", cache->name, ops->name); in fscache_add_cache()
260 _leave(" = 0 [%s]", cache->name); in fscache_add_cache()
266 * fscache_begin_cache_access - Pin a cache so it can be accessed
267 * @cache: The cache-level cookie
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
277 * then recheck the liveness, ending the access if it ceased to be live.
296 n_accesses = atomic_inc_return(&cache->n_accesses); in fscache_begin_cache_access()
297 smp_mb__after_atomic(); /* Reread live flag after n_accesses */ in fscache_begin_cache_access()
298 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_begin_cache_access()
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
320 n_accesses = atomic_dec_return(&cache->n_accesses); in fscache_end_cache_access()
321 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_end_cache_access()
324 wake_up_var(&cache->n_accesses); in fscache_end_cache_access()
328 * fscache_io_error - Note a cache I/O error
331 * Note that an I/O error occurred in a cache and that it should no longer be
334 * See Documentation/filesystems/caching/backend-api.rst for a complete
343 cache->name); in fscache_io_error()
348 * fscache_withdraw_cache - Withdraw a cache from the active service
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.
360 cache->name, atomic_read(&cache->object_count)); in fscache_withdraw_cache()
364 /* Allow wakeups on dec-to-0 */ in fscache_withdraw_cache()
365 n_accesses = atomic_dec_return(&cache->n_accesses); in fscache_withdraw_cache()
366 trace_fscache_access_cache(cache->debug_id, refcount_read(&cache->ref), in fscache_withdraw_cache()
369 wait_var_event(&cache->n_accesses, in fscache_withdraw_cache()
370 atomic_read(&cache->n_accesses) == 0); in fscache_withdraw_cache()
375 static const char fscache_cache_states[NR__FSCACHE_CACHE_STATE] = "-PAEW";
378 * Generate a list of caches in /proc/fs/fscache/caches
395 cache->debug_id, in fscache_caches_seq_show()
396 refcount_read(&cache->ref), in fscache_caches_seq_show()
397 atomic_read(&cache->n_volumes), in fscache_caches_seq_show()
398 atomic_read(&cache->object_count), in fscache_caches_seq_show()
399 atomic_read(&cache->n_accesses), in fscache_caches_seq_show()
400 fscache_cache_states[cache->state], in fscache_caches_seq_show()
401 cache->name ?: "-"); in fscache_caches_seq_show()