#5 SUSE kernel module package -kmp convention
Opened 2 months ago by stancheff. Modified a month ago
rpms/ stancheff/kmodtool suse-kmp-package-naming  into  master

file modified
+82 -50

@@ -38,6 +38,10 @@ 

  prefix=

  filterfile=

  target=

+ postfix_kmp=0

+ if [[ -f /etc/SuSE-release ]] || [[ -f /etc/SUSE-brand ]] ; then

+ 	postfix_kmp=1

+ fi

  

  error_out()

  {

@@ -59,9 +63,28 @@ 

  	echo

  }

  

+ kmod_kmp_package()

+ {

+ 	# Fedora kmod naming convention

+ 	kmod_pkg_name="kmod-${kmodname}"

+ 	pkg_kmod_name="${kmodname}-kmod"

+ 	if [[ ${obsolete_name} ]] ; then

+ 		kmod_obsolete="kmod-${obsolete_name}"

+ 	fi

+ 	# postfix kmp naming convention (Ex: SUSE and openSUSE)

+ 	if [[ ${postfix_kmp} -ne 0 ]] ; then

+ 		kmod_pkg_name="${kmodname}-kmp"

+ 		pkg_kmod_name="${kmodname}-kmp"

+ 		if [[ ${obsolete_name} ]] ; then

+ 			kmod_obsolete="${obsolete_name}-kmp"

+ 		fi

+ 	fi

+ }

+ 

  print_akmodtemplate ()

  {

  	echo

+ 	kmod_kmp_package

  	cat <<EOF

  

  %global akmod_install mkdir -p \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/; \\\

@@ -69,7 +92,7 @@ 

  --define "_srcrpmdir \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/" \\\

  %{?dist:--define 'dist %{dist}}' \\\

  -bs --nodeps %{_specdir}/%{name}.spec ; \\\

- ln -s \$(ls \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/) \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/${kmodname}-kmod.latest

+ ln -s \$(ls \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/) \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/${pkg_kmod_name}.latest

  

  %package       -n akmod-${kmodname}

  Summary:          Akmod package for ${kmodname} kernel module(s)

@@ -77,8 +100,8 @@ 

  Requires:         akmods

  %{?AkmodsBuildRequires:Requires: %{AkmodsBuildRequires}}

  # same requires and provides as a kmods package would have

- Requires:         ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}

- Provides:         ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}

+ Requires:         ${pkg_kmod_name}-common >= %{?epoch:%{epoch}:}%{version}

+ Provides:         ${pkg_kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}

  EOF

  

  	if [[ ${obsolete_name} ]] ; then

@@ -95,7 +118,7 @@ 

  nohup /usr/sbin/akmods --from-akmod-posttrans --akmod ${kmodname} &> /dev/null &

  

  %post     -n akmod-${kmodname}

- [ -x /usr/sbin/akmods-ostree-post ] && /usr/sbin/akmods-ostree-post ${kmodname} %{_usrsrc}/akmods/${kmodname}-kmod-%{version}-%{release}.src.rpm

+ [ -x /usr/sbin/akmods-ostree-post ] && /usr/sbin/akmods-ostree-post ${kmodname} %{_usrsrc}/akmods/${pkg_kmod_name}-%{version}-%{release}.src.rpm

  

  %files         -n akmod-${kmodname}

  %defattr(-,root,root,-)

@@ -105,30 +128,31 @@ 

  

  print_akmodmeta ()

  {

+ 	kmod_kmp_package

  	cat <<EOF

  

- %package       -n kmod-${kmodname}

+ %package       -n ${kmod_pkg_name}

  Summary:          Metapackage which tracks in ${kmodname} kernel module for newest kernel${dashvariant}

  

- Provides:         ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}

- Provides:         kmod-${kmodname}-xen = %{?epoch:%{epoch}:}%{version}-%{release}

- Provides:         kmod-${kmodname}-smp = %{?epoch:%{epoch}:}%{version}-%{release}

- Provides:         kmod-${kmodname}-PAE = %{?epoch:%{epoch}:}%{version}-%{release}

+ Provides:         ${pkg_kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}

+ Provides:         ${kmod_pkg_name}-xen = %{?epoch:%{epoch}:}%{version}-%{release}

+ Provides:         ${kmod_pkg_name}-smp = %{?epoch:%{epoch}:}%{version}-%{release}

