CgroupOps

Trait CgroupOps 

Source
pub trait CgroupOps {
Show 24 methods // Required methods fn parent_path(&self) -> &Path; fn setup(&self, controllers: &BTreeSet<Controller>) -> Result<()>; fn create_cgroup(&self, name: &str) -> Result<()>; fn remove_cgroup(&self, name: &str) -> Result<()>; fn set_cpuset(&self, name: &str, cpus: &BTreeSet<usize>) -> Result<()>; fn clear_cpuset(&self, name: &str) -> Result<()>; fn set_cpuset_mems(&self, name: &str, nodes: &BTreeSet<usize>) -> Result<()>; fn clear_cpuset_mems(&self, name: &str) -> Result<()>; fn set_cpu_max( &self, name: &str, quota_us: Option<u64>, period_us: u64, ) -> Result<()>; fn set_cpu_weight(&self, name: &str, weight: u32) -> Result<()>; fn set_memory_max(&self, name: &str, bytes: Option<u64>) -> Result<()>; fn set_memory_high(&self, name: &str, bytes: Option<u64>) -> Result<()>; fn set_memory_low(&self, name: &str, bytes: Option<u64>) -> Result<()>; fn set_io_weight(&self, name: &str, weight: u16) -> Result<()>; fn set_freeze(&self, name: &str, frozen: bool) -> Result<()>; fn set_pids_max(&self, name: &str, max: Option<u64>) -> Result<()>; fn set_memory_swap_max(&self, name: &str, bytes: Option<u64>) -> Result<()>; fn move_task(&self, name: &str, pid: pid_t) -> Result<()>; fn move_tasks(&self, name: &str, pids: &[pid_t]) -> Result<()>; fn place_task_during_handshake( &self, cgroup_name: &str, child_pid: pid_t, ) -> Result<()>; fn clear_subtree_control(&self, name: &str) -> Result<()>; fn drain_tasks(&self, name: &str) -> Result<()>; fn read_procs(&self, name: &str) -> Result<Vec<pid_t>>; fn cleanup_all(&self) -> Result<()>;
}
Expand description

Abstraction over the cgroup v2 filesystem surface used by the scenario runtime. The production implementation is CgroupManager, which translates each method into real writes under /sys/fs/cgroup.

Extracted so scenario::ops::apply_setup and related orchestration code can be unit-tested against an in-memory double: tests construct a recording or failure-injecting implementor, drive apply_setup against it, and assert on the recorded call sequence without touching the host cgroup hierarchy.

Object-safe by design — scenario code holds the trait object behind &dyn CgroupOps rather than being generic. Callers keep writing ctx.cgroups.set_cpuset(...) with no syntactic change; dynamic dispatch resolves to CgroupManager in production and to the test double under #[cfg(test)]. The per-call indirect-call cost is dominated by the filesystem I/O the trait abstracts over.

Required Methods§

Source

fn parent_path(&self) -> &Path

Path to the parent cgroup directory. See CgroupManager::parent_path.

Source

fn setup(&self, controllers: &BTreeSet<Controller>) -> Result<()>

Create the parent directory and enable controllers. See CgroupManager::setup.

Source

fn create_cgroup(&self, name: &str) -> Result<()>

Create a child cgroup. See CgroupManager::create_cgroup.

Source

fn remove_cgroup(&self, name: &str) -> Result<()>

Drain and remove a child cgroup. See CgroupManager::remove_cgroup.

Source

fn set_cpuset(&self, name: &str, cpus: &BTreeSet<usize>) -> Result<()>

Write cpuset.cpus. See CgroupManager::set_cpuset.

Source

fn clear_cpuset(&self, name: &str) -> Result<()>

Clear cpuset.cpus (inherit from parent). See CgroupManager::clear_cpuset.

Source

fn set_cpuset_mems(&self, name: &str, nodes: &BTreeSet<usize>) -> Result<()>

Write cpuset.mems. See CgroupManager::set_cpuset_mems.

Source

