Notifying Events on a Chain
Notifications are generated with notifier_call_chain, defined in kernel/sys.c. This function simply invokes, in order of priority, all the
callback routines registered against the chain. Note that callback routines are executed
in the context of the process that calls notifier_call_chain. A callback routine could, however, be implemented so that
it queues the notification somewhere and wakes up a process that will look at it.
int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v)
{
int ret = NOTIFY_DONE;
struct notifier_block *nb = *n;
while (nb)
{
ret = nb->notifier_call(nb, val, v);
if (ret & NOTIFY_STOP_MASK)
{
return ret;
}
nb = nb->next;
}
return ret;
}This is the meaning of its three input parameters:
-
n Notification chain.
-
val Event type. The chain itself identifies a class of events;
valunequivocally identifies an event type (i.e.,NETDEV_REGISTER).-
v Input parameter that can be used by the handlers registered by the various clients. This can be used in different ways under different circumstances. For instance, when a new network device is registered with the kernel, the associated notification uses
vto identify thenet_devicedata structure.
The callback routines called by notifier_call_chain
can return any of the NOTIFY_
XXX values defined in include/linux/notifier.h:
-
NOTIFY_OK Notification was processed correctly.
-
NOTIFY_DONE Not interested in the notification.[*]
-
NOTIFY_BAD Something went wrong. Stop calling the callback ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access