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

Sam
  • 4,521
  • 13
  • 46
  • 81

1 Answers1

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.

garritfra
  • 546
  • 4
  • 21
Alexander Dzyoba
  • 4,009
  • 1
  • 24
  • 29
  • 1
    Thanks. Can I think this as an item 1? Which is mostly triggered by hardware interrupt. – Sam Apr 18 '14 at 08:10
  • 2
    Maybe. Hardware interrupts causes mostly `KOBJ_ADD/REMOVE`. But there are `KOBJ_CHANGE` that could be triggered by some kernel process or userspace daemon. – Alexander Dzyoba Apr 18 '14 at 08:20
  • 1
    Thanks. Would you mind to provide an example about KOBJ_CHANGE which is triggered by some events without hardware interrupts? – Sam Apr 18 '14 at 08:23
  • 2
    Example from btrfs: in fs/btrfs/volumes.c there is a call to [`btrfs_kobject_uevent`](http://lxr.free-electrons.com/source/fs/btrfs/volumes.c#L1695) 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. – Alexander Dzyoba Apr 18 '14 at 08:40
  • 1
    Thanks! This is a great example to know. – Sam Apr 18 '14 at 08:48