Caching

Modules

 Cache
 Manager
 

Helps keeping caches up to date.


Cache Operations Sets



struct nl_cache_ops__nl_cache_ops_lookup (const char *name)
void nl_cache_ops_get (struct nl_cache_ops *ops)
 Increment reference counter.
void nl_cache_ops_put (struct nl_cache_ops *ops)
 Decrement reference counter.
struct nl_cache_opsnl_cache_ops_lookup (const char *name)
 Lookup cache operations by name.
struct nl_cache_opsnl_cache_ops_lookup_safe (const char *name)
 Lookup cache operations by name.
struct nl_cache_opsnl_cache_ops_associate (int protocol, int msgtype)
 Associate protocol and message type to cache operations.
struct nl_cache_opsnl_cache_ops_associate_safe (int protocol, int msgtype)
 Associate protocol and message type to cache operations.
struct nl_msgtypenl_msgtype_lookup (struct nl_cache_ops *ops, int msgtype)
 Lookup message type cache association.
void nl_cache_ops_foreach (void(*cb)(struct nl_cache_ops *, void *), void *arg)
 Call a function for each registered cache operation.
int nl_cache_mngt_register (struct nl_cache_ops *ops)
 Register a set of cache operations.
int nl_cache_mngt_unregister (struct nl_cache_ops *ops)
 Unregister a set of cache operations.

Global Cache Provisioning/Requiring



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

Function Documentation

void nl_cache_ops_get ( struct nl_cache_ops ops  ) 
Parameters:
ops Cache operations

Definition at line 45 of file cache_mngt.c.

References nl_cache_ops::co_refcnt.

Referenced by nl_cache_ops_associate_safe(), and nl_cache_ops_lookup_safe().

00046 {
00047         ops->co_refcnt++;
00048 }

void nl_cache_ops_put ( struct nl_cache_ops ops  ) 
Parameters:
ops Cache operations

Definition at line 54 of file cache_mngt.c.

References nl_cache_ops::co_refcnt.

00055 {
00056         ops->co_refcnt--;
00057 }

struct nl_cache_ops* nl_cache_ops_lookup ( const char *  name  )  [read]
Parameters:
name name of the cache type
Attention:
This function is not safe, it does not increment the reference counter. Please use nl_cache_ops_lookup_safe().
Returns:
The cache operations or NULL if not found.

Definition at line 68 of file cache_mngt.c.

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

00069 {
00070         struct nl_cache_ops *ops;
00071 
00072         nl_read_lock(&cache_ops_lock);
00073         ops = __nl_cache_ops_lookup(name);
00074         nl_read_unlock(&cache_ops_lock);
00075 
00076         return ops;
00077 }

struct nl_cache_ops* nl_cache_ops_lookup_safe ( const char *  name  )  [read]
Parameters:
name name of the cache type
Note:
The reference counter of the returned cache operation is incremented and must be decremented after use with nl_cache_ops_put().
Returns:
The cache operations or NULL if not found.

Definition at line 88 of file cache_mngt.c.

References nl_cache_ops_get().

00089 {
00090         struct nl_cache_ops *ops;
00091 
00092         nl_write_lock(&cache_ops_lock);
00093         if ((ops = __nl_cache_ops_lookup(name)))
00094                 nl_cache_ops_get(ops);
00095         nl_write_unlock(&cache_ops_lock);
00096 
00097         return ops;
00098 }

struct nl_cache_ops* nl_cache_ops_associate ( int  protocol,
int  msgtype 
) [read]
Parameters:
protocol netlink protocol
msgtype netlink message type
Attention:
This function is not safe, it does not increment the reference counter. Please use nl_cache_ops_associate_safe().
See also:
nl_cache_ops_associate_safe()
Returns:
The cache operations or NULL if no match found.

Definition at line 129 of file cache_mngt.c.

Referenced by nl_msg_dump().

00130 {
00131         struct nl_cache_ops *ops;
00132 
00133         nl_read_lock(&cache_ops_lock);
00134         ops = __cache_ops_associate(protocol, msgtype);
00135         nl_read_unlock(&cache_ops_lock);
00136 
00137         return ops;
00138 }

struct nl_cache_ops* nl_cache_ops_associate_safe ( int  protocol,
int  msgtype 
) [read]
Parameters:
protocol netlink protocol
msgtype netlink message type

Searches the registered cache operations for a matching protocol and message type.

Note:
The reference counter of the returned cache operation is incremented and must be decremented after use with nl_cache_ops_put().
Returns:
The cache operations or NULL if no no match was found.

Definition at line 153 of file cache_mngt.c.

References nl_cache_ops_get().

00154 {
00155         struct nl_cache_ops *ops;
00156 
00157         nl_write_lock(&cache_ops_lock);
00158         if ((ops = __cache_ops_associate(protocol, msgtype)))
00159                 nl_cache_ops_get(ops);
00160         nl_write_unlock(&cache_ops_lock);
00161 
00162         return ops;
00163 }

struct nl_msgtype* nl_msgtype_lookup ( struct nl_cache_ops ops,
int  msgtype 
) [read]
Parameters:
ops cache operations
msgtype netlink message type

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

