Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sled-agent] Stop self-managing physical disks #5987

Merged
merged 9 commits into from
Jul 15, 2024
85 changes: 2 additions & 83 deletions sled-storage/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use std::collections::HashSet;

use crate::config::MountConfig;
use crate::dataset::{DatasetName, CONFIG_DATASET};
use crate::disk::{
OmicronPhysicalDiskConfig, OmicronPhysicalDisksConfig, RawDisk,
};
use crate::disk::{OmicronPhysicalDisksConfig, RawDisk};
use crate::error::Error;
use crate::resources::{AllDisks, DisksManagementResult, StorageResources};
use camino::Utf8PathBuf;
Expand Down Expand Up @@ -589,91 +587,11 @@ impl StorageManager {
self.resources.set_config(&ledger.data().disks);
} else {
info!(self.log, "KeyManager ready, but no ledger detected");
let mut synthetic_config =
self.resources.get_config().values().cloned().collect();
// TODO(https://github.com/oxidecomputer/omicron/issues/5328): Once
// we are confident that we have migrated to a world where this
// ledger is universally used, we should remove the following
// kludge. The sled agent should not need to "self-manage" anything!
let changed = self
.self_manage_disks_with_zpools(&mut synthetic_config)
.await?;
if !changed {
info!(self.log, "No disks to be automatically managed");
return Ok(());
}
info!(self.log, "auto-managed disks"; "count" => synthetic_config.len());
self.resources.set_config(&synthetic_config);
}

Ok(())
}

// NOTE: What follows is an exceptional case: one where we have
// no record of "Control Plane Physical Disks", but we have zpools
// on our U.2s, and we want to use them regardless.
//
// THIS WOULD NORMALLY BE INCORRECT BEHAVIOR. In the future, these
// zpools will not be "automatically imported", and instead, we'll
// let Nexus decide whether or not to reformat the disks.
//
// However, because we are transitioning from "the set of disks /
// zpools is implicit" to a world where that set is explicit, this
// is a necessary transitional tool.
//
// Returns "true" if the synthetic_config has changed.
async fn self_manage_disks_with_zpools(
&mut self,
synthetic_config: &mut Vec<OmicronPhysicalDiskConfig>,
) -> Result<bool, Error> {
let mut changed = false;
for (identity, disk) in self.resources.disks().values.iter() {
match disk {
crate::resources::ManagedDisk::Unmanaged(raw) => {
let zpool_path = match raw.u2_zpool_path() {
Ok(zpool_path) => zpool_path,
Err(err) => {
info!(self.log, "Cannot find zpool path"; "identity" => ?identity, "err" => ?err);
continue;
}
};

let zpool_name =
match sled_hardware::disk::check_if_zpool_exists(
&zpool_path,
) {
Ok(zpool_name) => zpool_name,
Err(err) => {
info!(self.log, "Zpool does not exist"; "identity" => ?identity, "err" => ?err);
continue;
}
};

info!(self.log, "Found existing zpool on device without ledger";
"identity" => ?identity,
"zpool" => ?zpool_name);

// We found an unmanaged disk with a zpool, even though
// we have no prior record of a ledger of control-plane
// disks.
synthetic_config.push(
// These disks don't have a control-plane UUID --
// report "nil" until they're overwritten with real
// values.
OmicronPhysicalDiskConfig {
identity: identity.clone(),
id: Uuid::nil(),
pool_id: zpool_name.id(),
},
);
changed = true;
}
_ => continue,
}
}
Ok(changed)
}

// Makes an U.2 disk managed by the control plane within [`StorageResources`].
async fn omicron_physical_disks_ensure(
&mut self,
Expand Down Expand Up @@ -905,6 +823,7 @@ impl StorageManager {
#[cfg(all(test, target_os = "illumos"))]
mod tests {
use crate::dataset::DatasetKind;
use crate::disk::OmicronPhysicalDiskConfig;
use crate::disk::RawSyntheticDisk;
use crate::manager_test_harness::StorageManagerTestHarness;
use crate::resources::{DiskManagementError, ManagedDisk};
Expand Down
Loading