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§
Sourcefn parent_path(&self) -> &Path
fn parent_path(&self) -> &Path
Path to the parent cgroup directory. See
CgroupManager::parent_path.
Sourcefn setup(&self, controllers: &BTreeSet<Controller>) -> Result<()>
fn setup(&self, controllers: &BTreeSet<Controller>) -> Result<()>
Create the parent directory and enable controllers. See
CgroupManager::setup.
Sourcefn create_cgroup(&self, name: &str) -> Result<()>
fn create_cgroup(&self, name: &str) -> Result<()>
Create a child cgroup. See CgroupManager::create_cgroup.
Sourcefn remove_cgroup(&self, name: &str) -> Result<()>
fn remove_cgroup(&self, name: &str) -> Result<()>
Drain and remove a child cgroup. See
CgroupManager::remove_cgroup.
Sourcefn set_cpuset(&self, name: &str, cpus: &BTreeSet<usize>) -> Result<()>
fn set_cpuset(&self, name: &str, cpus: &BTreeSet<usize>) -> Result<()>
Write cpuset.cpus. See CgroupManager::set_cpuset.
Sourcefn clear_cpuset(&self, name: &str) -> Result<()>
fn clear_cpuset(&self, name: &str) -> Result<()>
Clear cpuset.cpus (inherit from parent). See
CgroupManager::clear_cpuset.
Sourcefn set_cpuset_mems(&self, name: &str, nodes: &BTreeSet<usize>) -> Result<()>
fn set_cpuset_mems(&self, name: &str, nodes: &BTreeSet<usize>) -> Result<()>
Write cpuset.mems. See CgroupManager::set_cpuset_mems.
Sourcefn clear_cpuset_mems(&self, name: &str) -> Result<()>
fn clear_cpuset_mems(&self, name: &str) -> Result<()>
Clear cpuset.mems (inherit from parent). See
CgroupManager::clear_cpuset_mems.
Sourcefn set_cpu_max(
&self,
name: &str,
quota_us: Option<u64>,
period_us: u64,
) -> Result<()>
fn set_cpu_max( &self, name: &str, quota_us: Option<u64>, period_us: u64, ) -> Result<()>
Write cpu.max. See CgroupManager::set_cpu_max.
Sourcefn set_cpu_weight(&self, name: &str, weight: u32) -> Result<()>
fn set_cpu_weight(&self, name: &str, weight: u32) -> Result<()>
Write cpu.weight. See CgroupManager::set_cpu_weight.
Sourcefn set_memory_max(&self, name: &str, bytes: Option<u64>) -> Result<()>
fn set_memory_max(&self, name: &str, bytes: Option<u64>) -> Result<()>
Write memory.max. See CgroupManager::set_memory_max.
Sourcefn set_memory_high(&self, name: &str, bytes: Option<u64>) -> Result<()>
fn set_memory_high(&self, name: &str, bytes: Option<u64>) -> Result<()>
Write memory.high. See CgroupManager::set_memory_high.
Sourcefn set_memory_low(&self, name: &str, bytes: Option<u64>) -> Result<()>
fn set_memory_low(&self, name: &str, bytes: Option<u64>) -> Result<()>
Write memory.low. See CgroupManager::set_memory_low.
Sourcefn set_io_weight(&self, name: &str, weight: u16) -> Result<()>
fn set_io_weight(&self, name: &str, weight: u16) -> Result<()>
Write io.weight. See CgroupManager::set_io_weight.
Sourcefn set_freeze(&self, name: &str, frozen: bool) -> Result<()>
fn set_freeze(&self, name: &str, frozen: bool) -> Result<()>
Write cgroup.freeze. See CgroupManager::set_freeze.
Sourcefn set_pids_max(&self, name: &str, max: Option<u64>) -> Result<()>
fn set_pids_max(&self, name: &str, max: Option<u64>) -> Result<()>
Write pids.max. See CgroupManager::set_pids_max.
Sourcefn set_memory_swap_max(&self, name: &str, bytes: Option<u64>) -> Result<()>
fn set_memory_swap_max(&self, name: &str, bytes: Option<u64>) -> Result<()>
Write memory.swap.max. See
CgroupManager::set_memory_swap_max.
Sourcefn move_task(&self, name: &str, pid: pid_t) -> Result<()>
fn move_task(&self, name: &str, pid: pid_t) -> Result<()>
Move a single task via cgroup.procs. See
CgroupManager::move_task.
Sourcefn move_tasks(&self, name: &str, pids: &[pid_t]) -> Result<()>
fn move_tasks(&self, name: &str, pids: &[pid_t]) -> Result<()>
Move multiple tasks (tolerates ESRCH, retries EBUSY). See
CgroupManager::move_tasks.
Sourcefn place_task_during_handshake(
&self,
cgroup_name: &str,
child_pid: pid_t,
) -> Result<()>
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_nameargument is the user-facing name the test author passed inOp::RunPayload { cgroup: Some(name), ... }orPayloadRun::in_cgroup(name)— NOT a derived absolute path. The implementation derives thecgroup.procspath from this name plus its own parent-path knowledge.
Sourcefn clear_subtree_control(&self, name: &str) -> Result<()>
fn clear_subtree_control(&self, name: &str) -> Result<()>
Clear cgroup.subtree_control on a child. See
CgroupManager::clear_subtree_control.
Sourcefn drain_tasks(&self, name: &str) -> Result<()>
fn drain_tasks(&self, name: &str) -> Result<()>
Drain tasks from a child to the cgroup root. See
CgroupManager::drain_tasks.
Sourcefn read_procs(&self, name: &str) -> Result<Vec<pid_t>>
fn read_procs(&self, name: &str) -> Result<Vec<pid_t>>
Read cgroup.procs of a child, returning thread-group leaders.
See CgroupManager::read_procs.
Sourcefn cleanup_all(&self) -> Result<()>
fn cleanup_all(&self) -> Result<()>
Remove all child cgroups under the parent. See
CgroupManager::cleanup_all.