Lines Matching +full:cache +full:- +full:name
1 /* SPDX-License-Identifier: LGPL-2.1-only */
3 * lib/cache_mngt.c Cache Management
10 * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
18 * - @core_doc{core_cache, Caching System}
23 * ------
25 * #include <netlink/cache.h>
29 #include <netlink-private/netlink.h>
31 #include <netlink/cache.h>
38 * @name Cache Operations Sets
42 static struct nl_cache_ops *__nl_cache_ops_lookup(const char *name) in __nl_cache_ops_lookup() argument
46 for (ops = cache_ops; ops; ops = ops->co_next) in __nl_cache_ops_lookup()
47 if (!strcmp(ops->co_name, name)) in __nl_cache_ops_lookup()
55 * @arg ops Cache operations
59 ops->co_refcnt++; in nl_cache_ops_get()
64 * @arg ops Cache operations
68 ops->co_refcnt--; in nl_cache_ops_put()
72 * Lookup cache operations by name
73 * @arg name name of the cache type
78 * @return The cache operations or NULL if not found.
80 struct nl_cache_ops *nl_cache_ops_lookup(const char *name) in nl_cache_ops_lookup() argument
85 ops = __nl_cache_ops_lookup(name); in nl_cache_ops_lookup()
92 * Lookup cache operations by name
93 * @arg name name of the cache type
95 * @note The reference counter of the returned cache operation is incremented
98 * @return The cache operations or NULL if not found.
100 struct nl_cache_ops *nl_cache_ops_lookup_safe(const char *name) in nl_cache_ops_lookup_safe() argument
105 if ((ops = __nl_cache_ops_lookup(name))) in nl_cache_ops_lookup_safe()
117 for (ops = cache_ops; ops; ops = ops->co_next) { in __cache_ops_associate()
118 if (ops->co_protocol != protocol) in __cache_ops_associate()
121 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) in __cache_ops_associate()
122 if (ops->co_msgtypes[i].mt_id == msgtype) in __cache_ops_associate()
130 * Associate protocol and message type to cache operations
139 * @return The cache operations or NULL if no match found.
153 * Associate protocol and message type to cache operations
157 * Searches the registered cache operations for a matching protocol
160 * @note The reference counter of the returned cache operation is incremented
163 * @return The cache operations or NULL if no no match was found.
178 * Lookup message type cache association
179 * @arg ops cache operations
183 * cache operations.
186 * to the lifetime of the underlying cache operations.
194 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) in nl_msgtype_lookup()
195 if (ops->co_msgtypes[i].mt_id == msgtype) in nl_msgtype_lookup()
196 return &ops->co_msgtypes[i]; in nl_msgtype_lookup()
206 for (ops = cache_ops; ops; ops = ops->co_next) in cache_ops_lookup_for_obj()
207 if (ops->co_obj_ops == obj_ops) in cache_ops_lookup_for_obj()
215 * Call a function for each registered cache operation
224 for (ops = cache_ops; ops; ops = ops->co_next) in nl_cache_ops_foreach()
231 * @arg ops Cache ops
234 * The cache operation flags will be derived to all caches allocates
235 * based on this set of cache operations.
240 ops->co_flags |= flags; in nl_cache_ops_set_flags()
245 * Register a set of cache operations
246 * @arg ops cache operations
249 * a certain cache type.
255 if (!ops->co_name || !ops->co_obj_ops) in nl_cache_mngt_register()
256 return -NLE_INVAL; in nl_cache_mngt_register()
259 BUG_ON (ops->co_obj_ops->oo_keygen && !ops->co_obj_ops->oo_compare); in nl_cache_mngt_register()
262 if (__nl_cache_ops_lookup(ops->co_name)) { in nl_cache_mngt_register()
264 return -NLE_EXIST; in nl_cache_mngt_register()
267 ops->co_refcnt = 0; in nl_cache_mngt_register()
268 ops->co_next = cache_ops; in nl_cache_mngt_register()
272 NL_DBG(1, "Registered cache operations %s\n", ops->co_name); in nl_cache_mngt_register()
278 * Unregister a set of cache operations
279 * @arg ops cache operations
282 * cache operations is no longer available. The
283 * specified cache operations must have been registered
295 if (ops->co_refcnt > 0) { in nl_cache_mngt_unregister()
296 err = -NLE_BUSY; in nl_cache_mngt_unregister()
300 for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->co_next) in nl_cache_mngt_unregister()
305 err = -NLE_NOCACHE; in nl_cache_mngt_unregister()
309 NL_DBG(1, "Unregistered cache operations %s\n", ops->co_name); in nl_cache_mngt_unregister()
311 *tp = t->co_next; in nl_cache_mngt_unregister()
321 * @name Global Cache Provisioning/Requiring
326 * Provide a cache for global use
327 * @arg cache cache to provide
329 * Offers the specified cache to be used by other modules.
330 * Only one cache per type may be shared at a time,
333 void nl_cache_mngt_provide(struct nl_cache *cache) in nl_cache_mngt_provide() argument
339 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops); in nl_cache_mngt_provide()
343 nl_cache_get(cache); in nl_cache_mngt_provide()
346 * Hold a reference to the cache operations to ensure the in nl_cache_mngt_provide()
347 * ops don't go away while we use it to store the cache pointer. in nl_cache_mngt_provide()
349 if (!ops->co_major_cache) in nl_cache_mngt_provide()
352 ops->co_major_cache = cache; in nl_cache_mngt_provide()
359 * Unprovide a cache for global use
360 * @arg cache cache to unprovide
362 * Cancels the offer to use a cache globally. The
363 * cache will no longer be returned via lookups but
366 void nl_cache_mngt_unprovide(struct nl_cache *cache) in nl_cache_mngt_unprovide() argument
372 ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops); in nl_cache_mngt_unprovide()
375 else if (ops->co_major_cache == cache) { in nl_cache_mngt_unprovide()
376 nl_cache_free(ops->co_major_cache); in nl_cache_mngt_unprovide()
378 ops->co_major_cache = NULL; in nl_cache_mngt_unprovide()
384 struct nl_cache *__nl_cache_mngt_require(const char *name) in __nl_cache_mngt_require() argument
387 struct nl_cache *cache = NULL; in __nl_cache_mngt_require() local
389 ops = nl_cache_ops_lookup_safe(name); in __nl_cache_mngt_require()
391 cache = ops->co_major_cache; in __nl_cache_mngt_require()
395 return cache; in __nl_cache_mngt_require()
399 * Return cache previously provided via nl_cache_mngt_provide()
400 * @arg name Name of cache to lookup
407 * @return Pointer to cache or NULL if none registered
409 struct nl_cache *nl_cache_mngt_require(const char *name) in nl_cache_mngt_require() argument
411 struct nl_cache *cache; in nl_cache_mngt_require() local
413 if (!(cache = __nl_cache_mngt_require(name))) in nl_cache_mngt_require()
416 "%s cache to be used for internal lookups.\nSee the " in nl_cache_mngt_require()
417 " API documentation for more details.\n", name); in nl_cache_mngt_require()
419 return cache; in nl_cache_mngt_require()
423 * Return cache previously provided via nl_cache_mngt_provide()
424 * @arg name Name of cache to lookup
426 * @note The reference counter of the returned cache is incremented
429 * @return Pointer to cache or NULL if none registered
431 struct nl_cache *nl_cache_mngt_require_safe(const char *name) in nl_cache_mngt_require_safe() argument
433 struct nl_cache *cache; in nl_cache_mngt_require_safe() local
435 if ((cache = nl_cache_mngt_require(name))) in nl_cache_mngt_require_safe()
436 nl_cache_get(cache); in nl_cache_mngt_require_safe()
438 return cache; in nl_cache_mngt_require_safe()