Skip to content

Commit

Permalink
Return a single blob of JSON, indexed on UUIDs
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Aug 1, 2024
1 parent 84195ff commit 43027a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
25 changes: 14 additions & 11 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,17 +760,20 @@ impl Pool for SimPool {
}

fn current_fs_metadata(&self, fs_name: Option<&str>) -> StratisResult<String> {
self.filesystems
.iter()
.filter_map(|(name, uuid, fs)| {
if fs_name.map(|n| *n == **name).unwrap_or(true) {
Some(serde_json::to_string(&fs.record(name, *uuid)).map_err(|e| e.into()))
} else {
None
}
})
.collect::<StratisResult<Vec<_>>>()
.map(|v| v.join("\n"))
serde_json::to_string(
&self
.filesystems
.iter()
.filter_map(|(name, uuid, fs)| {
if fs_name.map(|n| *n == **name).unwrap_or(true) {
Some((uuid, fs.record(name, *uuid)))
} else {
None
}
})
.collect::<HashMap<_, _>>(),
)
.map_err(|e| e.into())
}

fn last_fs_metadata(&self, fs_name: Option<&str>) -> StratisResult<String> {
Expand Down
52 changes: 29 additions & 23 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,33 +731,39 @@ impl<B> ThinPool<B> {

/// Calculate filesystem metadata from current state
pub fn current_fs_metadata(&self, fs_name: Option<&str>) -> StratisResult<String> {
self.filesystems
.iter()
.filter_map(|(name, uuid, fs)| {
if fs_name.map(|n| *n == **name).unwrap_or(true) {
Some(serde_json::to_string(&fs.record(name, *uuid)).map_err(|e| e.into()))
} else {
None
}
})
.collect::<StratisResult<Vec<_>>>()
.map(|v| v.join("\n"))
serde_json::to_string(
&self
.filesystems
.iter()
.filter_map(|(name, uuid, fs)| {
if fs_name.map(|n| *n == **name).unwrap_or(true) {
Some((*uuid, fs.record(name, *uuid)))
} else {
None
}
})
.collect::<HashMap<_, _>>(),
)
.map_err(|e| e.into())
}

/// Read filesystem metadata from mdv
pub fn last_fs_metadata(&self, fs_name: Option<&str>) -> StratisResult<String> {
self.mdv
.filesystems()?
.iter()
.filter_map(|fssave| {
if fs_name.map(|n| *n == fssave.name).unwrap_or(true) {
Some(serde_json::to_string(fssave).map_err(|e| e.into()))
} else {
None
}
})
.collect::<StratisResult<Vec<_>>>()
.map(|v| v.join("\n"))
serde_json::to_string(
&self
.mdv
.filesystems()?
.iter()
.filter_map(|fssave| {
if fs_name.map(|n| *n == fssave.name).unwrap_or(true) {
Some((fssave.uuid, fssave))
} else {
None
}
})
.collect::<HashMap<_, _>>(),
)
.map_err(|e| e.into())
}
}

Expand Down

0 comments on commit 43027a8

Please sign in to comment.