Skip to content

Commit

Permalink
Merge pull request #5945 from jkonecny12/rhel-9-compressed-kernel-mod…
Browse files Browse the repository at this point in the history
…ules

dd_extract: Add support for compressed kernel modules
  • Loading branch information
M4rtinK authored Nov 1, 2024
2 parents 6ca7b14 + 6405621 commit 20b99a2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
5 changes: 3 additions & 2 deletions docs/driverdisc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ to respect some rules.
Firmware and module update
--------------------------

The firmware files together with all .ko files from the RPMs are exploded to
special module location, which has preference over built-in Anaconda modules.
The firmware files together with all .ko, .ko.bz2, .ko.gz, .ko.xz and .ko.zst
files from the RPMs are exploded to special module location, which has
preference over built-in Anaconda modules.

Anaconda doesn't use built-in modules (except some storage modules needed for
the DD to function properly) during the DriverDisc mode, so even in case when
Expand Down
10 changes: 10 additions & 0 deletions docs/release-notes/dd-compressed-kernel-modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:Type: Driver Discs
:Summary: Add support for compressed kernel modules

:Description:
Support for Driver Discs containing compressed kernel modules has been
added. Support for compressed kernel modules is limited to file extensions
.ko.bz2, .ko.gz, .ko.xz and .ko.zst.

:Links:
- https://bugzilla.redhat.com/show_bug.cgi?id=2032638
14 changes: 11 additions & 3 deletions tests/unit_tests/dd_tests/test_dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ def create_source_file(self):
path="/lib/modules/KERNELVER/extra/net/fun.ko",
contents="KERNEL MODULE??? YOU BETCHA"
)
koxzfile = TextRPMFile(
path="/lib/modules/KERNELVER/extra/net/fun.ko.xz",
contents="XZ COMPRESSED KERNEL MODULE??? YOU BETCHA"
)
kozstfile = TextRPMFile(
path="/lib/modules/KERNELVER/extra/net/fun.ko.zst",
contents="ZSTD COMPRESSED KERNEL MODULE??? YOU BETCHA"
)


# Finally, the actual test cases
Expand Down Expand Up @@ -240,7 +248,7 @@ def setUpClass(cls):
cls.k_ver = "4.1.4-333"
cls.a_ver = "22.0"
cls.tmpdir = tempfile.mkdtemp(prefix="dd_tests.")
cls.rpmpayload = (binfile, kofile, fwfile, libfile)
cls.rpmpayload = (binfile, kofile, koxzfile, kozstfile, fwfile, libfile)
make_rpm(cls.tmpdir, payload=cls.rpmpayload)
(cls.rpmfile,) = listfiles(cls.tmpdir)

Expand Down Expand Up @@ -284,9 +292,9 @@ def test_dd_extract_chmod(self):
assert binmode & expectmode == expectmode

def test_dd_extract_modules(self):
"""dd_extract: using --modules extracts only .ko files"""
"""dd_extract: using --modules extracts only .ko, .ko.bz2, .ko.gz, .ko.xz and .ko.zst files"""
outfiles = self.dd_extract(flags='--modules')
assert outfiles == set([self.outdir+kofile.path])
assert outfiles == set([self.outdir+kofile.path, self.outdir+koxzfile.path, self.outdir+kozstfile.path])

def test_dd_extract_binaries(self):
"""dd_extract: using --binaries extracts only /bin, /sbin, etc."""
Expand Down
39 changes: 24 additions & 15 deletions utils/dd/dd_extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,31 @@ int dlabelFilter(const char* name, const struct stat *fstat, int packageflags, v
if ((packageflags & dup_firmwares) && !strncmp("lib/firmware/", name, 13))
return 1;

/* we do not want kernel files */
if (!(packageflags & dup_modules))
return 0;

/* check if the file has at least four chars eg X.SS */
if (l<3)
return 0;
l-=3;

/* and we want only .ko files here */
if (strcmp(".ko", name+l))
return 0;

/* we are unpacking kernel module.. */
/* unpack kernel modules if the package was marked as module-package */
if ((packageflags & dup_modules)) {
/* check if the file has at least three chars eg .SS */
if (l>=3) {
if (!strcmp(".ko", name+l-3))
return 1;
}
/* check if the file has at least six chars eg .SS.CC */
if (l>=6) {
if (!strcmp(".ko.gz", name+l-6))
return 1;
if (!strcmp(".ko.xz", name+l-6))
return 1;
}
/* check if the file has at least seven chars eg .SS.CCC */
if (l>=7) {
if (!strcmp(".ko.bz2", name+l-7))
return 1;
if (!strcmp(".ko.zst", name+l-7))
return 1;
}
}

return 1;
/* we do not want kernel files etc. */
return 0;
}

int main(int argc, char *argv[])
Expand Down

0 comments on commit 20b99a2

Please sign in to comment.