blob: c51cd070cc85dd880175c2e9f0616ca2cd3fe993 [file] [log] [blame]
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Preload network drivers"
author "chromium-os-dev@chromium.org"
# Run on boot-services; "stay running" until we stop system-services
# (which is shutdown).
start on starting boot-services
# crbug.com/810916: Use an event where we are confident all needed "net"
# driver modules have registered with "net" subsystem. The assumption is
# this set of drivers will be used again on next boot.
#
# "stop on stopped udev-trigger" has proven to be too early.
#
# "stop on starting system-services" means boot-services have completed
# (including udev-trigger) and conditions are meet to start system-services.
# But it's still racing.
# "stop on started system-services" is slightly better as this indicates
# some system-services have started. But it's still racing too.
#
# "stop on stopping system-services" would certainly qualify (shutdown) - but
# slows down shutdown which is expected to be quick (no benchmark though).
#
# Compromise is to check for WiFi (wlan0) device well after system services
# have been started. "failsafe" service meets that criteria even though
# it's not a 100% guarantee either that any given WiFi driver has registered
# with "net" subsystem.
#
# https://dev.chromium.org/chromium-os/chromiumos-design-docs/boot-design#TOC-Failsafe-service
stop on started failsafe
env drvfile=/var/lib/preload-network-drivers
pre-start script
# Drivers for Ethernet and WiFi devices are generally modules.
# Our post-stop script will have recorded the driver names on the
# previous boot cycle. Load those drivers now so shill can config
# the network sooner.
#
# Note: failure to probe the module here is NOT fatal.
if [ -s $drvfile ] ; then
for drv in $(head -1 $drvfile); do
if ! modprobe -q -- "${drv}"; then
# If modprobe didn't like the alias file for some reason, just
# move it out of the way. The post-stop script will make a new
# one.
mv $drvfile $drvfile.bad
logger -t "$UPSTART_JOB" \
"modprobe $drv failed. Renamed $drvfile with .bad suffix."
fi
done
fi
end script
post-stop script
# Create/Update list of networking driver names (i.e. Ethernet and WiFi).
# Used to preload Ethernet and WiFi drivers in pre-start script.
newdrv=''
for dev in eth0 wlan0 mlan0; do
# Get the module name
mod_link="/sys/class/net/${dev}/device/driver/module"
drvmod=''
if [ -e "${mod_link}" ] ; then
drvmod="$(basename "$(readlink "${mod_link}")")"
newdrv="$drvmod $newdrv"
fi
done
if [ -s $drvfile ] ; then
olddrv=$(head -1 $drvfile)
fi
# Only update contents if they've changed.
if [ "$newdrv" != "$olddrv" ] ; then
echo "$newdrv" > $drvfile
# Force ureadahead to rebuild its block list.
rm -f /var/lib/ureadahead/pack
fi
end script