Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions installinator/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ impl WriteDestination {
let mut drives = BTreeMap::new();

for disk in hardware.m2_disks() {
let Ok(slot) = M2Slot::try_from(disk.pcie_slot()) else {
let Some(slot) = M2Slot::from_chassis_location(disk.location())
else {
warn!(
log, "skipping M.2 drive with unexpected PCIe slot number";
"pcie_slot" => disk.pcie_slot(),
log, "skipping M.2 drive with unexpected chassis location";
"location" => disk.location(),
);
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/config-reconciler/src/internal_disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl From<&'_ Disk> for InternalDiskDetails {
is_boot_disk: disk.is_boot_disk(),
},
zpool_id,
slot: M2Slot::try_from(disk.pcie_slot()).ok(),
slot: M2Slot::from_chassis_location(disk.location()),
boot_image_raw_devfs_path: disk
.boot_image_devfs_path(true)
.map_err(Arc::new),
Expand Down
41 changes: 26 additions & 15 deletions sled-agent/types/versions/src/impls/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ impl M2Slot {
_ => None,
}
}

/// Look up the slot of an M.2 socket from its chassis label, returning
/// `None` for any other label.
///
/// Gimlet and Cosmo both pair M.2 East with boot storage unit A and
/// M.2 West with B.
pub fn from_chassis_location(location: &str) -> Option<Self> {
match location {
"M.2 East" => Some(Self::A),
"M.2 West" => Some(Self::B),
_ => None,
}
}
Comment thread
smklein marked this conversation as resolved.
Resolved
}

impl fmt::Display for M2Slot {
Expand All @@ -63,21 +76,6 @@ impl FromStr for M2Slot {
}
}

impl TryFrom<i64> for M2Slot {
type Error = anyhow::Error;

fn try_from(value: i64) -> Result<Self, Self::Error> {
match value {
// Gimlet and Cosmo have two M.2 drives. The value here is the
// PCIe physical slot number of the bridge above the drive:
// drive A is behind slot 0x11 and drive B behind slot 0x12.
17 => Ok(Self::A),
18 => Ok(Self::B),
_ => bail!("unexpected M.2 slot {value}"),
}
}
}

impl From<ZpoolKind> for DiskVariant {
fn from(kind: ZpoolKind) -> DiskVariant {
match kind {
Expand Down Expand Up @@ -152,3 +150,16 @@ impl FromStr for CompressionAlgorithm {
Ok(c)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn m2_slot_from_chassis_location() {
assert_eq!(M2Slot::from_chassis_location("M.2 East"), Some(M2Slot::A));
assert_eq!(M2Slot::from_chassis_location("M.2 West"), Some(M2Slot::B));
assert_eq!(M2Slot::from_chassis_location("N0"), None);
assert_eq!(M2Slot::from_chassis_location("M.2 2"), None);
}
}
Loading