From e4cba73bf4ff2d2b3232ae82709fb2f8b4cef389 Mon Sep 17 00:00:00 2001 From: mulhern Date: Mon, 9 Sep 2024 15:48:54 -0400 Subject: [PATCH] Patch up origin fields if deleted filesystem was an origin Make this change visible on the D-Bus. Signed-off-by: mulhern --- src/dbus_api/pool/pool_3_7/methods.rs | 18 +++++++++--------- src/engine/engine.rs | 2 +- src/engine/sim_engine/pool.rs | 15 ++++++++++----- src/engine/strat_engine/pool/dispatch.rs | 3 ++- src/engine/strat_engine/pool/v1.rs | 3 ++- src/engine/strat_engine/pool/v2.rs | 3 ++- src/engine/strat_engine/thinpool/thinpool.rs | 15 ++++++++++----- src/engine/types/actions.rs | 2 +- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/dbus_api/pool/pool_3_7/methods.rs b/src/dbus_api/pool/pool_3_7/methods.rs index cb725b8a9d..37fb97381c 100644 --- a/src/dbus_api/pool/pool_3_7/methods.rs +++ b/src/dbus_api/pool/pool_3_7/methods.rs @@ -74,16 +74,16 @@ pub fn destroy_filesystems(m: &MethodInfo<'_, MTSync, 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 diff --git a/src/engine/engine.rs b/src/engine/engine.rs index ade1dc8423..dc20fd76fa 100644 --- a/src/engine/engine.rs +++ b/src/engine/engine.rs @@ -212,7 +212,7 @@ pub trait Pool: Debug + Send + Sync { &mut self, pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult>; + ) -> StratisResult)>>; /// Rename filesystem /// Rename pool with uuid to new_name. diff --git a/src/engine/sim_engine/pool.rs b/src/engine/sim_engine/pool.rs index 8c6670c57b..eeac131d03 100644 --- a/src/engine/sim_engine/pool.rs +++ b/src/engine/sim_engine/pool.rs @@ -481,7 +481,8 @@ impl Pool for SimPool { &mut self, _pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult> { + ) -> StratisResult)>> + { let mut snapshots = self .filesystems() .iter() @@ -512,7 +513,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) { @@ -521,10 +526,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)); }; } } diff --git a/src/engine/strat_engine/pool/dispatch.rs b/src/engine/strat_engine/pool/dispatch.rs index c011ff3237..f9c8e84254 100644 --- a/src/engine/strat_engine/pool/dispatch.rs +++ b/src/engine/strat_engine/pool/dispatch.rs @@ -123,7 +123,8 @@ impl Pool for AnyPool { &mut self, pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult> { + ) -> StratisResult)>> + { match self { AnyPool::V1(p) => p.destroy_filesystems(pool_name, fs_uuids), AnyPool::V2(p) => p.destroy_filesystems(pool_name, fs_uuids), diff --git a/src/engine/strat_engine/pool/v1.rs b/src/engine/strat_engine/pool/v1.rs index 3a5987ed02..984e1c33a4 100644 --- a/src/engine/strat_engine/pool/v1.rs +++ b/src/engine/strat_engine/pool/v1.rs @@ -1022,7 +1022,8 @@ impl Pool for StratPool { &mut self, pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult> { + ) -> StratisResult)>> + { self.thin_pool.destroy_filesystems(pool_name, fs_uuids) } diff --git a/src/engine/strat_engine/pool/v2.rs b/src/engine/strat_engine/pool/v2.rs index 2d68869261..4169454d7e 100644 --- a/src/engine/strat_engine/pool/v2.rs +++ b/src/engine/strat_engine/pool/v2.rs @@ -927,7 +927,8 @@ impl Pool for StratPool { &mut self, pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult> { + ) -> StratisResult)>> + { self.thin_pool.destroy_filesystems(pool_name, fs_uuids) } diff --git a/src/engine/strat_engine/thinpool/thinpool.rs b/src/engine/strat_engine/thinpool/thinpool.rs index cf76709381..eb7ab8fe5c 100644 --- a/src/engine/strat_engine/thinpool/thinpool.rs +++ b/src/engine/strat_engine/thinpool/thinpool.rs @@ -774,7 +774,8 @@ impl ThinPool { &mut self, pool_name: &str, fs_uuids: &HashSet, - ) -> StratisResult> { + ) -> StratisResult)>> + { let to_be_merged = fs_uuids .iter() .filter(|u| { @@ -819,7 +820,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) { @@ -828,10 +833,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)?; diff --git a/src/engine/types/actions.rs b/src/engine/types/actions.rs index 3a764e6b53..dbd45cfcf2 100644 --- a/src/engine/types/actions.rs +++ b/src/engine/types/actions.rs @@ -612,7 +612,7 @@ impl EngineAction for SetDeleteAction { } } -impl Display for SetDeleteAction { +impl Display for SetDeleteAction)> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.changed.is_empty() { write!(