Whamcloud - gitweb
LU-17928 lnet: add kmod devel package 87/55387/7
authorShaun Tancheff <shaun.tancheff@hpe.com>
Wed, 10 Jul 2024 03:20:01 +0000 (10:20 +0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 17 Jul 2024 15:21:42 +0000 (15:21 +0000)
This creates a new kernel module development package for building
kernel modules that depend on the Lustre/LNet kAPI

The most notable of these is DVS which uses LNet

Along with the kernel includes add a package config file: lnet.pc
and the Module.symvers needed for linking against Lustre/LNet kAPI

Use:
   pkg-config --variable=symversdir lnet
to find the path to Module.symvers and include files.

In addition the dkms build can differ enough that the packaged
Module.symvers and config.h (and possibly the headers as well)
may diff enough that they are not interchangeable.

Use the update-alternatives subsystem to enable the dkms and kmp
packages to co-exist and the kmp-devel package to work with either.

Also loosens user space requirement to require:
 Lustre version >= major.minor
and not the exact build

Test-Parameters: trivial
HPE-bug-id: LUS-12246, LUS-12378, LUS-12351
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Signed-off-by: Caleb Carlson <caleb.carlson@hpe.com>
Change-Id: Idb00b881e8f6d4a703cc71fd0d8768e1f433fca3
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55387
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
autoMakefile.am
config/lustre-build.m4
lnet/utils/.gitignore
lnet/utils/Makefile.am
lnet/utils/lnet.pc.in [new file with mode: 0644]
lustre-dkms_post-build.sh
lustre-dkms_post-remove.sh [new file with mode: 0755]
lustre.spec.in
lustre/scripts/dkms.mkconf

index 5965eb2..62ebee6 100644 (file)
@@ -186,6 +186,7 @@ EXTRA_DIST = @PACKAGE_TARNAME@.spec \
        config.h.in                     \
        lustre-dkms_pre-build.sh        \
        lustre-dkms_post-build.sh       \
+       lustre-dkms_post-remove.sh      \
        LUSTRE-VERSION-GEN              \
        LUSTRE-VERSION-FILE             \
        undef.h                         \
index 737447a..3fd481b 100644 (file)
@@ -419,6 +419,7 @@ AC_DEFUN([LB_CONFIG_FILES], [
                AC_PACKAGE_TARNAME[-dkms.spec]
                ldiskfs/Makefile
                ldiskfs/autoMakefile
+               lnet/utils/lnet.pc
                lustre/utils/lustre.pc
                lustre-iokit/Makefile
                lustre-iokit/obdfilter-survey/Makefile
index bc0a39e..ec58fa3 100644 (file)
@@ -3,3 +3,4 @@
 /wirecheck
 /lnetctl
 /lst
+/lnet.pc
index 8c276c9..a75a6b3 100644 (file)
@@ -16,6 +16,9 @@ AM_LDFLAGS := -L. $(UTILS_LDFLAGS)
 
 SUBDIRS = lnetconfig
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = lnet.pc
+
 if UTILS
 sbin_PROGRAMS = routerstat lst lnetctl
 
diff --git a/lnet/utils/lnet.pc.in b/lnet/utils/lnet.pc.in
new file mode 100644 (file)
index 0000000..c25e9a8
--- /dev/null
@@ -0,0 +1,17 @@
+# For kABI and Module.symvers:
+#   pkg-config --variable=symversdir lnet
+# for user space utils use
+#   pkg-config --cflags --libs lnet
+#
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+version=@PACKAGE_VERSION@
+symversdir=${prefix}/src/lustre
+
+Cflags: -I${includedir}/libcfs -I${includedir}/lnet
+Libs: -L${libdir} -llnetconfig
+Description: Lustre Network API and kAPI
+Name: lnet-kapi
+Version: @PACKAGE_VERSION@
index bd4f788..e95d8a7 100755 (executable)
@@ -54,3 +54,40 @@ case $1 in
        done
        ;;
 esac
+
+flavor=$(echo $3 | tr '-' '\n' | tail -1)
+# for non-suse distros flavor should be 'default'
+elcheck=$(echo ${flavor} | tr '.' '\n' | tail -1)
+[[ ${elcheck} == $5 ]] && flavor='default'
+
+# includes for this kapi module:
+rm -fr $7/$1/$2/$3/$5/kapi
+kapi=$7/$1/$2/$3/$5/kapi/include
+mkdir -p ${kapi}/$5/$flavor
+ln -s $7/$1/$2/$3/$5/config.h ${kapi}/$5/$flavor
+ln -s $7/$1/$2/$3/$5/Module.symvers ${kapi}/$5/$flavor
+
+# LNet headers:
+for fname in $(find lnet/include -type f -name \*.h); do
+    target=$(echo ${fname} | sed -e 's:^lnet/include/::g')
+    if [[ ${target} == uapi/* ]]; then
+        header=$(echo ${target} | sed -e 's:^uapi/linux/lnet/::g')
+        install -D -m 0644 ${fname} ${kapi}/uapi/linux/lnet/${header}
+        install -D -m 0644 ${fname} ${kapi}/linux/lnet/${header}
+        >&2 echo "installing ${fname} => ${kapi}/uapi/linux/lnet/${header}"
+        >&2 echo "installing ${fname} => ${kapi}/linux/lnet/${header}"
+    else
+        install -D -m 0644 ${fname} ${kapi}/${target}
+        >&2 echo "installing ${fname} => ${kapi}/${target}"
+    fi
+done
+
+## Lustre headers:
+for fname in $(find libcfs/include/libcfs -type f -name \*.h); do
+    target=$(echo ${fname} | sed -e 's:^libcfs/include/::g')
+    install -D -m 0644 ${fname} ${kapi}/${target}
+    >&2 echo "installing ${fname} => ${kapi}/${target}"
+done
+
+alternatives --install /usr/src/lustre lustre ${kapi} 90
+
diff --git a/lustre-dkms_post-remove.sh b/lustre-dkms_post-remove.sh
new file mode 100755 (executable)
index 0000000..f41855b
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+#
+# This file is part of Lustre, http://www.lustre.org/
+#
+# lustre-dkms_post-remove.sh
+#
+# Script run after dkms remove
+#
+
+#
+# $1 : $module
+# $2 : $module_version
+# $3 : $kernelver
+# $4 : $kernel_source_dir
+# $5 : $arch
+# $6 : $source_tree
+# $7 : $dkms_tree
+# $8 : $kmoddir
+#
+
+kapi=$7/$1/$2/$3/$5/kapi/include
+alternatives --remove lustre ${kapi}
+rm -fr $7/$1/$2/$3/$5/kapi
index 44aba16..e875b7b 100644 (file)
                %global requires_kmod_tests_name kmod-%{lustre_name}-tests
        %endif
        %global requires_kmod_version %{version}
+       %global kmod_devel_pkg kmod-%{lustre_name}-devel
 #for Suse
 %else
        %global requires_kmod_name %{lustre_name}-kmp
        %else
                %global requires_kmod_version %{version}_%(echo %{krequires} | sed -r 'y/-/_/; s/^(2\.6\.[0-9]+)_/\\1.0_/;')
        %endif
+       %global kmod_devel_pkg %{lustre_name}-kmp-devel
 %endif
+%global requires_release_major_minor %(echo %version | cut -d. -f1).%(echo %version | cut -d. -f2)
 %endif
 
 # RHEL >= 7 comes with systemd
@@ -243,7 +246,11 @@ Source20: kmp-lnet-in-kernel-o2iblnd.files
 URL: https://wiki.whamcloud.com/
 BuildRoot: %{_tmppath}/lustre-%{version}-root
 %if %{with lustre_modules}
+%if 0%{?suse_version} < 1500 || 0%{?rhel} < 8 || 0%{?fedora} < 34
 Requires: %{requires_kmod_name} = %{requires_kmod_version}
+%else
+Requires: (%{lustre_name}-dkms or %{requires_kmod_name} >= %{requires_release_major_minor})
+%endif
 %endif
 %if %{with lustre_tests_lutf}
 Requires: python3 >= 3.6.0
@@ -388,8 +395,13 @@ BuildRequires: pkgconfig(mount)
 Provides: %{name}-osd-mount = %{version}
 Obsoletes: lustre-osd-mount < %{version}
 %if 0%{confzfsdobjpath} != 0
+%if 0%{?suse_version} < 1500 || 0%{?rhel} < 8 || 0%{?fedora} < 34
+# 'or' is not available so default is assuming 'zfs' is defined
+BuildRequires: libzfs%{?zfs}-devel
+%else
 BuildRequires: (libzfs-devel or libzfs4-devel or libzfs5-devel)
 %endif
+%endif
 # end confzfsdobjpath
 # Tests also require zpool from zfs package:
 Requires: zfs
@@ -425,7 +437,11 @@ Summary: Lustre include headers
 Provides: lustre-devel = %{version}
 Requires: %{lustre_name} = %{version}
 %if %{with lustre_modules}
-Requires: %{requires_kmod_name} = %{requires_kmod_version}
+%if 0%{?suse_version} < 1500 || 0%{?rhel} < 8 || 0%{?fedora} < 34
+Requires: %{requires_kmod_name} >= %{requires_release_major_minor}
+%else
+Requires: (%{lustre_name}-dkms or %{requires_kmod_name} >= %{requires_release_major_minor})
+%endif
 %endif
 
 %description devel
@@ -448,8 +464,12 @@ Requires: lustre-devel = %{version}
 Requires: python3 >= 3.6.0, python3-PyYAML
 %endif
 %if %{with lustre_modules}
+%if 0%{?suse_version} < 1500 || 0%{?rhel} < 8 || 0%{?fedora} < 34
 Requires: %{requires_kmod_name} = %{requires_kmod_version}
-Requires: %{requires_kmod_tests_name} = %{requires_kmod_version}
+%else
+Requires: (%{lustre_name}-dkms or %{requires_kmod_name} >= %{requires_release_major_minor})
+%endif
+Requires: %{requires_kmod_tests_name} >= %{requires_release_major_minor}
 %endif
 %if %{with lustre_tests_lutf}
 Requires: python3 >= 3.6.0
@@ -515,6 +535,17 @@ echo $TMPFILE
 # end multiple_lnds
 %endif
 
+%if %{with lustre_modules}
+%package -n %kmod_devel_pkg
+Summary: Includes and Module.symvers for kernel packages depending on Lustre/LNet
+
+%description -n %kmod_devel_pkg
+This package includes:
+  Module.symvers
+  package config file: lnet.pc
+  kernel headers
+%endif
+
 %if %{with lustre_iokit}
 %package -n %{lustre_name}-iokit
 Summary: Collection of benchmark tools for a cluster with the Lustre file system
@@ -733,6 +764,18 @@ make install DESTDIR=$RPM_BUILD_ROOT
 # kernel_module_path macro.
 basemodpath=$RPM_BUILD_ROOT%{modules_fs_path}/%{name}
 %{__install} -D -m 0644 ${PWD}/Module.symvers %{buildroot}/Module.symvers
+%if %{with lustre_modules}
+%{__install} -D -m 0644 ${PWD}/Module.symvers %{buildroot}/%{_usrsrc}/lustre-%{version}/%{_arch}/%{_flavor}/Module.symvers
+%{__install} -D -m 0644 ${PWD}/config.h %{buildroot}/%{_usrsrc}/lustre-%{version}/%{_arch}/%{_flavor}/config.h
+for fname in $(find lnet/include -type f -name \*.h); do
+       target=$(echo ${fname} | sed 's:^lnet/include/::g')
+       %{__install} -D -m 0644 ${fname} %{buildroot}/%{_usrsrc}/lustre-%{version}/${target}
+done
+for fname in $(find libcfs/include/libcfs -type f -name \*.h); do
+       target=$(echo ${fname} | sed -e 's:^libcfs/include/::g')
+       %{__install} -D -m 0644 ${fname} %{buildroot}/%{_usrsrc}/lustre-%{version}/${target}
+done
+%endif
 %if %{with ldiskfs}
 mkdir -p $basemodpath-osd-ldiskfs/fs
 mv $basemodpath/fs/osd_ldiskfs.ko $basemodpath-osd-ldiskfs/fs/osd_ldiskfs.ko
@@ -877,6 +920,12 @@ echo '%{_libdir}/lustre/tests/lutf/*' >>lustre-tests.files
 %exclude %{_includedir}/linux/lustre
 %endif
 
+%if %{with lustre_modules}
+%files -n %kmod_devel_pkg
+%{_libdir}/pkgconfig/lnet.pc
+%{_usrsrc}/lustre-%{version}
+%endif
+
 %files -f lustre.files
 %defattr(-,root,root)
 %{_sbindir}/*
@@ -1020,6 +1069,14 @@ echo '%{_libdir}/lustre/tests/lutf/*' >>lustre-tests.files
 %systemd_postun_with_restart lsvcgss.service
 %endif
 
+%if %{with lustre_modules}
+%post -n %kmod_devel_pkg
+alternatives --install %{_usrsrc}/lustre lustre %{_usrsrc}/lustre-%{version} 50
+
+%preun -n %kmod_devel_pkg
+alternatives --remove lustre %{_usrsrc}/lustre-%{version}
+%endif
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 rm -rf %{_tmppath}/kmp
index 47b5c54..8aacae8 100755 (executable)
@@ -29,6 +29,8 @@ PRE_BUILD="lustre-dkms_pre-build.sh \$module \$module_version \$kernelver \$kern
 # to ensure all just built Lustre kernel modules will be saved for further install
 POST_BUILD="lustre-dkms_post-build.sh \$module \$module_version \$kernelver \$kernel_source_dir \
         \$arch \$source_tree \$dkms_tree \$kmoddir"
+POST_REMOVE="lustre-dkms_post-remove.sh \$module \$module_version \$kernelver \$kernel_source_dir \
+        \$arch \$source_tree \$dkms_tree \$kmoddir"
 EOF
 if [ $pkgname = "lustre-zfs" -o $pkgname = "lustre-all" ] ; then
        cat >>${filename} <<EOF