+ Provides:         ${kmod_pkg_name}-PAE = %{?epoch:%{epoch}:}%{version}-%{release}

Are we sure this scheme is correct for SUSE KMPs? I recall that the naming convention for kernels in SUSE distributions might be slightly wonky...

  Requires:         akmod-${kmodname} = %{?epoch:%{epoch}:}%{version}-%{release}

  EOF

  

  	if [[ ${obsolete_name} ]] ; then

- 		echo "Provides:         kmod-${obsolete_name} = ${obsolete_version}"

- 		echo "Obsoletes:        kmod-${obsolete_name} < ${obsolete_version}"

+ 		echo "Provides:         ${kmod_obsolete} = ${obsolete_version}"

+ 		echo "Obsoletes:        ${kmod_obsolete} < ${obsolete_version}"

  	fi

  	cat <<EOF

  

- %description   -n kmod-${kmodname}${dashvariant}

+ %description   -n ${kmod_pkg_name}${dashvariant}

  This is a meta-package without payload which sole purpose is to require the

  ${kmodname} kernel module(s) for the newest kernel${dashvariant},

  to make sure you get it together with a new kernel.

  

- %files         -n kmod-${kmodname}${dashvariant}

+ %files         -n ${kmod_pkg_name}${dashvariant}

  %defattr(644,root,root,755)

  EOF

  }

@@ -155,25 +179,27 @@ 

  		echo '%global  _prefix_usr      '/usr

  	fi

  

+ 	kmod_kmp_package

+ 

      # first part

  	cat <<EOF

  

  %if 0%{?rhel}

- %package       -n kmod-${kmodname}

+ %package       -n ${kmod_pkg_name}

  Summary:          ${kmodname} kernel module(s) for ${kernel_uname_r_short}

  Provides:         kernel-modules = ${kernel_uname_r}

- Provides:         ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}

- Requires:         ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}

+ Provides:         ${pkg_kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}

+ Requires:         ${pkg_kmod_name}-common >= %{?epoch:%{epoch}:}%{version}

  Requires(post):   %{?_prefix_usr}/sbin/weak-modules

  Requires(post):   %{?_prefix_usr}/sbin/depmod

  Requires(postun): %{?_prefix_usr}/sbin/weak-modules

  Requires(postun): %{?_prefix_usr}/sbin/depmod

  %else

- %package       -n kmod-${kmodname}-${kernel_uname_r}

+ %package       -n ${kmod_pkg_name}-${kernel_uname_r}

  Summary:          ${kmodname} kernel module(s) for ${kernel_uname_r}

  Provides:         kernel-modules-for-kernel = ${kernel_uname_r}

- Provides:         ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}

- Requires:         ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}

+ Provides:         ${pkg_kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}

+ Requires:         ${pkg_kmod_name}-common >= %{?epoch:%{epoch}:}%{version}

  Requires(post):   %{?_prefix_usr}/sbin/depmod

  Requires(postun): %{?_prefix_usr}/sbin/depmod

  %endif

@@ -181,8 +207,8 @@ 

  

  	if [[ ${obsolete_name} ]] ; then

  		echo

- 		echo "Provides:         kmod-${obsolete_name}-${kernel_uname_r} = ${obsolete_version}"

- 		echo "Obsoletes:        kmod-${obsolete_name}-${kernel_uname_r} < ${obsolete_version}"

+ 		echo "Provides:         ${kmod_obsolete}-${kernel_uname_r} = ${obsolete_version}"

+ 		echo "Obsoletes:        ${kmod_obsolete}-${kernel_uname_r} < ${obsolete_version}"

  	fi

  

  	# second part

@@ -217,28 +243,28 @@ 

  Requires:         kernel < ${kernel_uname_r_short_plus_one}

  BuildRequires:    kernel-devel = ${kernel_uname_r_wo_arch} redhat-rpm-config kernel-abi-whitelists

  

- %post          -n kmod-${kmodname}

+ %post          -n ${kmod_pkg_name}

  %{_kmodtool_depmod_post}

  

  modules=( \$(find ${usr_lib_modules}/${kernel_uname_r}/extra/${kmodname}/ | grep -e '\.ko$') )

  printf '%s\n' "\${modules[@]}" | %{?_prefix_usr}/sbin/weak-modules --add-modules

  

