From 1431ea025cb1af2d8c038cfd02a085afe3f7efb6 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Wed, 14 Oct 2020 10:36:41 +0200 Subject: [PATCH] scripts/setup: Handle kenv while looking up contigmem opts In case contigmem is loaded, but the kernel environment hasn't been properly updated with hw.contigmem.* options, kenv will fail, breaking the check to determine if contigmem should be unloaded. Avoid the above scenario by determining first if given option is actually set in kernel's environment. Change-Id: I4118b7622fd876b28f0c07d081c583f5782f0357 Signed-off-by: Michal Berger Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4656 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- scripts/setup.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index ec54882a8..e8b897bc7 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -646,7 +646,13 @@ function configure_freebsd() { # If contigmem is already loaded but the HUGEMEM specified doesn't match the # previous value, unload contigmem so that we can reload with the new value. if kldstat -q -m contigmem; then - if [ $(kenv hw.contigmem.num_buffers) -ne "$((HUGEMEM / 256))" ]; then + # contigmem may be loaded, but the kernel environment doesn't have to + # be necessarily set at this point. If it isn't, kenv will fail to + # pick up the hw. options. Handle it. + if ! contigmem_num_buffers=$(kenv hw.contigmem.num_buffers); then + contigmem_num_buffers=-1 + fi 2> /dev/null + if ((contigmem_num_buffers != HUGEMEM / 256)); then kldunload contigmem.ko fi fi