Whamcloud - gitweb
LU-16359 build: RHEL use Module.symvers during find-provides 02/49302/4
authorShaun Tancheff <shaun.tancheff@hpe.com>
Fri, 2 Dec 2022 14:46:19 +0000 (08:46 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 13 Dec 2022 16:10:16 +0000 (16:10 +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.

Test-Parameters: trivial
HPE-bug-id: LUS-11383
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: I01c3b3692e6a2a6be86a6930eaead9df75147f90
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49302
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Petros Koutoupis <petros.koutoupis@hpe.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
.gitignore
lustre.spec.in
rpm/find-provides [new file with mode: 0755]
rpm/find-provides.ksyms [new file with mode: 0755]

index 6511188..56ccce0 100644 (file)
@@ -63,6 +63,8 @@ TAGS
 #
 # Top level generated files specific to this top level dir
 #
+/find-provides
+/find-provides.ksyms
 /.mergeinfo-*
 /.pc
 /.Xrefs-2.5
index 0dade50..16055a7 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}
@@ -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}
@@ -582,6 +590,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
@@ -778,7 +787,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 (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