what is the precise udev event that handles miscdevices?
i can trivially create misc character devices, and i know special device files for them will automatically show up under /dev, but what is the precise udev event/rule that comes into play for this? if i start to monitor udevadm with: $ udevadm monitor --kernel --udev --property and insert my misc char module, i see: KERNEL[5342.740294] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module KERNEL[5342.740528] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc UDEV [5342.741071] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module USEC_INITIALIZED=740419 UDEV [5342.741921] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc USEC_INITIALIZED=740750 so, yes, i can see the line "DEVNAME=/dev/mymisc", but is there something i can point at in the collection of udev rules that deals with that? or is that simply done internally? rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
On Wed, Apr 01, 2015 at 07:43:05AM -0400, Robert P. J. Day wrote:
i can trivially create misc character devices, and i know special device files for them will automatically show up under /dev, but what is the precise udev event/rule that comes into play for this?
There isn't one. Gee, this is going to be easy :)
On Wed, 1 Apr 2015, Greg KH wrote:
On Wed, Apr 01, 2015 at 07:43:05AM -0400, Robert P. J. Day wrote:
i can trivially create misc character devices, and i know special device files for them will automatically show up under /dev, but what is the precise udev event/rule that comes into play for this?
There isn't one.
Gee, this is going to be easy :)
don't get smug. :-) i had sort of concluded there was no actual udev rule i could point at, so it's just the case that udev processes those events internally? is this written down anywhere? everyone happily explains how misc devices get their /dev file automatically, but no one i've seen goes that extra step to explain how that happens. rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
don't get smug. :-) i had sort of concluded there was no actual udev rule i could point at, so it's just the case that udev processes those events internally? is this written down anywhere? everyone happily explains how misc devices get their /dev file automatically, but no one i've seen goes that extra step to explain how that happens.
misc_register() is ultimately calling device_add() which is again calling device_create_file() , and this one is actually creating the node in /dev . (if i am not wrong). regards sudip
On Wed, 1 Apr 2015, Sudip Mukherjee wrote:
don't get smug. :-) i had sort of concluded there was no actual udev rule i could point at, so it's just the case that udev processes those events internally? is this written down anywhere? everyone happily explains how misc devices get their /dev file automatically, but no one i've seen goes that extra step to explain how that happens.
misc_register() is ultimately calling device_add() which is again calling device_create_file() , and this one is actually creating the node in /dev . (if i am not wrong).
close, and now i can come across as an expert since i checked the source file. :-) from drivers/base/core.c, in device_add(): if (MAJOR(dev->devt)) { error = device_create_file(dev, &dev_attr_dev); if (error) goto DevAttrError; error = device_create_sys_dev_entry(dev); if (error) goto SysEntryError; devtmpfs_create_node(dev); } so device_add() creates device_create_file(), then calls devtmpfs_create_node() which, based on whether you selected that devtmpfs CONFIG option, either creates the /dev file or does nothing. it's all clear to me now ... rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
On Wed, Apr 01, 2015 at 07:43:05AM -0400, Robert P. J. Day wrote:
i can trivially create misc character devices, and i know special device files for them will automatically show up under /dev, but what is the precise udev event/rule that comes into play for this?
if i start to monitor udevadm with:
$ udevadm monitor --kernel --udev --property
and insert my misc char module, i see:
KERNEL[5342.740294] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module
KERNEL[5342.740528] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc
UDEV [5342.741071] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module USEC_INITIALIZED=740419
UDEV [5342.741921] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc USEC_INITIALIZED=740750
so, yes, i can see the line "DEVNAME=/dev/mymisc", but is there something i can point at in the collection of udev rules that deals with that? or is that simply done internally?
Ok, I'll be nice here, udev doesn't create device nodes anymore, and hasn't for years, the kernel does that directly with devtmpfs. Yes, if you want to write your own version of udev, you can listen to the uevent messages, and pick out the right one to trigger off of to create a device node, but as the kernel does this all for you with devtmpfs, why would you want to? In fact, no one does this anymore, and people run systems without udev and have dynamic device nodes just fine. And have been doing so for years, udev isn't needed for device nodes anymore, if that's all you care about. Hint, you are correct, it's the DEVNAME event, but watch out here, you are seeing events twice, once from the kernel, the second from UDEV, which is exposing how udev works internally, but will quickly get confusing if you aren't careful. I'd recommend just filtering on the KERNEL events to keep things "sane" for now. good luck, greg k-h
On Wed, 1 Apr 2015, Greg KH wrote:
On Wed, Apr 01, 2015 at 07:43:05AM -0400, Robert P. J. Day wrote:
i can trivially create misc character devices, and i know special device files for them will automatically show up under /dev, but what is the precise udev event/rule that comes into play for this?
if i start to monitor udevadm with:
$ udevadm monitor --kernel --udev --property
and insert my misc char module, i see:
KERNEL[5342.740294] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module
KERNEL[5342.740528] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc
UDEV [5342.741071] add /module/mymisc (module) ACTION=add DEVPATH=/module/mymisc SEQNUM=3007 SUBSYSTEM=module USEC_INITIALIZED=740419
UDEV [5342.741921] add /devices/virtual/misc/mymisc (misc) ACTION=add DEVNAME=/dev/mymisc DEVPATH=/devices/virtual/misc/mymisc MAJOR=10 MINOR=55 SEQNUM=3008 SUBSYSTEM=misc USEC_INITIALIZED=740750
so, yes, i can see the line "DEVNAME=/dev/mymisc", but is there something i can point at in the collection of udev rules that deals with that? or is that simply done internally?
Ok, I'll be nice here, udev doesn't create device nodes anymore, and hasn't for years, the kernel does that directly with devtmpfs.
and, suddenly, so many things make much more sense.
Yes, if you want to write your own version of udev, you can listen to the uevent messages, and pick out the right one to trigger off of to create a device node, but as the kernel does this all for you with devtmpfs, why would you want to?
at this point, of course i wouldn't.
In fact, no one does this anymore, and people run systems without udev and have dynamic device nodes just fine. And have been doing so for years, udev isn't needed for device nodes anymore, if that's all you care about.
yup, i can see that now. although i would *think* that you could still use udev to go above and beyond just creating device files, to do things like create symlinks, run arbitrary programs and so on. but, yes, for just straight device file manipulation, devtmpfs is sufficient.
Hint, you are correct, it's the DEVNAME event, but watch out here, you are seeing events twice, once from the kernel, the second from UDEV, which is exposing how udev works internally, but will quickly get confusing if you aren't careful. I'd recommend just filtering on the KERNEL events to keep things "sane" for now.
i figured as much. now i know what to go read to keep me busy for the rest of the day. thanks muchly. rday p.s. one more potentially silly question -- is there a devtmpfs monitoring utility, or is it adequate to just use udevadm to monitor kernel events to get the same effect? -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
On Wed, Apr 01, 2015 at 08:18:13AM -0400, Robert P. J. Day wrote:
On Wed, 1 Apr 2015, Greg KH wrote:
In fact, no one does this anymore, and people run systems without udev and have dynamic device nodes just fine. And have been doing so for years, udev isn't needed for device nodes anymore, if that's all you care about.
yup, i can see that now. although i would *think* that you could still use udev to go above and beyond just creating device files, to do things like create symlinks, run arbitrary programs and so on. but, yes, for just straight device file manipulation, devtmpfs is sufficient.
Yes, your persistent device names (the whole reason udev was created in the first name) are still created by udev, as that is best left up to userspace. Those are symlinks to the device nodes devtmpfs created. Also, sometimes you want different group/user permissions on device nodes from what the kernel provides (the kernel doesn't know the group file), so udev will modify the mode and owners of some nodes as well. good luck! greg k-h
participants (3)
-
Greg KH -
Robert P. J. Day -
Sudip Mukherjee