Skip to content

Commit

Permalink
Patch up origin fields if deleted filesystem was an origin
Browse files Browse the repository at this point in the history
Make this change visible on the D-Bus.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Oct 3, 2024
1 parent 4d60c10 commit 2a2be73
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/dbus_api/pool/pool_3_7/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ pub fn destroy_filesystems(m: &MethodInfo<'_, MTSync<TData>, TData>) -> MethodRe
dbus_context.push_remove(op, filesystem_interface_list());
}

for sn_op in m.tree.iter().filter(|op| {
op.get_data()
.as_ref()
.map(|data| match data.uuid {
StratisUuid::Fs(uuid) => updated_uuids.contains(&uuid),
_ => false,
})
.unwrap_or(false)
for (sn_op, origin) in m.tree.iter().filter_map(|op| {
op.get_data().as_ref().and_then(|data| match data.uuid {
StratisUuid::Fs(uuid) => updated_uuids
.iter()
.find(|(u, _)| *u == uuid)
.map(|(_, origin)| (op, *origin)),
_ => None,
})
}) {
dbus_context.push_filesystem_origin_change(sn_op.get_name(), None);
dbus_context.push_filesystem_origin_change(sn_op.get_name(), origin);
}

changed_uuids
Expand Down
2 changes: 1 addition & 1 deletion src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub trait Pool: Debug + Send + Sync {
&mut self,
pool_name: &str,
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>>;
) -> StratisResult<SetDeleteAction<FilesystemUuid, (FilesystemUuid, Option<FilesystemUuid>)>>;

/// Rename filesystem
/// Rename pool with uuid to new_name.
Expand Down
15 changes: 10 additions & 5 deletions src/engine/sim_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ impl Pool for SimPool {
&mut self,
_pool_name: &str,
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
) -> StratisResult<SetDeleteAction<FilesystemUuid, (FilesystemUuid, Option<FilesystemUuid>)>>
{
let mut snapshots = self
.filesystems()
.iter()
Expand Down Expand Up @@ -522,7 +523,11 @@ impl Pool for SimPool {

let (mut removed, mut updated_origins) = (Vec::new(), Vec::new());
for &uuid in fs_uuids {
if self.filesystems.remove_by_uuid(uuid).is_some() {
if let Some((_, fs)) = self.get_filesystem(uuid) {
let fs_origin = fs.origin();
self.filesystems
.remove_by_uuid(uuid)
.expect("just looked up");
removed.push(uuid);

for (sn_uuid, _) in snapshots.remove(&uuid).unwrap_or_else(Vec::new) {
Expand All @@ -531,10 +536,10 @@ impl Pool for SimPool {
// removal.
if let Some((_, sn)) = self.filesystems.get_mut_by_uuid(sn_uuid) {
assert!(
sn.set_origin(None),
"A snapshot can only have one origin, so it can be in snapshots.values() only once, so its origin value can be unset only once"
sn.set_origin(fs_origin),
"A snapshot can only have one origin, so it can be in snapshots.values() only once, so its origin value can be set only once"
);
updated_origins.push(sn_uuid);
updated_origins.push((sn_uuid, fs_origin));
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/strat_engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,8 @@ impl Pool for StratPool {
&mut self,
pool_name: &str,
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
) -> StratisResult<SetDeleteAction<FilesystemUuid, (FilesystemUuid, Option<FilesystemUuid>)>>
{
self.thin_pool.destroy_filesystems(pool_name, fs_uuids)
}

Expand Down
15 changes: 10 additions & 5 deletions src/engine/strat_engine/thinpool/thinpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,8 @@ impl ThinPool {
&mut self,
pool_name: &str,
fs_uuids: &HashSet<FilesystemUuid>,
) -> StratisResult<SetDeleteAction<FilesystemUuid, FilesystemUuid>> {
) -> StratisResult<SetDeleteAction<FilesystemUuid, (FilesystemUuid, Option<FilesystemUuid>)>>
{
let to_be_merged = fs_uuids
.iter()
.filter(|u| {
Expand Down Expand Up @@ -1871,7 +1872,11 @@ impl ThinPool {

let (mut removed, mut updated_origins) = (Vec::new(), Vec::new());
for &uuid in fs_uuids {
if let Some(uuid) = self.destroy_filesystem(pool_name, uuid)? {
if let Some((_, fs)) = self.get_filesystem_by_uuid(uuid) {
let fs_origin = fs.origin();
let uuid = self
.destroy_filesystem(pool_name, uuid)?
.expect("just looked up");
removed.push(uuid);

for (sn_uuid, _) in snapshots.remove(&uuid).unwrap_or_else(Vec::new) {
Expand All @@ -1880,10 +1885,10 @@ impl ThinPool {
// removal.
if let Some((_, sn)) = self.get_mut_filesystem_by_uuid(sn_uuid) {
assert!(
sn.set_origin(None),
"A snapshot can only have one origin, so it can be in snapshots.values() only once, so its origin value can be unset only once"
sn.set_origin(fs_origin),
"A snapshot can only have one origin, so it can be in snapshots.values() only once, so its origin value can be set only once"
);
updated_origins.push(sn_uuid);
updated_origins.push((sn_uuid, fs_origin));

let (name, sn) = self.get_filesystem_by_uuid(sn_uuid).expect("just got");
self.mdv.save_fs(&name, sn_uuid, sn)?;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/types/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl<T, U> EngineAction for SetDeleteAction<T, U> {
}
}

impl Display for SetDeleteAction<FilesystemUuid, FilesystemUuid> {
impl Display for SetDeleteAction<FilesystemUuid, (FilesystemUuid, Option<FilesystemUuid>)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.changed.is_empty() {
write!(
Expand Down

0 comments on commit 2a2be73

Please sign in to comment.