diff options
| author | Richard Tollerton <rich.tollerton@ni.com> | 2014-12-08 16:44:33 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-12-19 18:08:01 +0000 |
| commit | 24a159e16962477b105eeb144515fd16ddb3cdd0 (patch) | |
| tree | 7ead5b24add9958d3da14df4927b33e230ff575c | |
| parent | a957ff1dc4d084f4b7868359a508241f4af480f4 (diff) | |
| download | poky-24a159e16962477b105eeb144515fd16ddb3cdd0.tar.gz | |
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.
(From OE-Core rev: 107e7fa2b2cc2e06addb83518c03b3ab769fed6f)
Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/recipes-core/udev/udev/udev-cache | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/udev/udev-cache b/meta/recipes-core/udev/udev/udev-cache index 497d257397..a1410f5579 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 | |||
| 19 | DEVCACHE_TMP="/dev/shm/udev-cache-tmp.tar" | 19 | DEVCACHE_TMP="/dev/shm/udev-cache-tmp.tar" |
| 20 | SYSCONF_CACHED="/etc/udev/cache.data" | 20 | SYSCONF_CACHED="/etc/udev/cache.data" |
| 21 | SYSCONF_TMP="/dev/shm/udev.cache" | 21 | SYSCONF_TMP="/dev/shm/udev.cache" |
| 22 | |||
| 23 | # A list of files which are used as a criteria to judge whether the udev cache could be reused. | ||
| 24 | CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags" | ||
| 22 | [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache | 25 | [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache |
| 23 | 26 | ||
| 27 | readfiles () { | ||
| 28 | READDATA="" | ||
| 29 | for filename in $@; do | ||
| 30 | if [ -r $filename ]; then | ||
| 31 | while read line; do | ||
| 32 | READDATA="$READDATA$line" | ||
| 33 | done < $filename | ||
| 34 | fi | ||
| 35 | done | ||
| 36 | } | ||
| 37 | |||
| 24 | if [ "$ROOTFS_READ_ONLY" = "yes" ]; then | 38 | if [ "$ROOTFS_READ_ONLY" = "yes" ]; then |
| 25 | [ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache" | 39 | [ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache" |
| 26 | exit 0 | 40 | exit 0 |
| @@ -28,11 +42,15 @@ fi | |||
| 28 | 42 | ||
| 29 | if [ "$DEVCACHE" != "" -a -e "$SYSCONF_TMP" ]; then | 43 | if [ "$DEVCACHE" != "" -a -e "$SYSCONF_TMP" ]; then |
| 30 | echo "Populating dev cache" | 44 | echo "Populating dev cache" |
| 45 | udevadm control --stop-exec-queue | ||
| 46 | readfiles $CMP_FILE_LIST | ||
| 47 | echo "$READDATA" > "$SYSCONF_TMP" | ||
| 31 | find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \ | 48 | find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \ |
| 32 | | xargs tar cf "${DEVCACHE_TMP}" -T- | 49 | | xargs tar cf "${DEVCACHE_TMP}" -T- |
| 33 | gzip < "${DEVCACHE_TMP}" > "$DEVCACHE" | 50 | gzip < "${DEVCACHE_TMP}" > "$DEVCACHE" |
| 34 | rm -f "${DEVCACHE_TMP}" | 51 | rm -f "${DEVCACHE_TMP}" |
| 35 | mv "$SYSCONF_TMP" "$SYSCONF_CACHED" | 52 | mv "$SYSCONF_TMP" "$SYSCONF_CACHED" |
| 53 | udevadm control --start-exec-queue | ||
| 36 | fi | 54 | fi |
| 37 | 55 | ||
| 38 | exit 0 | 56 | exit 0 |
