Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Oct 2, 2023
1 parent 0bc3aa0 commit e2e7dc8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
5 changes: 4 additions & 1 deletion sled-storage/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! Storage related errors
use crate::dataset::DatasetName;
use crate::dataset::{DatasetError, DatasetName};
use crate::disk::DiskError;
use camino::Utf8PathBuf;
use omicron_common::api::external::ByteCountRangeError;
Expand All @@ -15,6 +15,9 @@ pub enum Error {
#[error(transparent)]
DiskError(#[from] DiskError),

#[error(transparent)]
DatasetError(#[from] DatasetError),

// TODO: We could add the context of "why are we doint this op", maybe?
#[error(transparent)]
ZfsListDataset(#[from] illumos_utils::zfs::ListDatasetsError),
Expand Down
57 changes: 52 additions & 5 deletions sled-storage/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl StorageManager {
loop {
if let Err(e) = self.step().await {
warn!(self.log, "{e}");
return;
}
}
}
Expand All @@ -103,15 +102,17 @@ impl StorageManager {
StorageRequest::AddDisk(unparsed_disk) => {
match unparsed_disk.variant() {
DiskVariant::U2 => self.add_u2_disk(unparsed_disk).await?,
DiskVariant::M2 => todo!(),
DiskVariant::M2 => self.add_m2_disk(unparsed_disk).await?,
}
}
StorageRequest::AddSyntheticDisk(zpool_name) => {
match zpool_name.kind() {
ZpoolKind::External => {
self.add_synthetic_u2_disk(zpool_name).await?
}
ZpoolKind::Internal => todo!(),
ZpoolKind::Internal => {
self.add_synthetic_m2_disk(zpool_name).await?
}
}
}
StorageRequest::RemoveDisk(_unparsed_disk) => todo!(),
Expand All @@ -121,7 +122,7 @@ impl StorageManager {
Ok(())
}

/// Add a real U.2 disk to storage resources or queue it to be added later
// Add a real U.2 disk to [`StorageResources`] or queue it to be added later
async fn add_u2_disk(
&mut self,
unparsed_disk: UnparsedDisk,
Expand Down Expand Up @@ -159,7 +160,53 @@ impl StorageManager {
}
}

/// Add a synthetic U.2 disk to storage resources or queue it to be added later
// Add a real U.2 disk to [`StorageResources`]
//
//
// We never queue M.2 drives, as they don't rely on [`KeyManager`] based
// encryption
async fn add_m2_disk(
&mut self,
unparsed_disk: UnparsedDisk,
) -> Result<(), Error> {
let disk = Disk::new(
&self.log,
unparsed_disk.clone(),
Some(&self.key_requester),
)
.await?;
self.resources.insert_real_disk(disk)?;
Ok(())
}

// Add a synthetic U.2 disk to [`StorageResources`]
//
// We never queue M.2 drives, as they don't rely on [`KeyManager`] based
// encryption
async fn add_synthetic_m2_disk(
&mut self,
zpool_name: ZpoolName,
) -> Result<(), Error> {
let synthetic_id = DiskIdentity {
vendor: "fake_vendor".to_string(),
serial: "fake_serial".to_string(),
model: zpool_name.id().to_string(),
};

debug!(self.log, "Ensure zpool has datasets: {zpool_name}");
dataset::ensure_zpool_has_datasets(
&self.log,
&zpool_name,
&synthetic_id,
Some(&self.key_requester),
)
.await?;
self.resources.insert_synthetic_disk(zpool_name)?;
Ok(())
}

// Add a synthetic U.2 disk to [`StorageResources`] or queue it to be added
// later
async fn add_synthetic_u2_disk(
&mut self,
zpool_name: ZpoolName,
Expand Down

0 comments on commit e2e7dc8

Please sign in to comment.