Lines Matching refs:cache
69 int nl_cache_nitems(struct nl_cache *cache) in nl_cache_nitems() argument
71 return cache->c_nitems; in nl_cache_nitems()
79 int nl_cache_nitems_filter(struct nl_cache *cache, struct nl_object *filter) in nl_cache_nitems_filter() argument
84 if (cache->c_ops == NULL) in nl_cache_nitems_filter()
87 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_nitems_filter()
102 int nl_cache_is_empty(struct nl_cache *cache) in nl_cache_is_empty() argument
104 return nl_list_empty(&cache->c_items); in nl_cache_is_empty()
111 struct nl_cache_ops *nl_cache_get_ops(struct nl_cache *cache) in nl_cache_get_ops() argument
113 return cache->c_ops; in nl_cache_get_ops()
120 struct nl_object *nl_cache_get_first(struct nl_cache *cache) in nl_cache_get_first() argument
122 if (nl_list_empty(&cache->c_items)) in nl_cache_get_first()
125 return nl_list_entry(cache->c_items.next, in nl_cache_get_first()
133 struct nl_object *nl_cache_get_last(struct nl_cache *cache) in nl_cache_get_last() argument
135 if (nl_list_empty(&cache->c_items)) in nl_cache_get_last()
138 return nl_list_entry(cache->c_items.prev, in nl_cache_get_last()
186 struct nl_cache *cache; in nl_cache_alloc() local
188 cache = calloc(1, sizeof(*cache)); in nl_cache_alloc()
189 if (!cache) in nl_cache_alloc()
192 nl_init_list_head(&cache->c_items); in nl_cache_alloc()
193 cache->c_ops = ops; in nl_cache_alloc()
194 cache->c_flags |= ops->co_flags; in nl_cache_alloc()
195 cache->c_refcnt = 1; in nl_cache_alloc()
210 cache->hashtable = nl_hash_table_alloc(hashtable_size); in nl_cache_alloc()
213 NL_DBG(2, "Allocated cache %p <%s>.\n", cache, nl_cache_name(cache)); in nl_cache_alloc()
215 return cache; in nl_cache_alloc()
237 struct nl_cache *cache; in nl_cache_alloc_and_fill() local
240 if (!(cache = nl_cache_alloc(ops))) in nl_cache_alloc_and_fill()
243 if (sock && (err = nl_cache_refill(sock, cache)) < 0) { in nl_cache_alloc_and_fill()
244 nl_cache_free(cache); in nl_cache_alloc_and_fill()
248 *result = cache; in nl_cache_alloc_and_fill()
268 struct nl_cache *cache; in nl_cache_alloc_name() local
274 cache = nl_cache_alloc(ops); in nl_cache_alloc_name()
276 if (!cache) in nl_cache_alloc_name()
279 *result = cache; in nl_cache_alloc_name()
301 struct nl_cache *cache; in nl_cache_subset() local
307 cache = nl_cache_alloc(orig->c_ops); in nl_cache_subset()
308 if (!cache) in nl_cache_subset()
312 orig, nl_cache_name(orig), filter, cache); in nl_cache_subset()
318 nl_cache_add(cache, obj); in nl_cache_subset()
321 return cache; in nl_cache_subset()
338 struct nl_cache *nl_cache_clone(struct nl_cache *cache) in nl_cache_clone() argument
340 struct nl_cache_ops *ops = nl_cache_get_ops(cache); in nl_cache_clone()
348 NL_DBG(2, "Cloning %p into %p\n", cache, clone); in nl_cache_clone()
350 nl_list_for_each_entry(obj, &cache->c_items, ce_list) in nl_cache_clone()
367 void nl_cache_clear(struct nl_cache *cache) in nl_cache_clear() argument
371 NL_DBG(2, "Clearing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_clear()
373 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) in nl_cache_clear()
377 static void __nl_cache_free(struct nl_cache *cache) in __nl_cache_free() argument
379 nl_cache_clear(cache); in __nl_cache_free()
381 if (cache->hashtable) in __nl_cache_free()
382 nl_hash_table_free(cache->hashtable); in __nl_cache_free()
384 NL_DBG(2, "Freeing cache %p <%s>...\n", cache, nl_cache_name(cache)); in __nl_cache_free()
385 free(cache); in __nl_cache_free()
392 void nl_cache_get(struct nl_cache *cache) in nl_cache_get() argument
394 cache->c_refcnt++; in nl_cache_get()
397 cache, nl_cache_name(cache), cache->c_refcnt); in nl_cache_get()
409 void nl_cache_free(struct nl_cache *cache) in nl_cache_free() argument
411 if (!cache) in nl_cache_free()
414 cache->c_refcnt--; in nl_cache_free()
417 cache, nl_cache_name(cache), cache->c_refcnt); in nl_cache_free()
419 if (cache->c_refcnt <= 0) in nl_cache_free()
420 __nl_cache_free(cache); in nl_cache_free()
423 void nl_cache_put(struct nl_cache *cache) in nl_cache_put() argument
425 nl_cache_free(cache); in nl_cache_put()
435 static int __cache_add(struct nl_cache *cache, struct nl_object *obj) in __cache_add() argument
439 obj->ce_cache = cache; in __cache_add()
441 if (cache->hashtable) { in __cache_add()
442 ret = nl_hash_table_add(cache->hashtable, obj); in __cache_add()
449 nl_list_add_tail(&obj->ce_list, &cache->c_items); in __cache_add()
450 cache->c_nitems++; in __cache_add()
453 obj, cache, nl_cache_name(cache), cache->c_nitems); in __cache_add()
480 int nl_cache_add(struct nl_cache *cache, struct nl_object *obj) in nl_cache_add() argument
485 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_add()
499 ret = __cache_add(cache, new); in nl_cache_add()
524 int nl_cache_move(struct nl_cache *cache, struct nl_object *obj) in nl_cache_move() argument
526 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_move()
530 obj, obj->ce_cache, cache); in nl_cache_move()
539 return __cache_add(cache, obj); in nl_cache_move()
555 struct nl_cache *cache = obj->ce_cache; in nl_cache_remove() local
557 if (cache == NULL) in nl_cache_remove()
560 if (cache->hashtable) { in nl_cache_remove()
561 ret = nl_hash_table_del(cache->hashtable, obj); in nl_cache_remove()
564 obj, cache, nl_cache_name(cache)); in nl_cache_remove()
570 cache->c_nitems--; in nl_cache_remove()
573 obj, cache, nl_cache_name(cache)); in nl_cache_remove()
591 void nl_cache_set_arg1(struct nl_cache *cache, int arg) in nl_cache_set_arg1() argument
593 cache->c_iarg1 = arg; in nl_cache_set_arg1()
604 void nl_cache_set_arg2(struct nl_cache *cache, int arg) in nl_cache_set_arg2() argument
606 cache->c_iarg2 = arg; in nl_cache_set_arg2()
614 void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags) in nl_cache_set_flags() argument
616 cache->c_flags |= flags; in nl_cache_set_flags()
646 struct nl_cache *cache) in nl_cache_request_full_dump() argument
648 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_request_full_dump()
651 if (cache->c_ops->co_request_update == NULL) in nl_cache_request_full_dump()
655 cache, nl_cache_name(cache)); in nl_cache_request_full_dump()
657 return cache->c_ops->co_request_update(cache, sk); in nl_cache_request_full_dump()
685 static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache, in __cache_pickup() argument
691 .ops = cache->c_ops, in __cache_pickup()
696 cache, nl_cache_name(cache)); in __cache_pickup()
707 cache, nl_cache_name(cache), err, nl_geterror(err)); in __cache_pickup()
716 struct nl_cache *cache = (struct nl_cache *)p->pp_arg; in pickup_checkdup_cb() local
719 old = nl_cache_search(cache, c); in pickup_checkdup_cb()
730 return nl_cache_add(cache, c); in pickup_checkdup_cb()
735 struct nl_cache *cache = p->pp_arg; in pickup_cb() local
737 return nl_cache_add(cache, c); in pickup_cb()
740 static int __nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache, in __nl_cache_pickup() argument
746 p.pp_arg = cache; in __nl_cache_pickup()
748 if (sk->s_proto != cache->c_ops->co_protocol) in __nl_cache_pickup()
751 return __cache_pickup(sk, cache, &p); in __nl_cache_pickup()
764 int nl_cache_pickup_checkdup(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_pickup_checkdup() argument
766 return __nl_cache_pickup(sk, cache, 1); in nl_cache_pickup_checkdup()
782 int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_pickup() argument
784 return __nl_cache_pickup(sk, cache, 0); in nl_cache_pickup()
787 static int cache_include(struct nl_cache *cache, struct nl_object *obj, in cache_include() argument
798 old = nl_cache_search(cache, obj); in cache_include()
811 cb_v2(cache, clone, obj, diff, in cache_include()
815 cb(cache, old, NL_ACT_CHANGE, data); in cache_include()
824 cb_v2(cache, old, NULL, 0, NL_ACT_DEL, in cache_include()
827 cb(cache, old, NL_ACT_DEL, data); in cache_include()
833 nl_cache_move(cache, obj); in cache_include()
836 cb_v2(cache, NULL, obj, 0, NL_ACT_NEW, in cache_include()
839 cb(cache, obj, NL_ACT_NEW, data); in cache_include()
845 cb_v2(cache, old, obj, diff, NL_ACT_CHANGE, in cache_include()
848 cb(cache, obj, NL_ACT_CHANGE, data); in cache_include()
862 int nl_cache_include(struct nl_cache *cache, struct nl_object *obj, in nl_cache_include() argument
865 struct nl_cache_ops *ops = cache->c_ops; in nl_cache_include()
873 return cache_include(cache, obj, &ops->co_msgtypes[i], in nl_cache_include()
877 obj, cache, nl_cache_name(cache)); in nl_cache_include()
882 int nl_cache_include_v2(struct nl_cache *cache, struct nl_object *obj, in nl_cache_include_v2() argument
885 struct nl_cache_ops *ops = cache->c_ops; in nl_cache_include_v2()
893 return cache_include(cache, obj, &ops->co_msgtypes[i], in nl_cache_include_v2()
897 obj, cache, nl_cache_name(cache)); in nl_cache_include_v2()
914 int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache, in nl_cache_resync() argument
920 .ca_cache = cache, in nl_cache_resync()
930 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_resync()
933 NL_DBG(1, "Resyncing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_resync()
936 nl_cache_mark_all(cache); in nl_cache_resync()
938 grp = cache->c_ops->co_groups; in nl_cache_resync()
941 (cache->c_flags & NL_CACHE_AF_ITER)) in nl_cache_resync()
942 nl_cache_set_arg1(cache, grp->ag_family); in nl_cache_resync()
945 err = nl_cache_request_full_dump(sk, cache); in nl_cache_resync()
949 err = __cache_pickup(sk, cache, &p); in nl_cache_resync()
958 (cache->c_flags & NL_CACHE_AF_ITER)); in nl_cache_resync()
960 nl_list_for_each_entry_safe(obj, next, &cache->c_items, ce_list) { in nl_cache_resync()
965 change_cb(cache, obj, NL_ACT_DEL, data); in nl_cache_resync()
970 NL_DBG(1, "Finished resyncing %p <%s>\n", cache, nl_cache_name(cache)); in nl_cache_resync()
1021 int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg) in nl_cache_parse_and_add() argument
1025 .pp_arg = cache, in nl_cache_parse_and_add()
1028 return nl_cache_parse(cache->c_ops, NULL, nlmsg_hdr(msg), &p); in nl_cache_parse_and_add()
1041 int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_refill() argument
1046 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_refill()
1049 nl_cache_clear(cache); in nl_cache_refill()
1050 grp = cache->c_ops->co_groups; in nl_cache_refill()
1053 (cache->c_flags & NL_CACHE_AF_ITER)) in nl_cache_refill()
1054 nl_cache_set_arg1(cache, grp->ag_family); in nl_cache_refill()
1057 err = nl_cache_request_full_dump(sk, cache); in nl_cache_refill()
1062 cache, nl_cache_name(cache), grp ? grp->ag_family : AF_UNSPEC); in nl_cache_refill()
1064 err = nl_cache_pickup(sk, cache); in nl_cache_refill()
1074 (cache->c_flags & NL_CACHE_AF_ITER)); in nl_cache_refill()
1085 static struct nl_object *__cache_fast_lookup(struct nl_cache *cache, in __cache_fast_lookup() argument
1090 obj = nl_hash_table_lookup(cache->hashtable, needle); in __cache_fast_lookup()
1114 struct nl_object *nl_cache_search(struct nl_cache *cache, in nl_cache_search() argument
1119 if (cache->hashtable) in nl_cache_search()
1120 return __cache_fast_lookup(cache, needle); in nl_cache_search()
1122 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_search()
1149 struct nl_object *nl_cache_find(struct nl_cache *cache, in nl_cache_find() argument
1154 if (cache->c_ops == NULL) in nl_cache_find()
1158 && cache->hashtable) in nl_cache_find()
1159 return __cache_fast_lookup(cache, filter); in nl_cache_find()
1161 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_find()
1178 void nl_cache_mark_all(struct nl_cache *cache) in nl_cache_mark_all() argument
1183 cache, nl_cache_name(cache)); in nl_cache_mark_all()
1185 nl_list_for_each_entry(obj, &cache->c_items, ce_list) in nl_cache_mark_all()
1203 void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params) in nl_cache_dump() argument
1205 nl_cache_dump_filter(cache, params, NULL); in nl_cache_dump()
1217 void nl_cache_dump_filter(struct nl_cache *cache, in nl_cache_dump_filter() argument
1226 cache, nl_cache_name(cache), filter); in nl_cache_dump_filter()
1231 if (cache->c_ops == NULL) in nl_cache_dump_filter()
1234 ops = cache->c_ops->co_obj_ops; in nl_cache_dump_filter()
1241 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_dump_filter()
1266 void nl_cache_foreach(struct nl_cache *cache, in nl_cache_foreach() argument
1269 nl_cache_foreach_filter(cache, NULL, cb, arg); in nl_cache_foreach()
1283 void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, in nl_cache_foreach_filter() argument
1288 if (cache->c_ops == NULL) in nl_cache_foreach_filter()
1291 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) { in nl_cache_foreach_filter()