From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Hannes Laimer <h.laimer@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox v8 3/6] ebpf: subsystem: add the shared tc program handling
Date: Thu, 5 Nov 2026 17:20:02 +0100 [thread overview]
Message-ID: <gkpnew2dpictqpyj5ukc33p4ql355azr7tczad4ry2ce2fhlnl@zc6nhnkz77yb> (raw)
In-Reply-To: <20261104172918.2643810-4-h.laimer@proxmox.com>
On Wed, Nov 04, 2026 at 06:29:15PM +0100, Hannes Laimer wrote:
> A subsystem owns tc classifier programs and their maps, attached per
> interface and pinned in bpffs under the object's fingerprint, the
> crate's version and the schema version. So state survives between
> the one-shot calls of its consumer, re-running never interrupts
> traffic, and an older build does not install over a newer one.
>
> Changes run under one lock per subsystem, taken before the change
> reads its input, so they reach the kernel in the order they read it.
>
> A subsystem writes its maps entry by entry through the live maps,
> or hands over the whole content. For the latter, and whenever its
> own programs and maps are not pinned yet, the object is loaded with
> fresh maps in a staging directory, the content is written there, and
> only then do the links move onto the new programs, one link update
> each, with the maps coming along since a program holds its maps. A
> write that stops halfway, such as an insert the kernel cannot
> allocate for, leaves the live maps whole instead of a mix of old and
> new entries. The pins of maps and programs switch in one rename, so a
> plug always finds the maps its program reads.
>
> A subsystem describes its programs with a macro, from its name, the
> program names, the maps and the schema version. The object is found
> by the subsystem's name, and its fingerprint is derived from its
> bytes.
(Maybe also describe the created directory tree here in the commit
message. IMO the cover letter did a better job of explaining this commit
than the message above 🤷)
>
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
> proxmox-ebpf/src/lib.rs | 1 +
> proxmox-ebpf/src/subsystem.rs | 1067 +++++++++++++++++++++++++++++++++
> proxmox-ebpf/src/tc.rs | 32 +-
> 3 files changed, 1088 insertions(+), 12 deletions(-)
> create mode 100644 proxmox-ebpf/src/subsystem.rs
>
> diff --git a/proxmox-ebpf/src/lib.rs b/proxmox-ebpf/src/lib.rs
> index 6281a024fd2b..ab0763ab3d3d 100644
> --- a/proxmox-ebpf/src/lib.rs
> +++ b/proxmox-ebpf/src/lib.rs
> @@ -2,4 +2,5 @@
> //! eBPF subsystems, one per concern, each behind a cargo feature of its name. Nothing here runs
> //! on its own, consumers pull in only the subsystem they drive.
>
> +pub mod subsystem;
> pub mod tc;
> diff --git a/proxmox-ebpf/src/subsystem.rs b/proxmox-ebpf/src/subsystem.rs
> new file mode 100644
> index 000000000000..39272060cd4e
> --- /dev/null
> +++ b/proxmox-ebpf/src/subsystem.rs
> @@ -0,0 +1,1067 @@
> +//! The shared subsystem code. A subsystem has one tc program per direction it declares, with
> +//! their maps and links. They are pinned under `/sys/fs/bpf/proxmox-ebpf/<name>/`, the links in
> +//! `links/` and the maps and programs under `<schema>/live/`. The programs are pinned by the
> +//! fingerprint of their object and selection and the version of the crate they were built into,
> +//! so the pinned state itself says which build it belongs to, and a build does not install over
> +//! a newer one.
> +//!
> +//! The loaded BPF stays in the kernel between invocations. [`ApplyLock::replace_maps`] loads the
> +//! object with fresh maps and moves the links onto it, a full apply calls it when what is pinned
> +//! is not this build's, when the last replacement stopped halfway, or whenever it wants the
> +//! content of its maps switched as a whole. Every other step works on what is pinned. Each
> +//! subsystem owns one [`TcPrograms`].
> +//!
> +//! Every change runs under the subsystem's apply lock, a full apply exclusively and a
> +//! single-interface step shared. The holder reads the input of its change under the lock and
> +//! writes before it lets go, so a full apply and every step reach the kernel in the order they
> +//! read their input. Two steps of one interface do not order each other.
Maybe add this (and verify, and fill missing things) to the TcPrograms
type doc comments - I tried to recreate this from the code…
// /sys/fs/bpf/proxmox-epbf PIN_ROOT
// └─ <TcPrograms::name> TcPrograms::pin_root()
// ├─ <schema_version> TcPrograms::schema_root()
// │ ├─ live/ TcPrograms::live_dir()
// │ │ └─ prog/ schema_progs_dir
// │ │ └─ <crate-version>-<program-fingerprint>/
// │ │ └─ <direction> BPF program
// │ └─ staging/ TcPrograms::staging_dir()
// └─ link/ TcPrograms::links_dir()
// └─ <LinkPin::filename()> TcPrograms::link_pin_path()
> +use std::{
> + collections::HashSet,
> + fs::File,
> + io::ErrorKind,
> + marker::PhantomData,
> + ops::{Deref, DerefMut},
> + os::unix::fs::{DirBuilderExt, OpenOptionsExt},
> + path::{Path, PathBuf},
> + time::{Duration, Instant},
> +};
> +
> +use anyhow::Context;
> +use aya::{EbpfLoader, programs::SchedClassifier};
> +use nix::{
> + errno::Errno,
> + fcntl::{Flock, FlockArg, RenameFlags, renameat2},
> +};
> +
> +use crate::tc::{self, Direction};
> +
> +const PIN_ROOT: &str = "/sys/fs/bpf/proxmox-ebpf";
> +const RUN_ROOT: &str = "/run/proxmox-ebpf";
> +
> +// FNV-1a over the object, the program selection and the map names, so the same object with
> +// another program chosen for a direction is another build
> +const fn build_fingerprint(obj: &[u8], programs: &[(Direction, &str)], maps: &[&str]) -> u64 {
> + let mut hash = fnv1a(0xcbf29ce484222325, obj);
> + let mut i = 0;
> + while i < programs.len() {
> + hash = fnv1a(hash, programs[i].0.as_str().as_bytes());
> + hash = fnv1a(hash, programs[i].1.as_bytes());
> + i += 1;
> + }
> + let mut i = 0;
> + while i < maps.len() {
> + hash = fnv1a(hash, maps[i].as_bytes());
> + i += 1;
> + }
> + hash
> +}
> +
> +// one field, ended by a zero byte so two fields cannot read as one
> +const fn fnv1a(mut hash: u64, bytes: &[u8]) -> u64 {
> + let mut i = 0;
> + while i < bytes.len() {
> + hash ^= bytes[i] as u64;
> + hash = hash.wrapping_mul(0x100000001b3);
> + i += 1;
> + }
> + hash.wrapping_mul(0x100000001b3)
> +}
> +
> +// one number of a cargo version as the environment hands it to the macro, digits only
> +const fn version_part(s: &str) -> u64 {
> + let bytes = s.as_bytes();
> + let mut n = 0u64;
> + let mut i = 0;
> + while i < bytes.len() {
> + assert!(bytes[i].is_ascii_digit(), "a cargo version part is digits");
> + n = n * 10 + (bytes[i] - b'0') as u64;
> + i += 1;
> + }
> + n
> +}
> +
> +/// A subsystem's [`TcPrograms`] from its name. The object is the build's `<name>.bpf.o`, the
> +/// fingerprint follows from the bytes and the version is the crate's own.
> +#[macro_export]
> +macro_rules! tc_programs {
> + (
> + name: $name:literal,
> + programs: $programs:expr,
> + maps: $maps:expr,
> + schema_version: $schema:expr $(,)?
> + ) => {
> + // built at compile time wherever the macro is used, a let binding included
> + const {
> + const OBJ: &[u8] =
> + ::aya::include_bytes_aligned!(concat!(env!("OUT_DIR"), "/", $name, ".bpf.o"));
> + $crate::subsystem::TcPrograms::new(
> + $name,
> + OBJ,
> + $programs,
> + $maps,
> + $schema,
> + [
> + env!("CARGO_PKG_VERSION_MAJOR"),
> + env!("CARGO_PKG_VERSION_MINOR"),
> + env!("CARGO_PKG_VERSION_PATCH"),
> + ],
> + )
> + }
> + };
> +}
> +
> +const LOCK_WAIT: Duration = Duration::from_secs(10);
> +const LOCK_POLL: Duration = Duration::from_millis(10);
> +
> +// flock takes a read-only descriptor, so nobody but root gets to open the lock files
> +fn private_dir(dir: &Path) -> std::io::Result<()> {
> + std::fs::DirBuilder::new()
> + .recursive(true)
> + .mode(0o700)
> + .create(dir)
> +}
> +
> +// flock has no timeout, so the wait retries a nonblocking flock with a sleep in between.
> +//
> +// not proxmox-sys lock because: blocks and gives up on a timer signal, and under pve-rs any signal
> +// perl handles cuts the blocked wait short the same way, since perl installs its handlers without
> +// restart
Have you actually tested if perl installs a handler for this particular
signal?
And even if it does, the perlmod entry point, can just temporarily
replace it.
pve-rs will still need to call `setup_timeout_handler()` in its init
once.
Busy-loops are always wrong.
> +fn flock_within(
> + path: &Path,
> + exclusive: bool,
> + what: &str,
> + subsystem: &str,
> +) -> anyhow::Result<Flock<File>> {
^ We normally have `anyhow::Error` imported.
Use `Result<…, Error>`.
> + let mut file = File::options()
> + .create(true)
> + .truncate(false)
> + .write(true)
> + .mode(0o600)
> + .open(path)
> + .with_context(|| format!("{subsystem}: open {what} {}", path.display()))?;
> + let arg = if exclusive {
> + FlockArg::LockExclusiveNonblock
> + } else {
> + FlockArg::LockSharedNonblock
> + };
> + let deadline = Instant::now() + LOCK_WAIT;
> + loop {
> + match Flock::lock(file, arg) {
> + Ok(lock) => return Ok(lock),
> + Err((returned, Errno::EWOULDBLOCK)) if Instant::now() < deadline => {
> + file = returned;
> + std::thread::sleep(LOCK_POLL);
> + }
> + Err((_, Errno::EWOULDBLOCK)) => anyhow::bail!(
> + "{subsystem}: {what} still held after {}s",
> + LOCK_WAIT.as_secs()
> + ),
> + Err((_, e)) => {
> + return Err(e)
> + .with_context(|| format!("{subsystem}: take {what} {}", path.display()));
> + }
> + }
> + }
> +}
> +
> +/// A step that needs the programs pinned found none. Only [`ApplyLock::replace_maps`] under the
> +/// exclusive lock brings them up.
> +#[derive(Debug)]
> +pub struct NotLoaded;
> +
> +impl std::fmt::Display for NotLoaded {
> + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
> + f.write_str("programs not loaded")
> + }
> +}
> +
> +impl std::error::Error for NotLoaded {}
> +
> +/// A subsystem's description of its tc programs, written with the `tc_programs!` macro. The
> +/// loaded programs live pinned in the kernel and are reached through those pins.
> +pub struct TcPrograms {
> + /// The subsystem's name, its directory under the pin root.
> + name: &'static str,
> + /// The embedded BPF object.
> + obj: &'static [u8],
> + /// FNV-1a of `obj`, `programs` and `maps`, the programs are pinned under it.
> + fingerprint: u64,
> + /// The version of the crate the object was built into, pinned next to the fingerprint. A
> + /// build does not install over a higher one.
> + version: [u64; 3],
Let's have types for fingerprint and version.
(Even if just newtypes, `Fingerprint(u64)`, `(Version([u64; 3]))`)
> + /// The directions the object carries a program for, each with that program's name in the
> + /// object. One entry per direction.
> + programs: &'static [(Direction, &'static str)],
> + /// The object's pinned maps. A missing one means the state is not current.
> + maps: &'static [&'static str],
> + /// Bumped with any change to a map's key or value layout. Each schema has its own live set,
> + /// so a step never writes into maps of another layout, and a build leaves the state of a
> + /// newer schema alone.
> + schema_version: u32,
> +}
> +
> +impl TcPrograms {
> + /// What [`tc_programs!`](crate::tc_programs) expands to, with the fingerprint derived and the
> + /// version parsed at compile time.
> + pub const fn new(
> + name: &'static str,
> + obj: &'static [u8],
> + programs: &'static [(Direction, &'static str)],
> + maps: &'static [&'static str],
> + schema_version: u32,
> + version: [&'static str; 3],
> + ) -> Self {
> + Self {
> + name,
> + obj,
> + fingerprint: build_fingerprint(obj, programs, maps),
> + version: [
> + version_part(version[0]),
> + version_part(version[1]),
> + version_part(version[2]),
> + ],
> + programs,
> + maps,
> + schema_version,
> + }
> + }
> +
> + fn pin_root(&self) -> PathBuf {
> + PathBuf::from(PIN_ROOT).join(self.name)
> + }
These are all sticking together a bit too much…
> + fn schema_root(&self) -> PathBuf {
> + self.pin_root().join(self.schema_version.to_string())
> + }
> + fn live_dir(&self) -> PathBuf {
> + schema_live_dir(&self.schema_root())
> + }
> + fn staging_dir(&self) -> PathBuf {
> + self.schema_root().join("staging")
> + }
> + fn links_dir(&self) -> PathBuf {
> + links_dir_of(self.name)
> + }
> + fn link_pin_path(&self, pin: &tc::LinkPin) -> PathBuf {
> + self.links_dir().join(pin.filename())
> + }
Somehow I'm not convinced all the path helpers are actually *helping* here.
At least without the tree being described anywhere first… (as I
mentioned at the top).
> + // the build directory of a set of maps and programs, the live one or a staged one
> + fn prog_dir_in(&self, set: &Path) -> PathBuf {
why not call it build_dir_in
Maybe drop the helper, it's used once. Document what the path looks like
in `pin_programs()` (its only user).
> + set.join("prog")
> + .join(build_dir_name(self.version, self.fingerprint))
> + }
> + // the builds with programs pinned in the live set, each with its directory
> + fn pinned_builds(&self) -> anyhow::Result<Vec<(PathBuf, [u64; 3], u64)>> {
> + let entries = match std::fs::read_dir(schema_progs_dir(&self.schema_root())) {
> + Ok(entries) => entries,
> + Err(e) if e.kind() == ErrorKind::NotFound => return Ok(Vec::new()),
> + Err(e) => return Err(e.into()),
> + };
> + let mut builds = Vec::new();
> + for entry in entries {
> + let entry = entry?;
> + if let Some((version, fingerprint)) =
> + entry.file_name().to_str().and_then(parse_build_dir_name)
> + {
> + builds.push((entry.path(), version, fingerprint));
> + }
> + }
> + Ok(builds)
> + }
> + // the directory this build's programs are pinned in, named by whichever version installed
> + // them, a release with the same object installs nothing
Why is the last part of the sentence *here* in particular?
> + fn own_prog_dir(&self) -> anyhow::Result<Option<PathBuf>> {
> + Ok(self
> + .pinned_builds()?
> + .into_iter()
> + .find(|&(_, _, fingerprint)| fingerprint == self.fingerprint)
> + .map(|(dir, _, _)| dir))
> + }
> + fn newer_version_installed(&self) -> anyhow::Result<Option<[u64; 3]>> {
> + Ok(self
> + .pinned_builds()?
> + .into_iter()
> + .map(|(_, version, _)| version)
> + .filter(|&version| version > self.version)
> + .max())
> + }
> + fn program_name(&self, dir: Direction) -> Option<&'static str> {
> + self.programs
> + .iter()
> + .find(|&&(d, _)| d == dir)
> + .map(|&(_, name)| name)
> + }
> + fn run_dir(&self) -> PathBuf {
> + PathBuf::from(RUN_ROOT).join(self.name)
> + }
> + fn hash_map<K: aya::Pod, V: aya::Pod>(
> + &self,
> + name: &str,
> + ) -> anyhow::Result<aya::maps::HashMap<aya::maps::MapData, K, V>> {
> + self.hash_map_in(&self.live_dir(), name)
> + }
> +
> + fn hash_map_in<K: aya::Pod, V: aya::Pod>(
> + &self,
> + set: &Path,
> + name: &str,
> + ) -> anyhow::Result<aya::maps::HashMap<aya::maps::MapData, K, V>> {
> + let path = set.join(name);
> + if !path.exists() {
> + // a set comes up with every map the object pins, so an existing set lacks only a map
> + // the object never had under that name
> + if set.exists() {
> + anyhow::bail!("{}: no map {name} pinned in {}", self.name, set.display());
> + }
> + return Err(NotLoaded.into());
> + }
> + let map = aya::maps::MapData::from_pin(path)
> + .with_context(|| format!("{}: open pinned map {name}", self.name))?;
> + Ok(aya::maps::HashMap::try_from(aya::maps::Map::HashMap(map))?)
> + }
> +
> + // open one direction's pinned program, NotLoaded when it is not pinned
> + fn program(&self, dir: Direction) -> anyhow::Result<SchedClassifier> {
> + let path = self.own_prog_dir()?.map(|d| d.join(dir.as_str()));
> + let Some(path) = path.filter(|p| p.exists()) else {
> + return Err(NotLoaded.into());
> + };
^ This map/filter/let-else expression is cumbersome to read.
How about
let path = self.own_prog_dir()?.ok_or(NotLoaded)?.join(dir.as_str());
if !path.exists() {
return Err(NotLoaded.into());
}
> + SchedClassifier::from_pin(path)
> + .with_context(|| format!("{}: open pinned program {}", self.name, dir.as_str()))
> + }
> +
> + // one direction's program pinned in the live set, by whichever build pinned it there
> + fn live_program(&self, dir: Direction) -> anyhow::Result<Option<SchedClassifier>> {
> + for (build, _, _) in self.pinned_builds()? {
> + let path = build.join(dir.as_str());
> + if !path.exists() {
> + continue;
> + }
> + let prog = SchedClassifier::from_pin(&path).with_context(|| {
> + format!("{}: open pinned program {}", self.name, path.display())
> + })?;
> + return Ok(Some(prog));
So this just returns the first one it can open? But they're not sorted
and there could potentially be multiple entries? Shouldn't we sort by
version first? If not, a comment might be warranted.
> + }
> + Ok(None)
> + }
> +
> + // the apply lock under /run. A full apply and a teardown take it exclusively, a
> + // single-interface step shared. A wait times out instead of hanging. Shared holders do not
> + // yield to a waiting exclusive one, so a node attaching interfaces without pause can keep a
> + // full apply waiting until it times out. Every write to the pinned state is a method of the
> + // returned guard, so a step cannot run outside the lock
> + fn lock<M>(&self, exclusive: bool) -> anyhow::Result<ApplyLock<'_, M>> {
> + let dir = self.run_dir();
> + private_dir(&dir).with_context(|| {
> + format!("{}: create the run directory {}", self.name, dir.display())
> + })?;
> + let lock = flock_within(&dir.join("lock"), exclusive, "apply lock", self.name)?;
> + Ok(ApplyLock {
> + programs: self,
> + _lock: lock,
> + _mode: PhantomData,
> + })
> + }
> +
> + /// Whether a link of the interface name is pinned, read without the lock. Most interfaces
> + /// never had a link and their unplug must not wait behind a full apply. A miss is a snapshot,
What does "A miss is a snapshot" mean?
> + /// a pin arriving after it is another attach's. A failed listing counts as a hit.
And what does the first part mean? And why the last part?
> + pub fn link_pinned(&self, name: &str) -> bool {
> + self.live_links()
> + .map_or(true, |links| links.iter().any(|pin| pin.name == name))
> + }
> +
> + /// Take the apply lock shared, for a single-interface step.
> + pub fn lock_shared(&self) -> anyhow::Result<ApplyLock<'_, Shared>> {
> + self.lock(false)
> + }
> +
> + /// Take the apply lock exclusively, for a full apply or a teardown.
> + pub fn lock_exclusive(&self) -> anyhow::Result<ApplyLock<'_, Exclusive>> {
> + self.lock(true)
> + }
> +
> + fn is_current(&self) -> bool {
> + let programs_pinned = match self.own_prog_dir() {
> + Ok(Some(dir)) => self
> + .programs
> + .iter()
> + .all(|&(d, _)| dir.join(d.as_str()).exists()),
> + _ => false,
> + };
> + programs_pinned
> + && self.maps_pinned()
> + // a failed listing cannot rule a newer schema out
> + && matches!(self.newer_schema_installed(), Ok(None))
> + }
> +
> + fn maps_pinned(&self) -> bool {
> + self.maps
> + .iter()
> + .all(|map| self.live_dir().join(map).exists())
> + }
> +
> + // the directories under the pin root other than this build's schema and the links. One whose
> + // name is not a version counts as well and goes with the old schemas
> + fn other_schemas(&self) -> anyhow::Result<Vec<(PathBuf, Option<u32>)>> {
> + let entries = match std::fs::read_dir(self.pin_root()) {
> + Ok(entries) => entries,
> + Err(e) if e.kind() == ErrorKind::NotFound => return Ok(Vec::new()),
> + Err(e) => return Err(e.into()),
> + };
> + let mut others = Vec::new();
> + for entry in entries {
> + let entry = entry?;
> + if !entry.file_type()?.is_dir() || entry.file_name() == LINKS_DIR {
> + continue;
> + }
> + let schema = entry
> + .file_name()
> + .to_str()
> + .and_then(|s| s.parse::<u32>().ok());
> + if schema != Some(self.schema_version) {
> + others.push((entry.path(), schema));
> + }
> + }
> + Ok(others)
> + }
> +
> + fn newer_schema_installed(&self) -> anyhow::Result<Option<u32>> {
> + let newer = self
> + .other_schemas()?
> + .iter()
> + .filter(|(dir, _)| any_program_pinned(&schema_progs_dir(dir)))
> + .filter_map(|(_, schema)| *schema)
> + .find(|&s| s > self.schema_version);
> + Ok(newer)
> + }
> +
> + fn interrupted(&self) -> bool {
> + let other_pinned = match self.other_schemas() {
> + Ok(others) => others
> + .iter()
> + .any(|(dir, _)| any_program_pinned(&schema_progs_dir(dir))),
> + // a failed listing cannot rule a leftover out
> + Err(_) => true,
> + };
> + self.staging_dir().exists() || other_pinned
Mh, if the staging dir is removed last on apply, doing that check here
first might be more efficient. If it's true, we skip the readdir which
is arguably more expensive.
> + }
> +
> + fn tear_down(&self) -> anyhow::Result<()> {
> + remove_dir_if_present(&self.pin_root())
> + .with_context(|| format!("{}: remove the pinned state", self.name))
> + }
> +
> + // this build's object with all of its programs loaded and its maps created and pinned under
> + // `set`. Everything is loaded before any link is touched, so a verifier rejection of one
> + // direction leaves the old state whole
> + fn load(&self, set: &Path) -> anyhow::Result<aya::Ebpf> {
> + let mut bpf = EbpfLoader::new()
> + .map_pin_path(set)
> + .load(self.obj)
> + .with_context(|| format!("{}: load the object", self.name))?;
> + for &(_, name) in self.programs {
> + let prog: &mut SchedClassifier = bpf
> + .program_mut(name)
> + .with_context(|| format!("{}: program {name} not found in object", self.name))?
> + .try_into()?;
> + prog.load()
> + .with_context(|| format!("{}: load program {name}", self.name))?;
> + }
> + Ok(bpf)
> + }
> +
> + // move every pinned link onto the loaded programs
> + fn swap_links(&self, bpf: &mut aya::Ebpf) -> anyhow::Result<()> {
> + let live = self.live_links()?;
> + for &(dir, _) in self.programs {
> + self.swap_links_onto(dir, self.loaded(bpf, dir)?, &live)?;
> + }
> + Ok(())
> + }
> +
> + // put the live set on every link, a link on it already stays as it is, and detach the links
> + // of a direction the live set has no program for, they run a retired program. The live set
> + // decides, not this build's directions, since a run that died before its exchange left the
> + // old set live, and that keeps its links until the exchange
> + fn repair_links(&self) -> anyhow::Result<()> {
> + let live = self.live_links()?;
> + for dir in Direction::ALL {
> + match self.live_program(dir)? {
> + Some(mut prog) => self.swap_links_onto(dir, &mut prog, &live)?,
> + None => {
> + for pin in live.iter().filter(|pin| pin.dir == dir) {
> + self.reclaim_link(pin)?;
> + }
> + }
> + }
> + }
> + Ok(())
> + }
> +
> + // the links of one direction onto `prog`. One that cannot be swapped is unpinned, the next
> + // full apply attaches it again if it is still wanted
> + fn swap_links_onto(
> + &self,
> + dir: Direction,
> + prog: &mut SchedClassifier,
> + links: &[tc::LinkPin],
> + ) -> anyhow::Result<()> {
> + for pin in links.iter().filter(|pin| pin.dir == dir) {
> + let path = self.link_pin_path(pin);
> + // a pin that does not open says nothing about the link, one that opens and cannot be
> + // updated is a link the kernel let go
> + let link = match tc::open_pinned_link(&path) {
> + Ok(link) => link,
> + Err(tc::Error::PinGone) => continue,
> + Err(e) => {
> + return Err(e)
> + .with_context(|| format!("{}: open {}", self.name, pin.filename()));
> + }
> + };
> + if let Err(e) = tc::swap_link(prog, link) {
> + log::warn!(
> + "{}: {} swap failed ({e:#}), reclaiming",
> + self.name,
> + pin.filename()
> + );
> + self.reclaim_link(pin)?;
> + }
> + }
> + Ok(())
> + }
> +
> + fn pin_programs(&self, bpf: &mut aya::Ebpf, set: &Path) -> anyhow::Result<()> {
> + let dir = self.prog_dir_in(set);
> + std::fs::create_dir_all(&dir)
> + .with_context(|| format!("{}: create the program directory", self.name))?;
> + for &(direction, _) in self.programs {
> + self.loaded(bpf, direction)?
> + .pin(dir.join(direction.as_str()))
> + .with_context(|| format!("{}: pin program {}", self.name, direction.as_str()))?;
> + }
> + Ok(())
> + }
> +
> + // load the object with fresh maps under `staging`, have `fill` write them, then put the
> + // staged set in the live one's place and move the links over. That is one rename, an
> + // exchange when a live set is there, so a plug never finds the maps of one set next to the
> + // programs of the other, and a failure before it leaves the live set untouched. The retired
> + // set and the directories of other schemas go last, their programs stay alive through the
> + // links until each is swapped
> + fn replace_maps(
> + &self,
> + fill: impl FnOnce(&Staged<'_>) -> anyhow::Result<()>,
> + ) -> anyhow::Result<()> {
> + let others = self.other_schemas()?;
> + // programs pinned under a newer schema or by a newer version of the crate mean a newer
> + // build runs here and this process is the stale one, so it leaves the state alone
> + if let Some(newer) = self.newer_schema_installed()? {
> + anyhow::bail!(
> + "{}: pinned state is of schema {newer}, newer than this build's {}",
> + self.name,
> + self.schema_version
> + );
> + }
> + if let Some(newer) = self.newer_version_installed()? {
> + anyhow::bail!(
> + "{}: pinned programs are of version {}, newer than this build's {}",
> + self.name,
> + version_text(newer),
> + version_text(self.version)
> + );
> + }
> + std::fs::create_dir_all(self.links_dir())
> + .with_context(|| format!("{}: create the links directory", self.name))?;
> + let staging = self.staging_dir();
> + let live = self.live_dir();
> + // a run that died may have left links on the set it retired, so first make sure every
> + // link has the live set, then clear what it left behind. Without a live set the links
> + // are another schema's, whose set stays until the end
> + if staging.exists() && live.exists() {
> + self.repair_links()?;
> + }
> + remove_dir_if_present(&staging)
> + .with_context(|| format!("{}: remove the previous staging directory", self.name))?;
> + let staged = self.stage(&staging, fill).and_then(|bpf| {
> + if live.exists() {
^ Just do the `renameat2` call below and the `else` path on `ENOENT`.
(The ENOENT won't refer to the staged *source* unless there's external
interference, in which case the `rename` will fail the same way (either
way, it's no worse than the TOCTOU from `live.exists()`. Generally,
calls to `Path::exists()` are rarely useful.))
> + renameat2(None, &staging, None, &live, RenameFlags::RENAME_EXCHANGE).with_context(
> + || format!("{}: exchange the staged set with the live one", self.name),
> + )?;
> + } else {
> + std::fs::rename(&staging, &live)
> + .with_context(|| format!("{}: move the staged set into place", self.name))?;
> + }
> + Ok(bpf)
> + });
> + let mut bpf = match staged {
> + Ok(bpf) => bpf,
> + Err(e) => {
> + // the pins would keep the fresh maps alive
> + if let Err(err) = std::fs::remove_dir_all(&staging) {
> + log::warn!("{}: remove the staged set: {err:#}", self.name);
> + }
> + return Err(e);
> + }
> + };
> + self.remove_foreign_pins()?;
> + self.swap_links(&mut bpf)?;
> + if let Err(e) = remove_dir_if_present(&staging) {
> + log::warn!("{}: remove the retired set: {e:#}", self.name);
> + }
> + for (dir, _) in others {
> + if let Err(e) = std::fs::remove_dir_all(&dir) {
> + log::warn!(
> + "{}: remove old pinned state {}: {e:#}",
> + self.name,
> + dir.display()
> + );
> + }
> + }
> + Ok(())
> + }
> +
> + // the fresh set under `staging`, its maps written by `fill` and its programs pinned
> + fn stage(
> + &self,
> + staging: &Path,
> + fill: impl FnOnce(&Staged<'_>) -> anyhow::Result<()>,
> + ) -> anyhow::Result<aya::Ebpf> {
> + std::fs::create_dir_all(staging)
> + .with_context(|| format!("{}: create the staging directory", self.name))?;
> + let mut bpf = self.load(staging)?;
> + fill(&Staged { programs: self })?;
> + self.pin_programs(&mut bpf, staging)?;
> + Ok(bpf)
> + }
> +
> + // one direction's program out of the loaded object, resolved once by the load loop
> + fn loaded<'b>(
> + &self,
> + bpf: &'b mut aya::Ebpf,
> + dir: Direction,
> + ) -> anyhow::Result<&'b mut SchedClassifier> {
> + let name = self
> + .program_name(dir)
> + .expect("only directions with a program are loaded");
> + let prog = bpf
> + .program_mut(name)
> + .expect("every program was resolved by the load loop")
> + .try_into()?;
> + Ok(prog)
> + }
> +
> + fn live_links(&self) -> anyhow::Result<Vec<tc::LinkPin>> {
> + tc::read_pinned_links(&self.links_dir())
> + }
> +
> + // a pin this build cannot read or has no program for is not its state. It would keep a link
> + // running with nothing to update it, so it goes with the next replacement or its repair
> + fn remove_foreign_pins(&self) -> anyhow::Result<()> {
> + for entry in std::fs::read_dir(self.links_dir())? {
> + let entry = entry?;
> + let name = entry.file_name();
> + let ours = name
> + .to_str()
> + .and_then(tc::LinkPin::parse)
> + .is_some_and(|pin| self.program_name(pin.dir).is_some());
> + if ours {
> + continue;
> + }
> + let name = name.to_string_lossy();
> + log::warn!("{}: removing pin {name} this build cannot use", self.name);
> + let path = entry.path();
> + if let Err(e) = tc::detach_pinned_link(&path) {
> + log::warn!("{}: detach {name}: {e:#}", self.name);
> + let _ = std::fs::remove_file(&path);
> + }
> + }
> + Ok(())
> + }
> +
> + fn detach_named(
> + &self,
> + name: &str,
> + keep: impl Fn(&tc::LinkPin) -> bool,
> + ) -> anyhow::Result<Vec<u32>> {
> + let mut ifindexes = Vec::new();
> + for pin in self.live_links()? {
> + if pin.name != name || keep(&pin) {
> + continue;
> + }
> + self.reclaim_link(&pin)?;
> + if !ifindexes.contains(&pin.ifindex) {
> + ifindexes.push(pin.ifindex);
> + }
> + }
> + Ok(ifindexes)
> + }
> +
> + // unpin a link. A pin that cannot be opened stays, a failed open says nothing about the link
"Unpin" vs "reclaim"? :/
> + // behind it
> + fn reclaim_link(&self, pin: &tc::LinkPin) -> anyhow::Result<()> {
> + let path = self.link_pin_path(pin);
> + match tc::detach_pinned_link(&path) {
And the operation is called detach.
I'm getting confused by the wording in this series.
> + Ok(()) => Ok(()),
> + // the other side of a lost race, another attach or unplug took the pin first
> + Err(tc::Error::PinGone) => {
> + log::debug!(
> + "{}: reclaim {}: pin gone already",
> + self.name,
> + pin.filename()
> + );
> + Ok(())
> + }
> + Err(e) => Err(e).with_context(|| format!("{}: unpin {}", self.name, pin.filename())),
> + }
> + }
> +
> + fn reconcile(&self, desired: &HashSet<u32>) -> anyhow::Result<()> {
> + // opened before anything is detached, so a missing program fails the full apply before it
> + // changes anything
> + let mut progs = Vec::new();
> + for &(dir, _) in self.programs {
> + progs.push((dir, self.program(dir)?));
> + }
> + let live = self.live_links()?;
> + let mut attached: HashSet<(u32, Direction)> = HashSet::new();
> +
> + for pin in &live {
> + // a pin whose index now belongs to another interface links nothing wanted
> + let alive = tc::iface_name(pin.ifindex)?.is_some_and(|name| name == pin.name);
> + if alive && desired.contains(&pin.ifindex) {
> + attached.insert((pin.ifindex, pin.dir));
> + continue;
> + }
> + log::info!("{}: detach {}", self.name, pin.filename());
> + if let Err(e) = self.reclaim_link(pin) {
> + log::warn!("{e:#}");
> + }
> + }
> +
> + let mut failed = 0usize;
> + for (dir, prog) in &mut progs {
> + let dir = *dir;
> + for &ifindex in desired {
> + if attached.contains(&(ifindex, dir)) {
> + continue;
> + }
> + let Some(name) = tc::iface_name(ifindex)? else {
> + log::info!("{}: {ifindex} vanished before the attach", self.name);
> + continue;
> + };
> + let pin = tc::LinkPin { ifindex, name, dir };
> + match tc::attach_and_pin(prog, &pin, &self.link_pin_path(&pin)) {
> + Ok(()) => {}
> + Err(tc::Error::IfaceGone) => {
> + log::info!("{}: {ifindex} vanished before the attach", self.name);
> + }
> + Err(e) => {
> + log::error!("{}: attach {}: {e:#}", self.name, pin.filename());
> + failed += 1;
> + }
> + }
> + }
> + }
> + if failed > 0 {
> + anyhow::bail!("{}: {failed} link(s) failed to attach", self.name);
> + }
> + Ok(())
> + }
> +
> + fn attach_iface(&self, ifindex: u32) -> anyhow::Result<()> {
> + // opened for every direction ahead of the pin checks, so a missing program fails here,
> + // never counts as a dead link and leaves no direction attached alone
> + let mut progs = Vec::new();
> + for &(dir, _) in self.programs {
> + progs.push((dir, self.program(dir)?));
> + }
> + let Some(name) = tc::iface_name(ifindex)? else {
> + log::info!("{}: {ifindex} vanished before the attach", self.name);
> + return Ok(());
> + };
> + let live = self.live_links()?;
> + for (dir, prog) in &mut progs {
> + let dir = *dir;
> + let pin = tc::LinkPin {
> + ifindex,
> + name: name.clone(),
> + dir,
> + };
> + let path = self.link_pin_path(&pin);
> + for stale in live.iter().filter(|p| p.ifindex == ifindex && p.dir == dir) {
> + if stale.name == name {
> + let link = match tc::open_pinned_link(&path) {
> + Ok(link) => link,
> + // the pin went away under the swap, another plug of the same interface
> + // is rebuilding it and the attach below finds its link
> + Err(tc::Error::PinGone) => {
> + log::debug!(
> + "{}: {} pin taken by another attach",
> + self.name,
> + path.display()
> + );
> + continue;
> + }
> + Err(e) => {
> + return Err(e).with_context(|| {
> + format!("{}: open {}", self.name, pin.filename())
> + });
> + }
> + };
> + if let Err(e) = tc::swap_link(prog, link) {
> + log::warn!(
> + "{}: {} swap failed ({e:#}), rebuilding",
> + self.name,
> + pin.filename()
> + );
> + self.reclaim_link(stale)?;
> + continue;
> + }
> + } else {
> + // the index was reused since, the old link is not this interface's and does
> + // not stand in the way of its own
> + if let Err(e) = self.reclaim_link(stale) {
> + log::warn!("{e:#}");
> + }
> + }
> + }
> + if path.exists() {
> + continue;
> + }
> + match tc::attach_and_pin(prog, &pin, &path) {
> + Ok(()) => {}
> + Err(tc::Error::IfaceGone) => {
> + log::info!("{}: {ifindex} vanished before the attach", self.name);
> + }
> + Err(tc::Error::AlreadyAttached) => {
> + log::debug!("{}: {} attached concurrently", self.name, pin.filename());
> + }
> + Err(e) => {
> + return Err(e)
> + .with_context(|| format!("{}: attach {}", self.name, pin.filename()));
> + }
> + }
> + }
> + Ok(())
> + }
> +}
> +
> +const LINKS_DIR: &str = "links";
> +
> +fn links_dir_of(subsystem: &str) -> PathBuf {
> + PathBuf::from(PIN_ROOT).join(subsystem).join(LINKS_DIR)
> +}
> +
> +// the name of a build's program directory, its version and fingerprint, with colons for the
> +// dots bpffs refuses in a name
> +fn build_dir_name(version: [u64; 3], fingerprint: u64) -> String {
> + format!(
> + "{}:{}:{}-{fingerprint:016x}",
> + version[0], version[1], version[2]
> + )
> +}
> +
> +fn parse_build_dir_name(name: &str) -> Option<([u64; 3], u64)> {
> + let (version, fingerprint) = name.split_once('-')?;
> + let mut parts = version.split(':').map(|part| part.parse::<u64>().ok());
> + let version = [parts.next()??, parts.next()??, parts.next()??];
> + if parts.next().is_some() || fingerprint.len() != 16 {
> + return None;
> + }
> + Some((version, u64::from_str_radix(fingerprint, 16).ok()?))
> +}
> +
> +fn version_text(version: [u64; 3]) -> String {
> + format!("{}.{}.{}", version[0], version[1], version[2])
> +}
> +
> +fn schema_live_dir(schema_root: &Path) -> PathBuf {
> + schema_root.join("live")
> +}
> +
> +fn schema_progs_dir(schema_root: &Path) -> PathBuf {
> + schema_live_dir(schema_root).join("prog")
> +}
^ The above 2 path helpers are outliers in that they aren't inside
`TcPrograms`. It gets a bit difficult to keep track of all the path
helpers.
Also, `TcPrograms::live_dir()` now calls out to this extra function
above, but could just be inline like the rest of them, as both of these
are only used inside `impl TcPrograms`.
> +
> +fn remove_dir_if_present(dir: &Path) -> std::io::Result<()> {
> + match std::fs::remove_dir_all(dir) {
> + Err(e) if e.kind() != ErrorKind::NotFound => Err(e),
> + _ => Ok(()),
> + }
> +}
> +
> +// a program pin is a file under a build directory. A run killed between creating that
> +// directory and pinning leaves it empty. Like the links, a directory that cannot be read may
> +// hold anything, a missing one is empty
> +fn any_program_pinned(progs_dir: &Path) -> bool {
> + let non_empty = |dir: &Path| match std::fs::read_dir(dir) {
> + Ok(mut entries) => entries.next().is_some(),
> + Err(e) => e.kind() != ErrorKind::NotFound,
> + };
> + match std::fs::read_dir(progs_dir) {
> + Ok(fingerprints) => fingerprints.into_iter().any(|fp| match fp {
> + Ok(fp) => non_empty(&fp.path()),
> + Err(_) => true,
> + }),
> + Err(e) => e.kind() != ErrorKind::NotFound,
> + }
> +}
> +
> +/// Marker for a guard holding the apply lock shared.
> +pub struct Shared;
> +
> +/// Marker for a guard holding the apply lock exclusively.
> +pub struct Exclusive;
> +
> +/// The apply lock of one subsystem, held for as long as the guard lives. Replacing the maps and
"held for as long as the guard lives" is superfluous.
> +/// matching the links to the desired set rewrite pinned state and exist only on the
> +/// [`Exclusive`] guard, so nothing runs them next to shared holders. A shared holder adds or
Weirdly worded and already seen from the impl blocks (which can also
have doc comments themselves FYI. Rustdoc shows them as separate blocks,
too.
> +/// drops its own link and writes map entries that stand on their own, each write atomic in the
*ugh*
> +/// kernel. A write that depends on what was read before it takes the exclusive lock, or the
> +/// kernel's conditional write. A shared holder cannot upgrade, one that finds nothing current
What conditional write is this referring to?
> +/// leaves bringing the set up to a full apply under the exclusive lock.
> +pub struct ApplyLock<'a, M> {
> + programs: &'a TcPrograms,
> + _lock: Flock<File>,
> + _mode: PhantomData<M>,
> +}
> +
> +impl<M> ApplyLock<'_, M> {
> + /// Whether this build's programs and maps are pinned and no newer schema is. A shared holder
> + /// checks this before it writes, since only a full apply brings the pins up and an older build
> + /// stays out of a newer schema. Under the lock the program and map pins do not change, only
> + /// links come and go, so the answer holds for the holder's steps.
> + pub fn is_current(&self) -> bool {
> + self.programs.is_current()
> + }
> +
> + /// Whether a replacement stopped halfway. Its staged set or the directories of other schemas
> + /// are still there, so the links may still run the programs it retired.
> + pub fn interrupted(&self) -> bool {
> + self.programs.interrupted()
> + }
> +
> + /// Open one of this build's live maps by name, [`NotLoaded`] when it is not pinned.
> + pub fn hash_map<K: aya::Pod, V: aya::Pod>(
> + &self,
> + name: &str,
> + ) -> anyhow::Result<MapHandle<'_, K, V>> {
> + Ok(MapHandle {
> + map: self.programs.hash_map(name)?,
> + _opened_through: PhantomData,
> + })
> + }
> +
> + /// Attach the programs to a single interface, leaving the others alone.
> + ///
> + /// If a pin already exists, swap the program in place with no traffic gap. A pin that cannot
> + /// be swapped is reclaimed and the interface attached fresh. Two concurrent attaches of the
> + /// same interface run under the shared lock, the one that loses the race finds the other's
> + /// link in place and is done. A failed attach returns the error, [`NotLoaded`] when nothing
> + /// is pinned yet, and the caller decides what an interface without the program means for it.
> + pub fn attach_iface(&self, ifindex: u32) -> anyhow::Result<()> {
> + self.programs.attach_iface(ifindex)
> + }
> +
> + /// Detach the programs from the interface of that name, even when the interface is gone
> + /// already. A pin for which `keep` returns true stays, such as one of a newer interface under
> + /// the same name. Returns the indexes the detached links had.
> + pub fn detach_named(
> + &self,
> + name: &str,
> + keep: impl Fn(&tc::LinkPin) -> bool,
> + ) -> anyhow::Result<Vec<u32>> {
> + self.programs.detach_named(name, keep)
> + }
> +
> + /// The links of this subsystem as their pins name them. A shared holder sees a snapshot,
> + /// another attach may add to it meanwhile. The name is not unique. A leftover pin of an
> + /// interface that went away and the pin of its successor under the name share it, only the
> + /// index tells them apart.
> + pub fn attached(&self) -> anyhow::Result<Vec<tc::LinkPin>> {
> + self.programs.live_links()
> + }
> +}
> +
> +impl ApplyLock<'_, Exclusive> {
> + /// Bring this build's programs and maps up, or replace the content of the maps when they are
> + /// up already, without a program ever reading a mix of old and new entries. A first install,
> + /// a new build and a schema change are all this one call. `fill` writes the whole desired
> + /// content into fresh maps, and only once it returned do the programs holding them take over
> + /// the links, one link at a time. A failure inside `fill`, a refused entry included, leaves
> + /// what is pinned untouched. Nothing written into the live maps carries over, a caller that
> + /// wants some of it reads it through [`hash_map`](Self::hash_map) before the call, which
> + /// answers [`NotLoaded`] when nothing of this build is pinned. Pinned state of a newer schema
> + /// or of a newer version of the subsystem's crate is refused.
This IMO does not properly describe what fill is *supposed* to do. But
it does claim to state what it "does".
> + ///
> + /// Takes the guard exclusively, a map handle open across the exchange would write the
> + /// retired map.
> + pub fn replace_maps(
> + &mut self,
> + fill: impl FnOnce(&Staged<'_>) -> anyhow::Result<()>,
> + ) -> anyhow::Result<()> {
> + self.programs.replace_maps(fill)
> + }
> +
> + /// Make the attached set match `desired`. Moving links onto new programs is
> + /// [`replace_maps`](Self::replace_maps)'s job. The live set cannot change under it, every
> + /// other writer waits on the exclusive lock. What may go is decided from the kernel's state.
Most of this paragraph does not seem to belong here?
The parameter is not really explained (and this is a public API not
called from anywhere in here).
> + ///
> + /// An interface that failed to attach fails the apply once every other was tried, since the
> + /// subsystem does not work on an interface without its program. One that vanished since it
> + /// was named is no failure, and a failed detach only leaves a program running longer and is
> + /// logged.
> + pub fn reconcile(&self, desired: &HashSet<u32>) -> anyhow::Result<()> {
> + self.programs.reconcile(desired)
> + }
> +
> + /// Drop the pinned state of this subsystem, links included. Leaving links attached would keep
> + /// the programs running with nothing left to update them. The lock under `/run` stays,
> + /// unlinking it under a waiter would let that waiter run unserialized. Takes the guard
> + /// exclusively like [`replace_maps`](Self::replace_maps).
> + pub fn clear(&mut self) -> anyhow::Result<()> {
> + self.programs.tear_down()
> + }
> +}
> +
> +/// The fresh maps of a [`replace_maps`](ApplyLock::replace_maps), seen only by the fill that
> +/// writes them.
> +pub struct Staged<'a> {
> + programs: &'a TcPrograms,
> +}
> +
> +impl Staged<'_> {
> + /// Open one of the staged maps by name, empty until the fill writes it.
> + pub fn hash_map<K: aya::Pod, V: aya::Pod>(
> + &self,
> + name: &str,
> + ) -> anyhow::Result<MapHandle<'_, K, V>> {
> + Ok(MapHandle {
> + map: self
> + .programs
> + .hash_map_in(&self.programs.staging_dir(), name)?,
> + _opened_through: PhantomData,
> + })
> + }
> +}
> +
> +/// A pinned hash map. It cannot outlive the lock or the fill it was opened under, so every write
> +/// to it runs under the lock and goes into the maps the programs use.
> +pub struct MapHandle<'a, K, V> {
> + map: aya::maps::HashMap<aya::maps::MapData, K, V>,
> + _opened_through: PhantomData<&'a ()>,
> +}
> +
> +impl<K, V> Deref for MapHandle<'_, K, V> {
> + type Target = aya::maps::HashMap<aya::maps::MapData, K, V>;
> +
> + fn deref(&self) -> &Self::Target {
> + &self.map
> + }
> +}
> +
> +impl<K, V> DerefMut for MapHandle<'_, K, V> {
> + fn deref_mut(&mut self) -> &mut Self::Target {
> + &mut self.map
> + }
> +}
> diff --git a/proxmox-ebpf/src/tc.rs b/proxmox-ebpf/src/tc.rs
> index 1217703e8906..09a02b2947cc 100644
> --- a/proxmox-ebpf/src/tc.rs
> +++ b/proxmox-ebpf/src/tc.rs
> @@ -10,14 +10,14 @@ use aya::{
> programs::{
> ProgramError, SchedClassifier, TcAttachType,
> links::{FdLink, LinkError, LinkOrder, PinnedLink},
> - tc::TcAttachOptions,
> + tc::{SchedClassifierLink, TcAttachOptions},
> },
> };
>
> /// Why a link step did not go through, with the kernel's own answer where it gives one, so a
> /// caller can tell a lost race or a vanished interface from a real failure.
> #[derive(Debug)]
> -pub enum Error {
> +pub(crate) enum Error {
> /// A link of the program is in place already, another attach of the interface won the race.
> AlreadyAttached,
> /// The interface is gone, its index names no netdev anymore.
> @@ -108,8 +108,11 @@ pub enum Direction {
> }
>
> impl Direction {
> + /// Both hooks.
> + pub(crate) const ALL: [Self; 2] = [Self::Ingress, Self::Egress];
> +
> /// The lowercase name, as it stands in pin file names.
> - pub fn as_str(self) -> &'static str {
> + pub const fn as_str(self) -> &'static str {
> match self {
> Self::Ingress => "ingress",
> Self::Egress => "egress",
> @@ -182,7 +185,7 @@ impl LinkPin {
> /// verdict ends the chain right there. So a subsystem's program returns `TC_ACT_UNSPEC` for
> /// whatever it leaves alone. Programs of several subsystems run in attach order, each new link
> /// goes last.
> -pub fn attach_and_pin(
> +pub(crate) fn attach_and_pin(
> prog: &mut SchedClassifier,
> pin: &LinkPin,
> pin_path: &Path,
> @@ -210,18 +213,23 @@ pub fn attach_and_pin(
> Ok(())
> }
>
> -/// Rebind a pinned link to `prog` via LINK_UPDATE. Atomic, traffic sees no detach/reattach gap.
> -pub fn swap_pinned_link(prog: &mut SchedClassifier, pin_path: &Path) -> Result<(), Error> {
> - let pinned = PinnedLink::from_pin(pin_path)?;
> - let fd_link: FdLink = pinned.into();
> - let link = fd_link.try_into()?;
> +pub(crate) fn open_pinned_link(pin_path: &Path) -> Result<SchedClassifierLink, Error> {
> + let fd_link: FdLink = PinnedLink::from_pin(pin_path)?.into();
> + Ok(fd_link.try_into()?)
> +}
> +
> +/// Rebind `link` to `prog` via LINK_UPDATE. Atomic, traffic sees no detach/reattach gap.
> +pub(crate) fn swap_link(
> + prog: &mut SchedClassifier,
> + link: SchedClassifierLink,
> +) -> Result<(), Error> {
> let new_id = prog.attach_to_link(link)?;
> // take the handle out of aya's internal tracking, we have the pin
> let _ = prog.take_link(new_id)?;
> Ok(())
> }
>
> -pub fn detach_pinned_link(pin_path: &Path) -> Result<(), Error> {
> +pub(crate) fn detach_pinned_link(pin_path: &Path) -> Result<(), Error> {
> let pinned = PinnedLink::from_pin(pin_path)?;
> let _fd_link = pinned.unpin()?;
> Ok(())
> @@ -229,7 +237,7 @@ pub fn detach_pinned_link(pin_path: &Path) -> Result<(), Error> {
>
> /// The name of an interface by index, none when it is gone. Any other failure says nothing
> /// about the interface and is not taken as its absence, so the lookup reads errno itself.
> -pub fn iface_name(ifindex: u32) -> anyhow::Result<Option<String>> {
> +pub(crate) fn iface_name(ifindex: u32) -> anyhow::Result<Option<String>> {
> let mut buf = [0u8; nix::libc::IF_NAMESIZE];
> // SAFETY: the buffer holds IF_NAMESIZE bytes, the most the call writes
> let name = unsafe { nix::libc::if_indextoname(ifindex, buf.as_mut_ptr().cast()) };
> @@ -247,7 +255,7 @@ pub fn iface_name(ifindex: u32) -> anyhow::Result<Option<String>> {
>
> /// The pins in `links_dir`, see [`LinkPin`], none for a missing directory. A file that is not a
> /// pin is skipped.
> -pub fn read_pinned_links(links_dir: &Path) -> anyhow::Result<Vec<LinkPin>> {
> +pub(crate) fn read_pinned_links(links_dir: &Path) -> anyhow::Result<Vec<LinkPin>> {
> let mut out = Vec::new();
> let dir = match std::fs::read_dir(links_dir) {
> Ok(d) => d,
> --
> 2.47.3
>
>
>
>
>
--
next prev parent reply other threads:[~2026-11-05 16:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 17:29 [PATCH proxmox v8 0/6] add proxmox-ebpf library Hannes Laimer
2026-11-04 17:29 ` [PATCH proxmox v8 1/6] ebpf: add the crate with its BPF build Hannes Laimer
2026-11-04 17:29 ` [PATCH proxmox v8 2/6] ebpf: tc: add the link plumbing Hannes Laimer
2026-11-04 17:29 ` [PATCH proxmox v8 3/6] ebpf: subsystem: add the shared tc program handling Hannes Laimer
2026-11-05 16:20 ` Wolfgang Bumiller [this message]
2026-11-04 17:29 ` [PATCH proxmox v8 4/6] ebpf: subsystem: place subsystem links in a fixed order Hannes Laimer
2026-11-06 13:30 ` Wolfgang Bumiller
2026-11-04 17:29 ` [PATCH proxmox v8 5/6] ebpf: tests: add a native harness for the BPF C programs Hannes Laimer
2026-11-04 17:29 ` [PATCH proxmox v8 6/6] ebpf: debian: package the crate as a Rust library Hannes Laimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=gkpnew2dpictqpyj5ukc33p4ql355azr7tczad4ry2ce2fhlnl@zc6nhnkz77yb \
--to=w.bumiller@proxmox.com \
--cc=h.laimer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.