Lines Matching +full:add +full:- +full:fs
1 /* FS-Cache cache handling
35 if (strcmp(tag->name, name) == 0) { in __fscache_lookup_cache_tag()
36 atomic_inc(&tag->usage); in __fscache_lookup_cache_tag()
44 /* the tag does not exist - create a candidate */ in __fscache_lookup_cache_tag()
48 return ERR_PTR(-ENOMEM); in __fscache_lookup_cache_tag()
50 atomic_set(&xtag->usage, 1); in __fscache_lookup_cache_tag()
51 strcpy(xtag->name, name); in __fscache_lookup_cache_tag()
53 /* write lock, search again and add if still not present */ in __fscache_lookup_cache_tag()
57 if (strcmp(tag->name, name) == 0) { in __fscache_lookup_cache_tag()
58 atomic_inc(&tag->usage); in __fscache_lookup_cache_tag()
65 list_add_tail(&xtag->link, &fscache_cache_tag_list); in __fscache_lookup_cache_tag()
75 if (tag != ERR_PTR(-ENOMEM)) { in __fscache_release_cache_tag()
78 if (atomic_dec_and_test(&tag->usage)) in __fscache_release_cache_tag()
79 list_del_init(&tag->link); in __fscache_release_cache_tag()
91 * - the cache addremove semaphore must be at least read-locked by the caller
92 * - the object will never be an index
109 spin_lock(&cookie->lock); in fscache_select_cache_for_object()
113 if (!hlist_empty(&cookie->backing_objects)) { in fscache_select_cache_for_object()
114 object = hlist_entry(cookie->backing_objects.first, in fscache_select_cache_for_object()
117 cache = object->cache; in fscache_select_cache_for_object()
118 if (object->state >= FSCACHE_OBJECT_DYING || in fscache_select_cache_for_object()
119 test_bit(FSCACHE_IOERROR, &cache->flags)) in fscache_select_cache_for_object()
122 spin_unlock(&cookie->lock); in fscache_select_cache_for_object()
128 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { in fscache_select_cache_for_object()
130 spin_unlock(&cookie->lock); in fscache_select_cache_for_object()
135 spin_unlock(&cookie->lock); in fscache_select_cache_for_object()
137 if (!cookie->def->select_cache) in fscache_select_cache_for_object()
141 tag = cookie->def->select_cache(cookie->parent->netfs_data, in fscache_select_cache_for_object()
142 cookie->netfs_data); in fscache_select_cache_for_object()
146 if (tag == ERR_PTR(-ENOMEM)) { 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()
171 * fscache_init_cache - Initialise a cache record
175 * @...: sprintf-style arguments
179 * See Documentation/filesystems/caching/backend-api.txt for a complete
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
209 * @ifsdef: The record of the cache object describing the top-level index
212 * Add a cache to the system, making it available for netfs's to use.
214 * See Documentation/filesystems/caching/backend-api.txt for a complete
223 BUG_ON(!cache->ops); in fscache_add_cache()
226 cache->flags = 0; in fscache_add_cache()
227 ifsdef->event_mask = ULONG_MAX & ~(1 << FSCACHE_OBJECT_EV_CLEARED); in fscache_add_cache()
228 ifsdef->state = FSCACHE_OBJECT_ACTIVE; in fscache_add_cache()
231 tagname = cache->identifier; in fscache_add_cache()
235 _enter("{%s.%s},,%s", cache->ops->name, cache->identifier, tagname); in fscache_add_cache()
242 if (test_and_set_bit(FSCACHE_TAG_RESERVED, &tag->flags)) in fscache_add_cache()
245 cache->kobj = kobject_create_and_add(tagname, fscache_root); in fscache_add_cache()
246 if (!cache->kobj) in fscache_add_cache()
249 ifsdef->cookie = &fscache_fsdef_index; in fscache_add_cache()
250 ifsdef->cache = cache; in fscache_add_cache()
251 cache->fsdef = ifsdef; in fscache_add_cache()
255 tag->cache = cache; in fscache_add_cache()
256 cache->tag = tag; in fscache_add_cache()
258 /* add the cache to the list */ in fscache_add_cache()
259 list_add(&cache->link, &fscache_cache_list); in fscache_add_cache()
261 /* add the cache's netfs definition index object to the cache's in fscache_add_cache()
263 spin_lock(&cache->object_list_lock); in fscache_add_cache()
264 list_add_tail(&ifsdef->cache_link, &cache->object_list); in fscache_add_cache()
265 spin_unlock(&cache->object_list_lock); in fscache_add_cache()
268 /* add the cache's netfs definition index object to the top level index in fscache_add_cache()
272 hlist_add_head(&ifsdef->cookie_link, in fscache_add_cache()
281 printk(KERN_NOTICE "FS-Cache: Cache \"%s\" added (type %s)\n", in fscache_add_cache()
282 cache->tag->name, cache->ops->name); in fscache_add_cache()
283 kobject_uevent(cache->kobj, KOBJ_ADD); in fscache_add_cache()
285 _leave(" = 0 [%s]", cache->identifier); in fscache_add_cache()
289 printk(KERN_ERR "FS-Cache: Cache tag '%s' already in use\n", tagname); in fscache_add_cache()
291 _leave(" = -EXIST"); in fscache_add_cache()
292 return -EEXIST; in fscache_add_cache()
296 _leave(" = -EINVAL"); in fscache_add_cache()
297 return -EINVAL; in fscache_add_cache()
300 _leave(" = -ENOMEM"); in fscache_add_cache()
301 return -ENOMEM; in fscache_add_cache()
306 * fscache_io_error - Note a cache I/O error
312 * See Documentation/filesystems/caching/backend-api.txt for a complete
317 set_bit(FSCACHE_IOERROR, &cache->flags); in fscache_io_error()
319 printk(KERN_ERR "FS-Cache: Cache %s stopped due to I/O error\n", in fscache_io_error()
320 cache->ops->name); in fscache_io_error()
326 * - all the objects being withdrawn are moved onto the supplied list
333 spin_lock(&cache->object_list_lock); in fscache_withdraw_all_objects()
335 while (!list_empty(&cache->object_list)) { in fscache_withdraw_all_objects()
336 object = list_entry(cache->object_list.next, in fscache_withdraw_all_objects()
338 list_move_tail(&object->cache_link, dying_objects); in fscache_withdraw_all_objects()
340 _debug("withdraw %p", object->cookie); in fscache_withdraw_all_objects()
342 spin_lock(&object->lock); in fscache_withdraw_all_objects()
343 spin_unlock(&cache->object_list_lock); in fscache_withdraw_all_objects()
345 spin_unlock(&object->lock); in fscache_withdraw_all_objects()
348 spin_lock(&cache->object_list_lock); in fscache_withdraw_all_objects()
351 spin_unlock(&cache->object_list_lock); in fscache_withdraw_all_objects()
355 * fscache_withdraw_cache - Withdraw a cache from the active service
361 * See Documentation/filesystems/caching/backend-api.txt for a complete
370 printk(KERN_NOTICE "FS-Cache: Withdrawing cache \"%s\"\n", in fscache_withdraw_cache()
371 cache->tag->name); in fscache_withdraw_cache()
374 if (test_and_set_bit(FSCACHE_CACHE_WITHDRAWN, &cache->flags)) in fscache_withdraw_cache()
378 list_del_init(&cache->link); in fscache_withdraw_cache()
379 cache->tag->cache = NULL; in fscache_withdraw_cache()
385 cache->ops->sync_cache(cache); in fscache_withdraw_cache()
391 cache->ops->dissociate_pages(cache); in fscache_withdraw_cache()
395 * cache - which we do by passing them off to thread pool to be in fscache_withdraw_cache()
405 atomic_read(&cache->object_count) == 0); in fscache_withdraw_cache()
408 list_empty(&cache->object_list)); in fscache_withdraw_cache()
412 kobject_put(cache->kobj); in fscache_withdraw_cache()
414 clear_bit(FSCACHE_TAG_RESERVED, &cache->tag->flags); in fscache_withdraw_cache()
415 fscache_release_cache_tag(cache->tag); in fscache_withdraw_cache()
416 cache->tag = NULL; in fscache_withdraw_cache()