Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions illumos-utils/src/zfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,31 @@ impl Zfs {
/// Creates a new ZFS filesystem named `name`, unless one already exists.
///
/// Applies an optional quota, provided _in bytes_.
///
/// Returns "true" if the filesystem was mounted, when it previously was
/// not.
pub fn ensure_filesystem(
name: &str,
mountpoint: Mountpoint,
zoned: bool,
do_format: bool,
encryption_details: Option<EncryptionDetails>,
quota: Option<usize>,
) -> Result<(), EnsureFilesystemError> {
) -> Result<bool, EnsureFilesystemError> {
let (exists, mounted) = Self::dataset_exists(name, &mountpoint)?;
if exists {
if encryption_details.is_none() {
// If the dataset exists, we're done. Unencrypted datasets are
// automatically mounted.
return Ok(());
return Ok(false);
} else {
if mounted {
// The dataset exists and is mounted
return Ok(());
return Ok(false);
}
// We need to load the encryption key and mount the filesystem
return Self::mount_encrypted_dataset(name, &mountpoint);
Self::mount_encrypted_dataset(name, &mountpoint)?;
return Ok(true);
}
}

Expand Down Expand Up @@ -258,7 +262,7 @@ impl Zfs {
});
}
}
Ok(())
Ok(true)
}

fn mount_encrypted_dataset(
Expand Down
14 changes: 9 additions & 5 deletions sled-hardware/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl Disk {

// Ensure the root encrypted filesystem exists
// Datasets below this in the hierarchy will inherit encryption
if let Some(dataset) = root {
let newly_mounted_crypt = if let Some(dataset) = root {
let Some(key_requester) = key_requester else {
return Err(DiskError::MissingStorageKeyRequester);
};
Expand Down Expand Up @@ -486,7 +486,9 @@ impl Disk {

info!(
log,
"Ensuring encryted filesystem: {} for epoch {}", dataset, epoch
"Ensuring encrypted filesystem: {} for epoch {}",
dataset,
epoch
);
let result = Zfs::ensure_filesystem(
&format!("{}/{}", zpool_name, dataset),
Expand All @@ -501,14 +503,16 @@ impl Disk {
DiskError::IoError { path: keyfile.path().0.clone(), error }
})?;

result?;
}
result?
} else {
false
};

for dataset in datasets.into_iter() {
let mountpoint = zpool_name.dataset_mountpoint(dataset.name);
let name = &format!("{}/{}", zpool_name, dataset.name);

if dataset.wipe {
if dataset.wipe && newly_mounted_crypt {
info!(log, "Automatically destroying dataset {}", name);
Zfs::destroy_dataset(name).or_else(|err| {
// If we can't find the dataset, that's fine -- it might
Expand Down