Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure required subdirectories of /var/fm/fmd exist #4445

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions sled-agent/src/backing_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use camino::Utf8PathBuf;
use illumos_utils::zfs::{
EnsureFilesystemError, GetValueError, Mountpoint, SizeDetails, Zfs,
};
use std::io;

#[derive(Debug, thiserror::Error)]
pub enum BackingFsError {
Expand All @@ -36,9 +37,12 @@ pub enum BackingFsError {

#[error("Error initializing dataset: {0}")]
Mount(#[from] EnsureFilesystemError),

#[error("Failed to ensure subdirectory {0}")]
EnsureSubdir(#[from] io::Error),
}

struct BackingFs {
struct BackingFs<'a> {
// Dataset name
name: &'static str,
// Mountpoint
Expand All @@ -49,16 +53,19 @@ struct BackingFs {
compression: Option<&'static str>,
// Linked service
service: Option<&'static str>,
// Subdirectories to ensure
subdirs: Option<&'a [&'static str]>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is completely fine as-is, but I'll just note that you could do Option<&'static [&'static str]> here to avoid the <'a> bound on BackingFs. (Doing so would be less flexible than what you have, but since everything else in here has a 'static bound we could make this match.)

}

impl BackingFs {
impl<'a> BackingFs<'a> {
const fn new(name: &'static str) -> Self {
Self {
name,
mountpoint: "legacy",
quota: None,
compression: None,
service: None,
subdirs: None,
}
}

Expand All @@ -81,10 +88,16 @@ impl BackingFs {
self.service = Some(service);
self
}

const fn subdirs(mut self, subdirs: &'a [&'static str]) -> Self {
self.subdirs = Some(subdirs);
self
}
}

const BACKING_FMD_DATASET: &'static str = "fmd";
const BACKING_FMD_MOUNTPOINT: &'static str = "/var/fm/fmd";
const BACKING_FMD_SUBDIRS: [&'static str; 3] = ["rsrc", "ckpt", "xprt"];
const BACKING_FMD_SERVICE: &'static str = "svc:/system/fmd:default";
const BACKING_FMD_QUOTA: usize = 500 * (1 << 20); // 500 MiB

Expand All @@ -94,6 +107,7 @@ const BACKINGFS_COUNT: usize = 1;
static BACKINGFS: [BackingFs; BACKINGFS_COUNT] =
[BackingFs::new(BACKING_FMD_DATASET)
.mountpoint(BACKING_FMD_MOUNTPOINT)
.subdirs(&BACKING_FMD_SUBDIRS)
.quota(BACKING_FMD_QUOTA)
.compression(BACKING_COMPRESSION)
.service(BACKING_FMD_SERVICE)];
Expand Down Expand Up @@ -165,6 +179,15 @@ pub(crate) fn ensure_backing_fs(

Zfs::mount_overlay_dataset(&dataset, &mountpoint)?;

if let Some(subdirs) = bfs.subdirs {
for dir in subdirs {
let subdir = format!("{}/{}", mountpoint, dir);

info!(log, "Ensuring directory {}", subdir);
std::fs::create_dir_all(subdir)?;
}
}

if let Some(service) = bfs.service {
info!(log, "Starting service {}", service);
smf::Adm::new()
Expand Down
Loading