Next: , Previous: Transactions and topological sorting, Up: Kernel



6.4 Hooks

Hook are used to inform some other modules (on which the kernel does not depend) that something important was changed in kernel data structures. Any module can register its callbacks to some parts of the data structures; the kernel will call the callbacks on certain specified occasions.

There are four kinds of hooks: object, GO, transaction and unit. For each hook kind, there is a specific hook structure type which contains pointers to hook callbacks and a void * for any additional data. To use hooks, a module should allocate its own hook structures, fill the callback pointers and the additional data accordingly (or set NULL to those pointers for which it does not want to register any callback), and then register the hook by calling a kernel function. When an action happens in the kernel, all hook callbacks registered for the appropriate action are called with a pointer to the registered hook structure as an argument. The hooks can then be removed, even during the call of a hook callback.

After registering, the hook structure is filled with pointers which link it in the kernel hook list; thus it is forbidden to have a hook structure registered more than once at the same time.

Object and unit hooks are global for the whole kernel, whereas GO and transaction hooks are local for pages. Now we give a description for the four hook types.

     struct obj_hook* obj_hook_add(struct obj_hook *hook);
     struct obj_hook* obj_hook_remove(struct obj_hook *hook);
     struct obj_hook* obj_hook_remove_by_data(void *data);
     struct go_hook* go_hook_add(struct obj_tlo *tlo, struct go_hook *hook);
     struct go_hook* go_hook_remove(struct obj_tlo *tlo, struct go_hook *hook);
     struct go_hook* go_hook_remove_by_data(struct obj_tlo *tlo, void * data);