public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup
@ 2023-12-28 12:21 Michał Górny
  2023-12-28 12:21 ` [gentoo-dev] [PATCH 2/3] kernel-install.eclass: Call module cleanup in postinst Michał Górny
  2023-12-28 12:21 ` [gentoo-dev] [PATCH 3/3] linux-mod-r1.eclass: " Michał Górny
  0 siblings, 2 replies; 3+ messages in thread
From: Michał Górny @ 2023-12-28 12:21 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/dist-kernel-utils.eclass | 37 +++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
index 67cb802151b2..8ccffd038474 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -210,5 +210,42 @@ dist-kernel_PV_to_KV() {
 	echo "${kv}"
 }
 
+# @FUNCTION: dist-kernel_compressed_module_cleanup
+# @USAGE: <path>
+# @DESCRIPTION:
+# Traverse path for duplicate (un)compressed modules and remove all
+# but the newest variant.
+dist-kernel_compressed_module_cleanup() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
+	local path=${1}
+	local basename f
+
+	while read -r basename; do
+		local prev=
+		for f in "${path}/${basename}"{,.gz,.xz,.zst}; do
+			if [[ ! -e ${f} ]]; then
+				continue
+			elif [[ -z ${prev} ]]; then
+				prev=${f}
+			elif [[ ${f} -nt ${prev} ]]; then
+				rm -v "${prev}" || die
+				prev=${f}
+			else
+				rm -v "${f}" || die
+			fi
+		done
+	done < <(
+		cd "${path}" &&
+		find -type f \
+			\( -name '*.ko' \
+			-o -name '*.ko.gz' \
+			-o -name '*.ko.xz' \
+			-o -name '*.ko.zst' \
+			\) | sed -e 's:[.]\(gz\|xz\|zst\)$::' | sort | uniq -d || die
+	)
+}
+
 _DIST_KERNEL_UTILS=1
 fi
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH 2/3] kernel-install.eclass: Call module cleanup in postinst
  2023-12-28 12:21 [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Michał Górny
@ 2023-12-28 12:21 ` Michał Górny
  2023-12-28 12:21 ` [gentoo-dev] [PATCH 3/3] linux-mod-r1.eclass: " Michał Górny
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Górny @ 2023-12-28 12:21 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/kernel-install.eclass | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index af4f5d839b0e..b4c3d5fe7b4d 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -592,6 +592,7 @@ kernel-install_pkg_preinst() {
 		die "Release file ${relfile} not installed!"
 	local release
 	release="$(<"${relfile}")" || die
+	DIST_KERNEL_RELEASE="${release}"
 
 	# perform the version check for release ebuilds only
 	if [[ ${PV} != *9999 ]]; then
@@ -706,6 +707,8 @@ kernel-install_pkg_postinst() {
 
 	local dir_ver=${PV}${KV_LOCALVERSION}
 	kernel-install_update_symlink "${EROOT}/usr/src/linux" "${dir_ver}"
+	dist-kernel_compressed_module_cleanup \
+		"${EROOT}/lib/modules/${DIST_KERNEL_RELEASE}"
 
 	if [[ -z ${ROOT} ]]; then
 		kernel-install_install_all "${dir_ver}"
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH 3/3] linux-mod-r1.eclass: Call module cleanup in postinst
  2023-12-28 12:21 [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Michał Górny
  2023-12-28 12:21 ` [gentoo-dev] [PATCH 2/3] kernel-install.eclass: Call module cleanup in postinst Michał Górny
@ 2023-12-28 12:21 ` Michał Górny
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Górny @ 2023-12-28 12:21 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/linux-mod-r1.eclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 54df2406e5c7..67a4b64eb481 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -109,7 +109,7 @@ esac
 if [[ ! ${_LINUX_MOD_R1_ECLASS} ]]; then
 _LINUX_MOD_R1_ECLASS=1
 
-inherit edo linux-info multiprocessing toolchain-funcs
+inherit dist-kernel-utils edo linux-info multiprocessing toolchain-funcs
 
 IUSE="dist-kernel modules-compress modules-sign +strip ${MODULES_OPTIONAL_IUSE}"
 
@@ -468,6 +468,7 @@ linux-mod-r1_pkg_postinst() {
 	debug-print-function ${FUNCNAME[0]} "${@}"
 	_modules_check_function ${#} 0 0 || return 0
 
+	dist-kernel_compressed_module_cleanup "${EROOT}/lib/modules/${KV_FULL}"
 	_modules_update_depmod
 
 	# post_process ensures modules were installed and that the eclass' USE
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-28 12:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-28 12:21 [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add dist-kernel_compressed_module_cleanup Michał Górny
2023-12-28 12:21 ` [gentoo-dev] [PATCH 2/3] kernel-install.eclass: Call module cleanup in postinst Michał Górny
2023-12-28 12:21 ` [gentoo-dev] [PATCH 3/3] linux-mod-r1.eclass: " Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox