Attempt to get merging of zfs options in zpool setup working
Some checks failed
/ dev-shell (push) Successful in 49s
/ terraform-providers (push) Successful in 59s
/ rust-packages (push) Successful in 1m2s
/ check (push) Failing after 3m6s
/ systems (push) Successful in 4m28s

I have not yet tested addition of new datasets, or the removal/
unmounting of newly disappeared datasets.
This commit is contained in:
Kaare Hoff Skovgaard 2025-08-07 22:32:18 +02:00
parent 89a3e16ab7
commit 5abaa9322e
Signed by: khs
GPG key ID: C7D890804F01E9F0
5 changed files with 224 additions and 12 deletions

View file

@ -1,6 +1,6 @@
use std::{borrow::Cow, collections::BTreeMap, path::PathBuf, str::FromStr};
use std::{borrow::Cow, collections::BTreeMap, ops::Deref, path::PathBuf, str::FromStr};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use crate::disk_mapping::DiskMapping;
@ -52,7 +52,7 @@ impl Vdev {
#[derive(Clone, Debug, Deserialize)]
#[serde(transparent)]
pub struct Vdevs(pub Vec<Vdev>);
pub struct Vdevs(Vec<Vdev>);
impl FromStr for Vdevs {
type Err = anyhow::Error;
@ -62,9 +62,17 @@ impl FromStr for Vdevs {
}
}
#[derive(Clone, Debug, Deserialize)]
impl Deref for Vdevs {
type Target = Vec<Vdev>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
#[serde(transparent)]
pub struct Options(pub BTreeMap<String, String>);
pub struct Options(BTreeMap<String, String>);
impl FromStr for Options {
type Err = anyhow::Error;
@ -73,13 +81,36 @@ impl FromStr for Options {
common::json::from_str(s)
}
}
impl Deref for Options {
type Target = BTreeMap<String, String>;
#[derive(Clone, Debug, Deserialize)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct Dataset {
pub options: Options,
pub mountpoint: Option<PathBuf>,
}
impl Dataset {
pub fn without_mountpoint(&self) -> Dataset {
Self {
mountpoint: None,
options: self.options.clone(),
}
}
pub fn with_options(options: &Options) -> Self {
Self {
mountpoint: None,
options: options.clone(),
}
}
}
#[derive(Clone, Debug, Deserialize)]
#[serde(transparent)]
pub struct Datasets(pub BTreeMap<String, Dataset>);