Skip to content

Commit

Permalink
Ensure required subdirectories of /var/fm/fmd exist
Browse files Browse the repository at this point in the history
When a blank ZFS dataset is created to back /var/fm/fmd, the fault
management daemon creates the files it needs but it does not create
subdirectories that are required to store data. sled-agent needs to
ensure these exist after mounting the dataset

Fixes #4444
  • Loading branch information
citrus-it committed Nov 6, 2023
1 parent cede9b3 commit a3bd5e4
Showing 1 changed file with 25 additions and 2 deletions.
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]>,
}

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

0 comments on commit a3bd5e4

Please sign in to comment.