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