22// License, v. 2.0. If a copy of the MPL was not distributed with this
33// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
5- use zbus:: Error ;
5+ use std:: sync:: Arc ;
6+
7+ use tokio:: sync:: RwLock ;
8+ use zbus:: { Connection , Error } ;
69
710use crate :: {
8- dbus:: util:: { option_to_tuple, tuple_to_option} ,
9- engine:: { BlockDev , BlockDevTier , DevUuid , Pool , PoolUuid , SomeLockWriteGuard } ,
11+ dbus:: {
12+ manager:: Manager ,
13+ util:: { option_to_tuple, send_user_info_signal, tuple_to_option} ,
14+ } ,
15+ engine:: { BlockDev , BlockDevTier , DevUuid , Lockable , Pool , PoolUuid , SomeLockWriteGuard } ,
1016} ;
1117
1218pub fn new_physical_size_prop ( _: BlockDevTier , _: DevUuid , dev : & dyn BlockDev ) -> ( bool , String ) {
@@ -16,11 +22,11 @@ pub fn new_physical_size_prop(_: BlockDevTier, _: DevUuid, dev: &dyn BlockDev) -
1622 )
1723}
1824
19- pub fn set_user_info_prop (
20- guard : & mut SomeLockWriteGuard < PoolUuid , dyn Pool > ,
25+ pub async fn set_user_info_prop (
26+ mut guard : SomeLockWriteGuard < PoolUuid , dyn Pool > ,
2127 dev_uuid : DevUuid ,
2228 user_info_tuple : ( bool , String ) ,
23- ) -> Result < ( ) , Error > {
29+ ) -> Result < bool , Error > {
2430 let user_info = tuple_to_option ( user_info_tuple) ;
2531 let user_info = user_info. as_deref ( ) ;
2632 let ( pool_name, _, pool) = guard. as_mut_tuple ( ) ;
@@ -31,10 +37,23 @@ pub fn set_user_info_prop(
3137 . user_info ( )
3238 == user_info
3339 {
34- Ok ( ( ) )
40+ Ok ( false )
3541 } else {
3642 pool. set_blockdev_user_info ( & pool_name, dev_uuid, user_info)
37- . map ( |_| ( ) )
38- . map_err ( |e| Error :: Failure ( e. to_string ( ) ) )
43+ . map_err ( |e| Error :: Failure ( e. to_string ( ) ) ) ?;
44+ Ok ( true )
45+ }
46+ }
47+
48+ pub async fn send_user_info_signal_on_change (
49+ connection : & Arc < Connection > ,
50+ manager : & Lockable < Arc < RwLock < Manager > > > ,
51+ dev_uuid : DevUuid ,
52+ ) {
53+ match manager. read ( ) . await . blockdev_get_path ( & dev_uuid) {
54+ Some ( p) => send_user_info_signal ( connection, & p. as_ref ( ) ) . await ,
55+ None => {
56+ warn ! ( "No path associated with blockdev UUID {dev_uuid}; cannot send property changed signal" ) ;
57+ }
3958 }
4059}
0 commit comments