ecb1a8
kpatch: clarify that "kpatch unload" isn't supported
ecb1a8
ecb1a8
Add a user-prompt to the kpatch unload subcommand and make a similiar
ecb1a8
mention in the manual page.
ecb1a8
ecb1a8
Provide an undocumented force option so that QE and dev scripts can
ecb1a8
still run unload kpatch modules from scripts.
ecb1a8
ecb1a8
RHEL-only.
ecb1a8
ecb1a8
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
ecb1a8
diff -Nupr kpatch-0.6.1.old/kpatch/kpatch kpatch-0.6.1/kpatch/kpatch
ecb1a8
--- kpatch-0.6.1.old/kpatch/kpatch	2019-08-28 10:35:01.191259434 -0400
ecb1a8
+++ kpatch-0.6.1/kpatch/kpatch	2019-08-28 16:11:13.067926576 -0400
ecb1a8
@@ -49,8 +49,8 @@ usage () {
ecb1a8
 	echo >&2
ecb1a8
 	usage_cmd "load --all" "load all installed patch modules into the running kernel"
ecb1a8
 	usage_cmd "load <module>" "load patch module into the running kernel"
ecb1a8
-	usage_cmd "unload --all" "unload all patch modules from the running kernel"
ecb1a8
-	usage_cmd "unload <module>" "unload patch module from the running kernel"
ecb1a8
+	usage_cmd "unload --all (UNSUPPORTED)" "unload all patch modules from the running kernel"
ecb1a8
+	usage_cmd "unload <module> (UNSUPPORTED)" "unload patch module from the running kernel"
ecb1a8
 	echo >&2
ecb1a8
 	usage_cmd "info <module>" "show information about a patch module"
ecb1a8
 	echo >&2
ecb1a8
@@ -71,6 +71,16 @@ die() {
ecb1a8
 	exit 1
ecb1a8
 }
ecb1a8
 
ecb1a8
+confirm_prompt() {
ecb1a8
+	local prompt="$1"
ecb1a8
+	local answer
ecb1a8
+	while true; do
ecb1a8
+		read -rp "$prompt [Y/N] " answer
ecb1a8
+		[[ $answer == 'Y' || $answer == 'y' ]] && return 0
ecb1a8
+		[[ $answer == 'N' || $answer == 'n' ]] && return 1
ecb1a8
+	done
ecb1a8
+}
ecb1a8
+
ecb1a8
 __find_module () {
ecb1a8
 	MODULE="$1"
ecb1a8
 	[[ -f "$MODULE" ]] && return
ecb1a8
@@ -406,6 +416,19 @@ unset MODULE
ecb1a8
 init_sysfs_var
ecb1a8
 
ecb1a8
 [[ "$#" -lt 1 ]] && usage
ecb1a8
+
ecb1a8
+# RHEL-specific support options
ecb1a8
+case "$1" in
ecb1a8
+"force")
ecb1a8
+	# For scripting purposes, support "kpatch force unload".
ecb1a8
+	# Shift out the "force" to avoid the user-prompt check below.
ecb1a8
+	shift
ecb1a8
+	;;
ecb1a8
+"unload")
ecb1a8
+	confirm_prompt "WARNING: Red Hat doesn't support unloading of kpatches, continue anyway?" || exit 1
ecb1a8
+	;;
ecb1a8
+esac
ecb1a8
+
ecb1a8
 case "$1" in
ecb1a8
 "load")
ecb1a8
 	[[ "$#" -ne 2 ]] && usage
ecb1a8
diff -Nupr kpatch-0.6.1.old/man/kpatch.1 kpatch-0.6.1/man/kpatch.1
ecb1a8
--- kpatch-0.6.1.old/man/kpatch.1	2019-08-28 10:35:01.191259434 -0400
ecb1a8
+++ kpatch-0.6.1/man/kpatch.1	2019-08-28 14:51:23.268198897 -0400
ecb1a8
@@ -23,10 +23,10 @@ load --all
ecb1a8
 load <module>
ecb1a8
        load patch module into the running kernel
ecb1a8
 
ecb1a8
-unload --all
ecb1a8
+unload --all (UNSUPPORTED)
ecb1a8
        unload all patch modules from the running kernel
ecb1a8
 
ecb1a8
-unload <module>
ecb1a8
+unload <module> (UNSUPPORTED)
ecb1a8
        unload patch module from the running kernel
ecb1a8
 
ecb1a8
 info <module>