Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dd_extract: Add support for compressed kernel modules #5041

Merged
merged 6 commits into from Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/driverdisc.rst
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
@@ -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
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"
)
pjgeorg marked this conversation as resolved.
Show resolved Hide resolved
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
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