Attention:
The guranteed lifetime of the returned message type is bound to the lifetime of the underlying cache operations.
Returns:
A message type association or NULL.

Definition at line 178 of file cache_mngt.c.

References nl_msgtype::mt_id.

00179 {
00180         int i;
00181 
00182         for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
00183                 if (ops->co_msgtypes[i].mt_id == msgtype)
00184                         return &ops->co_msgtypes[i];
00185 
00186         return NULL;
00187 }

void nl_cache_ops_foreach ( void(*)(struct nl_cache_ops *, void *)  cb,
void *  arg 
)
Parameters:
cb Callback function to be called
arg User specific argument.

Definition at line 207 of file cache_mngt.c.

00208 {
00209         struct nl_cache_ops *ops;
00210 
00211         nl_read_lock(&cache_ops_lock);
00212         for (ops = cache_ops; ops; ops = ops->co_next)
00213                 cb(ops, arg);
00214         nl_read_unlock(&cache_ops_lock);
00215 }

int nl_cache_mngt_register ( struct nl_cache_ops ops  ) 
Parameters:
ops cache 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 226 of file cache_mngt.c.

References nl_cache_ops::co_refcnt.

Referenced by genl_register().

00227 {
00228         if (!ops->co_name)
00229                 return nl_error(EINVAL, "No cache name specified");
00230 
00231         if (!ops->co_obj_ops)
00232                 return nl_error(EINVAL, "No obj cache ops specified");
00233 
00234         nl_write_lock(&cache_ops_lock);
00235         if (__nl_cache_ops_lookup(ops->co_name)) {
00236                 nl_write_unlock(&cache_ops_lock);
00237                 return nl_error(EEXIST, "Cache operations already exist");
00238         }
00239 
00240         ops->co_refcnt = 0;
00241         ops->co_next = cache_ops;
00242         cache_ops = ops;
00243         nl_write_unlock(&cache_ops_lock);
00244 
00245         NL_DBG(1, "Registered cache operations %s\n", ops->co_name);
00246 
00247         return 0;
00248 }

int nl_cache_mngt_unregister ( struct nl_cache_ops ops  ) 
Parameters:
ops cache 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 261 of file cache_mngt.c.

References nl_cache_ops::co_refcnt.

Referenced by genl_unregister().

00262 {
00263         struct nl_cache_ops *t, **tp;
00264 
00265         nl_write_lock(&cache_ops_lock);
00266 
00267         if (ops->co_refcnt > 0) {
00268                 nl_write_unlock(&cache_ops_lock);
00269                 return nl_error(EBUSY, "Cache operations busy");
00270         }
00271 
00272         for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->co_next)
00273                 if (t == ops)
00274                         break;
00275 
00276         if (!t) {
00277                 nl_write_unlock(&cache_ops_lock);
00278                 return nl_error(ENOENT, "No such cache operations");
00279         }
00280 
00281         NL_DBG(1, "Unregistered cache operations %s\n", ops->co_name);
00282 
00283         *tp = t->co_next;
00284         nl_write_unlock(&cache_ops_lock);
00285 
00286         return 0;
00287 }

void nl_cache_mngt_provide ( struct nl_cache *  cache  ) 
Parameters:
cache cache 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 304 of file cache_mngt.c.

References nl_cache_get().

Referenced by nl_cache_mngr_add().

00305 {
00306         struct nl_cache_ops *ops;
00307 
00308         nl_write_lock(&cache_ops_lock);
00309 
00310         ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
00311         if (!ops)
00312                 BUG();
00313         else {
00314                 nl_cache_get(cache);
00315                 ops->co_major_cache = cache;
00316         }
00317 
00318         nl_write_unlock(&cache_ops_lock);
00319 }

void nl_cache_mngt_unprovide ( struct nl_cache *  cache  ) 
Parameters:
cache cache 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 329 of file cache_mngt.c.

References nl_cache_free().

00330 {
00331         struct nl_cache_ops *ops;
00332 
00333         nl_write_lock(&cache_ops_lock);
00334 
00335         ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
00336         if (!ops)
00337                 BUG();
00338         else if (ops->co_major_cache == cache) {
00339                 nl_cache_free(ops->co_major_cache);
00340                 ops->co_major_cache = NULL;
00341         }
00342 
00343         nl_write_unlock(&cache_ops_lock);
00344 }

struct nl_cache* nl_cache_mngt_require ( const char *  name  )  [read]
Parameters:
name name 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 356 of file cache_mngt.c.

References nl_cache_ops_lookup().

00357 {
00358         struct nl_cache_ops *ops;
00359 
00360         ops = nl_cache_ops_lookup(name);
00361         if (!ops || !ops->co_major_cache) {
00362                 fprintf(stderr, "Application BUG: Your application must "
00363                         "call nl_cache_mngt_provide() and\nprovide a valid "
00364                         "%s cache to be used for internal lookups.\nSee the "
00365                         " API documentation for more details.\n", name);
00366 
00367                 return NULL;
00368         }
00369         
00370         return ops->co_major_cache;
00371 }


Generated on 14 Oct 2014 for libnl by  doxygen 1.6.1