Skip to content

Commit 3197380

Browse files
authored
Merge pull request #332 from Dstack-TEE/client-conf
Read qemu path from /etc/dstack/client.conf
2 parents a35663d + d9f4f75 commit 3197380

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ scale = { version = "3.7.4", package = "parity-scale-codec", features = [
115115
serde = { version = "1.0.219", features = ["derive"], default-features = false }
116116
serde-human-bytes = "0.1.0"
117117
serde_json = { version = "1.0.140", default-features = false }
118+
serde_ini = "0.2.0"
118119
toml = "0.8.20"
119120
toml_edit = { version = "0.22.24", features = ["serde"] }
120121
yasna = "0.5.2"

vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tailf.workspace = true
3232
tokio = { workspace = true, features = ["full"] }
3333
git-version.workspace = true
3434
rocket-apitoken.workspace = true
35+
serde_ini.workspace = true
3536

3637
supervisor-client.workspace = true
3738
ra-rpc = { workspace = true, features = ["client", "rocket"] }

vmm/src/config.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,32 @@ pub struct KeyProviderConfig {
310310
pub port: u16,
311311
}
312312

313+
const CLIENT_CONF_PATH: &str = "/etc/dstack/client.conf";
314+
fn read_qemu_path_from_client_conf() -> Option<PathBuf> {
315+
#[derive(Debug, Deserialize)]
316+
struct ClientQemuSection {
317+
path: Option<String>,
318+
}
319+
#[derive(Debug, Deserialize)]
320+
struct ClientIniConfig {
321+
qemu: Option<ClientQemuSection>,
322+
}
323+
324+
let raw = fs_err::read_to_string(CLIENT_CONF_PATH).ok()?;
325+
let parsed: ClientIniConfig = serde_ini::from_str(&raw).ok()?;
326+
let path = parsed.qemu?.path?;
327+
let path = path.trim().trim_matches('"').trim_matches('\'');
328+
if path.is_empty() {
329+
return None;
330+
}
331+
let path = PathBuf::from(path);
332+
if path.exists() {
333+
Some(path)
334+
} else {
335+
None
336+
}
337+
}
338+
313339
impl Config {
314340
pub fn extract_or_default(figment: &Figment) -> Result<Self> {
315341
let mut me: Self = figment.extract()?;
@@ -323,11 +349,18 @@ impl Config {
323349
me.run_path = app_home.join("vm");
324350
}
325351
if me.cvm.qemu_path == PathBuf::default() {
326-
let cpu_arch = std::env::consts::ARCH;
327-
let qemu_path = which::which(format!("qemu-system-{}", cpu_arch))
328-
.context("Failed to find qemu executable")?;
329-
me.cvm.qemu_path = qemu_path;
352+
// Prefer the path from dstack client config if present
353+
if let Some(qemu_path) = read_qemu_path_from_client_conf() {
354+
info!("Found QEMU path from client config: {CLIENT_CONF_PATH:?}");
355+
me.cvm.qemu_path = qemu_path;
356+
} else {
357+
let cpu_arch = std::env::consts::ARCH;
358+
let qemu_path = which::which(format!("qemu-system-{}", cpu_arch))
359+
.context("Failed to find qemu executable")?;
360+
me.cvm.qemu_path = qemu_path;
361+
}
330362
}
363+
info!("QEMU path: {}", me.cvm.qemu_path.display());
331364
}
332365
Ok(me)
333366
}

0 commit comments

Comments
 (0)