11// Copyright 2021 Oxide Computer Company
22
3- use anyhow:: { anyhow , bail , Result } ;
3+ use anyhow:: { Result , anyhow , bail } ;
44use crucible_agent_types:: { region:: * , snapshot:: * } ;
55use crucible_common:: write_json;
66use serde:: { Deserialize , Serialize } ;
7- use slog:: { crit, error, info, Logger } ;
7+ use slog:: { Logger , crit, error, info} ;
88use std:: collections:: BTreeMap ;
99use std:: net:: SocketAddr ;
1010use std:: path:: Path ;
1111use std:: path:: PathBuf ;
1212use std:: sync:: { Arc , Condvar , Mutex , MutexGuard } ;
1313
14+ use crate :: ZFSDataset ;
1415use crate :: resource:: Resource ;
1516use crate :: snapshot_interface:: SnapshotInterface ;
16- use crate :: ZFSDataset ;
1717
1818pub struct DataFile {
1919 log : Logger ,
@@ -434,31 +434,29 @@ impl DataFile {
434434 */
435435 if let Some ( running_snapshots) =
436436 inner. running_snapshots . get ( & request. id )
437+ && let Some ( running_snapshot) = running_snapshots. get ( & request. name )
437438 {
438- if let Some ( running_snapshot) = running_snapshots. get ( & request. name )
439- {
440- match running_snapshot. state {
441- State :: Requested | State :: Created | State :: Tombstoned => {
442- bail ! (
443- "read-only downstairs running for region {} snapshot {}" ,
444- request. id. 0 ,
445- request. name
446- ) ;
447- }
439+ match running_snapshot. state {
440+ State :: Requested | State :: Created | State :: Tombstoned => {
441+ bail ! (
442+ "read-only downstairs running for region {} snapshot {}" ,
443+ request. id. 0 ,
444+ request. name
445+ ) ;
446+ }
448447
449- State :: Destroyed => {
450- // ok to delete
451- }
448+ State :: Destroyed => {
449+ // ok to delete
450+ }
452451
453- State :: Failed => {
454- // Something has set the running snapshot to state
455- // failed, so we can't delete this snapshot.
456- bail ! (
457- "read-only downstairs state set to failed for region {} snapshot {}" ,
458- request. id. 0 ,
459- request. name
460- ) ;
461- }
452+ State :: Failed => {
453+ // Something has set the running snapshot to state
454+ // failed, so we can't delete this snapshot.
455+ bail ! (
456+ "read-only downstairs state set to failed for region {} snapshot {}" ,
457+ request. id. 0 ,
458+ request. name
459+ ) ;
462460 }
463461 }
464462 }
@@ -489,7 +487,10 @@ impl DataFile {
489487 // This is a bug: according to the agent's datafile,
490488 // the region exists, but according to zfs list, it
491489 // does not
492- bail ! ( "Agent thinks region {} exists but zfs list does not! {e}" , request. id. 0 ) ;
490+ bail ! (
491+ "Agent thinks region {} exists but zfs list does not! {e}" ,
492+ request. id. 0
493+ ) ;
493494 }
494495
495496 State :: Failed => {
@@ -503,7 +504,11 @@ impl DataFile {
503504 }
504505 } else {
505506 // In here, the region never existed!
506- bail ! ( "Inside region {} snapshot {} delete, region never existed! {e}" , request. id. 0 , request. name) ;
507+ bail ! (
508+ "Inside region {} snapshot {} delete, region never existed! {e}" ,
509+ request. id. 0 ,
510+ request. name
511+ ) ;
507512 }
508513 }
509514 } ;
@@ -863,7 +868,7 @@ impl DataFile {
863868
864869#[ cfg( test) ]
865870mod test {
866- use anyhow:: { bail , Result } ;
871+ use anyhow:: { Result , bail } ;
867872 use chrono:: { DateTime , TimeZone , Utc } ;
868873 use std:: process:: Command ;
869874
@@ -901,9 +906,8 @@ mod test {
901906 let cmd_stdout = String :: from_utf8_lossy ( & cmd. stdout ) ;
902907
903908 // Remove newline
904- let cmd_stdout = cmd_stdout. trim_end ( ) . to_string ( ) ;
905909
906- cmd_stdout
910+ cmd_stdout. trim_end ( ) . to_string ( )
907911 } ;
908912
909913 let _date = Utc . timestamp_opt ( cmd_stdout. parse ( ) ?, 0 ) . unwrap ( ) ;
0 commit comments