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
4 changes: 2 additions & 2 deletions sled-agent/src/long_running_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! This module is responsible for spawning, starting, and managing long running
//! tasks and task driven subsystems. These tasks run for the remainder of the
//! sled-agent process from the moment they begin. Primarily they include the
//! "managers", like `StorageManager`, `InstanceManager`, etc..., and are used
//! by both the bootstrap agent and the sled-agent.
//! "managers", like `KeyManager`, `ServiceManager`, etc., and are used by both
//! the bootstrap agent and the sled-agent.
//!
//! We don't bother keeping track of the spawned tasks handles because we know
//! these tasks are supposed to run forever, and they can shutdown if their
Expand Down
3 changes: 0 additions & 3 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

//! Sled-local service management.
//!
//! For controlling zone-based storage services, refer to
//! [sled_storage::manager::StorageManager].
//!
//! For controlling virtual machine instances, refer to
//! [crate::instance_manager::InstanceManager].
//!
Expand Down
77 changes: 75 additions & 2 deletions sled-agent/src/sim/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,13 @@ impl Zpool {
/// Represents a nested dataset
pub struct NestedDatasetStorage {
config: NestedDatasetConfig,
// In-memory flag for whether this dataset pretends to be mounted; defaults
// to true.
//
// Nothing in the simulated storage implementation acts on this value; it is
// merely a sticky bool that remembers the most recent value passed to
// `nested_dataset_set_mounted()`.
mounted: bool,
// We intentionally store the children before the mountpoint,
// so they are deleted first.
children: BTreeMap<String, NestedDatasetStorage>,
Expand Down Expand Up @@ -1262,6 +1269,7 @@ impl NestedDatasetStorage {

Self {
config: NestedDatasetConfig { name, inner: shared_config },
mounted: true,
children: BTreeMap::new(),
mountpoint,
}
Expand Down Expand Up @@ -1380,7 +1388,14 @@ impl StorageInner {
return Ok(DatasetProperties {
id: Some(*id),
name: dataset_name.to_string(),
mounted: true,
// We should have an entry in `self.nested_datasets` for
// every entry in `config.datasets` (`datasets_ensure()`
// keeps these in sync), but we only keeping track of a
// `mounted` property on nested datasets. Look that up here.
mounted: self
.nested_datasets
.get(&dataset.name)
.map_or(true, |d| d.mounted),
avail: ByteCount::from_kibibytes_u32(1024),
used: ByteCount::from_kibibytes_u32(1024),
quota: dataset.inner.quota,
Expand All @@ -1399,7 +1414,7 @@ impl StorageInner {
return Ok(DatasetProperties {
id: None,
name: dataset_name.to_string(),
mounted: true,
mounted: nested_dataset_storage.mounted,
avail: ByteCount::from_kibibytes_u32(1024),
used: ByteCount::from_kibibytes_u32(1024),
quota: config.quota,
Expand Down Expand Up @@ -1517,6 +1532,64 @@ impl StorageInner {
}
}

#[cfg(test)]
pub fn nested_dataset_is_mounted(
&self,
dataset: &NestedDatasetLocation,
) -> Result<bool, HttpError> {
let Some(mut nested_dataset) = self.nested_datasets.get(&dataset.root)
else {
return Err(HttpError::for_not_found(
None,
"Dataset not found".to_string(),
));
};
for component in dataset.path.split('/') {
if component.is_empty() {
continue;
}
nested_dataset =
nested_dataset.children.get(component).ok_or_else(|| {
HttpError::for_not_found(
None,
"Dataset not found".to_string(),
)
})?;
}
Ok(nested_dataset.mounted)
}

pub fn nested_dataset_set_mounted(
&mut self,
dataset: &NestedDatasetLocation,
mounted: bool,
) -> Result<(), HttpError> {
let Some(mut nested_dataset) =
self.nested_datasets.get_mut(&dataset.root)
else {
return Err(HttpError::for_not_found(
None,
"Dataset not found".to_string(),
));
};
for component in dataset.path.split('/') {
if component.is_empty() {
continue;
}
nested_dataset = nested_dataset
.children
.get_mut(component)
.ok_or_else(|| {
HttpError::for_not_found(
None,
"Dataset not found".to_string(),
)
})?;
}
nested_dataset.mounted = mounted;
Ok(())
}

pub fn nested_dataset_ensure(
&mut self,
config: NestedDatasetConfig,
Expand Down
Loading
Loading