Attempt to get merging of zfs options in zpool setup working
I have not yet tested addition of new datasets, or the removal/ unmounting of newly disappeared datasets.
This commit is contained in:
parent
89a3e16ab7
commit
5abaa9322e
5 changed files with 224 additions and 12 deletions
|
@ -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>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue