Hi BusyBox!
I'm using busybox 1.23.2 with mdev perfectly for hotplug and module loading.
In rc I have:
echo > /dev/mdev.seq
echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s
To get USB and some bus device drivers to load, I have the rule in mdev.conf:
$MODALIAS=.* 0:0 0660 @modprobe "$MODALIAS"
So far this is as per the mdev.txt documentation, and works well, though a
couple of devices that enumerate early get missed. Therefore after the above,
I synthesise uevents to ensure everthing gets modprobe'd too:
find /sys/devices/ -name "uevent" | while read L ; do echo add > $L ; done
This causes a number of mdev processes to be spawned from the kernel, and tick
through according to mdev.seq. All of this is wanted and works correctly.
The slight problem I have is knowing when all the 'queued' mdev processes have
completed so that I can let the remainder of startup continue knowing that /dev
is stable.
To this end, attached is a small patch to optionally add a "-w" option to mdev.
This waits until there are no other processes named mdev running, and then
returns.
The functionality is under ENABLE_FEATURE_MDEV_WAIT, and adds a some bytes to
mdev_main when enabled:
function old new delta
mdev_main 1252 1396 +144
.rodata 48899 48908 +9
packed_usage 1862 1868 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 159/0) Total: 159 bytes
text data bss dec hex filename
442232 1849 8704 452785 6e8b1 busybox_old
442385 1849 8704 452938 6e94a busybox_unstripped
Please consider the following patch for inclusion to busybox.
Kind Regards,
Mike
Signed-off-by: Michael McTernan <[email protected]>
--- busybox-1.23.2_orig/util-linux/mdev.c 2015-03-23 03:07:19.000000000
+0000
+++ busybox-1.23.2/util-linux/mdev.c 2015-06-01 10:34:36.158023487 +0100
@@ -65,13 +65,25 @@
//config: These devices will request userspace look up the files in
//config: /lib/firmware/ and if it exists, send it to the kernel for
//config: loading into the hardware.
+//config:config FEATURE_MDEV_WAIT
+//config: bool "Support waiting for mdev to complete"
+//config: default n
+//config: depends on MDEV
+//config: help
+//config: Allows running of mdev with the '-w' option to wait for all
other
+//config: mdev processes to complete before returning. This can be
+//config: particularly useful if using mdev with hotplug and mdev.seq to
+//config: ensure queued mdev processes have completed.
+
//applet:IF_MDEV(APPLET(mdev, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_MDEV) += mdev.o
//usage:#define mdev_trivial_usage
-//usage: "[-s]"
+//usage: "[-s"
+//usage: IF_FEATURE_MDEV_WAIT("w")
+//usage: "]"
//usage:#define mdev_full_usage "\n\n"
//usage: "mdev -s is to be run during boot to scan /sys and populate
/dev.\n"
//usage: "\n"
@@ -95,6 +107,12 @@
//usage: "To activate this feature, create empty /dev/mdev.seq at
boot.\n"
//usage: "\n"
//usage: "If /dev/mdev.log file exists, debug log will be appended to
it."
+//usage: IF_FEATURE_MDEV_WAIT(
+//usage: "\n"
+//usage: "mdev -w waits for any running mdev processes to complete.
This\n"
+//usage: "can be useful to wait for serialized hotplug invocations to"
+//usage: "finish.\n"
+//usage: )
#include "libbb.h"
#include "xregex.h"
@@ -1068,6 +1086,35 @@ int mdev_main(int argc UNUSED_PARAM, cha
recursive_action("/sys/class",
ACTION_RECURSE | ACTION_FOLLOWLINKS,
fileAction, dirAction, temp, 0);
+#if ENABLE_FEATURE_MDEV_WAIT
+ } else if (argv[1] && strcmp(argv[1], "-w") == 0) {
+ /*
+ * Wait for no mdev instances running
+ */
+ const unsigned my_pid = getpid();
+ bool running;
+
+ do
+ {
+ procps_status_t* p = NULL;
+
+ running = false;
+
+ while ((p = procps_scan(p, PSSCAN_ARGV0)) != NULL) {
+ if (p->pid != my_pid
+ && p->argv0
+ && strcmp(bb_basename(p->argv0), "mdev") == 0
+ ) {
+ waitpid(p->pid, NULL, 0);
+ running = true;
+ }
+ }
+
+ if (p)
+ free_procps_scan (p);
+
+ } while (running);
+#endif
} else {
char *fw;
char *seq;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox