Skip to content

Commit

Permalink
drbd: build dkms package for RPM distros
Browse files Browse the repository at this point in the history
Also build the DKMS package for RPM distros that support it. This is by default
available on amazonlinux, RHEL derived distros can use EPEL to get the required
dkms base package.

To make the dkms config available for builds, we move it to misc/. One subtle
change is that we now have a symlink in debian/ pointing to misc/. The default
options for "tar --transform" break this link, as the transformation is also
applied to the symlink target. So we have to tell tar to ignore symlink targets
for this command.
  • Loading branch information
WanzenBug committed Dec 5, 2024
1 parent 2da6f52 commit cd81ec6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ tgz:
$(if $(GITHEAD),$(if $(GITDIFF),,--pax-option=comment=$(GITHEAD))) \
$(tgz-extra-files) \
-T .filelist \
--transform 's,^,drbd-$(FDIST_VERSION)/,' \
--transform 's,^,drbd-$(FDIST_VERSION)/,S' \
> drbd-$(FDIST_VERSION).tar.gz

ifeq ($(FORCE),)
Expand Down
39 changes: 0 additions & 39 deletions debian/drbd-dkms.dkms

This file was deleted.

1 change: 1 addition & 0 deletions debian/drbd-dkms.dkms
45 changes: 44 additions & 1 deletion drbd-kernel.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Release: 1
# always require a suitable userland
Requires: drbd-utils >= 9.27.0

# Store the version, as later macros may mangle it
%global drbd_version %version
%global tarball_version %(echo "%{version}" | sed -e "s,%{?dist}$,," -e "s,~,-,")
Source: http://oss.linbit.com/drbd/drbd-%{tarball_version}.tar.gz
Source: http://pkg.linbit.com/downloads/drbd/9/drbd-%{tarball_version}.tar.gz

License: GPLv2+
Group: System Environment/Kernel
Expand All @@ -27,6 +29,9 @@ BuildRequires: %kernel_module_package_buildreqs
# rpmbuild --with gcov to set GCOV_PROFILE=y for make
%bcond_with gcov

# rpmbuild --with dkms to build drbd-dkms package
%bcond_with dkms

# rpmbuild --define "ofed_kernel_dir /usr/src/ofa_kernel/x86_64/4.18.0-147.5.1..."
# to build against an some mlnx-ofa_kernel-devel
%if %{defined ofed_kernel_dir}
Expand All @@ -38,6 +43,19 @@ BuildRequires: %kernel_module_package_buildreqs
%global dash_ofed -ofed
%endif

%if %{with dkms}
# Define this package here before kernel macros mess with the version
%package -n drbd-dkms
Summary: %{summary}
BuildArch: noarch
Requires: dkms
Requires: /usr/bin/diff
Requires: /usr/bin/patch

%description -n drbd-dkms
This package contains the sources for DRBD for building with DKMS.
%endif

%description
This package contains the kernel modules
for the DRBD core and various transports.
Expand Down Expand Up @@ -174,9 +192,34 @@ xargs -r printf "override %%-16s * weak-updates/%%s\n" \
install -D misc/SECURE-BOOT-KEY-linbit.com.der $RPM_BUILD_ROOT/etc/pki/linbit/SECURE-BOOT-KEY-linbit.com.der
%endif

%if %{with dkms}
# For DKMS, install the original source
%{__install} -d %{buildroot}%{_usrsrc}/drbd-%{drbd_version}-%{release}/src
%{__install} misc/dkms.conf %{buildroot}%{_usrsrc}/drbd-%{drbd_version}-%{release}/dkms.conf
tar -xvf %{S:0} -C %{buildroot}%{_usrsrc}/drbd-%{drbd_version}-%{release}/src --strip-components=1 drbd-%{tarball_version}/drbd
%endif

%clean
rm -rf %{buildroot}

%if %{with dkms}
%files -n drbd-dkms
%{_usrsrc}/drbd-%{drbd_version}-%{release}

%post -n drbd-dkms
DKMS_NAME=drbd
DKMS_VERSION=%{drbd_version}-%{release}
if [ $1 -gt 1 ] ; then
UPGRADE="1"
fi
/usr/lib/dkms/common.postinst $DKMS_NAME $DKMS_VERSION /usr/share/$DKMS_NAME-$DKMS_VERSION "" $UPGRADE

%preun -n drbd-dkms
DKMS_NAME=drbd
DKMS_VERSION=%{drbd_version}-%{release}
dkms remove -m $DKMS_NAME -v $DKMS_VERSION --all
%endif

%changelog
* Mon Nov 18 2024 Philipp Reisner <[email protected]> - 9.2.12
- New upstream release.
Expand Down
39 changes: 39 additions & 0 deletions misc/dkms.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PACKAGE_VERSION="#MODULE_VERSION#"
PACKAGE_NAME="drbd"
MAKE="make -C src/drbd KDIR=/lib/modules/$kernelver/build"
CLEAN="make -C src/drbd clean KDIR=/lib/modules/$kernelver/build"
AUTOINSTALL="yes"

BUILT_MODULE_NAME[0]="drbd"
BUILT_MODULE_NAME[1]="drbd_transport_tcp"
BUILT_MODULE_NAME[2]="drbd_transport_lb-tcp"
BUILT_MODULE_LOCATION[0]="./src/drbd/build-current/"
BUILT_MODULE_LOCATION[1]="./src/drbd/build-current/"
BUILT_MODULE_LOCATION[2]="./src/drbd/build-current/"
DEST_MODULE_LOCATION[0]="/kernel/drivers/block/drbd"
DEST_MODULE_LOCATION[1]="/kernel/drivers/block/drbd"
DEST_MODULE_LOCATION[2]="/kernel/drivers/block/drbd"

IDX=3

if grep -q ^CONFIG_INFINIBAND= /lib/modules/$kernelver/build/.config; then
BUILT_MODULE_NAME[$IDX]="drbd_transport_rdma"
BUILT_MODULE_LOCATION[$IDX]="./src/drbd/build-current/"
DEST_MODULE_LOCATION[$IDX]="/kernel/drivers/block/drbd"
IDX=$(($IDX + 1))
fi

test -z $BUILD_OFED &&
test -e /usr/src/ofa_kernel/default/Module.symvers &&
modinfo mlx_compat &>/dev/null &&
MAKE+=" BUILD_OFED=1"

# See drbd/Kbuild: this is that check for the kernel version, but worse: check for kernel >= 4.17
IFS=".-" read -ra KVER <<< "$kernelver"
if [ "${KVER[0]}" -ge 4 ] && ( [ "${KVER[0]}" -gt 4 ] || [ "${KVER[1]}" -ge 17 ] ) ; then
if grep -q ^CONFIG_TLS= /lib/modules/$kernelver/build/.config && ! grep -q ^CONFIG_NET_HANDSHAKE= /lib/modules/$kernelver/build/.config ; then
BUILT_MODULE_NAME[$IDX]="handshake"
BUILT_MODULE_LOCATION[$IDX]="./src/drbd/build-current/drbd-kernel-compat/handshake"
DEST_MODULE_LOCATION[$IDX]="/kernel/net/handshake"
fi
fi

0 comments on commit cd81ec6

Please sign in to comment.