From 5d7df4ba4d21757dae6467ba661bf2b57f03cca4 Mon Sep 17 00:00:00 2001 From: Mike Zeller Date: Fri, 9 Aug 2024 22:09:26 +0000 Subject: [PATCH] Update omdb command to print inventory firmware info --- dev-tools/omdb/src/bin/omdb/db.rs | 81 ++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index e3836f7cfff..89fb89a08da 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -57,6 +57,7 @@ use nexus_db_model::ExternalIp; use nexus_db_model::HwBaseboardId; use nexus_db_model::Instance; use nexus_db_model::InvCollection; +use nexus_db_model::InvNvmeDiskFirmware; use nexus_db_model::InvPhysicalDisk; use nexus_db_model::IpAttachState; use nexus_db_model::IpKind; @@ -3644,36 +3645,90 @@ async fn cmd_db_inventory_physical_disks( model: String, serial: String, variant: String, + firmware: String, + next_firmware: String, } - use db::schema::inv_physical_disk::dsl; - let mut query = dsl::inv_physical_disk.into_boxed(); + use db::schema::inv_nvme_disk_firmware::dsl as firmware_dsl; + use db::schema::inv_physical_disk::dsl as disk_dsl; + + let mut query = disk_dsl::inv_physical_disk.into_boxed(); query = query.limit(i64::from(u32::from(limit))); if let Some(collection_id) = args.collection_id { query = query.filter( - dsl::inv_collection_id.eq(collection_id.into_untyped_uuid()), + disk_dsl::inv_collection_id.eq(collection_id.into_untyped_uuid()), ); } if let Some(sled_id) = args.sled_id { - query = query.filter(dsl::sled_id.eq(sled_id.into_untyped_uuid())); + query = query.filter(disk_dsl::sled_id.eq(sled_id.into_untyped_uuid())); } let disks = query - .select(InvPhysicalDisk::as_select()) + .left_join( + firmware_dsl::inv_nvme_disk_firmware.on( + firmware_dsl::inv_collection_id + .eq(disk_dsl::inv_collection_id) + .and(firmware_dsl::sled_id.eq(disk_dsl::sled_id)) + .and(firmware_dsl::slot.eq(disk_dsl::slot)), + ), + ) + .select(( + InvPhysicalDisk::as_select(), + Option::::as_select(), + )) .load_async(&**conn) .await .context("loading physical disks")?; - let rows = disks.into_iter().map(|disk| DiskRow { - inv_collection_id: disk.inv_collection_id.into_untyped_uuid(), - sled_id: disk.sled_id.into_untyped_uuid(), - slot: disk.slot, - vendor: disk.vendor, - model: disk.model.clone(), - serial: disk.serial.clone(), - variant: format!("{:?}", disk.variant), + let rows = disks.into_iter().map(|(disk, firmware)| { + let mut active_firmware = "UNKNOWN".to_string(); + let mut next_firmware = String::new(); + + 'firmware: { + // Ensure we have matching firmware information for a physical disk. + let Some(firmware) = firmware else { + break 'firmware; + }; + + // Attempt to read the fw version for the active slot. + if let Some(slot_info) = &firmware + .slot_firmware_versions + .get(firmware.active_slot.0 as usize - 1) + { + if let Some(fw_ver) = slot_info { + active_firmware = fw_ver.clone(); + } + }; + + // If we don't have firmware staged for next reset break early. + let Some(next_slot) = firmware.next_active_slot else { + break 'firmware; + }; + + // We have firmware staged for the next reset so attempt to read + // the fw version. + if let Some(slot_info) = + &firmware.slot_firmware_versions.get(next_slot.0 as usize - 1) + { + if let Some(fw_ver) = slot_info { + next_firmware = fw_ver.clone(); + } + } + } + + DiskRow { + inv_collection_id: disk.inv_collection_id.into_untyped_uuid(), + sled_id: disk.sled_id.into_untyped_uuid(), + slot: disk.slot, + vendor: disk.vendor, + model: disk.model.clone(), + serial: disk.serial.clone(), + variant: format!("{:?}", disk.variant), + firmware: active_firmware, + next_firmware, + } }); let table = tabled::Table::new(rows)