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