-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back /var/fm/fmd with a dataset from the boot M.2
- Loading branch information
Showing
8 changed files
with
186 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Operations for dealing with persistent backing mounts for OS data | ||
use camino::Utf8PathBuf; | ||
use illumos_utils::zfs::{ | ||
EnsureFilesystemError, GetValueError, Mountpoint, Zfs, | ||
}; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum BackingFsError { | ||
#[error("Error administering service: {0}")] | ||
Adm(#[from] smf::AdmError), | ||
|
||
#[error("Error retrieving dataset property: {0}")] | ||
DatasetProperty(#[from] GetValueError), | ||
|
||
#[error("Error mounting dataset: {0}")] | ||
Mount(#[from] EnsureFilesystemError), | ||
} | ||
|
||
struct BackingFs { | ||
// Dataset name | ||
name: &'static str, | ||
// Linked service | ||
service: Option<&'static str>, | ||
} | ||
|
||
impl BackingFs { | ||
const fn new(name: &'static str) -> Self { | ||
Self { name, service: None } | ||
} | ||
|
||
const fn service(mut self, service: &'static str) -> Self { | ||
self.service = Some(service); | ||
self | ||
} | ||
} | ||
|
||
const BACKING_FS_COUNT: usize = 1; | ||
static BACKING_FS: [BackingFs; BACKING_FS_COUNT] = | ||
[BackingFs::new(sled_hardware::disk::M2_BACKING_FM_DATASET) | ||
.service("svc:/system/fmd:default")]; | ||
|
||
pub(crate) fn ensure_backing_fs( | ||
log: &slog::Logger, | ||
boot_zpool_name: &illumos_utils::zpool::ZpoolName, | ||
) -> Result<(), BackingFsError> { | ||
let log = log.new(o!( | ||
"component" => "BackingFs", | ||
)); | ||
for bfs in BACKING_FS.iter() { | ||
info!(log, "Processing backing FS {}", bfs.name); | ||
|
||
let dataset = format!("{}/{}", boot_zpool_name, bfs.name); | ||
|
||
if Zfs::get_value(&dataset, "mounted")? == "yes" { | ||
info!(log, "backing FS {} is already mounted", bfs.name); | ||
return Ok(()); | ||
} | ||
|
||
let mountpoint = Zfs::get_value(&dataset, "mountpoint")?; | ||
|
||
if let Some(service) = bfs.service { | ||
info!(log, "Stopping service {}", service); | ||
smf::Adm::new() | ||
.disable() | ||
.temporary() | ||
.synchronous() | ||
.run(smf::AdmSelection::ByPattern(&[service]))?; | ||
} | ||
|
||
info!(log, "Mounting backing FS {} on {}", bfs.name, mountpoint); | ||
|
||
Zfs::mount_overlay_dataset( | ||
&dataset, | ||
&Mountpoint::Path(Utf8PathBuf::from(mountpoint)), | ||
)?; | ||
|
||
if let Some(service) = bfs.service { | ||
info!(log, "Starting service {}", service); | ||
smf::Adm::new() | ||
.enable() | ||
.synchronous() | ||
.run(smf::AdmSelection::ByPattern(&[service]))?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters