• Home
  • Raw
  • Download

Lines Matching full:cache

1 /* FS-Cache cache handling
12 #define FSCACHE_DEBUG_LEVEL CACHE
25 * look up a cache tag
71 * release a reference to a cache tag
90 * select a cache in which to store an object
91 * - the cache addremove semaphore must be at least read-locked by the caller
99 struct fscache_cache *cache; in fscache_select_cache_for_object() local
104 _leave(" = NULL [no cache]"); in fscache_select_cache_for_object()
108 /* we check the parent to determine the cache to use */ in fscache_select_cache_for_object()
112 * cache */ in fscache_select_cache_for_object()
117 cache = object->cache; in fscache_select_cache_for_object()
119 test_bit(FSCACHE_IOERROR, &cache->flags)) in fscache_select_cache_for_object()
120 cache = NULL; in fscache_select_cache_for_object()
123 _leave(" = %p [parent]", cache); in fscache_select_cache_for_object()
124 return cache; in fscache_select_cache_for_object()
151 if (!tag->cache) { in fscache_select_cache_for_object()
156 if (test_bit(FSCACHE_IOERROR, &tag->cache->flags)) in fscache_select_cache_for_object()
159 _leave(" = %p [specific]", tag->cache); in fscache_select_cache_for_object()
160 return tag->cache; in fscache_select_cache_for_object()
163 /* netfs has no preference - just select first cache */ in fscache_select_cache_for_object()
164 cache = list_entry(fscache_cache_list.next, in fscache_select_cache_for_object()
166 _leave(" = %p [first]", cache); in fscache_select_cache_for_object()
167 return cache; in fscache_select_cache_for_object()
171 * fscache_init_cache - Initialise a cache record
172 * @cache: The cache record to be initialised
173 * @ops: The cache operations to be installed in that record
177 * Initialise a record of a cache and fill in the name.
182 void fscache_init_cache(struct fscache_cache *cache, in fscache_init_cache() argument
189 memset(cache, 0, sizeof(*cache)); in fscache_init_cache()
191 cache->ops = ops; in fscache_init_cache()
194 vsnprintf(cache->identifier, sizeof(cache->identifier), idfmt, va); in fscache_init_cache()
197 INIT_WORK(&cache->op_gc, fscache_operation_gc); in fscache_init_cache()
198 INIT_LIST_HEAD(&cache->link); in fscache_init_cache()
199 INIT_LIST_HEAD(&cache->object_list); in fscache_init_cache()
200 INIT_LIST_HEAD(&cache->op_gc_list); in fscache_init_cache()
201 spin_lock_init(&cache->object_list_lock); in fscache_init_cache()
202 spin_lock_init(&cache->op_gc_list_lock); in fscache_init_cache()
207 * fscache_add_cache - Declare a cache as being open for business
208 * @cache: The record describing the cache
209 * @ifsdef: The record of the cache object describing the top-level index
210 * @tagname: The tag describing this cache
212 * Add a cache to the system, making it available for netfs's to use.
217 int fscache_add_cache(struct fscache_cache *cache, in fscache_add_cache() argument
224 BUG_ON(!cache->ops); in fscache_add_cache()
227 cache->flags = 0; in fscache_add_cache()
234 tagname = cache->identifier; in fscache_add_cache()
238 _enter("{%s.%s},,%s", cache->ops->name, cache->identifier, tagname); in fscache_add_cache()
240 /* we use the cache tag to uniquely identify caches */ in fscache_add_cache()
248 cache->kobj = kobject_create_and_add(tagname, fscache_root); in fscache_add_cache()
249 if (!cache->kobj) in fscache_add_cache()
252 ifsdef->cache = cache; in fscache_add_cache()
253 cache->fsdef = ifsdef; in fscache_add_cache()
257 tag->cache = cache; in fscache_add_cache()
258 cache->tag = tag; in fscache_add_cache()
260 /* add the cache to the list */ in fscache_add_cache()
261 list_add(&cache->link, &fscache_cache_list); in fscache_add_cache()
263 /* add the cache's netfs definition index object to the cache's in fscache_add_cache()
265 spin_lock(&cache->object_list_lock); in fscache_add_cache()
266 list_add_tail(&ifsdef->cache_link, &cache->object_list); in fscache_add_cache()
267 spin_unlock(&cache->object_list_lock); in fscache_add_cache()
270 /* add the cache's netfs definition index object to the top level index in fscache_add_cache()
283 pr_notice("Cache \"%s\" added (type %s)\n", in fscache_add_cache()
284 cache->tag->name, cache->ops->name); in fscache_add_cache()
285 kobject_uevent(cache->kobj, KOBJ_ADD); in fscache_add_cache()
287 _leave(" = 0 [%s]", cache->identifier); in fscache_add_cache()
291 pr_err("Cache tag '%s' already in use\n", tagname); in fscache_add_cache()
308 * fscache_io_error - Note a cache I/O error
309 * @cache: The record describing the cache
311 * Note that an I/O error occurred in a cache and that it should no longer be
317 void fscache_io_error(struct fscache_cache *cache) in fscache_io_error() argument
319 if (!test_and_set_bit(FSCACHE_IOERROR, &cache->flags)) in fscache_io_error()
320 pr_err("Cache '%s' stopped due to I/O error\n", in fscache_io_error()
321 cache->ops->name); in fscache_io_error()
326 * request withdrawal of all the objects in a cache
329 static void fscache_withdraw_all_objects(struct fscache_cache *cache, in fscache_withdraw_all_objects() argument
334 while (!list_empty(&cache->object_list)) { in fscache_withdraw_all_objects()
335 spin_lock(&cache->object_list_lock); in fscache_withdraw_all_objects()
337 if (!list_empty(&cache->object_list)) { in fscache_withdraw_all_objects()
338 object = list_entry(cache->object_list.next, in fscache_withdraw_all_objects()
350 spin_unlock(&cache->object_list_lock); in fscache_withdraw_all_objects()
356 * fscache_withdraw_cache - Withdraw a cache from the active service
357 * @cache: The record describing the cache
359 * Withdraw a cache from service, unbinding all its cache objects from the
365 void fscache_withdraw_cache(struct fscache_cache *cache) in fscache_withdraw_cache() argument
371 pr_notice("Withdrawing cache \"%s\"\n", in fscache_withdraw_cache()
372 cache->tag->name); in fscache_withdraw_cache()
374 /* make the cache unavailable for cookie acquisition */ in fscache_withdraw_cache()
375 if (test_and_set_bit(FSCACHE_CACHE_WITHDRAWN, &cache->flags)) in fscache_withdraw_cache()
379 list_del_init(&cache->link); in fscache_withdraw_cache()
380 cache->tag->cache = NULL; in fscache_withdraw_cache()
386 cache->ops->sync_cache(cache); in fscache_withdraw_cache()
389 /* dissociate all the netfs pages backed by this cache from the block in fscache_withdraw_cache()
390 * mappings in the cache */ in fscache_withdraw_cache()
392 cache->ops->dissociate_pages(cache); in fscache_withdraw_cache()
396 * cache - which we do by passing them off to thread pool to be in fscache_withdraw_cache()
400 fscache_withdraw_all_objects(cache, &dying_objects); in fscache_withdraw_cache()
406 atomic_read(&cache->object_count) == 0); in fscache_withdraw_cache()
409 list_empty(&cache->object_list)); in fscache_withdraw_cache()
413 kobject_put(cache->kobj); in fscache_withdraw_cache()
415 clear_bit(FSCACHE_TAG_RESERVED, &cache->tag->flags); in fscache_withdraw_cache()
416 fscache_release_cache_tag(cache->tag); in fscache_withdraw_cache()
417 cache->tag = NULL; in fscache_withdraw_cache()