Begin initial attempt at getting zfs setup working
This commit is contained in:
parent
18651b63ed
commit
4fa553db56
15 changed files with 996 additions and 308 deletions
93
rust/program/zpool-setup/src/cli.rs
Normal file
93
rust/program/zpool-setup/src/cli.rs
Normal file
|
@ -0,0 +1,93 @@
|
|||
use std::{borrow::Cow, collections::BTreeMap, path::PathBuf, str::FromStr};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::disk_mapping::DiskMapping;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
|
||||
pub enum VdevMode {
|
||||
#[serde(rename = "mirror")]
|
||||
Mirror,
|
||||
#[serde(rename = "raidz")]
|
||||
Raidz,
|
||||
#[serde(rename = "raidz1")]
|
||||
Raidz1,
|
||||
#[serde(rename = "raidz2")]
|
||||
Raidz2,
|
||||
#[serde(rename = "raidz3")]
|
||||
Raidz3,
|
||||
}
|
||||
|
||||
impl VdevMode {
|
||||
fn str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Mirror => "mirror",
|
||||
Self::Raidz => "raidz",
|
||||
Self::Raidz1 => "raidz1",
|
||||
Self::Raidz2 => "raidz2",
|
||||
Self::Raidz3 => "raidz3",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Vdev {
|
||||
pub mode: VdevMode,
|
||||
pub members: Vec<String>,
|
||||
}
|
||||
|
||||
impl Vdev {
|
||||
pub fn cli_args(&self, disk_mapper: &DiskMapping) -> anyhow::Result<Vec<Cow<'static, str>>> {
|
||||
let mut args = Vec::with_capacity(self.members.len() + 1);
|
||||
if self.members.len() > 1 || self.mode != VdevMode::Mirror {
|
||||
args.push(Cow::Borrowed(self.mode.str()));
|
||||
}
|
||||
for member in self.members.iter() {
|
||||
let resolved = disk_mapper.resolve(member)?;
|
||||
args.push(resolved.into());
|
||||
}
|
||||
Ok(args)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Vdevs(pub Vec<Vdev>);
|
||||
|
||||
impl FromStr for Vdevs {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
common::json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Options(pub BTreeMap<String, String>);
|
||||
|
||||
impl FromStr for Options {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
common::json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Dataset {
|
||||
pub options: Options,
|
||||
pub mountpoint: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Datasets(pub BTreeMap<String, Dataset>);
|
||||
|
||||
impl FromStr for Datasets {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
common::json::from_str(s)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue