summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-02-21 19:49:24 +0200
committerLars Wirzenius <liw@liw.fi>2024-02-21 19:49:24 +0200
commit14a7e753bef321255d153767b24aa5f6fbf1afa2 (patch)
tree9cbc55b1c4954abc35e8b1db7654978ed61c45ba
parentae2907025fdc847634a81e70e84608ad1c477f5e (diff)
downloadambient-driver-14a7e753bef321255d153767b24aa5f6fbf1afa2.tar.gz
feat: allow configuring max size of cache, artifacts
Signed-off-by: Lars Wirzenius <liw@liw.fi> Sponsored-by: author
-rw-r--r--src/config.rs17
-rw-r--r--src/project.rs5
-rw-r--r--src/qemu.rs21
-rw-r--r--src/run.rs7
4 files changed, 43 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs
index 554212f..1d4e965 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -19,6 +19,9 @@ const APP: &str = env!("CARGO_PKG_NAME");
const DEFAULT_TMP: &str = "/tmp";
const DEFAULT_MEMORY: u64 = GIB;
+const DEFAULT_ARTIFACTS_MAX_SIZE: u64 = 10 * GIB;
+const DEFAULT_CACHE_MAX_SIZE: u64 = 10 * GIB;
+
#[derive(Debug, Parser)]
#[clap(name = APP, version = env!("CARGO_PKG_VERSION"))]
pub struct Args {
@@ -141,6 +144,8 @@ pub struct StoredConfig {
run_ci: Option<PathBuf>,
cpus: Option<usize>,
memory: Option<u64>,
+ artifacts_max_size: Option<u64>,
+ cache_max_size: Option<u64>,
}
impl StoredConfig {
@@ -202,6 +207,18 @@ impl EffectiveConfig {
pub fn cmd(&self) -> &Command {
&self.cmd
}
+
+ pub fn artfifacts_max_size(&self) -> u64 {
+ self.stored_config
+ .artifacts_max_size
+ .unwrap_or(DEFAULT_ARTIFACTS_MAX_SIZE)
+ }
+
+ pub fn cache_max_size(&self) -> u64 {
+ self.stored_config
+ .cache_max_size
+ .unwrap_or(DEFAULT_CACHE_MAX_SIZE)
+ }
}
impl TryFrom<&Args> for EffectiveConfig {
diff --git a/src/project.rs b/src/project.rs
index 8dd9c0d..959da5d 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -52,6 +52,7 @@ pub struct Project {
plan: Option<Vec<Action>>,
post_plan: Option<Vec<PostAction>>,
artifact_max_size: Option<u64>,
+ cache_max_size: Option<u64>,
}
impl Project {
@@ -95,6 +96,10 @@ impl Project {
self.artifact_max_size
}
+ pub fn cache_max_size(&self) -> Option<u64> {
+ self.cache_max_size
+ }
+
pub fn pre_plan(&self) -> &[PreAction] {
if let Some(plan) = &self.pre_plan {
plan.as_slice()
diff --git a/src/qemu.rs b/src/qemu.rs
index 3024f25..22c0bb9 100644
--- a/src/qemu.rs
+++ b/src/qemu.rs
@@ -12,7 +12,6 @@ use tempfile::tempdir_in;
use crate::vdrive::{VirtualDrive, VirtualDriveBuilder, VirtualDriveError};
-const MAX_OUTPUT_SIZE: u64 = 10 * 1024 * MIB;
const OVMF_FD: &str = "/usr/share/ovmf/OVMF.fd";
pub const RUN_CI_DRIVE: &str = "/dev/vdb";
@@ -39,6 +38,7 @@ pub struct Qemu {
artifact_max_xize: u64,
dependencies: Option<PathBuf>,
cache: Option<PathBuf>,
+ cache_max_size: u64,
cpus: usize,
memory: u64,
}
@@ -50,7 +50,6 @@ impl Qemu {
image: image.into(),
tmpdir: tmpdir.into(),
source: PathBuf::from("."),
- artifact_max_xize: MAX_OUTPUT_SIZE,
cpus,
memory,
..Default::default()
@@ -82,8 +81,8 @@ impl Qemu {
}
/// Set maximum length of output artifact.
- pub fn with_artifact_max_size(mut self, size: Option<u64>) -> Self {
- self.artifact_max_xize = size.unwrap_or(MAX_OUTPUT_SIZE);
+ pub fn with_artifact_max_size(mut self, size: u64) -> Self {
+ self.artifact_max_xize = size;
self
}
@@ -99,6 +98,12 @@ impl Qemu {
self
}
+ /// Set maximum length of cache.
+ pub fn with_cache_max_size(mut self, size: u64) -> Self {
+ self.cache_max_size = size;
+ self
+ }
+
/// Run QEMU in the specified way.
pub fn run(&self) -> Result<i32, QemuError> {
debug!("run QEMU");
@@ -131,10 +136,14 @@ impl Qemu {
let cache_drive = if let Some(dirname) = &self.cache {
debug!("create cache drive at {}", dirname.display());
- Self::create_tar_with_size(tmp.path().join("cache.tar"), dirname, MAX_OUTPUT_SIZE)?
+ Self::create_tar_with_size(tmp.path().join("cache.tar"), dirname, self.cache_max_size)?
} else {
debug!("no cache drive");
- Self::create_tar_with_size(tmp.path().join("cache.tar"), empty.path(), MAX_OUTPUT_SIZE)?
+ Self::create_tar_with_size(
+ tmp.path().join("cache.tar"),
+ empty.path(),
+ self.cache_max_size,
+ )?
};
let deps_drive = if let Some(dirname) = &self.dependencies {
diff --git a/src/run.rs b/src/run.rs
index 51cfd33..e0ee552 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -101,9 +101,14 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> {
.with_run_ci(&run_ci_dir)
.with_source(project.source())
.with_artifact(&Some(artifact.clone()))
- .with_artifact_max_size(project.artifact_max_size())
+ .with_artifact_max_size(
+ project
+ .artifact_max_size()
+ .unwrap_or(config.artfifacts_max_size()),
+ )
.with_dependencies(&Some(dependencies.clone()))
.with_cache(&Some(cachedir.clone()))
+ .with_cache_max_size(project.cache_max_size().unwrap_or(config.cache_max_size()))
.with_log(log);
let exit = qemu.run()?;
debug!("QEMU exit code {}", exit);