Skip to content
Merged
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: 2 additions & 0 deletions Cargo.lock

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

30 changes: 18 additions & 12 deletions illumos-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod destructor;
pub mod dkio;
pub mod dladm;
pub mod fstyp;
pub mod libc;
pub mod link;
pub mod opte;
pub mod running_zone;
Expand Down Expand Up @@ -71,6 +72,22 @@ mod inner {
.join(" ")
}

pub fn output_to_exec_error(
command: &std::process::Command,
output: &std::process::Output,
) -> ExecutionError {
ExecutionError::CommandFailure(Box::new(CommandFailureInfo {
command: command
.get_args()
.map(|s| s.to_string_lossy().into())
.collect::<Vec<String>>()
.join(" "),
status: output.status,
stdout: String::from_utf8_lossy(&output.stdout).to_string(),
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
}))
}

// Helper function for starting the process and checking the
// exit code result.
pub fn execute(
Expand All @@ -81,18 +98,7 @@ mod inner {
})?;

if !output.status.success() {
return Err(ExecutionError::CommandFailure(Box::new(
CommandFailureInfo {
command: command
.get_args()
.map(|s| s.to_string_lossy().into())
.collect::<Vec<String>>()
.join(" "),
status: output.status,
stdout: String::from_utf8_lossy(&output.stdout).to_string(),
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
},
)));
return Err(output_to_exec_error(command, &output));
}

Ok(output)
Expand Down
14 changes: 14 additions & 0 deletions illumos-utils/src/libc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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/.

//! Miscellaneous FFI wrapper functions for libc

/// sysconf(3c)
pub fn sysconf(arg: i32) -> std::io::Result<i64> {
let res = unsafe { libc::sysconf(arg) };
if res == -1 {
return Err(std::io::Error::last_os_error());
}
Ok(res)
}
2 changes: 1 addition & 1 deletion illumos-utils/src/zfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt;

pub const ZONE_ZFS_RAMDISK_DATASET_MOUNTPOINT: &str = "/zone";
pub const ZONE_ZFS_RAMDISK_DATASET: &str = "rpool/zone";
const ZFS: &str = "/usr/sbin/zfs";
pub const ZFS: &str = "/usr/sbin/zfs";
pub const KEYPATH_ROOT: &str = "/var/run/oxide/";

/// Error returned by [`Zfs::list_datasets`].
Expand Down
2 changes: 2 additions & 0 deletions sled-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal-dns.workspace = true
ipnetwork.workspace = true
itertools.workspace = true
key-manager.workspace = true
libc.workspace = true
macaddr.workspace = true
nexus-client.workspace = true
omicron-common.workspace = true
Expand Down Expand Up @@ -67,6 +68,7 @@ tokio = { workspace = true, features = [ "full" ] }
tokio-tungstenite.workspace = true
toml.workspace = true
uuid.workspace = true
zeroize.workspace = true
zone.workspace = true

[target.'cfg(target_os = "illumos")'.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions sled-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct Config {
pub sidecar_revision: SidecarRevision,
/// Optional percentage of DRAM to reserve for guest memory
pub vmm_reservoir_percentage: Option<u8>,
/// Optional swap device size in GiB
pub swap_device_size_gb: Option<u32>,
/// Optional VLAN ID to be used for tagging guest VNICs.
pub vlan: Option<VlanID>,
/// Optional list of zpools to be used as "discovered disks".
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async fn sled_role_get(
rqctx: RequestContext<SledAgent>,
) -> Result<HttpResponseOk<SledRole>, HttpError> {
let sa = rqctx.context();
Ok(HttpResponseOk(sa.get_role().await))
Ok(HttpResponseOk(sa.get_role()))
}

/// Initializes a CockroachDB cluster
Expand Down
1 change: 1 addition & 0 deletions sled-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod sled_agent;
mod smf_helper;
pub(crate) mod storage;
mod storage_manager;
mod swap_device;
mod updates;

#[cfg(test)]
Expand Down
27 changes: 26 additions & 1 deletion sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum Error {
#[error("Configuration error: {0}")]
Config(#[from] crate::config::ConfigError),

#[error("Error setting up swap device: {0}")]
SwapDevice(#[from] crate::swap_device::SwapDeviceError),

#[error("Failed to acquire etherstub: {0}")]
Etherstub(illumos_utils::ExecutionError),

Expand Down Expand Up @@ -230,6 +233,28 @@ impl SledAgent {
));
info!(&log, "SledAgent::new(..) starting");

// Configure a swap device of the configured size before other system setup.
match config.swap_device_size_gb {
Some(sz) if sz > 0 => {
info!(log, "Requested swap device of size {} GiB", sz);
let boot_disk =
storage.resources().boot_disk().await.ok_or_else(|| {
crate::swap_device::SwapDeviceError::BootDiskNotFound
})?;
crate::swap_device::ensure_swap_device(
&parent_log,
&boot_disk.1,
sz,
)?;
}
Some(sz) if sz == 0 => {
panic!("Invalid requested swap device size of 0 GiB");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your notes say that it's ok to set the size to 0

To test this, remove swap_device_size_gb (or set it to 0):

one or t'other should be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Good catch. I don't really want to change my approach in the code so I updated my notes.

}
None | Some(_) => {
info!(log, "Not setting up swap device: not configured");
}
}

let etherstub = Dladm::ensure_etherstub(
illumos_utils::dladm::UNDERLAY_ETHERSTUB_NAME,
)
Expand Down Expand Up @@ -609,7 +634,7 @@ impl SledAgent {
}

/// Returns whether or not the sled believes itself to be a scrimlet
pub async fn get_role(&self) -> SledRole {
pub fn get_role(&self) -> SledRole {
if self.inner.hardware.is_scrimlet() {
SledRole::Scrimlet
} else {
Expand Down
Loading