@@ -578,49 +578,43 @@ impl super::Nexus {
578
578
. db_datastore
579
579
. instance_fetch_with_vmm ( opctx, & authz_instance)
580
580
. await ?;
581
- let ( instance, vmm) = ( state. instance ( ) , state. vmm ( ) ) ;
582
-
583
- if let Some ( vmm) = vmm {
584
- match vmm. runtime . state {
585
- DbVmmState :: Starting
586
- | DbVmmState :: Running
587
- | DbVmmState :: Rebooting => {
588
- debug ! ( self . log, "asked to start an active instance" ;
589
- "instance_id" => %authz_instance. id( ) ) ;
590
581
591
- return Ok ( state) ;
592
- }
593
- // If there's a previous VMM left behind by an unwinding start
594
- // saga, no big deal. We can still start the instance, and the
595
- // start saga will remove the dead VMM, allowing it to be reaped.
596
- DbVmmState :: SagaUnwound => { }
597
- DbVmmState :: Stopped => {
598
- let propolis_id = instance
599
- . runtime ( )
600
- . propolis_id
601
- . expect ( "needed a VMM ID to fetch a VMM record" ) ;
602
- error ! ( self . log,
603
- "instance is stopped but still has an active VMM" ;
604
- "instance_id" => %authz_instance. id( ) ,
605
- "propolis_id" => %propolis_id) ;
582
+ match state. effective_state ( ) {
583
+ s @ InstanceState :: Starting
584
+ | s @ InstanceState :: Running
585
+ | s @ InstanceState :: Rebooting
586
+ | s @ InstanceState :: Migrating => {
587
+ debug ! ( self . log, "asked to start an active instance" ;
588
+ "instance_id" => %authz_instance. id( ) ,
589
+ "state" => ?s) ;
606
590
607
- return Err ( Error :: internal_error (
608
- "instance is stopped but still has an active VMM" ,
609
- ) ) ;
610
- }
611
- _ => {
612
- return Err ( Error :: conflict ( & format ! (
613
- "instance is in state {} but must be {} to be started" ,
614
- vmm. runtime. state,
615
- InstanceState :: Stopped
616
- ) ) ) ;
617
- }
591
+ return Ok ( state) ;
618
592
}
619
- }
593
+ InstanceState :: Stopping => {
594
+ let ( propolis_id, propolis_state) = match state. vmm ( ) {
595
+ Some ( vmm) => ( Some ( vmm. id ) , Some ( vmm. runtime . state ) ) ,
596
+ None => ( None , None ) ,
597
+ } ;
598
+ debug ! ( self . log, "instance's VMM is still in the process of stopping" ;
599
+ "instance_id" => %authz_instance. id( ) ,
600
+ "propolis_id" => ?propolis_id,
601
+ "propolis_state" => ?propolis_state) ;
602
+ return Err ( Error :: conflict (
603
+ "instance must finish stopping before it can be started" ,
604
+ ) ) ;
605
+ }
606
+ InstanceState :: Stopped => { }
607
+ s => {
608
+ return Err ( Error :: conflict ( & format ! (
609
+ "instance is in state {s} but it must be {} to be started" ,
610
+ InstanceState :: Stopped
611
+ ) ) )
612
+ }
613
+ } ;
620
614
621
615
let saga_params = sagas:: instance_start:: Params {
622
616
serialized_authn : authn:: saga:: Serialized :: for_opctx ( opctx) ,
623
- db_instance : instance. clone ( ) ,
617
+ db_instance : state . instance . clone ( ) ,
624
618
} ;
625
619
626
620
self . sagas
0 commit comments