how uevents get triggered in kernel

狂风中的少年 提交于 2019-12-07 23:05:00

问题


uevents has been sent from kernel space to user space through netlink socket.

In kernel, there must be something trigger uevent.

I guess there are two possibilities:

  1. Hardware interrupt - this means, once hardware interruption happened, kernel sends event to user space to signal that there is some events happened.

  2. software polling - this means, there is always a daemon to check these file system to see if there is anything changed. If so, then update these info to upper layer.

Could anyone provide your feedback?

Thanks


回答1:


I can't agree with you about polling. uevent is event-based, so there is no polling.

Triggering uevent happened in many cases and I would rather start with figuring out what uevent types are exist?

Little searching and here you go - in include/linux/kobject.h

enum kobject_action {
    KOBJ_ADD,
    KOBJ_REMOVE,
    KOBJ_CHANGE,
    KOBJ_MOVE,
    KOBJ_ONLINE,
    KOBJ_OFFLINE,
    KOBJ_MAX
};

So it's

  • Add event
  • Remove event
  • Change event
  • Move event
  • Online event
  • Offline event

KOBJ_MAX is special and marks and of enum.

There are 2 functions that actually sends uevent - kobject_uevent and kobject_uevent_env. These functions are called with on of the actions listed above.

Finally, to answer your questions. There are no predefined cases that will trigger uevent. If you search for calls of kobject_uevent and kobject_uevent_env you will see that it's happens in various callbacks in different unrelated kernel subsystems.

uevent is kernel facility to unify notifications from various unrelated drivers. So I think there are no well known list of things that will trigger uevent.



来源:https://stackoverflow.com/questions/23146915/how-uevents-get-triggered-in-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!