fn clear_cpuset_mems(&self, name: &str) -> Result<()>

Clear cpuset.mems (inherit from parent). See CgroupManager::clear_cpuset_mems.

Source

fn set_cpu_max( &self, name: &str, quota_us: Option<u64>, period_us: u64, ) -> Result<()>

Write cpu.max. See CgroupManager::set_cpu_max.

Source

fn set_cpu_weight(&self, name: &str, weight: u32) -> Result<()>

Write cpu.weight. See CgroupManager::set_cpu_weight.

Source

fn set_memory_max(&self, name: &str, bytes: Option<u64>) -> Result<()>

Write memory.max. See CgroupManager::set_memory_max.

Source

fn set_memory_high(&self, name: &str, bytes: Option<u64>) -> Result<()>

Write memory.high. See CgroupManager::set_memory_high.

Source

fn set_memory_low(&self, name: &str, bytes: Option<u64>) -> Result<()>

Write memory.low. See CgroupManager::set_memory_low.

Source

fn set_io_weight(&self, name: &str, weight: u16) -> Result<()>

Write io.weight. See CgroupManager::set_io_weight.

Source

fn set_freeze(&self, name: &str, frozen: bool) -> Result<()>

Write cgroup.freeze. See CgroupManager::set_freeze.

Source

fn set_pids_max(&self, name: &str, max: Option<u64>) -> Result<()>

Write pids.max. See CgroupManager::set_pids_max.

Source

fn set_memory_swap_max(&self, name: &str, bytes: Option<u64>) -> Result<()>

Write memory.swap.max. See CgroupManager::set_memory_swap_max.

Source

fn move_task(&self, name: &str, pid: pid_t) -> Result<()>

Move a single task via cgroup.procs. See CgroupManager::move_task.

Source

fn move_tasks(&self, name: &str, pids: &[pid_t]) -> Result<()>

Move multiple tasks (tolerates ESRCH, retries EBUSY). See CgroupManager::move_tasks.

Source

fn place_task_during_handshake( &self, cgroup_name: &str, child_pid: pid_t, ) -> Result<()>

Place a single task into a child cgroup’s cgroup.procs during the payload-spawn cgroup-sync handshake.

Distinct from Self::move_task / Self::move_tasks: those run post-spawn for synthetic workers whose pids are already in their final cgroup-permissive state. This method runs INSIDE the two-pipe handshake between the child’s pre_exec pid-notify and the parent’s release-signal write, when the child is paused between fork(2) and execve(2). The write MUST land BEFORE the release byte so the child’s execve lands in the destination cgroup — this is the placement-before-exec invariant required to keep tasks like Op::RunPayload { cgroup: Some(name), ... } from briefly inheriting the parent’s cgroup at exec time.

§Caller contract
  • MUST be invoked exactly once during the handshake between pid-notify and release-signal.
  • Failure MUST propagate to the caller, which is responsible for dropping the release pipe to unblock the child with EOF so it bails out of pre_exec rather than execve’ing into an unspecified cgroup.
  • The cgroup_name argument is the user-facing name the test author passed in Op::RunPayload { cgroup: Some(name), ... } or PayloadRun::in_cgroup(name) — NOT a derived absolute path. The implementation derives the cgroup.procs path from this name plus its own parent-path knowledge.

See CgroupManager::place_task_during_handshake.

Source

fn clear_subtree_control(&self, name: &str) -> Result<()>

Clear cgroup.subtree_control on a child. See CgroupManager::clear_subtree_control.

Source

fn drain_tasks(&self, name: &str) -> Result<()>

Drain tasks from a child to the cgroup root. See CgroupManager::drain_tasks.

Source

fn read_procs(&self, name: &str) -> Result<Vec<pid_t>>

Read cgroup.procs of a child, returning thread-group leaders. See CgroupManager::read_procs.

Source

fn cleanup_all(&self) -> Result<()>

Remove all child cgroups under the parent. See CgroupManager::cleanup_all.

Implementors§