- %preun         -n kmod-${kmodname}

- rpm -ql kmod-${kmodname}-%{version}-%{release}.$(arch) | grep -e '\.ko$' > /var/run/rpm-kmod-${kmodname}-modules

+ %preun         -n ${kmod_pkg_name}

+ rpm -ql ${kmod_pkg_name}-%{version}-%{release}.$(arch) | grep -e '\.ko$' > /var/run/rpm-${kmod_pkg_name}-modules

  

- %postun        -n kmod-${kmodname}

+ %postun        -n ${kmod_pkg_name}

  %{_kmodtool_depmod_post}

  

- modules=( \$(cat /var/run/rpm-kmod-${kmodname}-modules) )

- rm /var/run/rpm-kmod-${kmodname}-modules

+ modules=( \$(cat /var/run/rpm-${kmod_pkg_name}-modules) )

+ rm /var/run/rpm-${kmod_pkg_name}-modules

  printf '%s\n' "\${modules[@]}" | %{?_prefix_usr}/sbin/weak-modules --remove-modules

  %else

  Requires:         kernel-uname-r = ${kernel_uname_r}

  BuildRequires:    kernel-devel-uname-r = ${kernel_uname_r}

  BuildRequires:    gcc

- %post          -n kmod-${kmodname}-${kernel_uname_r}

+ %post          -n ${kmod_pkg_name}-${kernel_uname_r}

  %{_kmodtool_depmod_post}

- %postun        -n kmod-${kmodname}-${kernel_uname_r}

+ %postun        -n ${kmod_pkg_name}-${kernel_uname_r}

  %{_kmodtool_depmod_post}

  %endif

  EOF

@@ -246,7 +272,7 @@ 

  		cat <<EOF

  

  %if 0%{?rhel}

- %post          -n kmod-${kmodname}

+ %post          -n ${kmod_pkg_name}

  [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] && %{?_prefix_usr}/sbin/depmod -a > /dev/null || :

  

  if [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] ; then

@@ -254,23 +280,23 @@ 

    printf '%s\n' "\${modules[@]}" | %{?_prefix_usr}/sbin/weak-modules --add-modules

  fi

  

- %preun         -n kmod-${kmodname}

+ %preun         -n ${kmod_pkg_name}

  if [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] ; then

-   rpm -ql kmod-${kmodname}-%{version}-%{release}.$(arch) | grep -e '\.ko$' > /var/run/rpm-kmod-${kmodname}-modules

+   rpm -ql ${kmod_pkg_name}-%{version}-%{release}.$(arch) | grep -e '\.ko$' > /var/run/rpm-${kmod_pkg_name}-modules

  fi

  

- %postun        -n kmod-${kmodname}

+ %postun        -n ${kmod_pkg_name}

  [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] && %{?_prefix_usr}/sbin/depmod -a > /dev/null || :

  

  if [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] ; then

-   modules=( \$(cat /var/run/rpm-kmod-${kmodname}-modules) )

-   rm /var/run/rpm-kmod-${kmodname}-modules

+   modules=( \$(cat /var/run/rpm-${kmod_pkg_name}-modules) )

+   rm /var/run/rpm-${kmod_pkg_name}-modules

    printf '%s\n' "\${modules[@]}" | %{?_prefix_usr}/sbin/weak-modules --remove-modules

  fi

  %else

- %post          -n kmod-${kmodname}-${kernel_uname_r}

+ %post          -n ${kmod_pkg_name}-${kernel_uname_r}

  [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] && %{?_prefix_usr}/sbin/depmod -a > /dev/null || :

- %postun        -n kmod-${kmodname}-${kernel_uname_r}

+ %postun        -n ${kmod_pkg_name}-${kernel_uname_r}

  [[ "\$(uname -r)" == "${kernel_uname_r}"  ]] && %{?_prefix_usr}/sbin/depmod -a > /dev/null || :

  %endif

  EOF

@@ -280,18 +306,18 @@ 

  	cat <<EOF

  

  %if 0%{?rhel}

- %description   -n kmod-${kmodname}

+ %description   -n ${kmod_pkg_name}

  This package provides the ${kmodname} kernel modules built for the Linux

  kernel ${kernel_uname_r_short} for the %{_target_cpu} family of processors.

- %files         -n kmod-${kmodname}

