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.
struct nl_cache_opsnl_cache_ops_associate (int protocol, int msgtype)
 Associate a message type to a set of 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

struct nl_cache_ops* nl_cache_ops_lookup ( const char *  name  )  [read]
Parameters:
name name 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().

00037 {
00038         struct nl_cache_ops *ops;
00039 
00040         for (ops = cache_ops; ops; ops = ops->co_next)
00041                 if (!strcmp(ops->co_name, name))
00042                         return ops;
00043 
00044         return NULL;
00045 }

struct nl_cache_ops* nl_cache_ops_associate ( int  protocol,
int  msgtype 
) [read]
Parameters:
protocol netlink protocol
msgtype netlink 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().

00059 {
00060         int i;
00061         struct nl_cache_ops *ops;
00062 
00063         for (ops = cache_ops; ops; ops = ops->co_next)
00064                 for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
00065                         if (ops->co_msgtypes[i].mt_id == msgtype &&
00066                             ops->co_protocol == protocol)
00067                                 return ops;
00068 
00069         return NULL;
00070 }

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.

Returns:
A message type association or NULL.

Definition at line 82 of file cache_mngt.c.

References nl_msgtype::mt_id.

00083 {
00084         int i;
00085 
00086         for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
00087                 if (ops->co_msgtypes[i].mt_id == msgtype)
00088                         return &ops->co_msgtypes[i];
00089 
00090         return NULL;
00091 }

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 110 of file cache_mngt.c.

00111 {
00112         struct nl_cache_ops *ops;
00113 
00114         for (ops = cache_ops; ops; ops = ops->co_next)
00115                 cb(ops, arg);
00116 }

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 127 of file cache_mngt.c.

References nl_cache_ops_lookup().

Referenced by genl_register().

00128 {
00129         if (!ops->co_name)
00130                 return nl_error(EINVAL, "No cache name specified");
00131 
00132         if (!ops->co_obj_ops)
00133                 return nl_error(EINVAL, "No obj cache ops specified");
00134 
00135         if (nl_cache_ops_lookup(ops->co_name))
00136                 return nl_error(EEXIST, "Cache operations already exist");
00137             
00138         ops->co_next = cache_ops;
00139         cache_ops = ops;
00140 
00141         NL_DBG(1, "Registered cache operations %s\n", ops->co_name);
00142 
00143         return 0;
00144 }

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 157 of file cache_mngt.c.

Referenced by genl_unregister().

00158 {
00159         struct nl_cache_ops *t, **tp;
00160 
00161         for (tp = &cache_ops; (t=*tp) != NULL; tp = &t->co_next)
00162                 if (t == ops)
00163                         break;
00164 
00165         if (!t)
00166                 return nl_error(ENOENT, "No such cache operations");
00167 
00168         NL_DBG(1, "Unregistered cache operations %s\n", ops->co_name);
00169 
00170         *tp = t->co_next;
00171         return 0;
00172 }

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 189 of file cache_mngt.c.

Referenced by nl_cache_mngr_add().

00190 {
00191         struct nl_cache_ops *ops;
00192 
00193         ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
00194         if (!ops)
00195                 BUG();
00196         else
00197                 ops->co_major_cache = cache;
00198 }

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 208 of file cache_mngt.c.

00209 {
00210         struct nl_cache_ops *ops;
00211 
00212         ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
00213         if (!ops)
00214                 BUG();
00215         else if (ops->co_major_cache == cache)
00216                 ops->co_major_cache = NULL;
00217 }

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 229 of file cache_mngt.c.

References nl_cache_ops_lookup().

00230 {
00231         struct nl_cache_ops *ops;
00232 
00233         ops = nl_cache_ops_lookup(name);
00234         if (!ops || !ops->co_major_cache) {
00235                 fprintf(stderr, "Application BUG: Your application must "
00236                         "call nl_cache_mngt_provide() and\nprovide a valid "
00237                         "%s cache to be used for internal lookups.\nSee the "
00238                         " API documentation for more details.\n", name);
00239 
00240                 return NULL;
00241         }
00242         
00243         return ops->co_major_cache;
00244 }


Generated on 30 Oct 2009 for libnl by  doxygen 1.6.1