udevadm vs Linux热插拔 [英] udevadm vs linux hotplug
问题描述
我对下面列出的问题有些困惑:
I am a bit confused with the questions listed below:
-
当我在桌面上执行
udevadm
时,它能够侦听从内核发送的uevent
. 我认为在执行udevadm
之前,它将检查udevd
的可用性. 这意味着,如果udevd
在我的桌面上不可用,则udevadm
将无法工作. 我的想法正确吗?
While I execute
udevadm
on my desktop, it is able to listenuevent
sent from kernel. I think before the execution ofudevadm
, it will check the availability ofudevd
. That means, if theudevd
is not available on my desktop,udevadm
will not be able to work. Is my thinking correct?
要具有与udevadm
相同的功能,我发现linux还提供了另一种方法
存档.它称为netlink
.令我感到困惑的是,如果我以这种方式做事,我可能会与使用udevadm
完全一样.因此,udev
与netlink socket
有什么区别?
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);
< ----我创建的用于监听uevent
的套接字.
socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
<----The socket I created to listen to uevent
.
感谢avd的反馈.收到您的反馈后,我还有一些问题要问.
Thanks for avd's feedback. I still have some questions to ask after having your feedback.
-
不仅
udevd
可以侦听来自内核的消息,而且udevadm
也可以. 我的想法正确吗?或udevadm仅用于管理udevd
.
There are not only
udevd
can listen message from kernel, but alsoudevadm
does. Is my thinking correct? Or udevadm is only to manageudevd
.
通过设置与NETLINK_KOBJECT_UEVENT
的套接字绑定,用户空间代码还可以侦听从内核发送的uevent.此时,看来我没有理由选择udev
来完成此功能.这两种方法之间有什么不同吗?
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?
在用户空间中,两个不同的进程可以同时监听uevent
吗? netlink
可以同时将消息发送到这些进程吗?
In user space, Can two different processes listen to uevent
simultaneously? Can netlink
send the message to these processes in the same time?
推荐答案
- 是的,您是对的.
udevadm
用于管理udevd
. - 这是您真正困惑的地方.让我澄清一下.
udev
是用户空间设备管理器. udev负责使您的设备出现在/dev目录中.它还负责热插拔功能.为了完成任务,udev通过从内核接收消息来工作.内核通过netlink套接字发送消息. Netlink只是实现为单独的套接字系列的IPC设施,专门用于内核到用户空间的交互.因此内核通过netlink套接字发送特殊格式的消息(uevent).在另一个站点上(在用户空间中),必须有人正在侦听此消息,而udev正是这样做的.udev
的主要部分是udev守护程序-udevd
.该守护程序侦听这些消息并在/dev路径下创建特殊的设备文件,并提供给您(Linux用户)界面来管理设备和热插拔(udev规则).
- Yes, you're right.
udevadm
is to manageudevd
. - 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 ofudev
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.
其他答案:
-
来自udevadm联机帮助页:
From udevadm manpage:
udevadm需要一个命令和特定于命令的选项.它控制 systemd-udevd的运行时行为,请求内核事件,管理 事件队列,并提供简单的调试机制.
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.
所以它只是一个管理工具,尽管它可以通过admin命令请求内核事件.
So it's just a managing tool though it can requests kernel event on admin command.
(我可能无法正确理解您的问题).您可以编写自己的守护程序来监听uevent.这就是 gentoo的mdev 所做的.
(I might not understand you question correctly). You can write your own daemon to listen for uevents. That's what gentoo's mdev does.
Netlink允许您为Netlink消息提供多个侦听器.但这取决于内核套接字发送消息(单播,多播,广播)和netlink系列的方式. Netlink本身是系列的集合,因此它可能取决于您所使用的Netlink.例如,NETLINK_GENERIC系列允许您为消息绑定多个用户空间套接字,并且您将收到该消息.我认为回答这个问题的最好方法是编写一些简单的侦听代码(可能在 libudev 的帮助下)
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)
这篇关于udevadm vs Linux热插拔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!