@@ -1636,11 +1636,21 @@ struct CrucibleDatasetRow {
1636
1636
no_provision : bool ,
1637
1637
1638
1638
// zpool fields
1639
- control_plane_storage_buffer : i64 ,
1640
- pool_total_size : i64 ,
1639
+ #[ tabled( display_with = "option_impl_display" ) ]
1640
+ control_plane_storage_buffer : Option < i64 > ,
1641
+ #[ tabled( display_with = "option_impl_display" ) ]
1642
+ pool_total_size : Option < i64 > ,
1641
1643
1642
1644
// computed fields
1643
- size_left : i128 ,
1645
+ #[ tabled( display_with = "option_impl_display" ) ]
1646
+ size_left : Option < i128 > ,
1647
+ }
1648
+
1649
+ fn option_impl_display < T : std:: fmt:: Display > ( t : & Option < T > ) -> String {
1650
+ match t {
1651
+ Some ( v) => format ! ( "{v}" ) ,
1652
+ None => String :: from ( "n/a" ) ,
1653
+ }
1644
1654
}
1645
1655
1646
1656
async fn get_crucible_dataset_rows (
@@ -1676,16 +1686,14 @@ async fn get_crucible_dataset_rows(
1676
1686
Vec :: with_capacity ( crucible_datasets. len ( ) ) ;
1677
1687
1678
1688
for d in crucible_datasets {
1679
- let control_plane_storage_buffer: i64 = zpools
1689
+ let control_plane_storage_buffer: Option < i64 > = match zpools
1680
1690
. get ( & d. pool_id )
1681
- . ok_or_else ( || anyhow:: anyhow!( "zpool {} not found!" , d. pool_id) ) ?
1682
- . control_plane_storage_buffer ( )
1683
- . into ( ) ;
1691
+ {
1692
+ Some ( zpool) => Some ( zpool. control_plane_storage_buffer ( ) . into ( ) ) ,
1693
+ None => None ,
1694
+ } ;
1684
1695
1685
- let pool_total_size =
1686
- * zpool_total_size. get ( & d. pool_id ) . ok_or_else ( || {
1687
- anyhow:: anyhow!( "zpool {} not part of inventory!" , d. pool_id)
1688
- } ) ?;
1696
+ let pool_total_size = zpool_total_size. get ( & d. pool_id ) ;
1689
1697
1690
1698
result. push ( CrucibleDatasetRow {
1691
1699
// dataset fields
@@ -1701,12 +1709,18 @@ async fn get_crucible_dataset_rows(
1701
1709
1702
1710
// zpool fields
1703
1711
control_plane_storage_buffer,
1704
- pool_total_size,
1712
+ pool_total_size : pool_total_size . cloned ( ) ,
1705
1713
1706
1714
// computed fields
1707
- size_left : i128:: from ( pool_total_size)
1708
- - i128:: from ( control_plane_storage_buffer)
1709
- - i128:: from ( d. size_used ) ,
1715
+ size_left : match ( pool_total_size, control_plane_storage_buffer) {
1716
+ ( Some ( total_size) , Some ( control_plane_storage_buffer) ) => Some (
1717
+ i128:: from ( * total_size)
1718
+ - i128:: from ( control_plane_storage_buffer)
1719
+ - i128:: from ( d. size_used ) ,
1720
+ ) ,
1721
+
1722
+ _ => None ,
1723
+ } ,
1710
1724
} ) ;
1711
1725
}
1712
1726
@@ -1742,9 +1756,20 @@ async fn cmd_crucible_dataset_show_overprovisioned(
1742
1756
let rows: Vec < _ > = rows
1743
1757
. into_iter ( )
1744
1758
. filter ( |row| {
1745
- ( i128:: from ( row. size_used )
1746
- + i128:: from ( row. control_plane_storage_buffer ) )
1747
- >= i128:: from ( row. pool_total_size )
1759
+ match ( row. pool_total_size , row. control_plane_storage_buffer ) {
1760
+ ( Some ( pool_total_size) , Some ( control_plane_storage_buffer) ) => {
1761
+ ( i128:: from ( row. size_used )
1762
+ + i128:: from ( control_plane_storage_buffer) )
1763
+ >= i128:: from ( pool_total_size)
1764
+ }
1765
+
1766
+ _ => {
1767
+ // Without the total size or control plane storage buffer, we
1768
+ // can't determine if the dataset is overprovisioned or not.
1769
+ // Filter it out.
1770
+ false
1771
+ }
1772
+ }
1748
1773
} )
1749
1774
. collect ( ) ;
1750
1775
@@ -7858,7 +7883,8 @@ async fn cmd_db_zpool_list(
7858
7883
time_deleted : String ,
7859
7884
sled_id : Uuid ,
7860
7885
physical_disk_id : Uuid ,
7861
- total_size : i64 ,
7886
+ #[ tabled( display_with = "option_impl_display" ) ]
7887
+ total_size : Option < i64 > ,
7862
7888
control_plane_storage_buffer : i64 ,
7863
7889
}
7864
7890
@@ -7874,13 +7900,7 @@ async fn cmd_db_zpool_list(
7874
7900
} ,
7875
7901
sled_id : p. sled_id ,
7876
7902
physical_disk_id : p. physical_disk_id . into_untyped_uuid ( ) ,
7877
- total_size : * zpool_total_size. get ( & zpool_id) . ok_or_else (
7878
- || {
7879
- anyhow:: anyhow!(
7880
- "zpool {zpool_id} not found in inventory!"
7881
- )
7882
- } ,
7883
- ) ?,
7903
+ total_size : zpool_total_size. get ( & zpool_id) . cloned ( ) ,
7884
7904
control_plane_storage_buffer : p
7885
7905
. control_plane_storage_buffer ( )
7886
7906
. into ( ) ,
0 commit comments