Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions bin/cyclone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ async fn main() -> Result<()> {

let telemetry = Box::new(telemetry);

if config.enable_forwarder() {
let maybe_forwarder_handle = if config.enable_forwarder() {
#[cfg(target_os = "linux")]
TcpStreamForwarder::new().await?.start().await?;
}
{
Some(TcpStreamForwarder::new().await?.start().await?)
}
#[cfg(not(target_os = "linux"))]
{
None
}
} else {
None
};

#[cfg(target_os = "linux")]
let gatherer_shutdown = process_gatherer::init(
Expand All @@ -74,6 +82,9 @@ async fn main() -> Result<()> {
shutdown_token.cancel();
#[cfg(target_os = "linux")]
gatherer_shutdown.wait().await?;
if let Some(forwarder_handle) = maybe_forwarder_handle {
forwarder_handle.shutdown().await?;
}
task_tracker.wait().await;
telemetry_shutdown.wait().await?;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/si-firecracker/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ rust_library(
name = "si-firecracker",
deps = [
"//lib/cyclone-core:cyclone-core",
"//lib/telemetry-rs:telemetry",
"//third-party/rust:futures",
"//third-party/rust:remain",
"//third-party/rust:nix",
"//third-party/rust:remain",
"//third-party/rust:thiserror",
"//third-party/rust:tokio",
"//third-party/rust:tokio-util",
"//third-party/rust:tracing",
] + select({
"DEFAULT": [],
"config//os:linux": [
Expand Down
2 changes: 1 addition & 1 deletion lib/si-firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ cyclone-core = { path = "../cyclone-core" }
futures = { workspace = true }
nix = { workspace = true }
remain = { workspace = true }
telemetry = { path = "../../lib/telemetry-rs" }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]

Expand Down
18 changes: 10 additions & 8 deletions lib/si-firecracker/src/disk.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use nix::{errno::Errno, mount::umount};
use std::{
ffi::OsString,
fs::{self, remove_dir_all},
path::{Path, PathBuf},
result,
};

use crate::errors::FirecrackerJailError;
use devicemapper::{DevId, DmName, DmOptions, DM};

use krataloopdev::LoopDevice;
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};
use std::{fs::remove_dir_all, result};
use tracing::trace;
use nix::{errno::Errno, mount::umount};
use telemetry::prelude::*;

use crate::errors::FirecrackerJailError;

type Result<T> = result::Result<T, FirecrackerJailError>;

Expand Down
61 changes: 37 additions & 24 deletions lib/si-firecracker/src/firecracker.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use std::{
fs::Permissions,
io::{Error, ErrorKind},
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
result,
};

use cyclone_core::process;
use std::fs::Permissions;
use std::io::Error;
use std::io::ErrorKind;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::path::PathBuf;
use std::result;
use tokio::fs;
use tokio::process::Child;
use tokio::process::Command;
use tracing::info;

use crate::disk::FirecrackerDisk;
use crate::errors::FirecrackerJailError;
use telemetry::prelude::*;
use tokio::{
fs,
process::{Child, Command},
};

use crate::{
disk::FirecrackerDisk,
errors::FirecrackerJailError,
stream::{StreamForwarderHandle, UnixStreamForwarder},
};

type Result<T> = result::Result<T, FirecrackerJailError>;

Expand All @@ -28,8 +33,9 @@ const FIRECRACKER_SCRIPTS: &[(&str, &[u8])] = &[

#[derive(Debug)]
pub struct FirecrackerJail {
id: u32,
jailer: Command,
child: Option<Child>,
child: Option<(Child, Option<StreamForwarderHandle>)>,
socket: PathBuf,
}

Expand Down Expand Up @@ -64,6 +70,7 @@ impl FirecrackerJail {
let socket = PathBuf::from(&format!("/srv/jailer/firecracker/{}/root/v.sock", id));

Ok(Self {
id,
jailer: cmd,
child: None,
socket,
Expand All @@ -90,12 +97,6 @@ impl FirecrackerJail {
)));
}

// TODO(nick,john,fletcher): delete or restore this once verideath investigation is done.
// UnixStreamForwarder::new(FirecrackerDisk::jail_dir_from_id(id), id)
// .await?
// .start()
// .await?;

Ok(())
}

Expand Down Expand Up @@ -155,14 +156,26 @@ impl FirecrackerJail {
}

pub async fn spawn(&mut self) -> Result<()> {
self.child = Some(self.jailer.spawn().map_err(FirecrackerJailError::Spawn)?);
let handle = UnixStreamForwarder::new(FirecrackerDisk::jail_dir_from_id(self.id), self.id)
.await?
.start()
.await?;

self.child = Some((
self.jailer.spawn().map_err(FirecrackerJailError::Spawn)?,
Some(handle),
));
Ok(())
}

pub async fn terminate(&mut self) -> Result<()> {
match self.child.as_mut() {
Some(c) => {
process::child_shutdown(c, Some(process::Signal::SIGTERM), None).await?;
Some((child, handle)) => {
process::child_shutdown(child, Some(process::Signal::SIGTERM), None).await?;
// Handle shutdown consumes self so only call it once
if let Some(handle) = handle.take() {
handle.shutdown().await?;
}
Ok(())
}
None => Ok(()),
Expand Down
Loading