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