• Home
  • Raw
  • Download

Lines Matching +full:cache +full:- +full:name

1 /* SPDX-License-Identifier: LGPL-2.1-only */
3 * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
11 * - @core_doc{core_cache, Caching System}
16 * ------
18 * #include <netlink/cache.h>
22 #include "nl-default.h"
25 #include <netlink/cache.h>
28 #include "nl-priv-dynamic-core/nl-core.h"
29 #include "nl-priv-dynamic-core/object-api.h"
30 #include "nl-priv-dynamic-core/cache-api.h"
31 #include "nl-aux-core/nl-core.h"
37 * @name Cache Operations Sets
41 static struct nl_cache_ops *__nl_cache_ops_lookup(const char *name) in __nl_cache_ops_lookup() argument
45 for (ops = cache_ops; ops; ops = ops->co_next) in __nl_cache_ops_lookup()
46 if (!strcmp(ops->co_name, name)) in __nl_cache_ops_lookup()
54 * @arg ops Cache operations
58 ops->co_refcnt++; in nl_cache_ops_get()
63 * @arg ops Cache operations
67 ops->co_refcnt--; in nl_cache_ops_put()
71 * Lookup cache operations by name
72 * @arg name name of the cache type
77 * @return The cache operations or NULL if not found.
79 struct nl_cache_ops *nl_cache_ops_lookup(const char *name) in nl_cache_ops_lookup() argument
84 ops = __nl_cache_ops_lookup(name); in nl_cache_ops_lookup()
91 * Lookup cache operations by name
92 * @arg name name of the cache type
94 * @note The reference counter of the returned cache operation is incremented
97 * @return The cache operations or NULL if not found.
99 struct nl_cache_ops *nl_cache_ops_lookup_safe(const char *name) in nl_cache_ops_lookup_safe() argument
104 if ((ops = __nl_cache_ops_lookup(name))) in nl_cache_ops_lookup_safe()
116 for (ops = cache_ops; ops; ops = ops->co_next) { in __cache_ops_associate()
117 if (ops->co_protocol != protocol) in __cache_ops_associate()
120 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) in __cache_ops_associate()
121 if (ops->co_msgtypes[i].mt_id == msgtype) in __cache_ops_associate()
129 * Associate protocol and message type to cache operations
138 * @return The cache operations or NULL if no match found.
152 * Associate protocol and message type to cache operations
156 * Searches the registered cache operations for a matching protocol
159 * @note The reference counter of the returned cache operation is incremented
162 * @return The cache operations or NULL if no no match was found.
177 * Lookup message type cache association
178 * @arg ops cache operations
182 * cache operations.
185 * to the lifetime of the underlying cache operations.
193 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) in nl_msgtype_lookup()
194 if (ops->co_msgtypes[i].mt_id == msgtype) in nl_msgtype_lookup()
195 return &ops->co_msgtypes[i]; in nl_msgtype_lookup()
205 for (ops = cache_ops; ops; ops = ops->co_next) in cache_ops_lookup_for_obj()
206 if (ops->co_obj_ops == obj_ops) in cache_ops_lookup_for_obj()
214 * Call a function for each registered cache operation
223 for (ops = cache_ops; ops; ops = ops->co_next) in nl_cache_ops_foreach()
230 * @arg ops Cache ops
233 * The cache operation flags will be derived to all caches allocates
234 * based on this set of cache operations.
239 ops->co_flags |= flags; in nl_cache_ops_set_flags()
244 * Register a set of cache operations
245 * @arg ops cache operations
248 * a certain cache type.
254 if (!ops->co_name || !ops->co_obj_ops) in nl_cache_mngt_register()
255 return -NLE_INVAL; in nl_cache_mngt_register()
258 BUG_ON (ops->co_obj_ops->oo_keygen && !ops->co_obj_ops->oo_compare); in nl_cache_mngt_register()
261 if (__nl_cache_ops_lookup(ops->co_name)) { in nl_cache_mngt_register()
263 return -NLE_EXIST; in nl_cache_mngt_register()
266 ops->co_refcnt = 0; in nl_cache_mngt_register()
267 ops->co_next = cache_ops; in nl_cache_mngt_register()
271 NL_DBG(1, "Registered cache operations %s\n", ops->co_name); in nl_cache_mngt_register()
277 * Unregister a set of cache operations
278 * @arg ops cache operations
281 * cache operations is no longer available. The
282 * specified cache operations must have been registered
294 if (ops->co_refcnt > 0) { in nl_cache_mngt_unregister()
295 err = -NLE_BUSY; in nl_cache_mngt_unregister()
299 for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->co_next) in nl_cache_mngt_unregister()
304 err = -NLE_NOCACHE; in nl_cache_mngt_unregister()
308 NL_DBG(1, "Unregistered cache operations %s\n", ops->co_name); in nl_cache_mngt_unregister()
310 *tp = t->co_next; in nl_cache_mngt_unregister()
320 * @name Global Cache Provisioning/Requiring
325 * Provide a cache for global use
326 * @arg cache cache to provide
328 * Offers the specified cache to be used by other modules.
329 * Only one cache per type may be shared at a time,
332 void nl_cache_mngt_provide(struct nl_cache *cache) in nl_cache_mngt_provide() argument
338 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops); in nl_cache_mngt_provide()
342 nl_cache_get(cache); in nl_cache_mngt_provide()
345 * Hold a reference to the cache operations to ensure the in nl_cache_mngt_provide()
346 * ops don't go away while we use it to store the cache pointer. in nl_cache_mngt_provide()
348 if (!ops->co_major_cache) in nl_cache_mngt_provide()
351 ops->co_major_cache = cache; in nl_cache_mngt_provide()
358 * Unprovide a cache for global use
359 * @arg cache cache to unprovide
361 * Cancels the offer to use a cache globally. The
362 * cache will no longer be returned via lookups but
365 void nl_cache_mngt_unprovide(struct nl_cache *cache) in nl_cache_mngt_unprovide() argument
371 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops); in nl_cache_mngt_unprovide()
374 else if (ops->co_major_cache == cache) { in nl_cache_mngt_unprovide()
375 nl_cache_free(ops->co_major_cache); in nl_cache_mngt_unprovide()
377 ops->co_major_cache = NULL; in nl_cache_mngt_unprovide()
383 struct nl_cache *__nl_cache_mngt_require(const char *name) in __nl_cache_mngt_require() argument
386 struct nl_cache *cache = NULL; in __nl_cache_mngt_require() local
388 ops = nl_cache_ops_lookup_safe(name); in __nl_cache_mngt_require()
390 cache = ops->co_major_cache; in __nl_cache_mngt_require()
394 return cache; in __nl_cache_mngt_require()
398 * Return cache previously provided via nl_cache_mngt_provide()
399 * @arg name Name of cache to lookup
406 * @return Pointer to cache or NULL if none registered
408 struct nl_cache *nl_cache_mngt_require(const char *name) in nl_cache_mngt_require() argument
410 struct nl_cache *cache; in nl_cache_mngt_require() local
412 if (!(cache = __nl_cache_mngt_require(name))) in nl_cache_mngt_require()
415 "%s cache to be used for internal lookups.\nSee the " in nl_cache_mngt_require()
416 " API documentation for more details.\n", name); in nl_cache_mngt_require()
418 return cache; in nl_cache_mngt_require()
422 * Return cache previously provided via nl_cache_mngt_provide()
423 * @arg name Name of cache to lookup
425 * @note The reference counter of the returned cache is incremented
428 * @return Pointer to cache or NULL if none registered
430 struct nl_cache *nl_cache_mngt_require_safe(const char *name) in nl_cache_mngt_require_safe() argument
432 struct nl_cache *cache; in nl_cache_mngt_require_safe() local
434 if ((cache = nl_cache_mngt_require(name))) in nl_cache_mngt_require_safe()
435 nl_cache_get(cache); in nl_cache_mngt_require_safe()
437 return cache; in nl_cache_mngt_require_safe()