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

Add cgroup v2 support #3

Merged
merged 3 commits into from
Mar 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependency
- name: Install apt dependency
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev

# Need to use nightly toolchain for eBPF
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src

- name: Install bpf-linker
run: |
cargo install bpf-linker

- name: Build
run: cargo build --release

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/ott
/cgroup_device_filter/target
/ott
116 changes: 98 additions & 18 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ bollard = "0.16"
futures = "0.3"
rustix = { version = "0.38", features = ["fs", "stdio", "termios"] }
bitflags = "2"
aya = { git = "https://github.com/aya-rs/aya.git" }

[build-dependencies]
anyhow = { version = "1", features = ["backtrace"] }
walkdir = "2"

[workspace]
exclude = ["cgroup_device_filter"]
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ Another concern is providing a container with well known paths for the devices.
On bare-metal systems this would usually be achieved with a `SYMLINK` directive in a udev rule.
This program tries to provide a similar functionality for containers, allowing you to specify symlinks for certain devices.

## Limitations

`container-hotplug` needs to be run as root and relies on `cgroup v1`. It does not support `cgroup v2`.
On distributions with `cgroup v2`, you can switch back to `cgroup v1` by setting the [kernel parameter](https://wiki.ubuntu.com/Kernel/KernelBootParameters) `systemd.unified_cgroup_hierarchy=0`.
This tool supports both cgroup v1 and v2.

## Example

Expand Down
35 changes: 35 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use anyhow::{Context, Result};

fn main() -> Result<()> {
// We need to rerun the build script if any files in the cgroup_device_filter change.
for entry in walkdir::WalkDir::new("cgroup_device_filter")
.into_iter()
.filter_entry(|entry| {
entry
.file_name()
.to_str()
.map(|s| s != "target")
.unwrap_or(true)
})
{
let entry = entry?;
if entry.file_type().is_file() {
println!(
"cargo:rerun-if-changed={}",
entry.path().to_str().context("file name not UTF-8")?
);
}
}

// Run cargo to compile the eBPF program.
let status = std::process::Command::new("cargo")
.current_dir("cgroup_device_filter")
.args(["build", "--release"])
.status()?;

if !status.success() {
anyhow::bail!("Failed to build eBPF program");
}

Ok(())
}
5 changes: 5 additions & 0 deletions cgroup_device_filter/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "bpfel-unknown-none"

[unstable]
build-std = ["core"]
Loading
Loading