• Home
  • Raw
  • Download

Lines Matching refs:cookie

23 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,
30 static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix) in fscache_print_cookie() argument
37 prefix, cookie, cookie->parent, cookie->flags, in fscache_print_cookie()
38 atomic_read(&cookie->n_children), in fscache_print_cookie()
39 atomic_read(&cookie->n_active)); in fscache_print_cookie()
41 prefix, cookie->def, cookie->netfs_data); in fscache_print_cookie()
43 object = READ_ONCE(cookie->backing_objects.first); in fscache_print_cookie()
48 pr_err("%c-key=[%u] '", prefix, cookie->key_len); in fscache_print_cookie()
49 k = (cookie->key_len <= sizeof(cookie->inline_key)) ? in fscache_print_cookie()
50 cookie->inline_key : cookie->key; in fscache_print_cookie()
51 for (loop = 0; loop < cookie->key_len; loop++) in fscache_print_cookie()
56 void fscache_free_cookie(struct fscache_cookie *cookie) in fscache_free_cookie() argument
58 if (cookie) { in fscache_free_cookie()
59 BUG_ON(!hlist_empty(&cookie->backing_objects)); in fscache_free_cookie()
60 if (cookie->aux_len > sizeof(cookie->inline_aux)) in fscache_free_cookie()
61 kfree(cookie->aux); in fscache_free_cookie()
62 if (cookie->key_len > sizeof(cookie->inline_key)) in fscache_free_cookie()
63 kfree(cookie->key); in fscache_free_cookie()
64 kmem_cache_free(fscache_cookie_jar, cookie); in fscache_free_cookie()
74 static int fscache_set_key(struct fscache_cookie *cookie, in fscache_set_key() argument
84 if (index_key_len > sizeof(cookie->inline_key)) { in fscache_set_key()
88 cookie->key = buf; in fscache_set_key()
90 buf = (u32 *)cookie->inline_key; in fscache_set_key()
98 h = (unsigned long)cookie->parent; in fscache_set_key()
99 h += index_key_len + cookie->type; in fscache_set_key()
104 cookie->key_hash = h ^ (h >> 32); in fscache_set_key()
143 struct fscache_cookie *cookie; in fscache_alloc_cookie() local
146 cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); in fscache_alloc_cookie()
147 if (!cookie) in fscache_alloc_cookie()
150 cookie->key_len = index_key_len; in fscache_alloc_cookie()
151 cookie->aux_len = aux_data_len; in fscache_alloc_cookie()
153 if (fscache_set_key(cookie, index_key, index_key_len) < 0) in fscache_alloc_cookie()
156 if (cookie->aux_len <= sizeof(cookie->inline_aux)) { in fscache_alloc_cookie()
157 memcpy(cookie->inline_aux, aux_data, cookie->aux_len); in fscache_alloc_cookie()
159 cookie->aux = kmemdup(aux_data, cookie->aux_len, GFP_KERNEL); in fscache_alloc_cookie()
160 if (!cookie->aux) in fscache_alloc_cookie()
164 atomic_set(&cookie->usage, 1); in fscache_alloc_cookie()
165 atomic_set(&cookie->n_children, 0); in fscache_alloc_cookie()
170 atomic_set(&cookie->n_active, 1); in fscache_alloc_cookie()
172 cookie->def = def; in fscache_alloc_cookie()
173 cookie->parent = parent; in fscache_alloc_cookie()
174 cookie->netfs_data = netfs_data; in fscache_alloc_cookie()
175 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); in fscache_alloc_cookie()
176 cookie->type = def->type; in fscache_alloc_cookie()
177 spin_lock_init(&cookie->lock); in fscache_alloc_cookie()
178 spin_lock_init(&cookie->stores_lock); in fscache_alloc_cookie()
179 INIT_HLIST_HEAD(&cookie->backing_objects); in fscache_alloc_cookie()
183 INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in fscache_alloc_cookie()
184 return cookie; in fscache_alloc_cookie()
187 fscache_free_cookie(cookie); in fscache_alloc_cookie()
258 struct fscache_cookie *candidate, *cookie; in __fscache_acquire_cookie() local
298 cookie = fscache_hash_cookie(candidate); in __fscache_acquire_cookie()
299 if (!cookie) { in __fscache_acquire_cookie()
304 if (cookie == candidate) in __fscache_acquire_cookie()
307 switch (cookie->type) { in __fscache_acquire_cookie()
319 trace_fscache_acquire(cookie); in __fscache_acquire_cookie()
325 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_acquire_cookie()
326 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) { in __fscache_acquire_cookie()
327 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
330 fscache_cookie_put(cookie, in __fscache_acquire_cookie()
337 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
345 return cookie; in __fscache_acquire_cookie()
352 void __fscache_enable_cookie(struct fscache_cookie *cookie, in __fscache_enable_cookie() argument
358 _enter("%p", cookie); in __fscache_enable_cookie()
360 trace_fscache_enable(cookie); in __fscache_enable_cookie()
362 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_enable_cookie()
365 fscache_update_aux(cookie, aux_data); in __fscache_enable_cookie()
367 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_enable_cookie()
372 } else if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_enable_cookie()
374 __fscache_wait_on_invalidate(cookie); in __fscache_enable_cookie()
376 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) in __fscache_enable_cookie()
377 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
379 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
383 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_enable_cookie()
384 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_enable_cookie()
393 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, in fscache_acquire_non_index_cookie() argument
402 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); in fscache_acquire_non_index_cookie()
415 cache = fscache_select_cache_for_object(cookie->parent); in fscache_acquire_non_index_cookie()
425 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); in fscache_acquire_non_index_cookie()
429 ret = fscache_alloc_object(cache, cookie); in fscache_acquire_non_index_cookie()
436 spin_lock(&cookie->lock); in fscache_acquire_non_index_cookie()
437 if (hlist_empty(&cookie->backing_objects)) { in fscache_acquire_non_index_cookie()
438 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
442 object = hlist_entry(cookie->backing_objects.first, in fscache_acquire_non_index_cookie()
451 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
455 _debug("non-deferred lookup %p", &cookie->flags); in fscache_acquire_non_index_cookie()
456 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP, in fscache_acquire_non_index_cookie()
459 if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags)) in fscache_acquire_non_index_cookie()
478 struct fscache_cookie *cookie) in fscache_alloc_object() argument
483 _enter("%p,%p{%s}", cache, cookie, cookie->def->name); in fscache_alloc_object()
485 spin_lock(&cookie->lock); in fscache_alloc_object()
486 hlist_for_each_entry(object, &cookie->backing_objects, in fscache_alloc_object()
491 spin_unlock(&cookie->lock); in fscache_alloc_object()
496 object = cache->ops->alloc_object(cache, cookie); in fscache_alloc_object()
504 ASSERTCMP(object->cookie, ==, cookie); in fscache_alloc_object()
510 object->debug_id, cookie->def->name, object->events); in fscache_alloc_object()
512 ret = fscache_alloc_object(cache, cookie->parent); in fscache_alloc_object()
519 if (fscache_attach_object(cookie, object) < 0) { in fscache_alloc_object()
532 spin_unlock(&cookie->lock); in fscache_alloc_object()
535 spin_unlock(&cookie->lock); in fscache_alloc_object()
551 static int fscache_attach_object(struct fscache_cookie *cookie, in fscache_attach_object() argument
558 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); in fscache_attach_object()
560 ASSERTCMP(object->cookie, ==, cookie); in fscache_attach_object()
562 spin_lock(&cookie->lock); in fscache_attach_object()
567 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { in fscache_attach_object()
576 spin_lock_nested(&cookie->parent->lock, 1); in fscache_attach_object()
577 hlist_for_each_entry(p, &cookie->parent->backing_objects, in fscache_attach_object()
582 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
592 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
602 hlist_add_head(&object->cookie_link, &cookie->backing_objects); in fscache_attach_object()
608 spin_unlock(&cookie->lock); in fscache_attach_object()
616 void __fscache_invalidate(struct fscache_cookie *cookie) in __fscache_invalidate() argument
620 _enter("{%s}", cookie->def->name); in __fscache_invalidate()
629 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_invalidate()
634 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_invalidate()
635 spin_lock(&cookie->lock); in __fscache_invalidate()
637 if (fscache_cookie_enabled(cookie) && in __fscache_invalidate()
638 !hlist_empty(&cookie->backing_objects) && in __fscache_invalidate()
640 &cookie->flags)) { in __fscache_invalidate()
641 object = hlist_entry(cookie->backing_objects.first, in __fscache_invalidate()
649 spin_unlock(&cookie->lock); in __fscache_invalidate()
659 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) in __fscache_wait_on_invalidate() argument
661 _enter("%p", cookie); in __fscache_wait_on_invalidate()
663 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, in __fscache_wait_on_invalidate()
673 void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) in __fscache_update_cookie() argument
679 if (!cookie) { in __fscache_update_cookie()
685 _enter("{%s}", cookie->def->name); in __fscache_update_cookie()
687 spin_lock(&cookie->lock); in __fscache_update_cookie()
689 fscache_update_aux(cookie, aux_data); in __fscache_update_cookie()
691 if (fscache_cookie_enabled(cookie)) { in __fscache_update_cookie()
696 &cookie->backing_objects, cookie_link) { in __fscache_update_cookie()
701 spin_unlock(&cookie->lock); in __fscache_update_cookie()
709 void __fscache_disable_cookie(struct fscache_cookie *cookie, in __fscache_disable_cookie() argument
716 _enter("%p,%u", cookie, invalidate); in __fscache_disable_cookie()
718 trace_fscache_disable(cookie); in __fscache_disable_cookie()
720 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); in __fscache_disable_cookie()
722 if (atomic_read(&cookie->n_children) != 0) { in __fscache_disable_cookie()
724 cookie->def->name); in __fscache_disable_cookie()
728 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_disable_cookie()
731 fscache_update_aux(cookie, aux_data); in __fscache_disable_cookie()
733 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_disable_cookie()
739 __fscache_wait_on_invalidate(cookie); in __fscache_disable_cookie()
742 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); in __fscache_disable_cookie()
744 spin_lock(&cookie->lock); in __fscache_disable_cookie()
745 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_disable_cookie()
746 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { in __fscache_disable_cookie()
753 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) in __fscache_disable_cookie()
756 spin_unlock(&cookie->lock); in __fscache_disable_cookie()
758 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); in __fscache_disable_cookie()
764 if (!atomic_dec_and_test(&cookie->n_active)) { in __fscache_disable_cookie()
765 wait_var_event(&cookie->n_active, in __fscache_disable_cookie()
766 !atomic_read(&cookie->n_active)); in __fscache_disable_cookie()
770 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) in __fscache_disable_cookie()
771 fscache_invalidate_writes(cookie); in __fscache_disable_cookie()
774 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { in __fscache_disable_cookie()
775 atomic_inc(&cookie->n_active); in __fscache_disable_cookie()
776 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); in __fscache_disable_cookie()
780 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_disable_cookie()
781 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_disable_cookie()
792 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, in __fscache_relinquish_cookie() argument
800 if (!cookie) { in __fscache_relinquish_cookie()
807 cookie, cookie->def->name, cookie->netfs_data, in __fscache_relinquish_cookie()
808 atomic_read(&cookie->n_active), retire); in __fscache_relinquish_cookie()
810 trace_fscache_relinquish(cookie, retire); in __fscache_relinquish_cookie()
813 if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) in __fscache_relinquish_cookie()
816 __fscache_disable_cookie(cookie, aux_data, retire); in __fscache_relinquish_cookie()
819 cookie->netfs_data = NULL; in __fscache_relinquish_cookie()
820 cookie->def = NULL; in __fscache_relinquish_cookie()
821 BUG_ON(!radix_tree_empty(&cookie->stores)); in __fscache_relinquish_cookie()
823 if (cookie->parent) { in __fscache_relinquish_cookie()
824 ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); in __fscache_relinquish_cookie()
825 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); in __fscache_relinquish_cookie()
826 atomic_dec(&cookie->parent->n_children); in __fscache_relinquish_cookie()
830 ASSERTCMP(atomic_read(&cookie->usage), >, 0); in __fscache_relinquish_cookie()
831 fscache_cookie_put(cookie, fscache_cookie_put_relinquish); in __fscache_relinquish_cookie()
840 static void fscache_unhash_cookie(struct fscache_cookie *cookie) in fscache_unhash_cookie() argument
845 bucket = cookie->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); in fscache_unhash_cookie()
849 hlist_bl_del(&cookie->hash_link); in fscache_unhash_cookie()
856 void fscache_cookie_put(struct fscache_cookie *cookie, in fscache_cookie_put() argument
862 _enter("%p", cookie); in fscache_cookie_put()
865 usage = atomic_dec_return(&cookie->usage); in fscache_cookie_put()
866 trace_fscache_cookie(cookie, where, usage); in fscache_cookie_put()
872 parent = cookie->parent; in fscache_cookie_put()
873 fscache_unhash_cookie(cookie); in fscache_cookie_put()
874 fscache_free_cookie(cookie); in fscache_cookie_put()
876 cookie = parent; in fscache_cookie_put()
878 } while (cookie); in fscache_cookie_put()
888 int __fscache_check_consistency(struct fscache_cookie *cookie, in __fscache_check_consistency() argument
896 _enter("%p,", cookie); in __fscache_check_consistency()
898 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_check_consistency()
900 if (fscache_wait_for_deferred_lookup(cookie) < 0) in __fscache_check_consistency()
903 if (hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
910 fscache_operation_init(cookie, op, NULL, NULL, NULL); in __fscache_check_consistency()
914 trace_fscache_page_op(cookie, NULL, op, fscache_page_op_check_consistency); in __fscache_check_consistency()
916 spin_lock(&cookie->lock); in __fscache_check_consistency()
918 fscache_update_aux(cookie, aux_data); in __fscache_check_consistency()
920 if (!fscache_cookie_enabled(cookie) || in __fscache_check_consistency()
921 hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
923 object = hlist_entry(cookie->backing_objects.first, in __fscache_check_consistency()
930 __fscache_use_cookie(cookie); in __fscache_check_consistency()
935 spin_unlock(&cookie->lock); in __fscache_check_consistency()
951 wake_cookie = __fscache_unuse_cookie(cookie); in __fscache_check_consistency()
953 spin_unlock(&cookie->lock); in __fscache_check_consistency()
955 __fscache_wake_unused_cookie(cookie); in __fscache_check_consistency()