@@ -9,7 +9,6 @@ use zbus::Connection;
99
1010use crate :: {
1111 dbus:: {
12- blockdev:: unregister_blockdev,
1312 consts:: OK_STRING ,
1413 filesystem:: unregister_filesystem,
1514 manager:: Manager ,
@@ -57,72 +56,61 @@ pub async fn stop_pool_method(
5756
5857 let action = handle_action ! ( engine. stop_pool( id. clone( ) , true ) . await ) ;
5958
60- match action {
61- Ok ( StopAction :: Stopped ( _) | StopAction :: Partial ( _) ) | Err ( _) => {
62- let ( dev_uuids_rem, fs_uuids_rem) = match engine. get_pool ( id) . await {
63- Some ( p) => (
64- p. blockdevs ( )
65- . into_iter ( )
66- . map ( |( u, _, _) | u)
67- . collect :: < HashSet < _ > > ( ) ,
68- p. filesystems ( )
69- . into_iter ( )
70- . map ( |( _, u, _) | u)
71- . collect :: < HashSet < _ > > ( ) ,
72- ) ,
73- None => ( HashSet :: default ( ) , HashSet :: default ( ) ) ,
74- } ;
75-
76- for fs_uuid in fs_uuids. into_iter ( ) . filter ( |u| !fs_uuids_rem. contains ( u) ) {
77- let maybe_fs_path = manager. write ( ) . await . filesystem_get_path ( & fs_uuid) . cloned ( ) ;
78- if let Some ( fs_path) = maybe_fs_path {
79- if let Err ( e) = unregister_filesystem ( connection, manager, & fs_path) . await {
80- warn ! (
81- "Failed to unregister {fs_path} representing filesystem {fs_uuid}: {e}"
82- ) ;
59+ match & action {
60+ Ok ( StopAction :: Stopped ( pool_uuid) | StopAction :: Partial ( pool_uuid) ) => {
61+ let path = manager. read ( ) . await . pool_get_path ( pool_uuid) . cloned ( ) ;
62+ match path {
63+ Some ( pool) => {
64+ if let Err ( e) =
65+ unregister_pool ( connection, manager, & pool. as_ref ( ) , & fs_uuids, & dev_uuids)
66+ . await
67+ {
68+ warn ! ( "Failed to remove pool with path {pool} from the D-Bus: {e}" ) ;
8369 }
8470 }
85- }
86-
87- for dev_uuid in dev_uuids. into_iter ( ) . filter ( |u| !dev_uuids_rem. contains ( u) ) {
88- let maybe_dev_path = manager. write ( ) . await . blockdev_get_path ( & dev_uuid) . cloned ( ) ;
89- if let Some ( dev_path) = maybe_dev_path {
90- if let Err ( e) = unregister_blockdev ( connection, manager, & dev_path) . await {
91- warn ! (
92- "Failed to unregister {dev_path} representing blockdev {dev_uuid}: {e}"
93- ) ;
94- }
71+ None => {
72+ warn ! ( "Failed to unregister the stopped pool from the D-Bus" ) ;
9573 }
74+ } ;
75+ send_stopped_pools_signals ( connection) . await ;
76+ let stopped = {
77+ let stopped_pools = engine. stopped_pools ( ) . await ;
78+ stopped_pools
79+ . stopped
80+ . get ( pool_uuid)
81+ . or_else ( || stopped_pools. partially_constructed . get ( pool_uuid) )
82+ . map ( |s| s. info . is_some ( ) )
83+ . unwrap_or ( false )
84+ } ;
85+ if stopped {
86+ send_locked_pools_signals ( connection) . await ;
9687 }
9788 }
98- _ => { }
99- }
100-
101- if let Ok ( StopAction :: Stopped ( pool_uuid) | StopAction :: Partial ( pool_uuid) ) = action {
102- let path = manager. read ( ) . await . pool_get_path ( & pool_uuid) . cloned ( ) ;
103- match path {
104- Some ( pool) => {
105- if let Err ( e) = unregister_pool ( connection, manager, & pool. as_ref ( ) ) . await {
106- warn ! ( "Failed to remove pool with path {pool} from the D-Bus: {e}" ) ;
89+ Err ( _) => match engine. get_pool ( id. clone ( ) ) . await {
90+ Some ( g) => {
91+ let rem_fs = g
92+ . filesystems ( )
93+ . into_iter ( )
94+ . map ( |( _, uuid, _) | uuid)
95+ . collect :: < HashSet < _ > > ( ) ;
96+ for fs_uuid in fs_uuids. iter ( ) . filter ( |u| !rem_fs. contains ( u) ) {
97+ match manager. read ( ) . await . filesystem_get_path ( fs_uuid) . cloned ( ) {
98+ Some ( p) => {
99+ if let Err ( e) = unregister_filesystem ( connection, manager, & p) . await {
100+ warn ! ( "Failed to unregister filesystem: {e}" ) ;
101+ }
102+ }
103+ None => {
104+ warn ! ( "Could not find filesystem path for UUID {fs_uuid}" ) ;
105+ }
106+ }
107107 }
108108 }
109109 None => {
110- warn ! ( "Failed to unregister the stopped pool from the D-Bus " ) ;
110+ warn ! ( "Failed to find pool with ID {id:?} even though pool failed to stop " ) ;
111111 }
112- } ;
113- send_stopped_pools_signals ( connection) . await ;
114- let stopped = {
115- let stopped_pools = engine. stopped_pools ( ) . await ;
116- stopped_pools
117- . stopped
118- . get ( & pool_uuid)
119- . or_else ( || stopped_pools. partially_constructed . get ( & pool_uuid) )
120- . map ( |s| s. info . is_some ( ) )
121- . unwrap_or ( false )
122- } ;
123- if stopped {
124- send_locked_pools_signals ( connection) . await ;
125- }
112+ } ,
113+ Ok ( StopAction :: Identity | StopAction :: CleanedUp ( _) ) => { }
126114 }
127115
128116 match action {
@@ -131,7 +119,7 @@ pub async fn stop_pool_method(
131119 DbusErrorEnum :: OK as u16 ,
132120 OK_STRING . to_string ( ) ,
133121 ) ,
134- Ok ( StopAction :: Stopped ( pool_uuid) ) => (
122+ Ok ( StopAction :: Stopped ( pool_uuid) | StopAction :: CleanedUp ( pool_uuid ) ) => (
135123 ( true , pool_uuid. simple ( ) . to_string ( ) ) ,
136124 DbusErrorEnum :: OK as u16 ,
137125 OK_STRING . to_string ( ) ,
@@ -141,7 +129,6 @@ pub async fn stop_pool_method(
141129 DbusErrorEnum :: ERROR as u16 ,
142130 "Pool was stopped, but some component devices were not torn down" . to_string ( ) ,
143131 ) ,
144- Ok ( StopAction :: CleanedUp ( _) ) => unreachable ! ( "!has_partially_constructed above" ) ,
145132 Err ( e) => {
146133 let ( rc, rs) = engine_to_dbus_err_tuple ( & e) ;
147134 ( default_return, rc, rs)
0 commit comments