Libudev package

I've recently had a requirement for a real libudev, not the unfortunate cripple libudev-fbsd that only contains stubs for a lot of the functions. While libudev-fbsd allows a program to compile, it won't actually in most cases allow it to work.

I thought I'd share this with the community, since I actually find it quite useful. I realize not everyone will need this, but there may be some of you that would find it useful as well.

This is the old Openwrt package for Gentoo's libudev, cutdown to remove udevd and limit the udevadm binary to only the monitor and info commands.

This package was removed back in LEDE 17, ostensibly since it's incompatible with Openwrt. That's not entirely correct: udevd is incompatible, since we have hotplug, however the library itself coexists quite peacefully with hotplug and is fully functional, as is the udevadm utility.

The package I linked installs only the libraries and the modifed version of the udevadm binary.

The package serves two useful functions: 1.) it allows programs that require libudev to be compiled and to work on Openwrt and 2.) the udevadm utility is very useful for monitoring uevents and debugging hotplug.

Obviously one cannot use udev rules, since there is no udevd, but you can simply write replacement hotplug rules. I've done this successfully in porting Intel quickassist drivers to Openwrt, which require udev functionality in order to work properly.

Useful udevadm commands:

udevadm monitor
udevadm info --export-db
udevadm info --path=/devices/pci0000:00/0000:00:16.0/0000:06:00.0/net/eth0

Here is an example that shows the Intel quickassist drivers loading and the events that are fired

KERNEL[762148.389210] add      /module/intel_qat (module)
KERNEL[762148.389236] add      /class/qat_adf_ctl (class)
KERNEL[762148.389251] add      /devices/virtual/qat_adf_ctl/qat_adf_ctl (qat_adf_ctl)
KERNEL[762148.389599] add      /class/qat_dev_processes (class)
KERNEL[762148.389619] add      /devices/virtual/qat_dev_processes/qat_dev_processes (qat_dev_processes)
KERNEL[762148.404298] add      /module/usdm_drv (module)
KERNEL[762148.404317] add      /class/usdm_drv (class)
KERNEL[762148.404347] add      /devices/virtual/usdm_drv/usdm_drv (usdm_drv)
KERNEL[762148.418745] add      /module/qat_c3xxx (module)
KERNEL[762148.824481] bind     /devices/pci0000:00/0000:00:06.0/0000:01:00.0 (pci)
KERNEL[762148.824509] add      /bus/pci/drivers/c3xxx (drivers)
KERNEL[762148.846688] add      /module/qat_api (module)
KERNEL[762149.297965] add      /devices/pci0000:00/0000:00:06.0/0000:01:00.0/uio/uio0 (uio)
KERNEL[762149.297992] add      /devices/pci0000:00/0000:00:06.0/0000:01:00.0/uio/uio1 (uio)
KERNEL[762149.298006] add      /devices/pci0000:00/0000:00:06.0/0000:01:00.0/uio/uio2 (uio)
KERNEL[762149.298057] add      /devices/pci0000:00/0000:00:06.0/0000:01:00.0/uio/uio3 (uio)
KERNEL[762149.298085] add      /devices/pci0000:00/0000:00:06.0/0000:01:00.0/uio/uio4 (uio)```

So for the line KERNEL[762148.404298] add /module/usdm_drv (module) which is the event that is fired on loading a kernel module, I created a file /etc/hotplug.d/module/01-usdm which looks thus

#!/bin/sh

HUGE_PAGE_DIR="/dev/hugepages"

[ "$DEVICENAME" != "usdm_drv" ] && exit 0

[ "$ACTION" == "add" ] && {

	if [ -d ${HUGE_PAGE_DIR} ]; then

		mkdir ${HUGE_PAGE_DIR}/qat 2> /dev/null

		if [ $? -ne 0]; then
			logger -t "quickassist(usdm_drv): error creating ${HUGE_PAGE_DIR}/qat"
		else
			chgrp qat ${HUGE_PAGE_DIR}/qat
			chmod 0770 ${HUGE_PAGE_DIR}/qat
		fi

	else
		logger -t "quickassist(usdm_drv): ${HUGE_PAGE_DIR} not found"
		exit 1
	fi


}

[ "$ACTION" == "remove" ] && {

	rmdir ${HUGE_PAGE_DIR}/qat

}

The udevadm info --path=/devices/virtual/usdm_drv/usdm_drv command can give you the $DEVICENAME parameter you should use in the hotplug script.

udevadm info --path=/devices/virtual/usdm_drv/usdm_drv
P: /devices/virtual/usdm_drv/usdm_drv
N: usdm_drv
E: DEVNAME=/dev/usdm_drv
E: DEVPATH=/devices/virtual/usdm_drv/usdm_drv
E: MAJOR=238
E: MINOR=0
E: SUBSYSTEM=usdm_drv

EDIT: alternatively, invoke the utility thus: udevadm monitor --kernel --property

1 Like