Skip to content
Draft
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
229 changes: 169 additions & 60 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ base64 = "0.21.2"
bb8 = "0.8.1"
bcs = "0.1.5"
bincode = "1.3.3"
bitflags = "1.3.2"
bootstore = { path = "bootstore" }
bootstrap-agent-client = { path = "bootstrap-agent-client" }
buf-list = { version = "1.0.3", features = ["tokio1"] }
Expand Down Expand Up @@ -296,6 +297,7 @@ ring = "0.16"
rpassword = "7.2.0"
rustfmt-wrapper = "0.2"
rustls = "0.21.6"
rustyline = "12.0.0"
samael = { git = "https://github.com/njaremko/samael", features = ["xmlsec"], branch = "master" }
schemars = "0.8.12"
secrecy = "0.8.0"
Expand Down Expand Up @@ -333,7 +335,7 @@ static_assertions = "1.1.0"
# harder than expected to make breaking changes (even if you specify a specific
# SHA). Cut a new Steno release instead. See omicron#2117.
steno = "0.4.0"
strum = { version = "0.25", features = [ "derive" ] }
strum = { version = "0.25", features = [ "derive", "phf" ] }
subprocess = "0.2.9"
libsw = { version = "3.3.0", features = ["tokio"] }
syn = { version = "2.0" }
Expand Down
2 changes: 1 addition & 1 deletion common/src/vlan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::str::FromStr;
pub const VLAN_MAX: u16 = 4094;

/// Wrapper around a VLAN ID, ensuring it is valid.
#[derive(Debug, Deserialize, Clone, Copy)]
#[derive(Debug, Deserialize, Clone, Copy, Eq, PartialEq)]
pub struct VlanID(u16);

impl VlanID {
Expand Down
9 changes: 9 additions & 0 deletions helios/fusion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ license = "MPL-2.0"

[dependencies]
async-trait.workspace = true
camino.workspace = true
itertools.workspace = true
schemars.workspace = true
serde.workspace = true
shlex.workspace = true
slog.workspace = true
thiserror.workspace = true
tokio.workspace = true
uuid.workspace = true

[dev-dependencies]
regress.workspace = true
serde_json.workspace = true
toml.workspace = true
15 changes: 15 additions & 0 deletions illumos-utils/src/addrobj.rs → helios/fusion/src/addrobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

//! API for operating on addrobj objects.

use std::str::FromStr;

/// The name provided to all link-local IPv6 addresses.
pub const IPV6_LINK_LOCAL_NAME: &str = "ll";

Expand All @@ -26,6 +28,7 @@ pub struct AddrObject {
enum BadName {
Interface(String),
Object(String),
Other(String),
}

impl std::fmt::Display for BadName {
Expand All @@ -36,6 +39,7 @@ impl std::fmt::Display for BadName {
match self {
BadName::Interface(s) => write!(f, "Bad interface name: {}", s),
BadName::Object(s) => write!(f, "Bad object name: {}", s),
BadName::Other(s) => write!(f, "Bad name: {}", s),
}
}
}
Expand Down Expand Up @@ -84,6 +88,17 @@ impl AddrObject {
}
}

impl FromStr for AddrObject {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let (interface, name) = s.split_once('/').ok_or_else(|| {
ParseError { name: BadName::Other(s.to_string()) }
})?;
Self::new(interface, name)
}
}

impl std::fmt::Display for AddrObject {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}/{}", self.interface, self.name)
Expand Down
26 changes: 26 additions & 0 deletions helios/fusion/src/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Represents the entire emulated host system

use crate::interfaces::libc::Libc;
use crate::interfaces::swapctl::Swapctl;
use crate::Executor;
use std::sync::Arc;

/// The common wrapper around the host system, which makes it trivially
/// shareable.
pub type HostSystem = Arc<dyn Host>;

/// Describes the interface used by Omicron when interacting with a host OS.
pub trait Host: Send + Sync {
/// Access the executor, for creating new processes
fn executor(&self) -> &dyn Executor;

/// Access libswapctl
fn swapctl(&self) -> &dyn Swapctl;

/// Access libc
fn libc(&self) -> &dyn Libc;
}
10 changes: 10 additions & 0 deletions helios/fusion/src/interfaces/libc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Interface to the libc API

pub trait Libc {
/// sysconf(3c)
fn sysconf(&self, arg: i32) -> std::io::Result<i64>;
}
6 changes: 6 additions & 0 deletions helios/fusion/src/interfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub mod libc;
pub mod swapctl;
46 changes: 46 additions & 0 deletions helios/fusion/src/interfaces/swapctl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Interface to the swapctl API

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Error listing swap devices: {0}")]
ListDevices(String),

#[error("Error adding swap device: {msg} (path=\"{path}\", start={start}, length={length})")]
AddDevice { msg: String, path: String, start: u64, length: u64 },
}

/// A representation of a swap device, as returned from swapctl(2) SC_LIST
#[derive(Debug, Clone)]
pub struct SwapDevice {
/// path to the resource
pub path: String,

/// starting block on device used for swap
pub start: u64,

/// length of swap area
pub length: u64,

/// total number of pages used for swapping
pub total_pages: u64,

/// free npages for swapping
pub free_pages: u64,

pub flags: i64,
}

pub trait Swapctl {
/// List swap devices on the system.
fn list_swap_devices(&self) -> Result<Vec<SwapDevice>, Error>;
fn add_swap_device(
&self,
path: String,
start: u64,
length: u64,
) -> Result<(), Error>;
}
40 changes: 40 additions & 0 deletions helios/fusion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,54 @@

//! Interfaces used to interact with the underlying host system.

pub mod addrobj;
mod error;
mod executor;
mod host;
mod input;
pub mod interfaces;
mod output;
pub mod zpool;

pub use error::*;
pub use executor::*;
pub use host::*;
pub use input::*;
pub use output::*;

pub const COREADM: &str = "/usr/bin/coreadm";
pub const DLADM: &str = "/usr/sbin/dladm";
pub const DUMPADM: &str = "/usr/sbin/dumpadm";
pub const FSTYP: &str = "/usr/sbin/fstyp";
pub const IPADM: &str = "/usr/sbin/ipadm";
pub const PFEXEC: &str = "/usr/bin/pfexec";
pub const ROUTE: &str = "/usr/sbin/route";
pub const SAVECORE: &str = "/usr/bin/savecore";
pub const SVCADM: &str = "/usr/sbin/svcadm";
pub const SVCCFG: &str = "/usr/sbin/svccfg";
pub const ZFS: &str = "/usr/sbin/zfs";
pub const ZLOGIN: &str = "/usr/sbin/zlogin";
pub const ZONEADM: &str = "/usr/sbin/zoneadm";
pub const ZONECFG: &str = "/usr/sbin/zonecfg";
pub const ZPOOL: &str = "/usr/sbin/zpool";

pub fn which_binary(short: &str) -> &str {
match short {
"coreadm" => COREADM,
"dladm" => DLADM,
"dumpadm" => DUMPADM,
"fstyp" => FSTYP,
"ipadm" => IPADM,
"pfexec" => PFEXEC,
"route" => ROUTE,
"savecore" => SAVECORE,
"svcadm" => SVCADM,
"svccfg" => SVCCFG,
"zfs" => ZFS,
"zlogin" => ZLOGIN,
"zoneadm" => ZONEADM,
"zonecfg" => ZONECFG,
"zpool" => ZPOOL,
short => short,
}
}
Loading