Lines Matching refs:cookie

24 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
26 struct fscache_cookie *cookie);
27 static int fscache_attach_object(struct fscache_cookie *cookie,
35 struct fscache_cookie *cookie = _cookie; in fscache_cookie_init_once() local
37 memset(cookie, 0, sizeof(*cookie)); in fscache_cookie_init_once()
38 spin_lock_init(&cookie->lock); in fscache_cookie_init_once()
39 spin_lock_init(&cookie->stores_lock); in fscache_cookie_init_once()
40 INIT_HLIST_HEAD(&cookie->backing_objects); in fscache_cookie_init_once()
64 struct fscache_cookie *cookie; in __fscache_acquire_cookie() local
89 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL); in __fscache_acquire_cookie()
90 if (!cookie) { in __fscache_acquire_cookie()
96 atomic_set(&cookie->usage, 1); in __fscache_acquire_cookie()
97 atomic_set(&cookie->n_children, 0); in __fscache_acquire_cookie()
102 atomic_set(&cookie->n_active, 1); in __fscache_acquire_cookie()
107 cookie->def = def; in __fscache_acquire_cookie()
108 cookie->parent = parent; in __fscache_acquire_cookie()
109 cookie->netfs_data = netfs_data; in __fscache_acquire_cookie()
110 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); in __fscache_acquire_cookie()
114 INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in __fscache_acquire_cookie()
116 switch (cookie->def->type) { in __fscache_acquire_cookie()
132 if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_acquire_cookie()
133 if (fscache_acquire_non_index_cookie(cookie) == 0) { in __fscache_acquire_cookie()
134 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
137 __fscache_cookie_put(cookie); in __fscache_acquire_cookie()
143 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
148 _leave(" = %p", cookie); in __fscache_acquire_cookie()
149 return cookie; in __fscache_acquire_cookie()
156 void __fscache_enable_cookie(struct fscache_cookie *cookie, in __fscache_enable_cookie() argument
160 _enter("%p", cookie); in __fscache_enable_cookie()
162 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_enable_cookie()
165 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_enable_cookie()
170 } else if (cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_enable_cookie()
172 __fscache_wait_on_invalidate(cookie); in __fscache_enable_cookie()
174 if (fscache_acquire_non_index_cookie(cookie) == 0) in __fscache_enable_cookie()
175 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
177 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
181 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_enable_cookie()
182 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_enable_cookie()
191 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie) in fscache_acquire_non_index_cookie() argument
200 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); in fscache_acquire_non_index_cookie()
213 cache = fscache_select_cache_for_object(cookie->parent); in fscache_acquire_non_index_cookie()
223 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); in fscache_acquire_non_index_cookie()
227 ret = fscache_alloc_object(cache, cookie); in fscache_acquire_non_index_cookie()
235 cookie->def->get_attr(cookie->netfs_data, &i_size); in fscache_acquire_non_index_cookie()
237 spin_lock(&cookie->lock); in fscache_acquire_non_index_cookie()
238 if (hlist_empty(&cookie->backing_objects)) { in fscache_acquire_non_index_cookie()
239 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
243 object = hlist_entry(cookie->backing_objects.first, in fscache_acquire_non_index_cookie()
252 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
256 _debug("non-deferred lookup %p", &cookie->flags); in fscache_acquire_non_index_cookie()
257 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP, in fscache_acquire_non_index_cookie()
260 if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags)) in fscache_acquire_non_index_cookie()
279 struct fscache_cookie *cookie) in fscache_alloc_object() argument
284 _enter("%p,%p{%s}", cache, cookie, cookie->def->name); in fscache_alloc_object()
286 spin_lock(&cookie->lock); in fscache_alloc_object()
287 hlist_for_each_entry(object, &cookie->backing_objects, in fscache_alloc_object()
292 spin_unlock(&cookie->lock); in fscache_alloc_object()
297 object = cache->ops->alloc_object(cache, cookie); in fscache_alloc_object()
310 object->debug_id, cookie->def->name, object->events); in fscache_alloc_object()
312 ret = fscache_alloc_object(cache, cookie->parent); in fscache_alloc_object()
319 if (fscache_attach_object(cookie, object) < 0) { in fscache_alloc_object()
332 spin_unlock(&cookie->lock); in fscache_alloc_object()
335 spin_unlock(&cookie->lock); in fscache_alloc_object()
351 static int fscache_attach_object(struct fscache_cookie *cookie, in fscache_attach_object() argument
358 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); in fscache_attach_object()
360 spin_lock(&cookie->lock); in fscache_attach_object()
365 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { in fscache_attach_object()
374 spin_lock_nested(&cookie->parent->lock, 1); in fscache_attach_object()
375 hlist_for_each_entry(p, &cookie->parent->backing_objects, in fscache_attach_object()
380 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
390 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
400 object->cookie = cookie; in fscache_attach_object()
401 atomic_inc(&cookie->usage); in fscache_attach_object()
402 hlist_add_head(&object->cookie_link, &cookie->backing_objects); in fscache_attach_object()
408 spin_unlock(&cookie->lock); in fscache_attach_object()
416 void __fscache_invalidate(struct fscache_cookie *cookie) in __fscache_invalidate() argument
420 _enter("{%s}", cookie->def->name); in __fscache_invalidate()
429 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_invalidate()
432 BUG_ON(!cookie->def->get_aux); in __fscache_invalidate()
437 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_invalidate()
438 spin_lock(&cookie->lock); in __fscache_invalidate()
440 if (fscache_cookie_enabled(cookie) && in __fscache_invalidate()
441 !hlist_empty(&cookie->backing_objects) && in __fscache_invalidate()
443 &cookie->flags)) { in __fscache_invalidate()
444 object = hlist_entry(cookie->backing_objects.first, in __fscache_invalidate()
452 spin_unlock(&cookie->lock); in __fscache_invalidate()
462 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) in __fscache_wait_on_invalidate() argument
464 _enter("%p", cookie); in __fscache_wait_on_invalidate()
466 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, in __fscache_wait_on_invalidate()
476 void __fscache_update_cookie(struct fscache_cookie *cookie) in __fscache_update_cookie() argument
482 if (!cookie) { in __fscache_update_cookie()
488 _enter("{%s}", cookie->def->name); in __fscache_update_cookie()
490 BUG_ON(!cookie->def->get_aux); in __fscache_update_cookie()
492 spin_lock(&cookie->lock); in __fscache_update_cookie()
494 if (fscache_cookie_enabled(cookie)) { in __fscache_update_cookie()
499 &cookie->backing_objects, cookie_link) { in __fscache_update_cookie()
504 spin_unlock(&cookie->lock); in __fscache_update_cookie()
512 void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate) in __fscache_disable_cookie() argument
517 _enter("%p,%u", cookie, invalidate); in __fscache_disable_cookie()
519 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); in __fscache_disable_cookie()
521 if (atomic_read(&cookie->n_children) != 0) { in __fscache_disable_cookie()
523 cookie->def->name); in __fscache_disable_cookie()
527 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_disable_cookie()
529 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_disable_cookie()
535 __fscache_wait_on_invalidate(cookie); in __fscache_disable_cookie()
538 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); in __fscache_disable_cookie()
540 spin_lock(&cookie->lock); in __fscache_disable_cookie()
541 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_disable_cookie()
542 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { in __fscache_disable_cookie()
548 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) in __fscache_disable_cookie()
551 spin_unlock(&cookie->lock); in __fscache_disable_cookie()
553 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); in __fscache_disable_cookie()
559 if (!atomic_dec_and_test(&cookie->n_active)) in __fscache_disable_cookie()
560 wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t, in __fscache_disable_cookie()
564 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { in __fscache_disable_cookie()
565 atomic_inc(&cookie->n_active); in __fscache_disable_cookie()
566 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); in __fscache_disable_cookie()
570 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_disable_cookie()
571 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_disable_cookie()
582 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire) in __fscache_relinquish_cookie() argument
588 if (!cookie) { in __fscache_relinquish_cookie()
595 cookie, cookie->def->name, cookie->netfs_data, in __fscache_relinquish_cookie()
596 atomic_read(&cookie->n_active), retire); in __fscache_relinquish_cookie()
599 set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags); in __fscache_relinquish_cookie()
601 __fscache_disable_cookie(cookie, retire); in __fscache_relinquish_cookie()
604 cookie->netfs_data = NULL; in __fscache_relinquish_cookie()
605 cookie->def = NULL; in __fscache_relinquish_cookie()
606 BUG_ON(cookie->stores.rnode); in __fscache_relinquish_cookie()
608 if (cookie->parent) { in __fscache_relinquish_cookie()
609 ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); in __fscache_relinquish_cookie()
610 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); in __fscache_relinquish_cookie()
611 atomic_dec(&cookie->parent->n_children); in __fscache_relinquish_cookie()
615 ASSERTCMP(atomic_read(&cookie->usage), >, 0); in __fscache_relinquish_cookie()
616 fscache_cookie_put(cookie); in __fscache_relinquish_cookie()
625 void __fscache_cookie_put(struct fscache_cookie *cookie) in __fscache_cookie_put() argument
629 _enter("%p", cookie); in __fscache_cookie_put()
632 _debug("FREE COOKIE %p", cookie); in __fscache_cookie_put()
633 parent = cookie->parent; in __fscache_cookie_put()
634 BUG_ON(!hlist_empty(&cookie->backing_objects)); in __fscache_cookie_put()
635 kmem_cache_free(fscache_cookie_jar, cookie); in __fscache_cookie_put()
640 cookie = parent; in __fscache_cookie_put()
641 BUG_ON(atomic_read(&cookie->usage) <= 0); in __fscache_cookie_put()
642 if (!atomic_dec_and_test(&cookie->usage)) in __fscache_cookie_put()
654 int __fscache_check_consistency(struct fscache_cookie *cookie) in __fscache_check_consistency() argument
661 _enter("%p,", cookie); in __fscache_check_consistency()
663 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_check_consistency()
665 if (fscache_wait_for_deferred_lookup(cookie) < 0) in __fscache_check_consistency()
668 if (hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
680 spin_lock(&cookie->lock); in __fscache_check_consistency()
682 if (!fscache_cookie_enabled(cookie) || in __fscache_check_consistency()
683 hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
685 object = hlist_entry(cookie->backing_objects.first, in __fscache_check_consistency()
692 __fscache_use_cookie(cookie); in __fscache_check_consistency()
697 spin_unlock(&cookie->lock); in __fscache_check_consistency()
713 wake_cookie = __fscache_unuse_cookie(cookie); in __fscache_check_consistency()
715 spin_unlock(&cookie->lock); in __fscache_check_consistency()
717 __fscache_wake_unused_cookie(cookie); in __fscache_check_consistency()