udevadm vs linux hotplug

别说谁变了你拦得住时间么 提交于 2019-12-08 07:30:58

问题


I am a bit confused with the questions listed below:

  1. While I execute udevadm on my desktop, it is able to listen uevent sent from kernel. I think before the execution of udevadm, it will check the availability of udevd. That means, if the udevd is not available on my desktop, udevadm will not be able to work. Is my thinking correct?

  2. To have the same functionality of udevadm, I found that linux also provides another way
    to archive this. It's called netlink. What confuses me is If I do things this way, I could have exactly the same thing that I have by using udevadm. Hence, what's the difference between udev vs. netlink socket?

socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); <----The socket I created to listen to uevent.


Thanks for avd's feedback. I still have some questions to ask after having your feedback.

  1. There are not only udevd can listen message from kernel, but also udevadm does. Is my thinking correct? Or udevadm is only to manage udevd.

  2. By setting up the socket binding to the NETLINK_KOBJECT_UEVENT, the user space code can also listen uevent sent from kernel. At this point, It seems I have no reason to choose udev to complete this function. Is there any different between these two approaches?

  3. In user space, Can two different processes listen to uevent simultaneously? Can netlink send the message to these processes in the same time?


回答1:


  1. Yes, you're right. udevadm is to manage udevd.
  2. This is where you're really confused. Let me clarify this. udev is userspace device manager. udev is responsible for your devices to appear in /dev directory. It's also responsible for hotplug functionality. To make things done udev works by receiving messages from kernel. Kernel sends messages via netlink socket. Netlink is just IPC facility implemented as separate socket family specifically for kernel to userspace interaction. So kernel sends messages of special format (uevent) over netlink socket. On the other site (in userspace) there must be someone who is listening for this messages and that's what udev does. Main part of udev is udev daemon - udevd. That daemon listens for that messages and creates special device files under /dev path and provide to you (linux user) interface to manage devices and hotplug (udev rules).

I've answered related question - check it here.

Extra answers:

  1. From udevadm manpage:

    udevadm expects a command and command specific options. It controls the runtime behavior of systemd-udevd, requests kernel events, manages the event queue, and provides simple debugging mechanisms.

    So it's just a managing tool though it can requests kernel event on admin command.

  2. (I might not understand you question correctly). You can write your own daemon to listen for uevents. That's what gentoo's mdev does.

  3. Netlink allows you to provide multiple listeners for netlink messages. But it depends on a way that kernel socket sends message (unicast, multicast, broadcast) and netlink family. Netlink itself is a collection of families, so it may depends on what netlink you are using. For example, NETLINK_GENERIC family allows you to bind multiple userspace sockets for messages and you will receive that messages. I think the best way to answer this question is to write some simple listening code (probably with some help of libudev)



来源:https://stackoverflow.com/questions/22952692/udevadm-vs-linux-hotplug

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