Lines Matching refs:cookie

25 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie,
28 struct fscache_cookie *cookie);
29 static int fscache_attach_object(struct fscache_cookie *cookie,
32 static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix) in fscache_print_cookie() argument
41 cookie->debug_id, in fscache_print_cookie()
42 cookie->parent ? cookie->parent->debug_id : 0, in fscache_print_cookie()
43 cookie->flags, in fscache_print_cookie()
44 atomic_read(&cookie->n_children), in fscache_print_cookie()
45 atomic_read(&cookie->n_active)); in fscache_print_cookie()
48 cookie->def, in fscache_print_cookie()
49 cookie->def ? cookie->def->name : "?", in fscache_print_cookie()
50 cookie->netfs_data); in fscache_print_cookie()
52 o = READ_ONCE(cookie->backing_objects.first); in fscache_print_cookie()
58 pr_err("%c-key=[%u] '", prefix, cookie->key_len); in fscache_print_cookie()
59 k = (cookie->key_len <= sizeof(cookie->inline_key)) ? in fscache_print_cookie()
60 cookie->inline_key : cookie->key; in fscache_print_cookie()
61 for (loop = 0; loop < cookie->key_len; loop++) in fscache_print_cookie()
66 void fscache_free_cookie(struct fscache_cookie *cookie) in fscache_free_cookie() argument
68 if (cookie) { in fscache_free_cookie()
69 BUG_ON(!hlist_empty(&cookie->backing_objects)); in fscache_free_cookie()
71 list_del(&cookie->proc_link); in fscache_free_cookie()
73 if (cookie->aux_len > sizeof(cookie->inline_aux)) in fscache_free_cookie()
74 kfree(cookie->aux); in fscache_free_cookie()
75 if (cookie->key_len > sizeof(cookie->inline_key)) in fscache_free_cookie()
76 kfree(cookie->key); in fscache_free_cookie()
77 kmem_cache_free(fscache_cookie_jar, cookie); in fscache_free_cookie()
87 static int fscache_set_key(struct fscache_cookie *cookie, in fscache_set_key() argument
95 if (index_key_len > sizeof(cookie->inline_key)) { in fscache_set_key()
99 cookie->key = buf; in fscache_set_key()
101 buf = (u32 *)cookie->inline_key; in fscache_set_key()
105 cookie->key_hash = fscache_hash(0, buf, bufs); in fscache_set_key()
146 struct fscache_cookie *cookie; in fscache_alloc_cookie() local
149 cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); in fscache_alloc_cookie()
150 if (!cookie) in fscache_alloc_cookie()
153 cookie->key_len = index_key_len; in fscache_alloc_cookie()
154 cookie->aux_len = aux_data_len; in fscache_alloc_cookie()
156 if (fscache_set_key(cookie, index_key, index_key_len) < 0) in fscache_alloc_cookie()
159 if (cookie->aux_len <= sizeof(cookie->inline_aux)) { in fscache_alloc_cookie()
160 memcpy(cookie->inline_aux, aux_data, cookie->aux_len); in fscache_alloc_cookie()
162 cookie->aux = kmemdup(aux_data, cookie->aux_len, GFP_KERNEL); in fscache_alloc_cookie()
163 if (!cookie->aux) in fscache_alloc_cookie()
167 refcount_set(&cookie->ref, 1); in fscache_alloc_cookie()
168 atomic_set(&cookie->n_children, 0); in fscache_alloc_cookie()
169 cookie->debug_id = atomic_inc_return(&fscache_cookie_debug_id); in fscache_alloc_cookie()
174 atomic_set(&cookie->n_active, 1); in fscache_alloc_cookie()
176 cookie->def = def; in fscache_alloc_cookie()
177 cookie->parent = parent; in fscache_alloc_cookie()
178 cookie->netfs_data = netfs_data; in fscache_alloc_cookie()
179 cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); in fscache_alloc_cookie()
180 cookie->type = def->type; in fscache_alloc_cookie()
181 spin_lock_init(&cookie->lock); in fscache_alloc_cookie()
182 spin_lock_init(&cookie->stores_lock); in fscache_alloc_cookie()
183 INIT_HLIST_HEAD(&cookie->backing_objects); in fscache_alloc_cookie()
187 INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in fscache_alloc_cookie()
190 list_add_tail(&cookie->proc_link, &fscache_cookies); in fscache_alloc_cookie()
192 return cookie; in fscache_alloc_cookie()
195 fscache_free_cookie(cookie); in fscache_alloc_cookie()
266 struct fscache_cookie *candidate, *cookie; in __fscache_acquire_cookie() local
306 cookie = fscache_hash_cookie(candidate); in __fscache_acquire_cookie()
307 if (!cookie) { in __fscache_acquire_cookie()
313 if (cookie == candidate) in __fscache_acquire_cookie()
316 switch (cookie->type) { in __fscache_acquire_cookie()
328 trace_fscache_acquire(cookie); in __fscache_acquire_cookie()
334 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_acquire_cookie()
335 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) { in __fscache_acquire_cookie()
336 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
339 fscache_cookie_put(cookie, in __fscache_acquire_cookie()
346 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_acquire_cookie()
354 return cookie; in __fscache_acquire_cookie()
361 void __fscache_enable_cookie(struct fscache_cookie *cookie, in __fscache_enable_cookie() argument
367 _enter("%x", cookie->debug_id); in __fscache_enable_cookie()
369 trace_fscache_enable(cookie); in __fscache_enable_cookie()
371 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_enable_cookie()
374 fscache_update_aux(cookie, aux_data); in __fscache_enable_cookie()
376 if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_enable_cookie()
381 } else if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { in __fscache_enable_cookie()
383 __fscache_wait_on_invalidate(cookie); in __fscache_enable_cookie()
385 if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) in __fscache_enable_cookie()
386 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
388 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); in __fscache_enable_cookie()
392 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_enable_cookie()
393 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_enable_cookie()
402 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, in fscache_acquire_non_index_cookie() argument
411 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); in fscache_acquire_non_index_cookie()
424 cache = fscache_select_cache_for_object(cookie->parent); in fscache_acquire_non_index_cookie()
434 set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); in fscache_acquire_non_index_cookie()
438 ret = fscache_alloc_object(cache, cookie); in fscache_acquire_non_index_cookie()
445 spin_lock(&cookie->lock); in fscache_acquire_non_index_cookie()
446 if (hlist_empty(&cookie->backing_objects)) { in fscache_acquire_non_index_cookie()
447 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
451 object = hlist_entry(cookie->backing_objects.first, in fscache_acquire_non_index_cookie()
460 spin_unlock(&cookie->lock); in fscache_acquire_non_index_cookie()
464 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP, in fscache_acquire_non_index_cookie()
466 if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags)) in fscache_acquire_non_index_cookie()
485 struct fscache_cookie *cookie) in fscache_alloc_object() argument
490 _enter("%s,%x{%s}", cache->tag->name, cookie->debug_id, cookie->def->name); in fscache_alloc_object()
492 spin_lock(&cookie->lock); in fscache_alloc_object()
493 hlist_for_each_entry(object, &cookie->backing_objects, in fscache_alloc_object()
498 spin_unlock(&cookie->lock); in fscache_alloc_object()
503 object = cache->ops->alloc_object(cache, cookie); in fscache_alloc_object()
511 ASSERTCMP(object->cookie, ==, cookie); in fscache_alloc_object()
517 object->debug_id, cookie->def->name, object->events); in fscache_alloc_object()
519 ret = fscache_alloc_object(cache, cookie->parent); in fscache_alloc_object()
526 if (fscache_attach_object(cookie, object) < 0) { in fscache_alloc_object()
539 spin_unlock(&cookie->lock); in fscache_alloc_object()
542 spin_unlock(&cookie->lock); in fscache_alloc_object()
558 static int fscache_attach_object(struct fscache_cookie *cookie, in fscache_attach_object() argument
565 _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); in fscache_attach_object()
567 ASSERTCMP(object->cookie, ==, cookie); in fscache_attach_object()
569 spin_lock(&cookie->lock); in fscache_attach_object()
574 hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { in fscache_attach_object()
583 spin_lock_nested(&cookie->parent->lock, 1); in fscache_attach_object()
584 hlist_for_each_entry(p, &cookie->parent->backing_objects, in fscache_attach_object()
589 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
599 spin_unlock(&cookie->parent->lock); in fscache_attach_object()
609 hlist_add_head(&object->cookie_link, &cookie->backing_objects); in fscache_attach_object()
613 spin_unlock(&cookie->lock); in fscache_attach_object()
621 void __fscache_invalidate(struct fscache_cookie *cookie) in __fscache_invalidate() argument
625 _enter("{%s}", cookie->def->name); in __fscache_invalidate()
634 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_invalidate()
639 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_invalidate()
640 spin_lock(&cookie->lock); in __fscache_invalidate()
642 if (fscache_cookie_enabled(cookie) && in __fscache_invalidate()
643 !hlist_empty(&cookie->backing_objects) && in __fscache_invalidate()
645 &cookie->flags)) { in __fscache_invalidate()
646 object = hlist_entry(cookie->backing_objects.first, in __fscache_invalidate()
654 spin_unlock(&cookie->lock); in __fscache_invalidate()
664 void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) in __fscache_wait_on_invalidate() argument
666 _enter("%x", cookie->debug_id); in __fscache_wait_on_invalidate()
668 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, in __fscache_wait_on_invalidate()
678 void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) in __fscache_update_cookie() argument
684 if (!cookie) { in __fscache_update_cookie()
690 _enter("{%s}", cookie->def->name); in __fscache_update_cookie()
692 spin_lock(&cookie->lock); in __fscache_update_cookie()
694 fscache_update_aux(cookie, aux_data); in __fscache_update_cookie()
696 if (fscache_cookie_enabled(cookie)) { in __fscache_update_cookie()
701 &cookie->backing_objects, cookie_link) { in __fscache_update_cookie()
706 spin_unlock(&cookie->lock); in __fscache_update_cookie()
714 void __fscache_disable_cookie(struct fscache_cookie *cookie, in __fscache_disable_cookie() argument
721 _enter("%x,%u", cookie->debug_id, invalidate); in __fscache_disable_cookie()
723 trace_fscache_disable(cookie); in __fscache_disable_cookie()
725 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); in __fscache_disable_cookie()
727 if (atomic_read(&cookie->n_children) != 0) { in __fscache_disable_cookie()
729 cookie->def->name); in __fscache_disable_cookie()
733 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, in __fscache_disable_cookie()
736 fscache_update_aux(cookie, aux_data); in __fscache_disable_cookie()
738 if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) in __fscache_disable_cookie()
744 __fscache_wait_on_invalidate(cookie); in __fscache_disable_cookie()
747 set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); in __fscache_disable_cookie()
749 spin_lock(&cookie->lock); in __fscache_disable_cookie()
750 if (!hlist_empty(&cookie->backing_objects)) { in __fscache_disable_cookie()
751 hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { in __fscache_disable_cookie()
758 if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) in __fscache_disable_cookie()
761 spin_unlock(&cookie->lock); in __fscache_disable_cookie()
763 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); in __fscache_disable_cookie()
769 if (!atomic_dec_and_test(&cookie->n_active)) { in __fscache_disable_cookie()
770 wait_var_event(&cookie->n_active, in __fscache_disable_cookie()
771 !atomic_read(&cookie->n_active)); in __fscache_disable_cookie()
775 if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) in __fscache_disable_cookie()
776 fscache_invalidate_writes(cookie); in __fscache_disable_cookie()
779 if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { in __fscache_disable_cookie()
780 atomic_inc(&cookie->n_active); in __fscache_disable_cookie()
781 set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); in __fscache_disable_cookie()
785 clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); in __fscache_disable_cookie()
786 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); in __fscache_disable_cookie()
797 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, in __fscache_relinquish_cookie() argument
805 if (!cookie) { in __fscache_relinquish_cookie()
812 cookie->debug_id, cookie->def->name, in __fscache_relinquish_cookie()
813 atomic_read(&cookie->n_active), retire); in __fscache_relinquish_cookie()
815 trace_fscache_relinquish(cookie, retire); in __fscache_relinquish_cookie()
818 if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) in __fscache_relinquish_cookie()
821 __fscache_disable_cookie(cookie, aux_data, retire); in __fscache_relinquish_cookie()
824 cookie->netfs_data = NULL; in __fscache_relinquish_cookie()
825 cookie->def = NULL; in __fscache_relinquish_cookie()
826 BUG_ON(!radix_tree_empty(&cookie->stores)); in __fscache_relinquish_cookie()
828 if (cookie->parent) { in __fscache_relinquish_cookie()
829 ASSERTCMP(refcount_read(&cookie->parent->ref), >, 0); in __fscache_relinquish_cookie()
830 ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); in __fscache_relinquish_cookie()
831 atomic_dec(&cookie->parent->n_children); in __fscache_relinquish_cookie()
835 fscache_cookie_put(cookie, fscache_cookie_put_relinquish); in __fscache_relinquish_cookie()
844 static void fscache_unhash_cookie(struct fscache_cookie *cookie) in fscache_unhash_cookie() argument
849 bucket = cookie->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); in fscache_unhash_cookie()
853 hlist_bl_del(&cookie->hash_link); in fscache_unhash_cookie()
860 void fscache_cookie_put(struct fscache_cookie *cookie, in fscache_cookie_put() argument
866 _enter("%x", cookie->debug_id); in fscache_cookie_put()
869 unsigned int cookie_debug_id = cookie->debug_id; in fscache_cookie_put()
870 bool zero = __refcount_dec_and_test(&cookie->ref, &ref); in fscache_cookie_put()
876 parent = cookie->parent; in fscache_cookie_put()
877 fscache_unhash_cookie(cookie); in fscache_cookie_put()
878 fscache_free_cookie(cookie); in fscache_cookie_put()
880 cookie = parent; in fscache_cookie_put()
882 } while (cookie); in fscache_cookie_put()
890 struct fscache_cookie *fscache_cookie_get(struct fscache_cookie *cookie, in fscache_cookie_get() argument
895 __refcount_inc(&cookie->ref, &ref); in fscache_cookie_get()
896 trace_fscache_cookie(cookie->debug_id, ref + 1, where); in fscache_cookie_get()
897 return cookie; in fscache_cookie_get()
905 int __fscache_check_consistency(struct fscache_cookie *cookie, in __fscache_check_consistency() argument
913 _enter("%p,", cookie); in __fscache_check_consistency()
915 ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); in __fscache_check_consistency()
917 if (fscache_wait_for_deferred_lookup(cookie) < 0) in __fscache_check_consistency()
920 if (hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
927 fscache_operation_init(cookie, op, NULL, NULL, NULL); in __fscache_check_consistency()
931 trace_fscache_page_op(cookie, NULL, op, fscache_page_op_check_consistency); in __fscache_check_consistency()
933 spin_lock(&cookie->lock); in __fscache_check_consistency()
935 fscache_update_aux(cookie, aux_data); in __fscache_check_consistency()
937 if (!fscache_cookie_enabled(cookie) || in __fscache_check_consistency()
938 hlist_empty(&cookie->backing_objects)) in __fscache_check_consistency()
940 object = hlist_entry(cookie->backing_objects.first, in __fscache_check_consistency()
947 __fscache_use_cookie(cookie); in __fscache_check_consistency()
952 spin_unlock(&cookie->lock); in __fscache_check_consistency()
968 wake_cookie = __fscache_unuse_cookie(cookie); in __fscache_check_consistency()
970 spin_unlock(&cookie->lock); in __fscache_check_consistency()
972 __fscache_wake_unused_cookie(cookie); in __fscache_check_consistency()
984 struct fscache_cookie *cookie; in fscache_cookies_seq_show() local
997 cookie = list_entry(v, struct fscache_cookie, proc_link); in fscache_cookies_seq_show()
999 switch (cookie->type) { in fscache_cookies_seq_show()
1008 cookie->type); in fscache_cookies_seq_show()
1015 cookie->debug_id, in fscache_cookies_seq_show()
1016 cookie->parent ? cookie->parent->debug_id : 0, in fscache_cookies_seq_show()
1017 refcount_read(&cookie->ref), in fscache_cookies_seq_show()
1018 atomic_read(&cookie->n_children), in fscache_cookies_seq_show()
1019 atomic_read(&cookie->n_active), in fscache_cookies_seq_show()
1021 cookie->flags, in fscache_cookies_seq_show()
1022 cookie->def->name, in fscache_cookies_seq_show()
1023 cookie->netfs_data); in fscache_cookies_seq_show()
1025 keylen = cookie->key_len; in fscache_cookies_seq_show()
1026 auxlen = cookie->aux_len; in fscache_cookies_seq_show()
1030 p = keylen <= sizeof(cookie->inline_key) ? in fscache_cookies_seq_show()
1031 cookie->inline_key : cookie->key; in fscache_cookies_seq_show()
1036 p = auxlen <= sizeof(cookie->inline_aux) ? in fscache_cookies_seq_show()
1037 cookie->inline_aux : cookie->aux; in fscache_cookies_seq_show()