From 84ce33fbe16a2215600eb66beb08c9271115019f Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Thu, 26 Jan 2023 09:34:03 -0800 Subject: [PATCH] LU-16359 build: RHEL use Module.symvers during find-provides find-provides fails to find module versions on newer kernels. The generated Module.symvers is always generated and correct. Install it to the well known location BUILDROOT use it to generate provides and ignore it for installation. Create a new find-provides and find-provides.ksyms for lustre based on the one provided by the redhat-rpm-config package using Module.symvers to supply the symbol versions instead of extracting symbol versions from the .ko files. Lustre-change: https://review.whamcloud.com/49302 Lustre-commit: bb951b90268bb013b55166e1c0bcae1c2a66b165 Test-Parameters: trivial HPE-bug-id: LUS-11383 Signed-off-by: Shaun Tancheff Change-Id: I01c3b3692e6a2a6be86a6930eaead9df75147f90 Reviewed-by: Petros Koutoupis Reviewed-by: Jian Yu Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49785 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- .gitignore | 2 ++ lustre.spec.in | 11 ++++++++- rpm/find-provides | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ rpm/find-provides.ksyms | 44 +++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100755 rpm/find-provides create mode 100755 rpm/find-provides.ksyms diff --git a/.gitignore b/.gitignore index d9d43e0..e1e4bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,8 @@ TAGS # # Top level generated files specific to this top level dir # +/find-provides +/find-provides.ksyms /.mergeinfo-* /.pc /.Xrefs-2.5 diff --git a/lustre.spec.in b/lustre.spec.in index b67ca28..f4ac0c8 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -104,6 +104,12 @@ # response from them #%%global _use_internal_dependency_generator 0 +%if 0%{?rhel} > 7 || 0%{?fedora} > 33 +## SUSE uses another tool for provides: +## https://github.com/openSUSE/kernel-source/blob/master/patches.rpmify/Add-ksym-provides-tool.patch +%global __find_provides %{_sourcedir}/find-provides +%endif + # Set the package name prefix %if %{undefined lustre_name} %if %{with servers} @@ -185,6 +191,8 @@ Source4: kmp-lustre-osd-ldiskfs.files Source5: kmp-lustre-osd-zfs.preamble Source6: kmp-lustre-osd-zfs.files Source7: kmp-lustre-tests.files +Source8: find-provides +Source9: find-provides.ksyms URL: https://wiki.whamcloud.com/ BuildRoot: %{_tmppath}/lustre-%{version}-root %if %{with lustre_modules} @@ -575,6 +583,7 @@ make install DESTDIR=$RPM_BUILD_ROOT # Lustre's build system. This is not expected to bother SLES's # kernel_module_path macro. basemodpath=$RPM_BUILD_ROOT%{modules_fs_path}/%{name} +%{__install} -D -m 0644 ${PWD}/Module.symvers %{buildroot}/Module.symvers %if %{with ldiskfs} mkdir -p $basemodpath-osd-ldiskfs/fs mv $basemodpath/fs/osd_ldiskfs.ko $basemodpath-osd-ldiskfs/fs/osd_ldiskfs.ko @@ -769,7 +778,7 @@ echo '%{_libdir}/lustre/tests/lutf/*' >>lustre-tests.files %config(noreplace) %{_sysconfdir}/lnet_routes.conf %endif %if %{with lustre_modules} - +%exclude /Module.symvers %if %{with shared} %if %{with ldiskfs} %if %{with lustre_utils} diff --git a/rpm/find-provides b/rpm/find-provides new file mode 100755 index 0000000..e0738e0 --- /dev/null +++ b/rpm/find-provides @@ -0,0 +1,62 @@ +#!/bin/bash + +# This script reads filenames from STDIN and outputs any relevant provides +# information that needs to be included in the package. + +if [ "$1" ] +then + package_name="$1" +fi + +filelist=`sed "s/['\"]/\\\&/g"` + +[ -x /usr/lib/rpm/rpmdeps -a -n "$filelist" ] && + echo $filelist | tr '[:blank:]' \\n | /usr/lib/rpm/rpmdeps --provides + +# +# --- any other extra find-provides scripts +for i in /usr/lib/rpm/redhat/find-provides.d/*.prov +do + [ -x $i ] && + (echo $filelist | tr '[:blank:]' \\n | $i | sort -u) +done + +# +# --- Kernel module imported symbols +# +# Since we don't (yet) get passed the name of the package being built, we +# cheat a little here by looking first for a kernel, then for a kmod. +# + +is_kmod=1 +for f in $filelist; do + if [ $(echo "$f" | sed -r -ne 's:^.*/lib/modules/(.*)/(.*)\.ko(\.gz|\.bz2|\.xz)?$:\2:p') ] + then + is_kernel=1; + fi + if [ $(echo "$f" | sed -r -ne 's:^.*/boot/(.*):\1:p') ] + then + unset is_kmod; + fi +done +if [ ! "$is_kernel" ] || [ "$package_name" == "kernel" ] +then + unset is_kmod +fi + +FIND_PROVIDES_KSYMS=/usr/lib/rpm/redhat/find-provides.ksyms +MODULE_SYMVERS=$RPM_BUILD_ROOT/Module.symvers +if [[ -f $MODULE_SYMVERS ]] ; then + _sourcedir=$(realpath $(dirname "$0")) + FIND_PROVIDES_KSYMS=$_sourcedir/find-provides.ksyms +else + >&2 echo "*****************************************************************" + >&2 echo "$MODULE_SYMVERS not found." + >&2 echo "Falling back to redhad find-provides.ksyms" + >&2 echo "*****************************************************************" +fi + +[ -x $FIND_PROVIDES_KSYMS ] && [ "$is_kmod" ] && + printf "%s\n" "${filelist[@]}" | $FIND_PROVIDES_KSYMS + +exit 0 diff --git a/rpm/find-provides.ksyms b/rpm/find-provides.ksyms new file mode 100755 index 0000000..7f4c863 --- /dev/null +++ b/rpm/find-provides.ksyms @@ -0,0 +1,44 @@ +#! /bin/bash + +IFS=$'\n' + +MODULE_SYMVERS=$RPM_BUILD_ROOT/Module.symvers + +for module in $(grep -E '/lib/modules/.+\.ko(\.gz|\.bz2|\.xz)?$'); do + tmpfile="" + if [ "x${module%.ko}" = "x${module}" ]; then + tmpfile=$(mktemp -t ${0##*/}.XXXXXX.ko) + proc_bin= + case "${module##*.}" in + xz) + proc_bin=xz + ;; + bz2) + proc_bin=bzip2 + ;; + gz) + proc_bin=gzip + ;; + esac + + [ -n "$proc_bin" ] || continue + + "$proc_bin" -d -c - < "$module" > "$tmpfile" || continue + module="$tmpfile" + fi + + if [[ -f $MODULE_SYMVERS ]] ; then + # all symbols prefixed with __rcr_ where the symbol is: + # A - symbol is an absolute value + # D,d - symbol is in the initialized data section + # R,r - symbol is in the read-only data section + # T,t - symbol is in the text (code) section + for sym in $(nm $module | sed -r -ne 's:^0*([0-9a-f]+) [ADdRr] __crc_(.+):\2:p'); do + grep -w $sym $MODULE_SYMVERS | awk '{printf("ksym(%s) = %08s\n", $2, $1)}' + done \ + | LC_ALL=C sort -u + else + >&2 echo "Module.symvers required for provides." + fi + [ -z "$tmpfile" ] || rm -f -- "$tmpfile" +done -- 1.8.3.1