[oe-commits] Richard Tollerton : udev-cache: stop race between sysconf and cache generation

git at git.openembedded.org git at git.openembedded.org
Fri Dec 19 18:08:43 UTC 2014


Module: openembedded-core.git
Branch: master
Commit: 107e7fa2b2cc2e06addb83518c03b3ab769fed6f
URL:    http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=107e7fa2b2cc2e06addb83518c03b3ab769fed6f

Author: Richard Tollerton <rich.tollerton at ni.com>
Date:   Mon Dec  8 16:44:33 2014 -0600

udev-cache: stop race between sysconf and cache generation

The validity of the udev cache is determined by the sysconf
file (/etc/udev/cache.data). Currently, there is a substantial delay
between sysconf generation in /etc/init.d/udev and cache generation in
/etc/init.d/udev-cache. If a hotplug event arrives in the middle of
this, then the sysconf will be out of date with respect to the cache.

The solution is two-pronged. First, we minimize the race window by
regenerating the sysconf immediately before the cache, in
/etc/init.d/udev-cache. This allows us to kill the race entirely by
stopping the udev event queue while the sysconf and cache are being
generated.

Signed-off-by: Richard Tollerton <rich.tollerton at ni.com>

---

 meta/recipes-core/udev/udev/udev-cache | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/meta/recipes-core/udev/udev/udev-cache b/meta/recipes-core/udev/udev/udev-cache
index 497d257..a1410f5 100644
--- a/meta/recipes-core/udev/udev/udev-cache
+++ b/meta/recipes-core/udev/udev/udev-cache
@@ -19,8 +19,22 @@ export TZ=/etc/localtime
 DEVCACHE_TMP="/dev/shm/udev-cache-tmp.tar"
 SYSCONF_CACHED="/etc/udev/cache.data"
 SYSCONF_TMP="/dev/shm/udev.cache"
+
+# A list of files which are used as a criteria to judge whether the udev cache could be reused.
+CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
 [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
 
+readfiles () {
+   READDATA=""
+   for filename in $@; do
+	   if [ -r $filename ]; then
+		   while read line; do
+			   READDATA="$READDATA$line"
+		   done < $filename
+	   fi
+   done
+}
+
 if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
     [ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache"
     exit 0
@@ -28,11 +42,15 @@ fi
 
 if [ "$DEVCACHE" != "" -a -e "$SYSCONF_TMP" ]; then
 	echo "Populating dev cache"
+	udevadm control --stop-exec-queue
+	readfiles $CMP_FILE_LIST
+	echo "$READDATA" > "$SYSCONF_TMP"
 	find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \
 		| xargs tar cf "${DEVCACHE_TMP}" -T-
 	gzip < "${DEVCACHE_TMP}" > "$DEVCACHE"
 	rm -f "${DEVCACHE_TMP}"
 	mv "$SYSCONF_TMP" "$SYSCONF_CACHED"
+	udevadm control --start-exec-queue
 fi
 
 exit 0



More information about the Openembedded-commits mailing list