mirror of
https://github.com/dynup/kpatch
synced 2025-02-12 07:27:04 +00:00
Merge pull request #790 from euspectre/retry-disable
If kpatch fails to disable a patch, retry a few times
This commit is contained in:
commit
07c7200cc9
@ -348,19 +348,44 @@ load_module () {
|
||||
return 0
|
||||
}
|
||||
|
||||
disable_patch () {
|
||||
local modname="$1"
|
||||
|
||||
local enabled="$SYSFS/$modname/enabled"
|
||||
[[ -e "$enabled" ]] || die "patch module $1 is not loaded"
|
||||
|
||||
if [[ "$(cat "$enabled")" -eq 1 ]]; then
|
||||
echo "disabling patch module: $modname"
|
||||
local i=0
|
||||
while true; do
|
||||
out="$(export LC_ALL=C; sh -c "echo 0 > $enabled" 2>&1)"
|
||||
[[ -z "$out" ]] && break
|
||||
echo "$out" 1>&2
|
||||
if [[ ! "$out" =~ "Device or resource busy" ]]; then
|
||||
die "failed to disable module $modname"
|
||||
fi
|
||||
|
||||
# "Device or resource busy" means the activeness safety check
|
||||
# failed. Retry in a few seconds.
|
||||
i=$((i+1))
|
||||
if [[ $i = $MAX_LOAD_ATTEMPTS ]]; then
|
||||
die "failed to disable module $modname"
|
||||
else
|
||||
warn "retrying..."
|
||||
sleep $RETRY_INTERVAL
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if ! wait_for_patch_transition "$modname" ; then
|
||||
die "transition stalled for $modname"
|
||||
fi
|
||||
}
|
||||
|
||||
unload_module () {
|
||||
PATCH="${1//-/_}"
|
||||
PATCH="${PATCH%.ko}"
|
||||
ENABLED="$SYSFS/$PATCH/enabled"
|
||||
[[ -e "$ENABLED" ]] || die "patch module $1 is not loaded"
|
||||
if [[ "$(cat "$ENABLED")" -eq 1 ]]; then
|
||||
echo "disabling patch module: $PATCH"
|
||||
echo 0 > "$ENABLED" || die "can't disable $PATCH"
|
||||
fi
|
||||
|
||||
if ! wait_for_patch_transition "$PATCH" ; then
|
||||
die "error: failed to unload module $PATCH (transition stalled)"
|
||||
fi
|
||||
disable_patch "$PATCH"
|
||||
|
||||
echo "unloading patch module: $PATCH"
|
||||
# ignore any error here because rmmod can fail if the module used
|
||||
|
Loading…
Reference in New Issue
Block a user