From 89c494f023114464676d3c57d71a3555a70d4e00 Mon Sep 17 00:00:00 2001 From: "zhangyongde.zyd" Date: Wed, 17 Jan 2024 12:45:12 +0800 Subject: [PATCH 1/2] kpatch-build: simplify distro support Rather than adding yet another set of conditionals to handle the Anolis OS distribution, refactor the SUPPORTED_DISTROS code using an associative array. The array is keyed by the short distro name, and contains the longer distribution description. Signed-off-by: Wardenjohn --- kpatch-build/kpatch-build | 52 +++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 5e02faa..da4563e 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -65,6 +65,20 @@ LLD="${CROSS_COMPILE:-}ld.lld" READELF="${CROSS_COMPILE:-}readelf" OBJCOPY="${CROSS_COMPILE:-}objcopy" + +declare -rA SUPPORTED_DEB_DISTROS=( + ["debian"]="Debian OS" + ["ubuntu"]="Ubuntu OS") + +declare -rA SUPPORTED_RPM_DISTROS=( + ["centos"]="CentOS" + ["fedora"]="Fedora" + ["openEuler"]="OpenEuler" + ["ol"]="Oracle" + ["photon"]="Photon OS" + ["rhel"]="RHEL") + + warn() { echo "ERROR: $1" >&2 } @@ -649,6 +663,25 @@ module_name_string() { echo "${1//[^a-zA-Z0-9_-]/-}" | cut -c 1-55 } +is_supported_deb_distro(){ + [[ -n "${SUPPORTED_DEB_DISTROS[$1]:-}" ]] +} + +is_supported_rpm_distro(){ + [[ -n "${SUPPORTED_RPM_DISTROS[$1]:-}" ]] +} + +print_supported_distro(){ + if is_supported_deb_distro "$DISTRO"; then + echo "${SUPPORTED_DEB_DISTROS[$DISTRO]} distribution detected" + elif is_supported_rpm_distro "$DISTRO"; then + echo "${SUPPORTED_RPM_DISTROS[$DISTRO]} distribution detected" + else + echo "$DISTRO is not supported" + fi +} + + usage() { echo "usage: $(basename "$0") [options] " >&2 echo " patchN Input patchfile(s)" >&2 @@ -865,16 +898,14 @@ fi [[ -z "$TARGETS" ]] && TARGETS="vmlinux modules" -if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || - [[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] || - [[ "$DISTRO" = photon ]]; then +if is_supported_rpm_distro "$DISTRO"; then [[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux" [[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed" export PATH="/usr/lib64/ccache:$PATH" -elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then +elif is_supported_deb_distro "$DISTRO"; then [[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/boot/vmlinux-$ARCHVERSION" if [[ "$DISTRO" = ubuntu ]]; then @@ -906,14 +937,9 @@ elif [[ -e "$KERNEL_SRCDIR"/.config ]] && [[ -e "$VERSIONFILE" ]] && [[ "$(cat " echo "Using cache at $KERNEL_SRCDIR" else - if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] || [[ "$DISTRO" = photon ]]; then + if is_supported_rpm_distro "$DISTRO"; then - [[ "$DISTRO" = fedora ]] && echo "Fedora distribution detected" - [[ "$DISTRO" = rhel ]] && echo "RHEL distribution detected" - [[ "$DISTRO" = ol ]] && echo "Oracle Linux distribution detected" - [[ "$DISTRO" = centos ]] && echo "CentOS distribution detected" - [[ "$DISTRO" = openEuler ]] && echo "OpenEuler distribution detected" - [[ "$DISTRO" = photon ]] && echo "Photon OS distribution detected" + print_supported_distro "$DISTRO" clean_cache @@ -1009,9 +1035,9 @@ else (cd "$KERNEL_SRCDIR" && make mrproper 2>&1 | logger) || die - elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then + elif is_supported_deb_distro "$DISTRO"; then - echo "Debian/Ubuntu distribution detected" + print_supported_distro "$DISTRO" if [[ "$DISTRO" = ubuntu ]]; then From d51179299868b3509188ce6cea46e9f2871d5ae9 Mon Sep 17 00:00:00 2001 From: "zhangyongde.zyd" Date: Wed, 17 Jan 2024 12:46:34 +0800 Subject: [PATCH 2/2] kpatch-build: Support distro Anolis OS Support Anolis OS Signed-off-by: Wardenjohn --- kpatch-build/kpatch-build | 1 + test/integration/lib.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index da4563e..246a08b 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -71,6 +71,7 @@ declare -rA SUPPORTED_DEB_DISTROS=( ["ubuntu"]="Ubuntu OS") declare -rA SUPPORTED_RPM_DISTROS=( + ["anolis"]="Anolis OS" ["centos"]="CentOS" ["fedora"]="Fedora" ["openEuler"]="OpenEuler" diff --git a/test/integration/lib.sh b/test/integration/lib.sh index 961e588..036391b 100644 --- a/test/integration/lib.sh +++ b/test/integration/lib.sh @@ -120,6 +120,18 @@ kpatch_photon_dependencies() fi } +kpatch_anolis_dependencies() +{ + local kernel_version + local arch + kernel_version=$(uname -r) + arch=$(uname -m) + sudo yum install -y make gcc patch bison flex openssl-devel dwarves \ + rpm-build dnf-plugins-core python3-devel openssl-devel ncurses-devel elfutils-libelf-devel + sudo yum install -y "kernel-debuginfo-${kernel_version%.*}"\ + "kernel-devel-${kernel_version%.*}" +} + kpatch_dependencies() { # shellcheck disable=SC1091