Skip to content

Commit

Permalink
fix: add toggle for actor fs mounts (#1478)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->
Fixes RVT-4226
## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Nov 27, 2024
1 parent 496d9dc commit dea5633
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
6 changes: 6 additions & 0 deletions packages/infra/client/config/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct Cluster {
#[serde(rename_all = "snake_case", deny_unknown_fields)]
pub struct Runner {
pub flavor: protocol::ClientFlavor,
/// Whether or not to use a mount for actor file systems.
pub use_mounts: Option<bool>,

/// WebSocket Port for runners on this machine to connect to.
pub port: Option<u16>,
Expand All @@ -89,6 +91,10 @@ pub struct Runner {
}

impl Runner {
pub fn use_mounts(&self) -> bool {
self.use_mounts.unwrap_or(true)
}

pub fn port(&self) -> u16 {
self.port.unwrap_or(7080)
}
Expand Down
84 changes: 44 additions & 40 deletions packages/infra/client/manager/src/actor/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,39 @@ impl Actor {

tracing::info!(actor_id=?self.actor_id, "creating fs");

// Create a zero-filled file
let fs_img = File::create(&fs_img_path).await?;
fs_img
.set_len(self.config.resources.disk as u64 * 1024 * 1024)
.await?;
fs::create_dir(&fs_path).await?;

// Format file as ext4
let cmd_out = Command::new("mkfs.ext4").arg(&fs_img_path).output().await?;
if ctx.config().runner.use_mounts() {
// Create a zero-filled file
let fs_img = File::create(&fs_img_path).await?;
fs_img
.set_len(self.config.resources.disk as u64 * 1024 * 1024)
.await?;

ensure!(
cmd_out.status.success(),
"failed `mkfs.ext4` command\n{}",
std::str::from_utf8(&cmd_out.stderr)?
);
// Format file as ext4
let cmd_out = Command::new("mkfs.ext4").arg(&fs_img_path).output().await?;

fs::create_dir(&fs_path).await?;
ensure!(
cmd_out.status.success(),
"failed `mkfs.ext4` command\n{}",
std::str::from_utf8(&cmd_out.stderr)?
);

// Mount fs img as loop mount
let cmd_out = Command::new("mount")
.arg("-o")
.arg("loop")
.arg(&fs_img_path)
.arg(&fs_path)
.output()
.await?;
// Mount fs img as loop mount
let cmd_out = Command::new("mount")
.arg("-o")
.arg("loop")
.arg(&fs_img_path)
.arg(&fs_path)
.output()
.await?;

ensure!(
cmd_out.status.success(),
"failed `mount` command\n{}",
std::str::from_utf8(&cmd_out.stderr)?
);
ensure!(
cmd_out.status.success(),
"failed `mount` command\n{}",
std::str::from_utf8(&cmd_out.stderr)?
);
}

Ok(())
}
Expand Down Expand Up @@ -573,22 +575,24 @@ impl Actor {
let actor_path = ctx.actor_path(self.actor_id);
let netns_path = self.netns_path();

match Command::new("umount")
.arg("-dl")
.arg(actor_path.join("fs"))
.output()
.await
{
Result::Ok(cmd_out) => {
if !cmd_out.status.success() {
tracing::error!(
stdout=%std::str::from_utf8(&cmd_out.stdout)?,
stderr=%std::str::from_utf8(&cmd_out.stderr)?,
"failed `umount` command",
);
if ctx.config().runner.use_mounts() {
match Command::new("umount")
.arg("-dl")
.arg(actor_path.join("fs"))
.output()
.await
{
Result::Ok(cmd_out) => {
if !cmd_out.status.success() {
tracing::error!(
stdout=%std::str::from_utf8(&cmd_out.stdout)?,
stderr=%std::str::from_utf8(&cmd_out.stderr)?,
"failed `umount` command",
);
}
}
Err(err) => tracing::error!(?err, "failed to run `umount` command"),
}
Err(err) => tracing::error!(?err, "failed to run `umount` command"),
}

match self.config.image.kind {
Expand Down

0 comments on commit dea5633

Please sign in to comment.