From e1817b60bb60b98241124e32c5fca3eb36a3007a Mon Sep 17 00:00:00 2001 From: Stephen Bates Date: Thu, 1 Mar 2018 18:43:20 -0700 Subject: [PATCH] setup.sh: Add support for built-in modules setup.sh uses lsmod to detect if a module is present but this does not work when modules are built-in. We add a second check (on /sys/module/) and place the check in a function. We also change the sense of driver_loaded so it is more sane and also allows us to return different positive values depending on if the driver is a module or built-in. Change-Id: Iccc4dca212a6f04fb2ac9bd4768935f8b2bb240a Signed-off-by: Stephen Bates Reviewed-on: https://review.gerrithub.io/402178 Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- scripts/setup.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 90ceeef42..fa047e034 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -49,6 +49,23 @@ function usage() exit 0 } +# In monolithic kernels the lsmod won't work. So +# back that with a /sys/modules check. Return a different code for +# built-in vs module just in case we want that down the road. +function check_for_driver { + $(lsmod | grep $1 > /dev/null) + if [ $? -eq 0 ]; then + return 1 + else + if [[ -d /sys/module/$1 ]]; then + return 2 + else + return 0 + fi + fi + return 0 +} + function pci_can_bind() { if [[ ${#PCI_WHITELIST[@]} == 0 ]]; then #no whitelist specified, bind all devices @@ -275,7 +292,7 @@ function configure_linux { function reset_linux_pci { # NVMe set +e - lsmod | grep nvme > /dev/null + check_for_driver nvme driver_loaded=$? set -e for bdf in $(iter_pci_class_code 01 08 02); do @@ -283,7 +300,7 @@ function reset_linux_pci { echo "Skipping un-whitelisted NVMe controller $blkname ($bdf)" continue fi - if [ $driver_loaded -eq 0 ]; then + if [ $driver_loaded -ne 0 ]; then linux_bind_driver "$bdf" nvme else linux_unbind_driver "$bdf" @@ -297,7 +314,7 @@ function reset_linux_pci { | awk -F"x" '{print $2}' > $TMP set +e - lsmod | grep ioatdma > /dev/null + check_for_driver ioatdma driver_loaded=$? set -e for dev_id in `cat $TMP`; do @@ -306,7 +323,7 @@ function reset_linux_pci { echo "Skipping un-whitelisted I/OAT device at $bdf" continue fi - if [ $driver_loaded -eq 0 ]; then + if [ $driver_loaded -ne 0 ]; then linux_bind_driver "$bdf" ioatdma else linux_unbind_driver "$bdf"