Skip to content

Commit

Permalink
sources: add driver dog
Browse files Browse the repository at this point in the history
driverdog is a tool to link kernel modules at runtime, given a
configuration. The configuration must be provided per driver vendor, and
it is created at runtime by the tmpfilesd daemon, using a file
from the %{_cross_factorydir} directory.

Signed-off-by: Arnaldo Garcia Rincon <[email protected]>
  • Loading branch information
arnaldo2792 committed Jan 10, 2022
1 parent 4ec9530 commit cf7b439
Show file tree
Hide file tree
Showing 13 changed files with 617 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ source-groups = [
"models",
"imdsclient",
"retry-read",
"shimpei"
"shimpei",
"driverdog"
]

[lib]
Expand All @@ -40,5 +41,7 @@ glibc = { path = "../glibc" }
# kexec-tools and makedumpfile required for prairiedog functionality
# kexec-tools = { path = "../kexec-tools" }
# makedumpfile = { path = "../makedumpfile" }
# binutils required for driverdog functionality
# binutils = { path = "../binutils" }
# oci-add-hooks required for shimpei functionality
# oci-add-hooks = { path = "../oci-add-hooks" }
17 changes: 17 additions & 0 deletions packages/os/link-kernel-modules.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Link additional kernel modules
# Rerunning this service after the system is fully loaded will override
# the already linked kernel modules. This doesn't affect the running system,
# since kernel modules are linked early in the boot sequence, but we still
# disable manual restarts to prevent unnecessary kernel modules rewrites.
RefuseManualStart=true
RefuseManualStop=true

[Service]
Type=oneshot
ExecStart=/usr/bin/driverdog link-modules
RemainAfterExit=true
StandardError=journal+console

[Install]
RequiredBy=preconfigured.target
17 changes: 17 additions & 0 deletions packages/os/load-kernel-modules.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Load additional kernel modules
After=link-kernel-modules.service
Requires=link-kernel-modules.service
# Disable manual restarts to prevent loading kernel modules
# that weren't linked by the running system
RefuseManualStart=true
RefuseManualStop=true

[Service]
Type=oneshot
ExecStart=/usr/bin/driverdog load-modules
RemainAfterExit=true
StandardError=journal+console

[Install]
RequiredBy=preconfigured.target
31 changes: 31 additions & 0 deletions packages/os/os.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%global _cross_first_party 1
%global _is_k8s_variant %(if echo %{_cross_variant} | grep -Fqw "k8s"; then echo 1; else echo 0; fi)
%global _is_aws_variant %(if echo %{_cross_variant} | grep -Fqw "aws"; then echo 1; else echo 0; fi)
%global _is_vendor_variant %(if echo %{_cross_variant} | grep -Fqw "nvidia"; then echo 1; else echo 0; fi)
%undefine _debugsource_packages

Name: %{_cross_os}os
Expand Down Expand Up @@ -39,6 +40,8 @@ Source111: metricdog.service
Source112: metricdog.timer
Source113: send-boot-success.service
Source114: [email protected]
Source115: link-kernel-modules.service
Source116: load-kernel-modules.service

# 2xx sources: tmpfilesd configs
Source200: migration-tmpfiles.conf
Expand Down Expand Up @@ -91,6 +94,10 @@ Requires: %{_cross_os}shibaken
Requires: %{_cross_os}ecs-settings-applier
%endif

%if %{_is_vendor_variant}
Requires: %{_cross_os}driverdog
%endif

%description
%{summary}.

Expand Down Expand Up @@ -251,6 +258,14 @@ Requires: %{_cross_os}hotdog
%description -n %{_cross_os}shimpei
%{summary}.

%if %{_is_vendor_variant}
%package -n %{_cross_os}driverdog
Summary: Tool to load additional drivers
Requires: %{_cross_os}binutils
%description -n %{_cross_os}driverdog
%{summary}.
%endif

