@@ -1277,41 +1277,32 @@ impl Pool for StratPool {
12771277 }
12781278
12791279 #[ pool_mutating_action( "NoRequests" ) ]
1280- fn decrypt_pool (
1280+ fn decrypt_pool_idem_check (
12811281 & mut self ,
1282- name : & Name ,
12831282 pool_uuid : PoolUuid ,
12841283 ) -> StratisResult < DeleteAction < EncryptedDevice > > {
1285- let offset = DEFAULT_CRYPT_DATA_OFFSET_V2 ;
1286- let direction = OffsetDirection :: Forwards ;
12871284 match self . backstore . encryption_info ( ) {
12881285 None => Ok ( DeleteAction :: Identity ) ,
1289- Some ( _) => {
1290- match self . backstore . decrypt ( pool_uuid) {
1291- Ok ( _) => {
1292- self . last_reencrypt = None ;
1293- }
1294- Err ( e) => return Err ( e) ,
1295- }
1296- self . thin_pool . suspend ( ) ?;
1297- let set_device_res = self . thin_pool . set_device (
1298- self . backstore . device ( ) . expect (
1299- "Since thin pool exists, space must have been allocated \
1300- from the backstore, so backstore must have a cap device",
1301- ) ,
1302- offset,
1303- direction,
1304- ) ;
1305- self . thin_pool . resume ( ) ?;
1306- self . backstore . shift_alloc_offset ( offset, direction) ;
1307- let metadata_res = self . write_metadata ( name) ;
1308- let _ = set_device_res?;
1309- metadata_res?;
1310- Ok ( DeleteAction :: Deleted ( EncryptedDevice ( pool_uuid) ) )
1311- }
1286+ Some ( _) => Ok ( DeleteAction :: Deleted ( EncryptedDevice ( pool_uuid) ) ) ,
13121287 }
13131288 }
13141289
1290+ #[ pool_mutating_action( "NoRequests" ) ]
1291+ fn do_decrypt_pool ( & self , pool_uuid : PoolUuid ) -> StratisResult < ( ) > {
1292+ self . backstore . do_decrypt ( pool_uuid)
1293+ }
1294+
1295+ #[ pool_mutating_action( "NoRequests" ) ]
1296+ fn finish_decrypt_pool ( & mut self , pool_uuid : PoolUuid , name : & Name ) -> StratisResult < ( ) > {
1297+ let offset = DEFAULT_CRYPT_DATA_OFFSET_V2 ;
1298+ let direction = OffsetDirection :: Forwards ;
1299+ self . backstore
1300+ . finish_decrypt ( pool_uuid, & mut self . thin_pool , offset, direction) ?;
1301+ self . last_reencrypt = None ;
1302+ self . write_metadata ( name) ?;
1303+ Ok ( ( ) )
1304+ }
1305+
13151306 fn current_metadata ( & self , pool_name : & Name ) -> StratisResult < String > {
13161307 serde_json:: to_string ( & self . record ( pool_name) ) . map_err ( |e| e. into ( ) )
13171308 }
@@ -2382,12 +2373,13 @@ mod tests {
23822373 . unwrap ( ) ;
23832374
23842375 {
2385- let mut handle =
2386- test_async ! ( engine. get_mut_pool( PoolIdentifier :: Uuid ( pool_uuid) ) ) . unwrap ( ) ;
2387- let ( name, _, pool) = handle. as_mut_tuple ( ) ;
2388- assert ! ( pool. is_encrypted( ) ) ;
2389- pool. decrypt_pool ( & name, pool_uuid) . unwrap ( ) ;
2390- assert ! ( !pool. is_encrypted( ) ) ;
2376+ let handle = test_async ! ( engine. get_pool( PoolIdentifier :: Uuid ( pool_uuid) ) ) . unwrap ( ) ;
2377+ assert ! ( handle. is_encrypted( ) ) ;
2378+ handle. do_decrypt_pool ( pool_uuid) . unwrap ( ) ;
2379+ let ( name, _, _) = handle. as_tuple ( ) ;
2380+ let mut handle = test_async ! ( engine. upgrade_pool( handle. into_dyn( ) ) ) ;
2381+ handle. finish_decrypt_pool ( pool_uuid, & name) . unwrap ( ) ;
2382+ assert ! ( !handle. is_encrypted( ) ) ;
23912383 }
23922384
23932385 test_async ! ( engine. stop_pool( PoolIdentifier :: Uuid ( pool_uuid) , true ) ) . unwrap ( ) ;
0 commit comments