summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-09-01 14:14:51 +0300
committerLars Wirzenius <liw@liw.fi>2023-09-01 15:30:03 +0300
commit337577a9a207ad2ab84a00c8d7e88b64f51099fe (patch)
tree4013ba241512b7d58cfc409ff900fb8a5e090c17
parentad1663f151988e3d01df85bc9f796fd3d5fd3b01 (diff)
downloadambient-run-337577a9a207ad2ab84a00c8d7e88b64f51099fe.tar.gz
feat: set max output size to writable virtual drives
Currently, the max size is hard coded to 1 GiB, but that can be made user-configurable later. Sponsored-by: author
-rw-r--r--src/qemu.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/qemu.rs b/src/qemu.rs
index c0aa1b1..98254bf 100644
--- a/src/qemu.rs
+++ b/src/qemu.rs
@@ -8,6 +8,7 @@ use std::{
process::{Command, Stdio},
};
+const MAX_OUTPUT_SIZE: u64 = 1024 * 1024 * 1024;
const OVMF_FD: &str = "/usr/share/ovmf/OVMF.fd";
/// A QEMU runner.
@@ -57,8 +58,10 @@ impl Qemu {
copy(&self.image, &image).map_err(|e| QemuError::Copy(self.image.clone(), e))?;
copy(OVMF_FD, &vars).map_err(|e| QemuError::Copy(OVMF_FD.into(), e))?;
- let output_drive = Self::create_tar(tmp.path().join("output"), empty.path())?;
- let cache_drive = Self::create_tar(tmp.path().join("cache"), empty.path())?;
+ let output_drive =
+ Self::create_tar_with_size(tmp.path().join("output"), empty.path(), MAX_OUTPUT_SIZE)?;
+ let cache_drive =
+ Self::create_tar_with_size(tmp.path().join("cache"), empty.path(), MAX_OUTPUT_SIZE)?;
let deps_drive = Self::create_tar(tmp.path().join("deps"), empty.path())?;
if let Some(shell) = &self.shell {
@@ -121,6 +124,20 @@ impl Qemu {
.map_err(|e| QemuError::Tar(dirname.into(), e))?;
Ok(tar)
}
+
+ fn create_tar_with_size(
+ tar_filename: PathBuf,
+ dirname: &Path,
+ size: u64,
+ ) -> Result<VirtualDrive, QemuError> {
+ let tar = VirtualDriveBuilder::default()
+ .filename(&tar_filename)
+ .root_directory(dirname)
+ .size(size)
+ .create()
+ .map_err(|e| QemuError::Tar(dirname.into(), e))?;
+ Ok(tar)
+ }
}
#[derive(Debug, Default)]