Lines Matching refs:cache

2  * lib/cache.c		Caching Module
14 * @defgroup cache Cache
26 * 2) destroy old cache +----------- pp_cb ---------|---+
45 #include <netlink/cache.h>
55 * Allocate an empty cache
56 * @arg ops cache operations to base the cache on
58 * @return A newly allocated and initialized cache.
62 struct nl_cache *cache;
64 cache = calloc(1, sizeof(*cache));
65 if (!cache)
68 nl_init_list_head(&cache->c_items);
69 cache->c_ops = ops;
71 NL_DBG(2, "Allocated cache %p <%s>.\n", cache, nl_cache_name(cache));
73 return cache;
79 struct nl_cache *cache;
82 if (!(cache = nl_cache_alloc(ops)))
85 if (sock && (err = nl_cache_refill(sock, cache)) < 0) {
86 nl_cache_free(cache);
90 *result = cache;
95 * Clear a cache.
96 * @arg cache cache to clear
98 * Removes all elements of a cache.
100 void nl_cache_clear(struct nl_cache *cache)
104 NL_DBG(1, "Clearing cache %p <%s>...\n", cache, nl_cache_name(cache));
106 nl_list_for_each_entry_safe(obj, tmp, &cache->c_items, ce_list)
111 * Free a cache.
112 * @arg cache Cache to free.
114 * Removes all elements of a cache and frees all memory.
118 void nl_cache_free(struct nl_cache *cache)
120 if (!cache)
123 nl_cache_clear(cache);
124 NL_DBG(1, "Freeing cache %p <%s>...\n", cache, nl_cache_name(cache));
125 free(cache);
135 static int __cache_add(struct nl_cache *cache, struct nl_object *obj)
137 obj->ce_cache = cache;
139 nl_list_add_tail(&obj->ce_list, &cache->c_items);
140 cache->c_nitems++;
142 NL_DBG(1, "Added %p to cache %p <%s>.\n",
143 obj, cache, nl_cache_name(cache));
149 * Add object to a cache.
150 * @arg cache Cache to add object to
151 * @arg obj Object to be added to the cache
153 * Adds the given object to the specified cache. The object is cloned
154 * if it has been added to another cache already.
158 int nl_cache_add(struct nl_cache *cache, struct nl_object *obj)
162 if (cache->c_ops->co_obj_ops != obj->ce_ops)
174 return __cache_add(cache, new);
178 * Removes an object from a cache.
179 * @arg obj Object to remove from its cache
181 * Removes the object \c obj from the cache it is assigned to, since
182 * an object can only be assigned to one cache at a time, the cache
187 struct nl_cache *cache = obj->ce_cache;
189 if (cache == NULL)
195 cache->c_nitems--;
197 NL_DBG(1, "Deleted %p from cache %p <%s>.\n",
198 obj, cache, nl_cache_name(cache));
209 * Request a full dump from the kernel to fill a cache
211 * @arg cache Cache subjected to be filled.
214 * related to the specified cache to the netlink socket.
217 * into a cache.
219 int nl_cache_request_full_dump(struct nl_sock *sk, struct nl_cache *cache)
221 NL_DBG(2, "Requesting dump from kernel for cache %p <%s>...\n",
222 cache, nl_cache_name(cache));
224 if (cache->c_ops->co_request_update == NULL)
227 return cache->c_ops->co_request_update(cache, sk);
244 int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
250 .ops = cache->c_ops,
254 NL_DBG(1, "Picking up answer for cache %p <%s>...\n",
255 cache, nl_cache_name(cache));
266 "%d: %s", cache, nl_cache_name(cache),
280 * Pickup a netlink dump response and put it into a cache.
282 * @arg cache Cache to put items into.
285 * the specified cache.
289 int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache)
293 .pp_arg = cache,
296 return __cache_pickup(sk, cache, &p);
332 * Parse a netlink message and add it to the cache.
333 * @arg cache cache to add element to
336 * Parses a netlink message by calling the cache specific message parser
337 * and adds the new element to the cache.
341 int nl_cache_parse_and_add(struct nl_cache *cache, struct nl_msg *msg)
345 .pp_arg = cache,
348 return nl_cache_parse(cache->c_ops, NULL, nlmsg_hdr(msg), &p);
352 * (Re)fill a cache with the contents in the kernel.
354 * @arg cache cache to update
356 * Clears the specified cache and fills it with the current state in
361 int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
365 err = nl_cache_request_full_dump(sk, cache);
369 NL_DBG(2, "Upading cache %p <%s>, request sent, waiting for dump...\n",
370 cache, nl_cache_name(cache));
371 nl_cache_clear(cache);
373 return nl_cache_pickup(sk, cache);