Lines Matching refs:cache

58 int nl_cache_nitems(struct nl_cache *cache)  in nl_cache_nitems()  argument
60 return cache->c_nitems; in nl_cache_nitems()
68 int nl_cache_nitems_filter(struct nl_cache *cache, struct nl_object *filter) in nl_cache_nitems_filter() argument
74 if (cache->c_ops == NULL) in nl_cache_nitems_filter()
77 ops = cache->c_ops->co_obj_ops; in nl_cache_nitems_filter()
79 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_nitems_filter()
94 int nl_cache_is_empty(struct nl_cache *cache) in nl_cache_is_empty() argument
96 return nl_list_empty(&cache->c_items); in nl_cache_is_empty()
103 struct nl_cache_ops *nl_cache_get_ops(struct nl_cache *cache) in nl_cache_get_ops() argument
105 return cache->c_ops; in nl_cache_get_ops()
112 struct nl_object *nl_cache_get_first(struct nl_cache *cache) in nl_cache_get_first() argument
114 if (nl_list_empty(&cache->c_items)) in nl_cache_get_first()
117 return nl_list_entry(cache->c_items.next, in nl_cache_get_first()
125 struct nl_object *nl_cache_get_last(struct nl_cache *cache) in nl_cache_get_last() argument
127 if (nl_list_empty(&cache->c_items)) in nl_cache_get_last()
130 return nl_list_entry(cache->c_items.prev, in nl_cache_get_last()
175 struct nl_cache *cache; in nl_cache_alloc() local
177 cache = calloc(1, sizeof(*cache)); in nl_cache_alloc()
178 if (!cache) in nl_cache_alloc()
181 nl_init_list_head(&cache->c_items); in nl_cache_alloc()
182 cache->c_ops = ops; in nl_cache_alloc()
184 NL_DBG(2, "Allocated cache %p <%s>.\n", cache, nl_cache_name(cache)); in nl_cache_alloc()
186 return cache; in nl_cache_alloc()
192 struct nl_cache *cache; in nl_cache_alloc_and_fill() local
195 if (!(cache = nl_cache_alloc(ops))) in nl_cache_alloc_and_fill()
198 if (sock && (err = nl_cache_refill(sock, cache)) < 0) { in nl_cache_alloc_and_fill()
199 nl_cache_free(cache); in nl_cache_alloc_and_fill()
203 *result = cache; in nl_cache_alloc_and_fill()
215 struct nl_cache *cache; in nl_cache_alloc_name() local
221 if (!(cache = nl_cache_alloc(ops))) in nl_cache_alloc_name()
224 *result = cache; in nl_cache_alloc_name()
237 struct nl_cache *cache; in nl_cache_subset() local
244 cache = nl_cache_alloc(orig->c_ops); in nl_cache_subset()
245 if (!cache) in nl_cache_subset()
254 nl_cache_add(cache, obj); in nl_cache_subset()
257 return cache; in nl_cache_subset()
266 void nl_cache_clear(struct nl_cache *cache) in nl_cache_clear() argument
270 NL_DBG(1, "Clearing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_clear()
272 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) in nl_cache_clear()
284 void nl_cache_free(struct nl_cache *cache) in nl_cache_free() argument
286 if (!cache) in nl_cache_free()
289 nl_cache_clear(cache); in nl_cache_free()
290 NL_DBG(1, "Freeing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_free()
291 free(cache); in nl_cache_free()
301 static int __cache_add(struct nl_cache *cache, struct nl_object *obj) in __cache_add() argument
303 obj->ce_cache = cache; in __cache_add()
305 nl_list_add_tail(&obj->ce_list, &cache->c_items); in __cache_add()
306 cache->c_nitems++; in __cache_add()
309 obj, cache, nl_cache_name(cache)); in __cache_add()
324 int nl_cache_add(struct nl_cache *cache, struct nl_object *obj) in nl_cache_add() argument
328 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_add()
340 return __cache_add(cache, new); in nl_cache_add()
353 int nl_cache_move(struct nl_cache *cache, struct nl_object *obj) in nl_cache_move() argument
355 if (cache->c_ops->co_obj_ops != obj->ce_ops) in nl_cache_move()
358 NL_DBG(3, "Moving object %p to cache %p\n", obj, cache); in nl_cache_move()
367 return __cache_add(cache, obj); in nl_cache_move()
380 struct nl_cache *cache = obj->ce_cache; in nl_cache_remove() local
382 if (cache == NULL) in nl_cache_remove()
388 cache->c_nitems--; in nl_cache_remove()
391 obj, cache, nl_cache_name(cache)); in nl_cache_remove()
405 struct nl_object *nl_cache_search(struct nl_cache *cache, in nl_cache_search() argument
410 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_search()
439 int nl_cache_request_full_dump(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_request_full_dump() argument
442 cache, nl_cache_name(cache)); in nl_cache_request_full_dump()
444 if (cache->c_ops->co_request_update == NULL) in nl_cache_request_full_dump()
447 return cache->c_ops->co_request_update(cache, sk); in nl_cache_request_full_dump()
464 int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache, in __cache_pickup() argument
470 .ops = cache->c_ops, in __cache_pickup()
475 cache, nl_cache_name(cache)); in __cache_pickup()
486 "%d: %s", cache, nl_cache_name(cache), in __cache_pickup()
509 int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_pickup() argument
513 .pp_arg = cache, in nl_cache_pickup()
516 return __cache_pickup(sk, cache, &p); in nl_cache_pickup()
519 static int cache_include(struct nl_cache *cache, struct nl_object *obj, in cache_include() argument
527 old = nl_cache_search(cache, obj); in cache_include()
532 cb(cache, old, NL_ACT_DEL, data); in cache_include()
538 nl_cache_move(cache, obj); in cache_include()
540 cb(cache, obj, NL_ACT_NEW, data); in cache_include()
543 cb(cache, obj, NL_ACT_CHANGE, data); in cache_include()
557 int nl_cache_include(struct nl_cache *cache, struct nl_object *obj, in nl_cache_include() argument
560 struct nl_cache_ops *ops = cache->c_ops; in nl_cache_include()
568 return cache_include(cache, obj, &ops->co_msgtypes[i], in nl_cache_include()
581 int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache, in nl_cache_resync() argument
586 .ca_cache = cache, in nl_cache_resync()
596 NL_DBG(1, "Resyncing cache %p <%s>...\n", cache, nl_cache_name(cache)); in nl_cache_resync()
599 nl_cache_mark_all(cache); in nl_cache_resync()
601 err = nl_cache_request_full_dump(sk, cache); in nl_cache_resync()
605 err = __cache_pickup(sk, cache, &p); in nl_cache_resync()
609 nl_list_for_each_entry_safe(obj, next, &cache->c_items, ce_list) { in nl_cache_resync()
614 change_cb(cache, obj, NL_ACT_DEL, data); in nl_cache_resync()
619 NL_DBG(1, "Finished resyncing %p <%s>\n", cache, nl_cache_name(cache)); in nl_cache_resync()
667 int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg) in nl_cache_parse_and_add() argument
671 .pp_arg = cache, in nl_cache_parse_and_add()
674 return nl_cache_parse(cache->c_ops, NULL, nlmsg_hdr(msg), &p); in nl_cache_parse_and_add()
687 int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache) in nl_cache_refill() argument
691 err = nl_cache_request_full_dump(sk, cache); in nl_cache_refill()
696 cache, nl_cache_name(cache)); in nl_cache_refill()
697 nl_cache_clear(cache); in nl_cache_refill()
699 return nl_cache_pickup(sk, cache); in nl_cache_refill()
713 void nl_cache_mark_all(struct nl_cache *cache) in nl_cache_mark_all() argument
718 cache, nl_cache_name(cache)); in nl_cache_mark_all()
720 nl_list_for_each_entry(obj, &cache->c_items, ce_list) in nl_cache_mark_all()
738 void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params) in nl_cache_dump() argument
740 nl_cache_dump_filter(cache, params, NULL); in nl_cache_dump()
752 void nl_cache_dump_filter(struct nl_cache *cache, in nl_cache_dump_filter() argument
761 cache, nl_cache_name(cache), filter); in nl_cache_dump_filter()
766 if (cache->c_ops == NULL) in nl_cache_dump_filter()
769 ops = cache->c_ops->co_obj_ops; in nl_cache_dump_filter()
773 nl_list_for_each_entry(obj, &cache->c_items, ce_list) { in nl_cache_dump_filter()
798 void nl_cache_foreach(struct nl_cache *cache, in nl_cache_foreach() argument
801 nl_cache_foreach_filter(cache, NULL, cb, arg); in nl_cache_foreach()
815 void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, in nl_cache_foreach_filter() argument
821 if (cache->c_ops == NULL) in nl_cache_foreach_filter()
824 ops = cache->c_ops->co_obj_ops; in nl_cache_foreach_filter()
826 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list) { in nl_cache_foreach_filter()