Lines Matching refs:cache
68 int nl_cache_nitems(struct nl_cache *cache) in nl_cache_nitems() argument
70 return cache->c_nitems; in nl_cache_nitems()
78 int nl_cache_nitems_filter(struct nl_cache *cache, struct nl_object *filter) in nl_cache_nitems_filter() argument
83 if (cache->c_ops == NULL) in nl_cache_nitems_filter()
86 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_nitems_filter()
101 int nl_cache_is_empty(struct nl_cache *cache) in nl_cache_is_empty() argument
103 return nl_list_empty(&cache->c_items); in nl_cache_is_empty()
110 struct nl_cache_ops *nl_cache_get_ops(struct nl_cache *cache) in nl_cache_get_ops() argument
112 return cache->c_ops; in nl_cache_get_ops()
119 struct nl_object *nl_cache_get_first(struct nl_cache *cache) in nl_cache_get_first() argument
121 if (nl_list_empty(&cache->c_items)) in nl_cache_get_first()
124 return nl_list_entry(cache->c_items.next, in nl_cache_get_first()
132 struct nl_object *nl_cache_get_last(struct nl_cache *cache) in nl_cache_get_last() argument
134 if (nl_list_empty(&cache->c_items)) in nl_cache_get_last()
137 return nl_list_entry(cache->c_items.prev, in nl_cache_get_last()
185 struct nl_cache *cache; in nl_cache_alloc() local
187 cache = calloc(1, sizeof(*cache)); in nl_cache_alloc()
188 if (!cache) in nl_cache_alloc()
191 nl_init_list_head(&cache->c_items); in nl_cache_alloc()
192 cache->c_ops = ops; in nl_cache_alloc()
193 cache->c_flags |= ops->co_flags; in nl_cache_alloc()
194 cache->c_refcnt = 1; in nl_cache_alloc()
209 cache->hashtable = nl_hash_table_alloc(hashtable_size); in nl_cache_alloc()
212 NL_DBG(2, "Allocated cache %p <%s>.\n", cache, nl_cache_name(cache)); in nl_cache_alloc()
214 return cache; in nl_cache_alloc()
236 struct nl_cache *cache; in nl_cache_alloc_and_fill() local
239 if (!(cache = nl_cache_alloc(ops))) in nl_cache_alloc_and_fill()
242 if (sock && (err = nl_cache_refill(sock, cache)) < 0) { in nl_cache_alloc_and_fill()
243 nl_cache_free(cache); in nl_cache_alloc_and_fill()
247 *result = cache; in nl_cache_alloc_and_fill()
267 struct nl_cache *cache; in nl_cache_alloc_name() local
273 cache = nl_cache_alloc(ops); in nl_cache_alloc_name()
275 if (!cache) in nl_cache_alloc_name()
278 *result = cache; in nl_cache_alloc_name()
300 struct nl_cache *cache; in nl_cache_subset() local
306 cache = nl_cache_alloc(orig->c_ops); in nl_cache_subset()
307 if (!cache) in nl_cache_subset()
311 orig, nl_cache_name(orig), filter, cache); in nl_cache_subset()
317 nl_cache_add(cache, obj); in nl_cache_subset()
320 return cache; in nl_cache_subset()
337 struct nl_cache *nl_cache_clone(struct nl_cache *cache) in nl_cache_clone() argument
339 struct nl_cache_ops *ops = nl_cache_get_ops(cache); in nl_cache_clone()
347 NL_DBG(2, "Cloning %p into %p\n", cache, clone); in nl_cache_clone()
349 nl_list_for_each_entry(obj, &cache->c_items, ce_list) in nl_cache_clone()
366 void nl_cache_clear(struct nl_cache *cache) in nl_cache_clear() argument
370 NL_DBG(2, "Clearing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_clear()
372 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) in nl_cache_clear()
376 static void __nl_cache_free(struct nl_cache *cache) in __nl_cache_free() argument
378 nl_cache_clear(cache); in __nl_cache_free()
380 if (cache->hashtable) in __nl_cache_free()
381 nl_hash_table_free(cache->hashtable); in __nl_cache_free()
383 NL_DBG(2, "Freeing cache %p <%s>...\n", cache, nl_cache_name(cache)); in __nl_cache_free()
384 free(cache); in __nl_cache_free()
391 void nl_cache_get(struct nl_cache *cache) in nl_cache_get() argument
393 cache->c_refcnt++; in nl_cache_get()
396 cache, nl_cache_name(cache), cache->c_refcnt); in nl_cache_get()
408 void nl_cache_free(struct nl_cache *cache) in nl_cache_free() argument
410 if (!cache) in nl_cache_free()
413 cache->c_refcnt--; in nl_cache_free()
416 cache, nl_cache_name(cache), cache->c_refcnt); in nl_cache_free()
418 if (cache->c_refcnt <= 0) in nl_cache_free()
419 __nl_cache_free(cache); in nl_cache_free()
422 void nl_cache_put(struct nl_cache *cache) in nl_cache_put() argument
424 return nl_cache_free(cache); in nl_cache_put()
434 static int __cache_add(struct nl_cache *cache, struct nl_object *obj) in __cache_add() argument
438 obj->ce_cache = cache; in __cache_add()
440 if (cache->hashtable) { in __cache_add()
441 ret = nl_hash_table_add(cache->hashtable, obj); in __cache_add()
448 nl_list_add_tail(&obj->ce_list, &cache->c_items); in __cache_add()
449 cache->c_nitems++; in __cache_add()
452 obj, cache, nl_cache_name(cache), cache->c_nitems); in __cache_add()
479 int nl_cache_add(struct nl_cache *cache, struct nl_object *obj) in nl_cache_add() argument
484 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_add()
498 ret = __cache_add(cache, new); in nl_cache_add()
523 int nl_cache_move(struct nl_cache *cache, struct nl_object *obj) in nl_cache_move() argument
525 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_move()
529 obj, obj->ce_cache, cache); in nl_cache_move()
538 return __cache_add(cache, obj); in nl_cache_move()
554 struct nl_cache *cache = obj->ce_cache; in nl_cache_remove() local
556 if (cache == NULL) in nl_cache_remove()
559 if (cache->hashtable) { in nl_cache_remove()
560 ret = nl_hash_table_del(cache->hashtable, obj); in nl_cache_remove()
563 obj, cache, nl_cache_name(cache)); in nl_cache_remove()
569 cache->c_nitems--; in nl_cache_remove()
572 obj, cache, nl_cache_name(cache)); in nl_cache_remove()
590 void nl_cache_set_arg1(struct nl_cache *cache, int arg) in nl_cache_set_arg1() argument
592 cache->c_iarg1 = arg; in nl_cache_set_arg1()
603 void nl_cache_set_arg2(struct nl_cache *cache, int arg) in nl_cache_set_arg2() argument
605 cache->c_iarg2 = arg; in nl_cache_set_arg2()
613 void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags) in nl_cache_set_flags() argument
615 cache->c_flags |= flags; in nl_cache_set_flags()
643 struct nl_cache *cache) in nl_cache_request_full_dump() argument
645 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_request_full_dump()
648 if (cache->c_ops->co_request_update == NULL) in nl_cache_request_full_dump()
652 cache, nl_cache_name(cache)); in nl_cache_request_full_dump()
654 return cache->c_ops->co_request_update(cache, sk); in nl_cache_request_full_dump()
682 static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache, in __cache_pickup() argument
688 .ops = cache->c_ops, in __cache_pickup()
693 cache, nl_cache_name(cache)); in __cache_pickup()
704 cache, nl_cache_name(cache), err, nl_geterror(err)); in __cache_pickup()
713 struct nl_cache *cache = (struct nl_cache *)p->pp_arg; in pickup_cb() local
716 old = nl_cache_search(cache, c); in pickup_cb()
727 return nl_cache_add(cache, c); in pickup_cb()
743 int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_pickup() argument
747 .pp_arg = cache, in nl_cache_pickup()
750 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_pickup()
753 return __cache_pickup(sk, cache, &p); in nl_cache_pickup()
756 static int cache_include(struct nl_cache *cache, struct nl_object *obj, in cache_include() argument
764 old = nl_cache_search(cache, obj); in cache_include()
773 cb(cache, old, NL_ACT_CHANGE, data); in cache_include()
781 cb(cache, old, NL_ACT_DEL, data); in cache_include()
787 nl_cache_move(cache, obj); in cache_include()
789 cb(cache, obj, NL_ACT_NEW, data); in cache_include()
792 cb(cache, obj, NL_ACT_CHANGE, data); in cache_include()
806 int nl_cache_include(struct nl_cache *cache, struct nl_object *obj, in nl_cache_include() argument
809 struct nl_cache_ops *ops = cache->c_ops; in nl_cache_include()
817 return cache_include(cache, obj, &ops->co_msgtypes[i], in nl_cache_include()
821 obj, cache, nl_cache_name(cache)); in nl_cache_include()
833 int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache, in nl_cache_resync() argument
839 .ca_cache = cache, in nl_cache_resync()
849 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_resync()
852 NL_DBG(1, "Resyncing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_resync()
855 nl_cache_mark_all(cache); in nl_cache_resync()
857 grp = cache->c_ops->co_groups; in nl_cache_resync()
860 (cache->c_flags & NL_CACHE_AF_ITER)) in nl_cache_resync()
861 nl_cache_set_arg1(cache, grp->ag_family); in nl_cache_resync()
864 err = nl_cache_request_full_dump(sk, cache); in nl_cache_resync()
868 err = __cache_pickup(sk, cache, &p); in nl_cache_resync()
877 (cache->c_flags & NL_CACHE_AF_ITER)); in nl_cache_resync()
879 nl_list_for_each_entry_safe(obj, next, &cache->c_items, ce_list) { in nl_cache_resync()
884 change_cb(cache, obj, NL_ACT_DEL, data); in nl_cache_resync()
889 NL_DBG(1, "Finished resyncing %p <%s>\n", cache, nl_cache_name(cache)); in nl_cache_resync()
940 int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg) in nl_cache_parse_and_add() argument
944 .pp_arg = cache, in nl_cache_parse_and_add()
947 return nl_cache_parse(cache->c_ops, NULL, nlmsg_hdr(msg), &p); in nl_cache_parse_and_add()
960 int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_refill() argument
965 if (sk->s_proto != cache->c_ops->co_protocol) in nl_cache_refill()
968 nl_cache_clear(cache); in nl_cache_refill()
969 grp = cache->c_ops->co_groups; in nl_cache_refill()
972 (cache->c_flags & NL_CACHE_AF_ITER)) in nl_cache_refill()
973 nl_cache_set_arg1(cache, grp->ag_family); in nl_cache_refill()
976 err = nl_cache_request_full_dump(sk, cache); in nl_cache_refill()
981 cache, nl_cache_name(cache), grp ? grp->ag_family : AF_UNSPEC); in nl_cache_refill()
983 err = nl_cache_pickup(sk, cache); in nl_cache_refill()
993 (cache->c_flags & NL_CACHE_AF_ITER)); in nl_cache_refill()
1004 static struct nl_object *__cache_fast_lookup(struct nl_cache *cache, in __cache_fast_lookup() argument
1009 obj = nl_hash_table_lookup(cache->hashtable, needle); in __cache_fast_lookup()
1033 struct nl_object *nl_cache_search(struct nl_cache *cache, in nl_cache_search() argument
1038 if (cache->hashtable) in nl_cache_search()
1039 return __cache_fast_lookup(cache, needle); in nl_cache_search()
1041 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_search()
1068 struct nl_object *nl_cache_find(struct nl_cache *cache, in nl_cache_find() argument
1073 if (cache->c_ops == NULL) in nl_cache_find()
1077 && cache->hashtable) in nl_cache_find()
1078 return __cache_fast_lookup(cache, filter); in nl_cache_find()
1080 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_find()
1097 void nl_cache_mark_all(struct nl_cache *cache) in nl_cache_mark_all() argument
1102 cache, nl_cache_name(cache)); in nl_cache_mark_all()
1104 nl_list_for_each_entry(obj, &cache->c_items, ce_list) in nl_cache_mark_all()
1122 void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params) in nl_cache_dump() argument
1124 nl_cache_dump_filter(cache, params, NULL); in nl_cache_dump()
1136 void nl_cache_dump_filter(struct nl_cache *cache, in nl_cache_dump_filter() argument
1145 cache, nl_cache_name(cache), filter); in nl_cache_dump_filter()
1150 if (cache->c_ops == NULL) in nl_cache_dump_filter()
1153 ops = cache->c_ops->co_obj_ops; in nl_cache_dump_filter()
1160 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_dump_filter()
1185 void nl_cache_foreach(struct nl_cache *cache, in nl_cache_foreach() argument
1188 nl_cache_foreach_filter(cache, NULL, cb, arg); in nl_cache_foreach()
1202 void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, in nl_cache_foreach_filter() argument
1207 if (cache->c_ops == NULL) in nl_cache_foreach_filter()
1210 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) { in nl_cache_foreach_filter()