@@ -15,9 +15,8 @@ use zbus::{
1515
1616use crate :: {
1717 dbus:: {
18- blockdev:: unregister_blockdev,
1918 consts:: OK_STRING ,
20- filesystem:: { register_filesystem , unregister_filesystem} ,
19+ filesystem:: unregister_filesystem,
2120 manager:: Manager ,
2221 pool:: { register_pool, unregister_pool} ,
2322 types:: DbusErrorEnum ,
@@ -83,30 +82,11 @@ pub async fn start_pool_method(
8382 ) ;
8483 }
8584 } ;
86- let mut fs_paths = Vec :: default ( ) ;
87- for fs_uuid in guard
88- . filesystems ( )
89- . into_iter ( )
90- . map ( |( _, fs_uuid, _) | fs_uuid)
91- . collect :: < Vec < _ > > ( )
92- {
93- let fs_path = match register_filesystem (
94- engine, connection, manager, counter, pool_uuid, fs_uuid,
95- )
96- . await
97- {
98- Ok ( fp) => fp,
99- Err ( e) => {
100- let ( rc, rs) = engine_to_dbus_err_tuple ( & e) ;
101- return ( default_return, rc, rs) ;
102- }
103- } ;
104- fs_paths. push ( OwnedObjectPath :: from ( fs_path) ) ;
105- }
106- let ( pool_path, dev_paths) =
85+ let ( pool_path, fs_paths, dev_paths) =
10786 match register_pool ( engine, connection, manager, counter, pool_uuid) . await {
108- Ok ( ( pp, dp) ) => (
87+ Ok ( ( pp, fp , dp) ) => (
10988 OwnedObjectPath :: from ( pp) ,
89+ fp. into_iter ( ) . map ( OwnedObjectPath :: from) . collect ( ) ,
11090 dp. into_iter ( ) . map ( OwnedObjectPath :: from) . collect ( ) ,
11191 ) ,
11292 Err ( e) => {
@@ -171,61 +151,48 @@ pub async fn stop_pool_method(
171151 . await
172152 ) ;
173153
174- match action {
175- Ok ( StopAction :: Stopped ( _) | StopAction :: Partial ( _) ) | Err ( _) => {
176- let ( dev_uuids_rem, fs_uuids_rem) =
177- match engine. get_pool ( PoolIdentifier :: Uuid ( pool_uuid) ) . await {
178- Some ( p) => (
179- p. blockdevs ( )
180- . into_iter ( )
181- . map ( |( u, _, _) | u)
182- . collect :: < HashSet < _ > > ( ) ,
183- p. filesystems ( )
184- . into_iter ( )
185- . map ( |( _, u, _) | u)
186- . collect :: < HashSet < _ > > ( ) ,
187- ) ,
188- None => ( HashSet :: default ( ) , HashSet :: default ( ) ) ,
189- } ;
190-
191- for fs_uuid in fs_uuids. into_iter ( ) . filter ( |u| !fs_uuids_rem. contains ( u) ) {
192- let maybe_fs_path = manager. write ( ) . await . filesystem_get_path ( & fs_uuid) . cloned ( ) ;
193- if let Some ( fs_path) = maybe_fs_path {
194- if let Err ( e) = unregister_filesystem ( connection, manager, & fs_path) . await {
195- warn ! (
196- "Failed to unregister {fs_path} representing filesystem {fs_uuid}: {e}"
197- ) ;
198- }
199- }
154+ match & action {
155+ Ok ( StopAction :: Stopped ( _) | StopAction :: Partial ( _) ) => {
156+ if let Err ( e) = unregister_pool ( connection, manager, & pool, & fs_uuids, & dev_uuids) . await
157+ {
158+ warn ! ( "Failed to remove pool with path {pool} from the D-Bus: {e}" ) ;
200159 }
201-
202- for dev_uuid in dev_uuids. into_iter ( ) . filter ( |u| !dev_uuids_rem. contains ( u) ) {
203- let maybe_dev_path = manager. write ( ) . await . blockdev_get_path ( & dev_uuid) . cloned ( ) ;
204- if let Some ( dev_path) = maybe_dev_path {
205- if let Err ( e) = unregister_blockdev ( connection, manager, & dev_path) . await {
206- warn ! (
207- "Failed to unregister {dev_path} representing blockdev {dev_uuid}: {e}"
208- ) ;
160+ send_stopped_pools_signals ( connection) . await ;
161+ let stopped_pools = engine. stopped_pools ( ) . await ;
162+ let stopped = stopped_pools
163+ . stopped
164+ . get ( & pool_uuid)
165+ . or_else ( || stopped_pools. partially_constructed . get ( & pool_uuid) ) ;
166+ if stopped. map ( |s| s. info . is_some ( ) ) . unwrap_or ( false ) {
167+ send_locked_pools_signals ( connection) . await ;
168+ }
169+ }
170+ Err ( _) => match engine. get_pool ( PoolIdentifier :: Uuid ( pool_uuid) ) . await {
171+ Some ( g) => {
172+ let rem_fs = g
173+ . filesystems ( )
174+ . into_iter ( )
175+ . map ( |( _, uuid, _) | uuid)
176+ . collect :: < HashSet < _ > > ( ) ;
177+ for fs_uuid in fs_uuids. iter ( ) . filter ( |u| !rem_fs. contains ( u) ) {
178+ match manager. read ( ) . await . filesystem_get_path ( fs_uuid) . cloned ( ) {
179+ Some ( p) => {
180+ if let Err ( e) = unregister_filesystem ( connection, manager, & p) . await {
181+ warn ! ( "Failed to unregister filesystem: {e}" ) ;
182+ }
183+ }
184+ None => {
185+ warn ! ( "Could not find filesystem path for UUID {fs_uuid}" ) ;
186+ }
209187 }
210188 }
211189 }
212- }
213- _ => { }
214- }
215-
216- if let Ok ( StopAction :: Stopped ( _) | StopAction :: Partial ( _) ) = action {
217- if let Err ( e) = unregister_pool ( connection, manager, & pool) . await {
218- warn ! ( "Failed to remove pool with path {pool} from the D-Bus: {e}" ) ;
219- }
220- send_stopped_pools_signals ( connection) . await ;
221- let stopped_pools = engine. stopped_pools ( ) . await ;
222- let stopped = stopped_pools
223- . stopped
224- . get ( & pool_uuid)
225- . or_else ( || stopped_pools. partially_constructed . get ( & pool_uuid) ) ;
226- if stopped. map ( |s| s. info . is_some ( ) ) . unwrap_or ( false ) {
227- send_locked_pools_signals ( connection) . await ;
228- }
190+ None => {
191+ warn ! ( "Failed to find pool with UUID {pool_uuid} even though pool failed to stop" ) ;
192+ }
193+ } ,
194+ Ok ( StopAction :: Identity ) => { }
195+ Ok ( StopAction :: CleanedUp ( _) ) => unreachable ! ( "!has_partially_constructed above" ) ,
229196 }
230197
231198 match action {
0 commit comments