Add some comments in the zpool setup code wrt. adding/removing
Some checks failed
/ dev-shell (push) Successful in 1m44s
/ rust-packages (push) Successful in 6m57s
/ systems (push) Successful in 16m11s
/ check (push) Failing after 51s
/ terraform-providers (push) Successful in 57s

disks from zpools
This commit is contained in:
Kaare Hoff Skovgaard 2025-08-10 00:03:15 +02:00
parent 3027ff2f1a
commit dbe31fd176
Signed by: khs
GPG key ID: C7D890804F01E9F0

View file

@ -145,6 +145,7 @@ struct ZpoolStatus {
#[derive(Deserialize)] #[derive(Deserialize)]
struct ZpoolStatusPool { struct ZpoolStatusPool {
state: Option<ZpoolState>, state: Option<ZpoolState>,
vdevs: HashMap<String, ZpoolStatusVdev>,
} }
#[derive(Clone, Copy, Deserialize, PartialEq)] #[derive(Clone, Copy, Deserialize, PartialEq)]
@ -153,6 +154,29 @@ enum ZpoolState {
Online, Online,
} }
#[derive(Deserialize)]
#[serde(tag = "vdev_type")]
enum ZpoolStatusVdev {
#[serde(rename = "root")]
Root {
name: String,
state: ZpoolState,
vdevs: HashMap<String, ZpoolStatusVdev>,
},
#[serde(rename = "disk")]
Disk {
name: String,
state: ZpoolState,
path: PathBuf,
},
#[serde(rename = "mirror")]
Mirror {
name: String,
state: ZpoolState,
vdevs: HashMap<String, ZpoolStatusVdev>,
}
}
fn setup_zpool(p: SetupZpool) -> anyhow::Result<()> { fn setup_zpool(p: SetupZpool) -> anyhow::Result<()> {
let disk_mapping_file = common::env::read_path_env("DISK_MAPPING_FILE")?; let disk_mapping_file = common::env::read_path_env("DISK_MAPPING_FILE")?;
let disk_mapping = common::fs::read_to_string(&disk_mapping_file)?; let disk_mapping = common::fs::read_to_string(&disk_mapping_file)?;
@ -184,6 +208,13 @@ fn setup_zpool(p: SetupZpool) -> anyhow::Result<()> {
{ {
return Err(anyhow::format_err!("Zpool {} is not online", p.pool_name)); return Err(anyhow::format_err!("Zpool {} is not online", p.pool_name));
} }
// TODO: Run through the existing VDevs and add any missing vdevs, and add any missing disks
// as needed to any vdevs. Not exactly sure how this should be coded, but I guess we can utilize
// the fact we cannot really change vdev type beyond turning a disk vdev into a mirror vdev,
// and any single disk can only belong to one vdev. So we can simply not support moving disks between vdevs.
// Also, to begin with, we can simply not support any vdev other than disk vdevs, as it doesn't make much
// sense for my use case.
for vdev in p.vdevs.iter() { for vdev in p.vdevs.iter() {
for member in vdev.members.iter() { for member in vdev.members.iter() {
@ -192,6 +223,8 @@ fn setup_zpool(p: SetupZpool) -> anyhow::Result<()> {
} }
} }
// TODO: zpool remove any extra vdevs.
let mut existing_datasets = zfs::list_datasets(&p.pool_name)?; let mut existing_datasets = zfs::list_datasets(&p.pool_name)?;
log::info!("Existing datasets found: {existing_datasets:?}"); log::info!("Existing datasets found: {existing_datasets:?}");