]> code.ossystems Code Review - openembedded-core.git/commitdiff
udev: improve udev-cache robustness
authorOtavio Salvador <otavio@ossystems.com.br>
Tue, 20 Dec 2011 14:13:14 +0000 (14:13 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 2 Feb 2012 14:55:44 +0000 (14:55 +0000)
 * allow udev-cache to be disabled at runtime (using
   /etc/default/udev-cache);

 * make cache invalidated if kernel, bootparams or device list
   changes;

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
meta/recipes-core/udev/udev.inc
meta/recipes-core/udev/udev/init
meta/recipes-core/udev/udev/udev-cache
meta/recipes-core/udev/udev/udev-cache.default [new file with mode: 0644]
meta/recipes-core/udev/udev_164.bb

index 0e571d6646463fb340e9cadcd62bb16ba1f4aa77..e5fbe403af9e2d7c47789a794e157adbd99d7735 100644 (file)
@@ -25,6 +25,7 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/kernel/hotplug/udev-${PV}.tar.gz \
            file://network.sh \
            file://local.rules \
            file://udev-cache \
+           file://udev-cache.default \
            file://init"
 
 inherit autotools pkgconfig update-rc.d
@@ -58,7 +59,7 @@ FILES_libgudev = "${base_libdir}/libgudev*.so.* ${libdir}/libgudev*.so.*"
 FILES_libgudev-dbg = "${base_libdir}/.debug/libgudev*.so.* ${libdir}/.debug/libgudev*.so.*"
 FILES_libgudev-dev = "${includedir}/gudev* ${libdir}/libgudev*.so ${libdir}/libgudev*.la \
                      ${libdir}/libgudev*.a ${libdir}/pkgconfig/gudev*.pc"
-FILES_udev-cache = "${sysconfdir}/init.d/udev-cache"
+FILES_udev-cache = "${sysconfdir}/init.d/udev-cache ${sysconfdir}/default/udev-cache"
 
 FILES_udev-acl = "${base_libdir}/udev/udev-acl ${base_libdir}/udev/rules.d/70-acl.rules"
 
@@ -72,6 +73,11 @@ do_install_append () {
        install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/udev
        install -m 0755 ${WORKDIR}/udev-cache ${D}${sysconfdir}/init.d/udev-cache
 
+       install -d ${D}${sysconfdir}/default
+       install -m 0755 ${WORKDIR}/udev-cache.default ${D}${sysconfdir}/default/udev-cache
+
+       touch ${D}${sysconfdir}/udev/cache.data
+
        install -d ${D}${sysconfdir}/udev/rules.d/
 
        install -m 0644 ${WORKDIR}/local.rules         ${D}${sysconfdir}/udev/rules.d/local.rules
index 6a4464c6396e9e97173239eaec8ef6fae52392ab..78b5b1c4b66ecd8492bff54451e4a997e990d047 100644 (file)
@@ -14,8 +14,19 @@ export TZ=/etc/localtime
 [ -d /sys/class ] || exit 1
 [ -r /proc/mounts ] || exit 1
 [ -x /sbin/udevd ] || exit 1
+[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
 [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
 
+readfile () {
+   filename=$1
+   READDATA=""
+   if [ -r $filename ]; then
+       while read line; do
+           READDATA="$READDATA$line"
+       done < $filename
+   fi
+}
+
 kill_udevd() {
        if [ -x /sbin/pidof ]; then
                pid=`/sbin/pidof -x udevd`
@@ -34,10 +45,26 @@ LANG=C awk '$2 == "/dev" && ($3 == "tmpfs" || $3 == "devtmpfs") { exit 1 }' /pro
 [ -e /dev/pts ] || mkdir -m 0755 /dev/pts
 [ -e /dev/shm ] || mkdir -m 1777 /dev/shm
 
+# cache handling
+if [ "$DEVCACHE" != "" ]; then
+       readfile /proc/version
+       VERSION="$READDATA"
+       readfile /proc/cmdline
+       CMDLINE="$READDATA"
+       readfile /proc/devices
+       DEVICES="$READDATA"
+       readfile /proc/atags
+       ATAGS="$READDATA"
 
-if [ -e /etc/dev.tar ]; then
-       (cd /; tar xf /etc/dev.tar 2>&1 | grep -v 'time stamp' || true)
-       not_first_boot=1
+       if [ -e $DEVCACHE ]; then
+               readfile /etc/udev/cache.data
+               if [ "$READDATA" = "$VERSION$CMDLINE$DEVICES$ATAGS" ]; then
+                       (cd /; tar xf $DEVCACHE > /dev/null 2>&1)
+                       not_first_boot=1
+               fi
+
+               echo "$VERSION$CMDLINE$DEVICES$ATAGS" > /dev/shm/udev.cache
+       fi
 fi
 
 # make_extra_nodes
index 77bbda6f1b8156206ba437de12e48a57e40e09a9..9c24e76514f4a603ca8535bb7e31217d7acbb383 100644 (file)
@@ -9,12 +9,20 @@
 # Short-Description: cache /dev to speedup the udev next boot
 ### END INIT INFO
 
-[ -d /sys/class ] || exit 1
+export TZ=/etc/localtime
+
 [ -r /proc/mounts ] || exit 1
 [ -x /sbin/udevd ] || exit 1
+[ -d /sys/class ] || exit 1
+
+[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
 
-if [ ! -e /etc/dev.tar ]; then
-       (cd /; tar cf /etc/dev.tar dev)
+if [ "$DEVCACHE" != "" ]; then
+       echo "Populating dev cache"
+       (cd /; tar cf "$DEVCACHE" dev)
+       mv /dev/shm/udev.cache /etc/udev/cache.data
+else
+       rm -f /dev/shm/udev.cache
 fi
 
 exit 0
diff --git a/meta/recipes-core/udev/udev/udev-cache.default b/meta/recipes-core/udev/udev/udev-cache.default
new file mode 100644 (file)
index 0000000..5c4937a
--- /dev/null
@@ -0,0 +1,4 @@
+# Default for /etc/init.d/udev
+
+# Comment this out to disable device cache
+DEVCACHE="/etc/dev.tar"
index c89eab4016eab9b59c2ad672b597c179e28ba013..6d71f4dc1b853a1a189a98fc6e58e57c70d54817 100644 (file)
@@ -1,6 +1,6 @@
 include udev.inc
 
-PR = "r9"
+PR = "r10"
 
 SRC_URI += "file://udev-166-v4l1-1.patch"