Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/backends/qemu/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
},
},
instance::{InstanceClient, ThreadPoolSnapshot},
util::Path,
};

/// Wire client for an QEMU-managed VM.
Expand Down Expand Up @@ -261,7 +262,7 @@ impl InstanceClient for QemuInstanceClient {
"qemu topology reported no iothread TIDs".into(),
));
}
let pid = Process::new(first_tid)?
let pid = Process::new_with_root(Path::proc_pid(first_tid))?
.status()
.map_err(|e| BackendClientError::InvalidState(format!("pid resolution: {e}")))?
.tgid;
Expand Down
7 changes: 5 additions & 2 deletions src/backends/qemu/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use regex::Regex;
use rustix::param;
use thiserror::Error;

use crate::backends::{BackendClientError, VqMapping};
use crate::{
backends::{BackendClientError, VqMapping},
util::Path,
};

/// Errors produced while querying or reconfiguring a QEMU vm.
#[derive(Debug, Error)]
Expand Down Expand Up @@ -200,7 +203,7 @@ impl CpuSample {
wall: Instant::now(),
};

let p = Process::new(pid)?;
let p = Process::new_with_root(Path::proc_pid(pid))?;
for &tid in iothread_tids.values() {
let stat = p.task_from_tid(tid)?.stat()?;
out.jiffies.insert(tid, stat.utime + stat.stime);
Expand Down
7 changes: 5 additions & 2 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

use futures_util::future::join_all;
use procfs::{CurrentSI, ProcError};
use procfs::{FromReadSI, ProcError};
use serde::{Deserialize, Serialize};
use statistical::median;
use thiserror::Error;
Expand All @@ -25,6 +25,7 @@ use crate::{
instance::{Instance, InstanceStatus},
rolling::format_1_5_15,
state::{StateError, VmOwnership, VmStateStore},
util::Path,
};
/// Wire-facing container for the D-Bus `GetSnapshot` reply.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -804,7 +805,9 @@ impl Controller {

/// Read aggregate host CPU counters.
fn read_host_cpu_sample() -> Result<HostCpuSample, ControllerError> {
let total = procfs::KernelStats::current()?.total;
let total =
procfs::KernelStats::from_file(Path::new("/proc/stat"), procfs::current_system_info())?
.total;
let idle_ticks = total.idle.saturating_add(total.iowait.unwrap_or(0));
let total_ticks = total
.user
Expand Down
2 changes: 1 addition & 1 deletion src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ fn read_cpu_sample(
pid: i32,
filter: &crate::instance::ThreadNameFilter,
) -> Result<CpuSample, CpuSampleError> {
let process = Process::new(pid)?;
let process = Process::new_with_root(Path::proc_pid(pid))?;
let tasks = process.tasks()?;
let mut cpu_ticks = 0u64;
let mut thread_count = 0u32;
Expand Down
10 changes: 10 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ impl Path {
pub fn glob(&self) -> glob::Paths {
glob::glob(&self.path.to_string_lossy()).expect("valid glob pattern")
}

/// `/proc/<pid>` after applying [`IO_THREAD_CONTROLLER_ROOT_PATH`].
///
/// `procfs::process::Process::new` always opens the real `/proc`. Callers
/// that should honor the mock root pass this path to
/// `Process::new_with_root`.
pub fn proc_pid(pid: i32) -> std::path::PathBuf {
let path = Self::new(&format!("/proc/{pid}"));
std::path::PathBuf::from(std::path::Path::as_os_str(&path))
}
}

impl From<&str> for Path {
Expand Down
Loading