how uevents get triggered in kernel
Asked Answered
P

1

3

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

Papageno answered 18/4, 2014 at 3:27 Comment(0)
H
5

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.

Hothouse answered 18/4, 2014 at 7:33 Comment(5)
Thanks. Can I think this as an item 1? Which is mostly triggered by hardware interrupt.Papageno
Maybe. Hardware interrupts causes mostly KOBJ_ADD/REMOVE. But there are KOBJ_CHANGE that could be triggered by some kernel process or userspace daemon.Hothouse
Thanks. Would you mind to provide an example about KOBJ_CHANGE which is triggered by some events without hardware interrupts?Papageno
Example from btrfs: in fs/btrfs/volumes.c there is a call to btrfs_kobject_uevent from btrfs_rm_device and btrfs_rm_device is called from btrfs_ioctl_rm_dev. This event is not hardware based - it's ioctl handler.Hothouse
Thanks! This is a great example to know.Papageno

© 2022 - 2024 — McMap. All rights reserved.