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
82 if (index_key_len > sizeof(cookie->inline_key)) { in fscache_set_key()
86 cookie->key = buf; in fscache_set_key()
88 buf = (u32 *)cookie->inline_key; in fscache_set_key()
92 cookie->key_hash = fscache_hash(0, buf, bufs); in fscache_set_key()
131 struct fscache_cookie *cookie; in fscache_alloc_cookie() local
134 cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); in fscache_alloc_cookie()
135 if (!cookie) in fscache_alloc_cookie()
138 cookie->key_len = index_key_len; in fscache_alloc_cookie()
139 cookie->aux_len = aux_data_len; in fscache_alloc_cookie()
141 if (fscache_set_key(cookie, index_key, index_key_len) < 0) in fscache_alloc_cookie()
144 if (cookie->aux_len <= sizeof(cookie->inline_aux)) { in fscache_alloc_cookie()
145 memcpy(cookie->inline_aux, aux_data, cookie->aux_len); in fscache_alloc_cookie()
147 cookie->aux = kmemdup(aux_data, cookie->aux_len, GFP_KERNEL); in fscache_alloc_cookie()
148 if (!cookie->aux) in fscache_alloc_cookie()
152 atomic_set(&cookie->usage, 1); in fscache_alloc_cookie()
153 atomic_set(&cookie->n_children, 0); in fscache_alloc_cookie()
158 atomic_set(&cookie->n_active, 1); in fscache_alloc_cookie()
160 cookie->def = def; in fscache_alloc_cookie()
161 cookie->parent = parent; in fscache_alloc_cookie()
162 cookie->netfs_data = netfs_data; in fscache_alloc_cookie()
163 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); in fscache_alloc_cookie()
164 cookie->type = def->type; in fscache_alloc_cookie()
165 spin_lock_init(&cookie->lock); in fscache_alloc_cookie()
166 spin_lock_init(&cookie->stores_lock); in fscache_alloc_cookie()
167 INIT_HLIST_HEAD(&cookie->backing_objects); in fscache_alloc_cookie()
171 INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in fscache_alloc_cookie()
172 return cookie; in fscache_alloc_cookie()
175 fscache_free_cookie(cookie); in fscache_alloc_cookie()
246 struct fscache_cookie *candidate, *cookie; in __fscache_acquire_cookie() local
286 cookie = fscache_hash_cookie(candidate); in __fscache_acquire_cookie()
287 if (!cookie) { in __fscache_acquire_cookie()
292 if (cookie == candidate) in __fscache_acquire_cookie()
295 switch (cookie->type) { in __fscache_acquire_cookie()
307 trace_fscache_acquire(cookie); in __fscache_acquire_cookie()
313 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_acquire_cookie()
314 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) { in __fscache_acquire_cookie()
315 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
318 fscache_cookie_put(cookie, in __fscache_acquire_cookie()
325 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
333 return cookie; in __fscache_acquire_cookie()
340 void __fscache_enable_cookie(struct fscache_cookie *cookie, in __fscache_enable_cookie() argument
346 _enter("%p", cookie); in __fscache_enable_cookie()
348 trace_fscache_enable(cookie); in __fscache_enable_cookie()
350 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_enable_cookie()
353 fscache_update_aux(cookie, aux_data); in __fscache_enable_cookie()
355 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_enable_cookie()
360 } else if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_enable_cookie()
362 __fscache_wait_on_invalidate(cookie); in __fscache_enable_cookie()
364 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) in __fscache_enable_cookie()
365 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
367 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
371 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_enable_cookie()
372 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_enable_cookie()
381 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, in fscache_acquire_non_index_cookie() argument
390 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); in fscache_acquire_non_index_cookie()
403 cache = fscache_select_cache_for_object(cookie->parent); in fscache_acquire_non_index_cookie()
413 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); in fscache_acquire_non_index_cookie()
417 ret = fscache_alloc_object(cache, cookie); in fscache_acquire_non_index_cookie()
424 spin_lock(&cookie->lock); in fscache_acquire_non_index_cookie()
425 if (hlist_empty(&cookie->backing_objects)) { in fscache_acquire_non_index_cookie()
426 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
430 object = hlist_entry(cookie->backing_objects.first, in fscache_acquire_non_index_cookie()
439 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
443 _debug("non-deferred lookup %p", &cookie->flags); in fscache_acquire_non_index_cookie()
444 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP, in fscache_acquire_non_index_cookie()
447 if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags)) in fscache_acquire_non_index_cookie()
466 struct fscache_cookie *cookie) in fscache_alloc_object() argument
471 _enter("%p,%p{%s}", cache, cookie, cookie->def->name); in fscache_alloc_object()
473 spin_lock(&cookie->lock); in fscache_alloc_object()
474 hlist_for_each_entry(object, &cookie->backing_objects, in fscache_alloc_object()
479 spin_unlock(&cookie->lock); in fscache_alloc_object()
484 object = cache->ops->alloc_object(cache, cookie); in fscache_alloc_object()
492 ASSERTCMP(object->cookie, ==, cookie); in fscache_alloc_object()
498 object->debug_id, cookie->def->name, object->events); in fscache_alloc_object()
500 ret = fscache_alloc_object(cache, cookie->parent); in fscache_alloc_object()
507 if (fscache_attach_object(cookie, object) < 0) { in fscache_alloc_object()
520 spin_unlock(&cookie->lock); in fscache_alloc_object()
523 spin_unlock(&cookie->lock); in fscache_alloc_object()
539 static int fscache_attach_object(struct fscache_cookie *cookie, in fscache_attach_object() argument
546 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); in fscache_attach_object()
548 ASSERTCMP(object->cookie, ==, cookie); in fscache_attach_object()
550 spin_lock(&cookie->lock); in fscache_attach_object()
555 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { in fscache_attach_object()
564 spin_lock_nested(&cookie->parent->lock, 1); in fscache_attach_object()
565 hlist_for_each_entry(p, &cookie->parent->backing_objects, in fscache_attach_object()
570 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
580 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
590 hlist_add_head(&object->cookie_link, &cookie->backing_objects); in fscache_attach_object()
596 spin_unlock(&cookie->lock); in fscache_attach_object()
604 void __fscache_invalidate(struct fscache_cookie *cookie) in __fscache_invalidate() argument
608 _enter("{%s}", cookie->def->name); in __fscache_invalidate()
617 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_invalidate()
622 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_invalidate()
623 spin_lock(&cookie->lock); in __fscache_invalidate()
625 if (fscache_cookie_enabled(cookie) && in __fscache_invalidate()
626 !hlist_empty(&cookie->backing_objects) && in __fscache_invalidate()
628 &cookie->flags)) { in __fscache_invalidate()
629 object = hlist_entry(cookie->backing_objects.first, in __fscache_invalidate()
637 spin_unlock(&cookie->lock); in __fscache_invalidate()
647 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) in __fscache_wait_on_invalidate() argument
649 _enter("%p", cookie); in __fscache_wait_on_invalidate()
651 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, in __fscache_wait_on_invalidate()
661 void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) in __fscache_update_cookie() argument
667 if (!cookie) { in __fscache_update_cookie()
673 _enter("{%s}", cookie->def->name); in __fscache_update_cookie()
675 spin_lock(&cookie->lock); in __fscache_update_cookie()
677 fscache_update_aux(cookie, aux_data); in __fscache_update_cookie()
679 if (fscache_cookie_enabled(cookie)) { in __fscache_update_cookie()
684 &cookie->backing_objects, cookie_link) { in __fscache_update_cookie()
689 spin_unlock(&cookie->lock); in __fscache_update_cookie()
697 void __fscache_disable_cookie(struct fscache_cookie *cookie, in __fscache_disable_cookie() argument
704 _enter("%p,%u", cookie, invalidate); in __fscache_disable_cookie()
706 trace_fscache_disable(cookie); in __fscache_disable_cookie()
708 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); in __fscache_disable_cookie()
710 if (atomic_read(&cookie->n_children) != 0) { in __fscache_disable_cookie()
712 cookie->def->name); in __fscache_disable_cookie()
716 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_disable_cookie()
719 fscache_update_aux(cookie, aux_data); in __fscache_disable_cookie()
721 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_disable_cookie()
727 __fscache_wait_on_invalidate(cookie); in __fscache_disable_cookie()
730 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); in __fscache_disable_cookie()
732 spin_lock(&cookie->lock); in __fscache_disable_cookie()
733 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_disable_cookie()
734 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { in __fscache_disable_cookie()
741 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) in __fscache_disable_cookie()
744 spin_unlock(&cookie->lock); in __fscache_disable_cookie()
746 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); in __fscache_disable_cookie()
752 if (!atomic_dec_and_test(&cookie->n_active)) { in __fscache_disable_cookie()
753 wait_var_event(&cookie->n_active, in __fscache_disable_cookie()
754 !atomic_read(&cookie->n_active)); in __fscache_disable_cookie()
758 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) in __fscache_disable_cookie()
759 fscache_invalidate_writes(cookie); in __fscache_disable_cookie()
762 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { in __fscache_disable_cookie()
763 atomic_inc(&cookie->n_active); in __fscache_disable_cookie()
764 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); in __fscache_disable_cookie()
768 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_disable_cookie()
769 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_disable_cookie()
780 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, in __fscache_relinquish_cookie() argument
788 if (!cookie) { in __fscache_relinquish_cookie()
795 cookie, cookie->def->name, cookie->netfs_data, in __fscache_relinquish_cookie()
796 atomic_read(&cookie->n_active), retire); in __fscache_relinquish_cookie()
798 trace_fscache_relinquish(cookie, retire); in __fscache_relinquish_cookie()
801 if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) in __fscache_relinquish_cookie()
804 __fscache_disable_cookie(cookie, aux_data, retire); in __fscache_relinquish_cookie()
807 cookie->netfs_data = NULL; in __fscache_relinquish_cookie()
808 cookie->def = NULL; in __fscache_relinquish_cookie()
809 BUG_ON(!radix_tree_empty(&cookie->stores)); in __fscache_relinquish_cookie()
811 if (cookie->parent) { in __fscache_relinquish_cookie()
812 ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); in __fscache_relinquish_cookie()
813 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); in __fscache_relinquish_cookie()
814 atomic_dec(&cookie->parent->n_children); in __fscache_relinquish_cookie()
818 ASSERTCMP(atomic_read(&cookie->usage), >, 0); in __fscache_relinquish_cookie()
819 fscache_cookie_put(cookie, fscache_cookie_put_relinquish); in __fscache_relinquish_cookie()
828 static void fscache_unhash_cookie(struct fscache_cookie *cookie) in fscache_unhash_cookie() argument
833 bucket = cookie->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); in fscache_unhash_cookie()
837 hlist_bl_del(&cookie->hash_link); in fscache_unhash_cookie()
844 void fscache_cookie_put(struct fscache_cookie *cookie, in fscache_cookie_put() argument
850 _enter("%p", cookie); in fscache_cookie_put()
853 usage = atomic_dec_return(&cookie->usage); in fscache_cookie_put()
854 trace_fscache_cookie(cookie, where, usage); in fscache_cookie_put()
860 parent = cookie->parent; in fscache_cookie_put()
861 fscache_unhash_cookie(cookie); in fscache_cookie_put()
862 fscache_free_cookie(cookie); in fscache_cookie_put()
864 cookie = parent; in fscache_cookie_put()
866 } while (cookie); in fscache_cookie_put()
876 int __fscache_check_consistency(struct fscache_cookie *cookie, in __fscache_check_consistency() argument
884 _enter("%p,", cookie); in __fscache_check_consistency()
886 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_check_consistency()
888 if (fscache_wait_for_deferred_lookup(cookie) < 0) in __fscache_check_consistency()
891 if (hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
898 fscache_operation_init(cookie, op, NULL, NULL, NULL); in __fscache_check_consistency()
902 trace_fscache_page_op(cookie, NULL, op, fscache_page_op_check_consistency); in __fscache_check_consistency()
904 spin_lock(&cookie->lock); in __fscache_check_consistency()
906 fscache_update_aux(cookie, aux_data); in __fscache_check_consistency()
908 if (!fscache_cookie_enabled(cookie) || in __fscache_check_consistency()
909 hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
911 object = hlist_entry(cookie->backing_objects.first, in __fscache_check_consistency()
918 __fscache_use_cookie(cookie); in __fscache_check_consistency()
923 spin_unlock(&cookie->lock); in __fscache_check_consistency()
939 wake_cookie = __fscache_unuse_cookie(cookie); in __fscache_check_consistency()
941 spin_unlock(&cookie->lock); in __fscache_check_consistency()
943 __fscache_wake_unused_cookie(cookie); in __fscache_check_consistency()