From dbe31fd176ec09d55e185fbc5abcab86f95587b6 Mon Sep 17 00:00:00 2001 From: Kaare Hoff Skovgaard Date: Sun, 10 Aug 2025 00:03:15 +0200 Subject: [PATCH] Add some comments in the zpool setup code wrt. adding/removing disks from zpools --- rust/program/zpool-setup/src/main.rs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/program/zpool-setup/src/main.rs b/rust/program/zpool-setup/src/main.rs index 814a948..b7bdf0f 100644 --- a/rust/program/zpool-setup/src/main.rs +++ b/rust/program/zpool-setup/src/main.rs @@ -145,6 +145,7 @@ struct ZpoolStatus { #[derive(Deserialize)] struct ZpoolStatusPool { state: Option, + vdevs: HashMap, } #[derive(Clone, Copy, Deserialize, PartialEq)] @@ -153,6 +154,29 @@ enum ZpoolState { Online, } +#[derive(Deserialize)] +#[serde(tag = "vdev_type")] +enum ZpoolStatusVdev { + #[serde(rename = "root")] + Root { + name: String, + state: ZpoolState, + vdevs: HashMap, + }, + #[serde(rename = "disk")] + Disk { + name: String, + state: ZpoolState, + path: PathBuf, + }, + #[serde(rename = "mirror")] + Mirror { + name: String, + state: ZpoolState, + vdevs: HashMap, + } +} + fn setup_zpool(p: SetupZpool) -> anyhow::Result<()> { let disk_mapping_file = common::env::read_path_env("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)); } + + // 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 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)?; log::info!("Existing datasets found: {existing_datasets:?}");