Whamcloud - gitweb
LU-16359 build: RHEL use Module.symvers during find-provides
authorShaun Tancheff <shaun.tancheff@hpe.com>
Tue, 31 Jan 2023 08:28:47 +0000 (00:28 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 16 Feb 2023 21:16:49 +0000 (21:16 +0000)
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 <shaun.tancheff@hpe.com>
Change-Id: I01c3b3692e6a2a6be86a6930eaead9df75147f90
Reviewed-by: Petros Koutoupis <petros.koutoupis@hpe.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/49836
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
.gitignore
lustre.spec.in
rpm/find-provides [new file with mode: 0755]
rpm/find-provides.ksyms [new file with mode: 0755]

index 4ea9363..046d04c 100644 (file)
@@ -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
index 60ac32e..17a93e8 100644 (file)
 # 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}
@@ -208,6 +214,8 @@ Source8: kmp-lustre-o2ib-mlnx.preamble
 Source9: kmp-lustre-o2ib-mlnx.files
 Source10: kmp-lustre-o2ib-ofed.preamble
 Source11: kmp-lustre-o2ib-ofed.files
+Source12: find-provides
+Source13: find-provides.ksyms
 URL: https://wiki.whamcloud.com/
 BuildRoot: %{_tmppath}/lustre-%{version}-root
 %if %{with lustre_modules}
@@ -769,6 +777,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 mlnx}
        #This is a bit ugly though..
        cp lnet/klnds/o2iblnd/autoMakefile lnet/klnds/o2iblnd-mlnx
@@ -953,7 +962,7 @@ fi
 %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 (executable)
index 0000000..e0738e0
--- /dev/null
@@ -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 (executable)
index 0000000..7f4c863
--- /dev/null
@@ -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