+ %files         -n ${kmod_pkg_name}

  %defattr(644,root,root,755)

  %dir ${usr_lib_modules}/${kernel_uname_r}/extra

  ${usr_lib_modules}/${kernel_uname_r}/extra/${kmodname}/

  %else

- %description   -n kmod-${kmodname}-${kernel_uname_r}

+ %description   -n ${kmod_pkg_name}-${kernel_uname_r}

  This package provides the ${kmodname} kernel modules built for the Linux

  kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.

- %files         -n kmod-${kmodname}-${kernel_uname_r}

+ %files         -n ${kmod_pkg_name}-${kernel_uname_r}

  %defattr(644,root,root,755)

  %dir ${usr_lib_modules}/${kernel_uname_r}/extra

  ${usr_lib_modules}/${kernel_uname_r}/extra/${kmodname}/

@@ -303,29 +329,30 @@ 

  {

  		local kernel_uname_r=${1}

  		local kernel_variant="${2:+-${2}}"

+ 		kmod_kmp_package

  

  		cat <<EOF

  

- %package       -n kmod-${kmodname}${kernel_variant}

+ %package       -n ${kmod_pkg_name}${kernel_variant}

  Summary:          Metapackage which tracks in ${kmodname} kernel module for newest kernel${kernel_variant}

  

- Provides:         ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}

- Requires:         kmod-${kmodname}-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}

+ Provides:         ${pkg_kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}

+ Requires:         ${kmod_pkg_name}-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}

  EOF

  

  		if [[ ${obsolete_name} ]] ; then

- 			echo "Provides:         kmod-${obsolete_name}${kernel_variant} = ${obsolete_version}"

- 			echo "Obsoletes:        kmod-${obsolete_name}${kernel_variant} < ${obsolete_version}"

+ 			echo "Provides:         ${kmod_obsolete}${kernel_variant} = ${obsolete_version}"

+ 			echo "Obsoletes:        ${kmod_obsolete}${kernel_variant} < ${obsolete_version}"

  		fi

  

  		cat <<EOF

  

- %description   -n kmod-${kmodname}${kernel_variant}

+ %description   -n ${kmod_pkg_name}${kernel_variant}

  This is a meta-package without payload which sole purpose is to require the

  ${kmodname} kernel module(s) for the newest kernel${kernel_variant}.

  to make sure you get it together with a new kernel.

  

- %files         -n kmod-${kmodname}${kernel_variant}

+ %files         -n ${kmod_pkg_name}${kernel_variant}

  %defattr(644,root,root,755)

  

  

@@ -414,8 +441,13 @@ 

  			if [[ ! "${1}" ]] ; then

  				error_out 2 "Please provide the name of the kmod together with --kmodname" >&2

  			fi

- 			# strip pending -kmod

- 			kmodname="${1%%-kmod}"

+ 			if [[ ${postfix_kmp} -ne 0 ]]  && [[ "${1}" == *-kmp ]] ; then

+ 				# strip pending -kmp

+ 				kmodname="${1%%-kmp}"

+ 			else

+ 				# strip pending -kmod

+ 				kmodname="${1%%-kmod}"

+ 			fi

  			shift

  			;;

  		--repo)

SUSE packaging style is to include kernel modules in a package
named PACKAGE-kmp where the Fedora convention is kmod-PACKAGE
and PACKAGE-kmod.

Update the kmodtool to generate packages named using the SUSE
convention style when the host machine is SUSE based.

Signed-off-by: Shaun Tancheff stancheff@cray.com

This is a little bit cleaner that the first version.

Why not just use /etc/os-release and check for ID_LIKE=suse? That seems like it'd be simpler than this check...

So something like:

if [[ -f /etc/os-release ]] ; then
source /etc/os-release
if [[ X"${ID_LIKE}" == Xsuse ]] ; then
suse_kmp=1
fi
fi

So something like:

if [[ -f /etc/os-release ]] ; then
    source /etc/os-release
    if [[ X"${ID_LIKE}" == Xsuse ]] ; then
        suse_kmp=1
   fi
fi

if suse_kmp can be assumed to be always the case when ID_LIKE=suse, then I would drop the former and always use the latter.

I checked openSuSE 12 (as the oldest supported SuSE) that is systemd based (SLES 11 is went to extended support in June). Unfortunately there is no ID_LIKE there.

