From 2ac771fbe2d58308d3611a82b57c84ffd3e1476b Mon Sep 17 00:00:00 2001 From: Evgenii Shatokhin Date: Thu, 8 Feb 2018 14:44:23 +0300 Subject: [PATCH 1/2] kpatch: set LC_ALL=C explicitly when loading the patch module kpatch checks the messages output by insmod to decide if loading failed with -EBUSY (i.e. activeness safety check failed). It looks for "Device or resource busy" message, but one cannot guarantee it is not output in some other language. Let us use LC_ALL=C to be sure. Signed-off-by: Evgenii Shatokhin --- kpatch/kpatch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch/kpatch b/kpatch/kpatch index 9040dc9..89328e2 100755 --- a/kpatch/kpatch +++ b/kpatch/kpatch @@ -316,7 +316,7 @@ load_module () { echo "loading patch module: $module" local i=0 while true; do - out="$(insmod "$module" 2>&1)" + out="$(LC_ALL=C insmod "$module" 2>&1)" [[ -z "$out" ]] && break echo "$out" 1>&2 [[ ! "$out" =~ "Device or resource busy" ]] && From 58cc8fc626653ea34ff568dbad0174996ebc9650 Mon Sep 17 00:00:00 2001 From: Evgenii Shatokhin Date: Thu, 8 Feb 2018 14:59:00 +0300 Subject: [PATCH 2/2] kpatch: make it easier to tune the number of attempts to load the patch ... and the interval between the retries. If activeness safety check fails and the patch fails to load, kpatch waits for 2 seconds and then retries loading of that patch. It may be needed to change the number of retries and the interval between them in some cases, e.g. during stress testing of patches, etc. Make it a bit easier by keeping these values in the variables close to the beginning of the script. Signed-off-by: Evgenii Shatokhin --- kpatch/kpatch | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kpatch/kpatch b/kpatch/kpatch index 89328e2..6dd26e0 100755 --- a/kpatch/kpatch +++ b/kpatch/kpatch @@ -29,6 +29,11 @@ VERSION="0.5.0" POST_ENABLE_WAIT=5 # seconds POST_SIGNAL_WAIT=60 # seconds +# How many times to try loading the patch if activeness safety check fails. +MAX_LOAD_ATTEMPTS=5 +# How long to wait before retry, in seconds. +RETRY_INTERVAL=2 + usage_cmd() { printf ' %-20s\n %s\n' "$1" "$2" >&2 } @@ -325,12 +330,12 @@ load_module () { # "Device or resource busy" means the activeness safety check # failed. Retry in a few seconds. i=$((i+1)) - if [[ $i = 5 ]]; then + if [[ $i = $MAX_LOAD_ATTEMPTS ]]; then die "failed to load module $module" break else warn "retrying..." - sleep 2 + sleep $RETRY_INTERVAL fi done