experimental udevd with builtin udev
Here is an experiment to build udev into udevd instead of loading the binary from disk. It still forks a child, but the child only handles node creation/removal and dev.d/ execution.
The rules are only parsed once on startup of udevd. The parsed config is available to the child, cause we don't exec() anything, we just continue the execution in the child.
If /dev is on tmpfs, no disk activity will happen on an udev event!
Changes to rules only apply on restart of udevd.
Don't install it! This is highly experimental and may render you system unusable. It can be easily tested by building it, killing the running udevd and start the copy in the tree with ./udevd. This copy will listen to the socket and handle all udev events from udevsend.
The log looks like this:
udevd[11974]: main: version 039
udevd[11974]: get_dirs: sysfs_path='/sys'
udevd[11974]: parse_config_file: reading '/etc/udev/udev.conf' as config file
udevd[11974]: namedev_parse_rules: reading '/etc/udev/rules.d/50-udev.rules' as rules file udevd[11974]: namedev_parse_permissions: reading '/etc/udev/permissions.d/50-udev.permissions' as permissions file
...
kernel: usb 3-2: USB disconnect, address 9
udevd(event)[11977]: removing device node '/dev/input/mouse2'
udevd(event)[11979]: removing device node '/dev/input/event3'
...
kernel: usb 3-2: new low speed USB device using address 10
kernel: input: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:00:1d.1-2 udevd(event)[11989]: configured rule in '/etc/udev/rules.d/50-udev.rules' at line 24 applied, 'mouse2' becomes 'input/%k' udevd(event)[11989]: creating device node '/dev/input/mouse2'
udevd(event)[11996]: configured rule in '/etc/udev/rules.d/50-udev.rules' at line 25 applied, 'event3' becomes 'input/%k' udevd(event)[11996]: creating device node '/dev/input/event3'
...
What do you think?
Kay
===== Makefile 1.195 vs edited =====
Makefile +3 -2
@@ -216,6 +216,7 @@ OBJS = udev_lib.o \ namedev.o \ namedev_parse.o \ dev_d.o \ + udevstart.o \ $(SYSFS) \ $(TDB)
@@ -283,7 +284,7 @@ $(STARTER).o: $(GEN_HEADERS) $(HOST_PROG $(WAIT).o: $(GEN_HEADERS) $(HOST_PROGS) $(ROOT): $(LIBC) $(ROOT).o $(STARTER).o $(OBJS) $(HEADERS) $(GEN_MANPAGES) - $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o udevstart.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
@@ -295,7 +296,7 @@ $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEA $(QUIET) $(STRIPCMD) $@ $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h - $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(OBJS) $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
===== udevd.c 1.42 vs edited =====
udevd.c +143 -51
314 lines not on this page · raw message
===== udevd.h 1.12 vs edited =====
udevd.h +0 -1
@@ -26,7 +26,6 @@#define UDEV_MAGIC "udevd_" UDEV_VERSION#define EVENT_TIMEOUT_SEC 10 -#define UDEVSEND_CONNECT_RETRY 20/* x 100 millisec */ #define UDEVD_SOCK_PATH "udevd"struct hotplug_msg {
===== udevsend.c 1.33 vs edited =====
udevsend.c +7 -7
@@ -41,6 +41,9 @@#include "udevd.h" #include "logging.h" +#define WAIT_MAX_SECONDS 3 +#define WAIT_LOOP_PER_SECOND 10 +#ifdef LOG unsigned char logname[LOGNAME_SIZE ];void log_message (int level,const char *format, ...)
@@ -117,7 +120,6 @@ int main(int argc, char* argv[])unsigned long long seq;int retval =1 ;int loop; -struct timespec tspec;int sock =-1 ;struct sockaddr_un saddr;socklen_t addrlen;
@@ -175,8 +177,8 @@ int main(int argc, char* argv[])strfieldcpy (msg.devpath, devpath);strfieldcpy (msg.subsystem, subsystem); -/* If we can't send, try to start daemon and resend message */ - loop =UDEVSEND_CONNECT_RETRY ; +/* If we can't send, try to start daemon and resend message */ ; + loop =WAIT_MAX_SECONDS *WAIT_LOOP_PER_SECOND ;while (loop--) { retval =sendto (sock, &msg,sizeof (struct hotplug_msg ),0 , (struct sockaddr *)&saddr, addrlen);
@@ -200,10 +202,8 @@ int main(int argc, char* argv[])dbg ("daemon started" ); started_daemon =1 ; }else { -dbg ("retry to connect %d" ,UDEVSEND_CONNECT_RETRY - loop); - tspec.tv_sec =0 ; - tspec.tv_nsec =100000000 ;/* 100 millisec */ -nanosleep (&tspec,NULL ); +dbg ("retry to connect %d" ,WAIT_MAX_SECONDS *WAIT_LOOP_PER_SECOND - loop); +usleep (1000 *1000 /WAIT_LOOP_PER_SECOND ); } }
Quoted 37 lines · Kay Sievers
Here is an experiment to build udev into udevd instead of loading the binary from disk. It still forks a child, but the child only handles node creation/removal and dev.d/ execution.
The rules are only parsed once on startup of udevd. The parsed config is available to the child, cause we don't
exec()anything, we just continue the execution in the child.If /dev is on tmpfs, no disk activity will happen on an udev event!
Changes to rules only apply on restart of udevd.
Don't install it! This is highly experimental and may render you system unusable. It can be easily tested by building it, killing the running udevd and start the copy in the tree with ./udevd. This copy will listen to the socket and handle all udev events from udevsend.
The log looks like this:
udevd[11974]: main: version 039
udevd[11974]:get_dirs: sysfs_path='/sys'
udevd[11974]:parse_config_file: reading '/etc/udev/udev.conf' as config file
udevd[11974]:namedev_parse_rules: reading '/etc/udev/rules.d/50-udev.rules' as rules file udevd[11974]:namedev_parse_permissions: reading '/etc/udev/permissions.d/50-udev.permissions' as permissions file
...
kernel: usb 3-2: USB disconnect, address 9
udevd(event)[11977]: removing device node '/dev/input/mouse2'
udevd(event)[11979]: removing device node '/dev/input/event3'
...
kernel: usb 3-2: new low speed USB device using address 10
kernel: input: USB HID v1.10 Mouse [Logitech USB-PS/2 Optical Mouse] on usb-0000:00:1d.1-2 udevd(event)[11989]: configured rule in '/etc/udev/rules.d/50-udev.rules' at line 24 applied, 'mouse2' becomes 'input/%k' udevd(event)[11989]: creating device node '/dev/input/mouse2'
udevd(event)[11996]: configured rule in '/etc/udev/rules.d/50-udev.rules' at line 25 applied, 'event3' becomes 'input/%k' udevd(event)[11996]: creating device node '/dev/input/event3'
...
Quoted 1 line
What do you think?
Here is the version to apply after the last the sysfs-expose and the udevd-cleanup patch.
Enough for today, thanks,
Kay
===== Makefile 1.197 vs edited =====
Makefile +3 -2
@@ -217,6 +217,7 @@ OBJS = udev_lib.o \ namedev.o \ namedev_parse.o \ dev_d.o \ + udevstart.o \ $(SYSFS) \ $(TDB)
@@ -285,7 +286,7 @@ $(STARTER).o: $(GEN_HEADERS) $(HOST_PROG $(WAIT).o: $(GEN_HEADERS) $(HOST_PROGS) $(ROOT): $(LIBC) $(ROOT).o $(STARTER).o $(OBJS) $(HEADERS) $(GEN_MANPAGES) - $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o udevstart.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
@@ -297,7 +298,7 @@ $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEA $(QUIET) $(STRIPCMD) $@ $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h - $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS) + $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(OBJS) $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
===== udevd.c 1.43 vs edited =====
udevd.c +89 -23
150 lines not on this page · raw message