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_WAIT); 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()
331 spin_unlock(&cookie->lock); in fscache_alloc_object()
334 spin_unlock(&cookie->lock); in fscache_alloc_object()
350 static int fscache_attach_object(struct fscache_cookie *cookie, in fscache_attach_object() argument
357 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); in fscache_attach_object()
359 spin_lock(&cookie->lock); in fscache_attach_object()
364 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { in fscache_attach_object()
373 spin_lock_nested(&cookie->parent->lock, 1); in fscache_attach_object()
374 hlist_for_each_entry(p, &cookie->parent->backing_objects, in fscache_attach_object()
379 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
389 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
399 object->cookie = cookie; in fscache_attach_object()
400 atomic_inc(&cookie->usage); in fscache_attach_object()
401 hlist_add_head(&object->cookie_link, &cookie->backing_objects); in fscache_attach_object()
407 spin_unlock(&cookie->lock); in fscache_attach_object()
415 void __fscache_invalidate(struct fscache_cookie *cookie) in __fscache_invalidate() argument
419 _enter("{%s}", cookie->def->name); in __fscache_invalidate()
428 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_invalidate()
431 BUG_ON(!cookie->def->get_aux); in __fscache_invalidate()
436 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_invalidate()
437 spin_lock(&cookie->lock); in __fscache_invalidate()
439 if (fscache_cookie_enabled(cookie) && in __fscache_invalidate()
440 !hlist_empty(&cookie->backing_objects) && in __fscache_invalidate()
442 &cookie->flags)) { in __fscache_invalidate()
443 object = hlist_entry(cookie->backing_objects.first, in __fscache_invalidate()
451 spin_unlock(&cookie->lock); in __fscache_invalidate()
461 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) in __fscache_wait_on_invalidate() argument
463 _enter("%p", cookie); in __fscache_wait_on_invalidate()
465 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, in __fscache_wait_on_invalidate()
475 void __fscache_update_cookie(struct fscache_cookie *cookie) in __fscache_update_cookie() argument
481 if (!cookie) { in __fscache_update_cookie()
487 _enter("{%s}", cookie->def->name); in __fscache_update_cookie()
489 BUG_ON(!cookie->def->get_aux); in __fscache_update_cookie()
491 spin_lock(&cookie->lock); in __fscache_update_cookie()
493 if (fscache_cookie_enabled(cookie)) { in __fscache_update_cookie()
498 &cookie->backing_objects, cookie_link) { in __fscache_update_cookie()
503 spin_unlock(&cookie->lock); in __fscache_update_cookie()
511 void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate) in __fscache_disable_cookie() argument
516 _enter("%p,%u", cookie, invalidate); in __fscache_disable_cookie()
518 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); in __fscache_disable_cookie()
520 if (atomic_read(&cookie->n_children) != 0) { in __fscache_disable_cookie()
522 cookie->def->name); in __fscache_disable_cookie()
526 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_disable_cookie()
528 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_disable_cookie()
534 __fscache_wait_on_invalidate(cookie); in __fscache_disable_cookie()
537 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); in __fscache_disable_cookie()
539 spin_lock(&cookie->lock); in __fscache_disable_cookie()
540 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_disable_cookie()
541 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { in __fscache_disable_cookie()
547 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) in __fscache_disable_cookie()
550 spin_unlock(&cookie->lock); in __fscache_disable_cookie()
552 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); in __fscache_disable_cookie()
558 if (!atomic_dec_and_test(&cookie->n_active)) in __fscache_disable_cookie()
559 wait_on_atomic_t(&cookie->n_active, fscache_wait_atomic_t, in __fscache_disable_cookie()
563 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { in __fscache_disable_cookie()
564 atomic_inc(&cookie->n_active); in __fscache_disable_cookie()
565 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); in __fscache_disable_cookie()
569 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_disable_cookie()
570 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_disable_cookie()
581 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire) in __fscache_relinquish_cookie() argument
587 if (!cookie) { in __fscache_relinquish_cookie()
594 cookie, cookie->def->name, cookie->netfs_data, in __fscache_relinquish_cookie()
595 atomic_read(&cookie->n_active), retire); in __fscache_relinquish_cookie()
598 set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags); in __fscache_relinquish_cookie()
600 __fscache_disable_cookie(cookie, retire); in __fscache_relinquish_cookie()
603 cookie->netfs_data = NULL; in __fscache_relinquish_cookie()
604 cookie->def = NULL; in __fscache_relinquish_cookie()
605 BUG_ON(cookie->stores.rnode); in __fscache_relinquish_cookie()
607 if (cookie->parent) { in __fscache_relinquish_cookie()
608 ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); in __fscache_relinquish_cookie()
609 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); in __fscache_relinquish_cookie()
610 atomic_dec(&cookie->parent->n_children); in __fscache_relinquish_cookie()
614 ASSERTCMP(atomic_read(&cookie->usage), >, 0); in __fscache_relinquish_cookie()
615 fscache_cookie_put(cookie); in __fscache_relinquish_cookie()
624 void __fscache_cookie_put(struct fscache_cookie *cookie) in __fscache_cookie_put() argument
628 _enter("%p", cookie); in __fscache_cookie_put()
631 _debug("FREE COOKIE %p", cookie); in __fscache_cookie_put()
632 parent = cookie->parent; in __fscache_cookie_put()
633 BUG_ON(!hlist_empty(&cookie->backing_objects)); in __fscache_cookie_put()
634 kmem_cache_free(fscache_cookie_jar, cookie); in __fscache_cookie_put()
639 cookie = parent; in __fscache_cookie_put()
640 BUG_ON(atomic_read(&cookie->usage) <= 0); in __fscache_cookie_put()
641 if (!atomic_dec_and_test(&cookie->usage)) in __fscache_cookie_put()
653 int __fscache_check_consistency(struct fscache_cookie *cookie) in __fscache_check_consistency() argument
660 _enter("%p,", cookie); in __fscache_check_consistency()
662 ASSERTCMP(cookie->def->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_check_consistency()
664 if (fscache_wait_for_deferred_lookup(cookie) < 0) in __fscache_check_consistency()
667 if (hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
679 spin_lock(&cookie->lock); in __fscache_check_consistency()
681 if (!fscache_cookie_enabled(cookie) || in __fscache_check_consistency()
682 hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
684 object = hlist_entry(cookie->backing_objects.first, in __fscache_check_consistency()
691 __fscache_use_cookie(cookie); in __fscache_check_consistency()
696 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()