libnl  1.1
Modules
Caching

Modules

 Cache
 
 Manager
 Helps keeping caches up to date.
 

Cache Operations Sets

struct nl_cache_opsnl_cache_ops_lookup (const char *name)
 Lookup the set cache operations of a certain cache type. More...
 
struct nl_cache_opsnl_cache_ops_associate (int protocol, int msgtype)
 Associate a message type to a set of cache operations. More...
 
struct nl_msgtypenl_msgtype_lookup (struct nl_cache_ops *ops, int msgtype)
 Lookup message type cache association. More...
 
void nl_cache_ops_foreach (void(*cb)(struct nl_cache_ops *, void *), void *arg)
 Call a function for each registered cache operation. More...
 
int nl_cache_mngt_register (struct nl_cache_ops *ops)
 Register a set of cache operations. More...
 
int nl_cache_mngt_unregister (struct nl_cache_ops *ops)
 Unregister a set of cache operations. More...
 

Global Cache Provisioning/Requiring

void nl_cache_mngt_provide (struct nl_cache *cache)
 Provide a cache for global use. More...
 
void nl_cache_mngt_unprovide (struct nl_cache *cache)
 Unprovide a cache for global use. More...
 
struct nl_cache * nl_cache_mngt_require (const char *name)
 Demand the use of a global cache. More...
 

Detailed Description

Function Documentation

struct nl_cache_ops* nl_cache_ops_lookup ( const char *  name)
Parameters
namename of the cache type
Returns
The cache operations or NULL if no operations have been registered under the specified name.

Definition at line 36 of file cache_mngt.c.

Referenced by nl_cache_alloc_name(), nl_cache_mngr_add(), nl_cache_mngt_register(), nl_cache_mngt_require(), and nl_object_alloc_name().

37 {
38  struct nl_cache_ops *ops;
39 
40  for (ops = cache_ops; ops; ops = ops->co_next)
41  if (!strcmp(ops->co_name, name))
42  return ops;
43 
44  return NULL;
45 }
struct nl_cache_ops* nl_cache_ops_associate ( int  protocol,
int  msgtype 
)
Parameters
protocolnetlink protocol
msgtypenetlink message type

Associates the specified netlink message type with a registered set of cache operations.

Returns
The cache operations or NULL if no association could be made.

Definition at line 58 of file cache_mngt.c.

References nl_msgtype::mt_id.

Referenced by nl_msg_dump().

59 {
60  int i;
61  struct nl_cache_ops *ops;
62 
63  for (ops = cache_ops; ops; ops = ops->co_next)
64  for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
65  if (ops->co_msgtypes[i].mt_id == msgtype &&
66  ops->co_protocol == protocol)
67  return ops;
68 
69  return NULL;
70 }
struct nl_msgtype* nl_msgtype_lookup ( struct nl_cache_ops ops,
int  msgtype 
)
Parameters
opscache operations
msgtypenetlink message type

Searches for a matching message type association ing the specified cache operations.

Returns
A message type association or NULL.

Definition at line 82 of file cache_mngt.c.

References nl_msgtype::mt_id.

83 {
84  int i;
85 
86  for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
87  if (ops->co_msgtypes[i].mt_id == msgtype)
88  return &ops->co_msgtypes[i];
89 
90  return NULL;
91 }
void nl_cache_ops_foreach ( void(*)(struct nl_cache_ops *, void *)  cb,
void *  arg 
)
Parameters
cbCallback function to be called
argUser specific argument.

Definition at line 110 of file cache_mngt.c.

111 {
112  struct nl_cache_ops *ops;
113 
114  for (ops = cache_ops; ops; ops = ops->co_next)
115  cb(ops, arg);
116 }
int nl_cache_mngt_register ( struct nl_cache_ops ops)
Parameters
opscache operations

Called by users of caches to announce the avaibility of a certain cache type.

Returns
0 on success or a negative error code.

Definition at line 127 of file cache_mngt.c.

References nl_cache_ops_lookup().

Referenced by genl_register().

128 {
129  if (!ops->co_name)
130  return nl_error(EINVAL, "No cache name specified");
131 
132  if (!ops->co_obj_ops)
133  return nl_error(EINVAL, "No obj cache ops specified");
134 
135  if (nl_cache_ops_lookup(ops->co_name))
136  return nl_error(EEXIST, "Cache operations already exist");
137 
138  ops->co_next = cache_ops;
139  cache_ops = ops;
140 
141  NL_DBG(1, "Registered cache operations %s\n", ops->co_name);
142 
143  return 0;
144 }
int nl_cache_mngt_unregister ( struct nl_cache_ops ops)
Parameters
opscache operations

Called by users of caches to announce a set of cache operations is no longer available. The specified cache operations must have been registered previously using nl_cache_mngt_register()

Returns
0 on success or a negative error code

Definition at line 157 of file cache_mngt.c.

Referenced by genl_unregister().

158 {
159  struct nl_cache_ops *t, **tp;
160 
161  for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->co_next)
162  if (t == ops)
163  break;
164 
165  if (!t)
166  return nl_error(ENOENT, "No such cache operations");
167 
168  NL_DBG(1, "Unregistered cache operations %s\n", ops->co_name);
169 
170  *tp = t->co_next;
171  return 0;
172 }
void nl_cache_mngt_provide ( struct nl_cache *  cache)
Parameters
cachecache to provide

Offers the specified cache to be used by other modules. Only one cache per type may be shared at a time, a previsouly provided caches will be overwritten.

Definition at line 189 of file cache_mngt.c.

Referenced by nl_cache_mngr_add().

190 {
191  struct nl_cache_ops *ops;
192 
193  ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
194  if (!ops)
195  BUG();
196  else
197  ops->co_major_cache = cache;
198 }
void nl_cache_mngt_unprovide ( struct nl_cache *  cache)
Parameters
cachecache to unprovide

Cancels the offer to use a cache globally. The cache will no longer be returned via lookups but may still be in use.

Definition at line 208 of file cache_mngt.c.

209 {
210  struct nl_cache_ops *ops;
211 
212  ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
213  if (!ops)
214  BUG();
215  else if (ops->co_major_cache == cache)
216  ops->co_major_cache = NULL;
217 }
struct nl_cache* nl_cache_mngt_require ( const char *  name)
Parameters
namename of the required object type

Trys to find a cache of the specified type for global use.

Returns
A cache provided by another subsystem of the specified type marked to be available.

Definition at line 229 of file cache_mngt.c.

References nl_cache_ops_lookup().

230 {
231  struct nl_cache_ops *ops;
232 
233  ops = nl_cache_ops_lookup(name);
234  if (!ops || !ops->co_major_cache) {
235  fprintf(stderr, "Application BUG: Your application must "
236  "call nl_cache_mngt_provide() and\nprovide a valid "
237  "%s cache to be used for internal lookups.\nSee the "
238  " API documentation for more details.\n", name);
239 
240  return NULL;
241  }
242 
243  return ops->co_major_cache;
244 }