linux:~ # cat /etc/os-release 
NAME=openSUSE
VERSION = 12.1 (Asparagus)
VERSION_ID="12.1"
PRETTY_NAME="openSUSE 12.1 (Asparagus) (x86_64)"
ID=opensuse

Hello,

As /etc/os-release contains ID variable (for fedora it is "ID=fedora"), it seems reasonable to modify the test from ID_LIKE to ID. Below an example as a proposal that can take care of old releases (using Suse or other distributions specific files):

if [[ -f /etc/os-release ]] ; then
    case $(sed -n 's/^ID=\(.*\)/\1/p' /etc/os-release) in
        opensuse|sles)
            suse_kmp=1
            ;;
        otherdistro)
            otherdistro_kmp=1
            ;;
        *)
            unknowndistro_kmp=1
            ;;
    esac
elif [[ -f /etc/SuSE-release ]] || [[ -f /etc/SUSE-brand ]] ; then
    suse_kmp=1
elif [[ -f /etc/otherdistro-release ]] || [[ -f /etc/otherdistro-brand ]] ; then
    otherdistro_kmp=1
else
    unknowndistro_kmp=1
fi

Hope this help.

Cordially,

--
NVieville

Given the above is extensible (thank you @nvieville) I'm not sure this deserves such complete treatment.
As far as I am aware only SUSE diverges in package naming from kmod- to -kmp.

Also those ID= strings have many flavors, ex:
openSUSE 15.1

shaun@s15bld:~> cat /etc/os-release 
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
...

While your fallback covers everything SUSE related today and for some time to come:

if [[ -f /etc/SuSE-release ]] || [[ -f /etc/SUSE-brand ]] ; then
    suse_kmp=1
fi

If other distributions are found that use the -kmp naming then naming this suse_kmp may be the wrong thing to do. Maybe postfix_kmp would be better?

@stancheff SLE 11's os-release(5) file is sadly annoyingly incomplete:

NAME="SLES"
VERSION="11.4"
VERSION_ID="11.4"
PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:11:4"

And SLE 12...

NAME="SLES"
VERSION="12"
VERSION_ID="12"
PRETTY_NAME="SUSE Linux Enterprise Server 12"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:12"

Forgive my ignorance, but why use new package scheme on old releases? Isn't they're uses/compatible with old scheme?

My current case is for ZFS which uses kmodtool.
SUSE 12 and 15 are active targets and it would be nice to be able to use the upstream spec files directly as is the case with the RHEL/CentOS targets.

1 new commit added

  • Enable kernel module package postfix-kmp convention
2 months ago

Changed suse_kmp to postfix_kmp
Fix / cleanup setting of postfix_kmp

Tested as part of ZFS build on SUSE 15.1
https://github.com/stancheff/zfs/tree/kmp-v7

Just a friendly ping. Any objections including this?

Are we sure this scheme is correct for SUSE KMPs? I recall that the naming convention for kernels in SUSE distributions might be slightly wonky...

Are we sure this scheme is correct for SUSE KMPs? I recall that the naming convention for kernels in SUSE distributions might be slightly wonky...

According to this section of this document:
https://www.suse.com/documentation/suse-best-practices/singlehtml/sbp-kmp-manual/sbp-kmp-manual.html#sec.kernel_module_packages

there seems that naming convention is probably not so straight forward. If kmodtool is used to build third-party modules for Suse, maybe the naming scheme should be only modified to fit a part of the naming convention suggested in the document linked above (for example use only "-kmp-default" suffix). But there are other instructions on building kernel modules packages for Suse in that document that are not implemented in the actual kmodtool. Should they be just ignored and kmodtool uses only the simplified naming convention proposed above?

Feel free to make any comment about this subject.

Cordially,

--
NVieville

As it sits the package names (for zfs on SUSE 15) end up looking like:

     zfs-kmp-4.12.14-197.7-default-0.8.0-171_g935d1f4ee.x86_64.rpm

So

     <pkg>-kmp-<kernel>-<flavor>-<pkgvers>.<arch>.rpm

vs the referenced document specifying:

     <pkg>-kmp-<flavor>-<pkgvers>_k<kernel>.<arch>.rpm

I think following _k<kernel> for regardless of SUSE version seems like the right thing to do. Should be able to swap some things around without too much disruption (at least all the pieces seem to be showing up).

Thanks!

Metadata