mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
instrument all the things
This commit is contained in:
committed by
Aiden McClelland
parent
11bd1e0609
commit
69382f788d
@@ -1,6 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
use tokio::process::Command;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::util::Invoke;
|
||||
use crate::{Error, ResultExt};
|
||||
@@ -10,6 +11,7 @@ pub const DEFAULT_PASSWORD: &'static str = "password";
|
||||
|
||||
// TODO: use IncorrectDisk / DiskNotAvailable / DiskCorrupted
|
||||
|
||||
#[instrument(skip(disks))]
|
||||
pub async fn create<I: IntoIterator<Item = P>, P: AsRef<Path>>(
|
||||
pool_name: &str,
|
||||
disks: I,
|
||||
@@ -21,6 +23,7 @@ pub async fn create<I: IntoIterator<Item = P>, P: AsRef<Path>>(
|
||||
Ok(guid)
|
||||
}
|
||||
|
||||
#[instrument(skip(datadir))]
|
||||
pub async fn load<P: AsRef<Path>>(
|
||||
guid: &str,
|
||||
pool_name: &str,
|
||||
@@ -32,6 +35,7 @@ pub async fn load<P: AsRef<Path>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(disks))]
|
||||
pub async fn create_pool<I: IntoIterator<Item = P>, P: AsRef<Path>>(
|
||||
pool_name: &str,
|
||||
disks: I,
|
||||
@@ -56,6 +60,7 @@ pub async fn create_pool<I: IntoIterator<Item = P>, P: AsRef<Path>>(
|
||||
.to_owned())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn create_fs(pool_name: &str, password: &str) -> Result<(), Error> {
|
||||
tokio::fs::write(PASSWORD_PATH, password)
|
||||
.await
|
||||
@@ -108,6 +113,7 @@ pub async fn create_fs(pool_name: &str, password: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn create_swap(pool_name: &str) -> Result<(), Error> {
|
||||
let pagesize = String::from_utf8(
|
||||
Command::new("getconf")
|
||||
@@ -138,6 +144,7 @@ pub async fn create_swap(pool_name: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn use_swap(pool_name: &str) -> Result<(), Error> {
|
||||
Command::new("swapon")
|
||||
.arg(Path::new("/dev/zvol").join(pool_name).join("swap"))
|
||||
@@ -146,6 +153,7 @@ pub async fn use_swap(pool_name: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn export(pool_name: &str) -> Result<(), Error> {
|
||||
Command::new("zpool")
|
||||
.arg("export")
|
||||
@@ -155,6 +163,7 @@ pub async fn export(pool_name: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn import(guid: &str) -> Result<(), Error> {
|
||||
Command::new("zpool")
|
||||
.arg("import")
|
||||
@@ -165,6 +174,7 @@ pub async fn import(guid: &str) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(datadir))]
|
||||
pub async fn mount<P: AsRef<Path>>(
|
||||
pool_name: &str,
|
||||
datadir: P,
|
||||
|
||||
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
use tokio::fs::File;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::process::Command;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::util::io::from_yaml_async_reader;
|
||||
use crate::util::{GeneralGuard, Invoke, Version};
|
||||
@@ -49,6 +50,7 @@ lazy_static::lazy_static! {
|
||||
static ref PARTITION_REGEX: Regex = Regex::new("-part[0-9]+$").unwrap();
|
||||
}
|
||||
|
||||
#[instrument(skip(path))]
|
||||
pub async fn get_vendor<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error> {
|
||||
let vendor = tokio::fs::read_to_string(
|
||||
Path::new(SYS_BLOCK_PATH)
|
||||
@@ -69,6 +71,7 @@ pub async fn get_vendor<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(path))]
|
||||
pub async fn get_model<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error> {
|
||||
let model = tokio::fs::read_to_string(
|
||||
Path::new(SYS_BLOCK_PATH)
|
||||
@@ -85,6 +88,7 @@ pub async fn get_model<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error>
|
||||
Ok(if model.is_empty() { None } else { Some(model) })
|
||||
}
|
||||
|
||||
#[instrument(skip(path))]
|
||||
pub async fn get_capacity<P: AsRef<Path>>(path: P) -> Result<usize, Error> {
|
||||
Ok(String::from_utf8(
|
||||
Command::new("blockdev")
|
||||
@@ -97,6 +101,7 @@ pub async fn get_capacity<P: AsRef<Path>>(path: P) -> Result<usize, Error> {
|
||||
.parse()?)
|
||||
}
|
||||
|
||||
#[instrument(skip(path))]
|
||||
pub async fn get_label<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error> {
|
||||
let label = String::from_utf8(
|
||||
Command::new("lsblk")
|
||||
@@ -111,6 +116,7 @@ pub async fn get_label<P: AsRef<Path>>(path: P) -> Result<Option<String>, Error>
|
||||
Ok(if label.is_empty() { None } else { Some(label) })
|
||||
}
|
||||
|
||||
#[instrument(skip(path))]
|
||||
pub async fn get_used<P: AsRef<Path>>(path: P) -> Result<usize, Error> {
|
||||
Ok(String::from_utf8(
|
||||
Command::new("df")
|
||||
@@ -127,6 +133,7 @@ pub async fn get_used<P: AsRef<Path>>(path: P) -> Result<usize, Error> {
|
||||
.parse()?)
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn list() -> Result<Vec<DiskInfo>, Error> {
|
||||
if tokio::fs::metadata(TMP_MOUNTPOINT).await.is_err() {
|
||||
tokio::fs::create_dir_all(TMP_MOUNTPOINT)
|
||||
@@ -261,6 +268,7 @@ pub async fn list() -> Result<Vec<DiskInfo>, Error> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
#[instrument(skip(logicalname, mount_point))]
|
||||
pub async fn mount<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
logicalname: P0,
|
||||
mount_point: P1,
|
||||
@@ -291,6 +299,7 @@ pub async fn mount<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(src, dst, password))]
|
||||
pub async fn mount_encfs<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
src: P0,
|
||||
dst: P1,
|
||||
@@ -320,6 +329,7 @@ pub async fn mount_encfs<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(src, dst))]
|
||||
pub async fn bind<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
src: P0,
|
||||
dst: P1,
|
||||
@@ -363,6 +373,7 @@ pub async fn bind<P0: AsRef<Path>, P1: AsRef<Path>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(mount_point))]
|
||||
pub async fn unmount<P: AsRef<Path>>(mount_point: P) -> Result<(), Error> {
|
||||
tracing::info!("Unmounting {}.", mount_point.as_ref().display());
|
||||
let umount_output = tokio::process::Command::new("umount")
|
||||
|
||||
Reference in New Issue
Block a user