%package -n %{_cross_os}bootstrap-containers
Summary: Manages bootstrap-containers
%description -n %{_cross_os}bootstrap-containers
Expand Down Expand Up @@ -327,6 +342,9 @@ echo "** Output from non-static builds:"
-p pluto \
%endif
-p static-pods \
%endif
%if %{_is_vendor_variant}
-p driverdog \
%endif
%{nil}

Expand Down Expand Up @@ -361,6 +379,9 @@ for p in \
%endif
static-pods \
%endif
%if %{_is_vendor_variant}
driverdog \
%endif
; do
install -p -m 0755 ${HOME}/.cache/%{__cargo_target}/release/${p} %{buildroot}%{_cross_bindir}
done
Expand Down Expand Up @@ -413,6 +434,9 @@ install -p -m 0644 \
%{S:100} %{S:101} %{S:102} %{S:103} %{S:105} \
%{S:106} %{S:107} %{S:110} %{S:111} %{S:112} \
%{S:113} %{S:114} \
%if %{_is_vendor_variant}
%{S:115} %{S:116} \
%endif
%{buildroot}%{_cross_unitdir}

install -d %{buildroot}%{_cross_tmpfilesdir}
Expand Down Expand Up @@ -540,6 +564,13 @@ install -p -m 0644 %{S:300} %{buildroot}%{_cross_udevrulesdir}/80-ephemeral-stor
%{_cross_datadir}/eks/eni-max-pods
%endif

%if %{_is_vendor_variant}
%files -n %{_cross_os}driverdog
%{_cross_bindir}/driverdog
%{_cross_unitdir}/link-kernel-modules.service
%{_cross_unitdir}/load-kernel-modules.service
%endif

%files -n %{_cross_os}static-pods
%{_cross_bindir}/static-pods
%endif
Expand Down
1 change: 1 addition & 0 deletions packages/release/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ path = "pkg.rs"
# RPM Requires
[dependencies]
acpid = { path = "../acpid" }
binutils = { path = "../binutils" }
ca-certificates = { path = "../ca-certificates" }
chrony = { path = "../chrony" }
conntrack-tools = { path = "../conntrack-tools" }
Expand Down
14 changes: 14 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ members = [

"imdsclient",

"driverdog",

"ghostdog",

"growpart",
Expand Down
21 changes: 21 additions & 0 deletions sources/driverdog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "driverdog"
version = "0.1.0"
authors = ["Arnaldo Garcia Rincon <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2018"
publish = false
# Don't rebuild crate just because of changes to README.
exclude = ["README.md"]

[dependencies]
argh = "0.1.3"
log = "0.4"
simplelog = "0.10"
snafu = "0.6"
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.2.0"
toml = "0.5.8"

[build-dependencies]
cargo-readme = "3.1"
14 changes: 14 additions & 0 deletions sources/driverdog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# driverdog

Current version: 0.1.0

driverdog is a tool to link kernel modules at runtime. It uses a toml configuration file with the following shape:

`lib-modules-path`: destination path for the .ko linked files
`objects-source`: path where the objects used to link the kernel module are
`object-files`: hash with the object files to be linked, each object in the map should include the files used to link it
`kernel-modules`: hash with the kernel modules to be linked, each kernel module in the map should include the files used to link it

## Colophon

This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`.
9 changes: 9 additions & 0 deletions sources/driverdog/README.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# {{crate}}

Current version: {{version}}

{{readme}}

## Colophon

This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`.
32 changes: 32 additions & 0 deletions sources/driverdog/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Automatically generate README.md from rustdoc.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Check for environment variable "SKIP_README". If it is set,
// skip README generation
if env::var_os("SKIP_README").is_some() {
return;
}

let mut source = File::open("src/main.rs").unwrap();
let mut template = File::open("README.tpl").unwrap();

let content = cargo_readme::generate_readme(
&PathBuf::from("."), // root
&mut source, // source
Some(&mut template), // template
// The "add x" arguments don't apply when using a template.
true, // add title
false, // add badges
false, // add license
true, // indent headings
)
.unwrap();

let mut readme = File::create("README.md").unwrap();
readme.write_all(content.as_bytes()).unwrap();
}
Loading

0 comments on commit cf7b439

Please sign in to comment.