@@ -92,8 +92,6 @@ static const int BSP;
92
92
93
93
static cpuset_t cpumask ;
94
94
95
- static void do_close_pre (struct vmctx * ctx );
96
- static void do_close_post (struct vmctx * ctx );
97
95
static void vm_loop (struct vmctx * ctx );
98
96
99
97
static int quit_vm_loop ;
@@ -531,24 +529,6 @@ do_open(const char *vmname)
531
529
return ctx ;
532
530
}
533
531
534
- static void
535
- do_close_pre (struct vmctx * ctx )
536
- {
537
- vm_destroy (ctx );
538
- vm_close (ctx );
539
- }
540
-
541
- static void
542
- do_close_post (struct vmctx * ctx )
543
- {
544
- pci_irq_deinit (ctx );
545
- deinit_pci (ctx );
546
- atkbdc_deinit (ctx );
547
- vrtc_deinit (ctx );
548
- vm_destroy (ctx );
549
- vm_close (ctx );
550
- }
551
-
552
532
static void
553
533
sig_handler_term (int signo )
554
534
{
@@ -768,30 +748,26 @@ main(int argc, char *argv[])
768
748
/* set IOReq buffer page */
769
749
error = vm_set_shared_io_page (ctx , (unsigned long )vhm_req_buf );
770
750
if (error )
771
- do_close_pre (ctx );
772
- assert (error == 0 );
751
+ goto fail ;
773
752
774
753
if (guest_ncpus < 1 ) {
775
754
fprintf (stderr , "Invalid guest vCPUs (%d)\n" ,
776
755
guest_ncpus );
777
- do_close_pre (ctx );
778
- exit (1 );
756
+ goto fail ;
779
757
}
780
758
781
759
max_vcpus = num_vcpus_allowed (ctx );
782
760
if (guest_ncpus > max_vcpus ) {
783
761
fprintf (stderr , "%d vCPUs requested but %d available\n" ,
784
762
guest_ncpus , max_vcpus );
785
- do_close_pre (ctx );
786
- exit (1 );
763
+ goto fail ;
787
764
}
788
765
789
766
vm_set_memflags (ctx , memflags );
790
767
err = vm_setup_memory (ctx , memsize , VM_MMAP_ALL );
791
768
if (err ) {
792
769
fprintf (stderr , "Unable to setup memory (%d)\n" , errno );
793
- do_close_pre (ctx );
794
- exit (1 );
770
+ goto fail ;
795
771
}
796
772
797
773
init_mem ();
@@ -809,8 +785,7 @@ main(int argc, char *argv[])
809
785
* initialization
810
786
*/
811
787
if (init_pci (ctx ) != 0 ) {
812
- do_close_pre (ctx );
813
- exit (1 );
788
+ goto pci_fail ;
814
789
}
815
790
816
791
if (gdb_port != 0 )
@@ -825,27 +800,23 @@ main(int argc, char *argv[])
825
800
if (mptgen ) {
826
801
error = mptable_build (ctx , guest_ncpus );
827
802
if (error ) {
828
- do_close_post (ctx );
829
- exit (1 );
803
+ goto vm_fail ;
830
804
}
831
805
}
832
806
833
807
error = smbios_build (ctx );
834
808
if (error )
835
- do_close_post (ctx );
836
- assert (error == 0 );
809
+ goto vm_fail ;
837
810
838
811
if (acpi ) {
839
812
error = acpi_build (ctx , guest_ncpus );
840
813
if (error )
841
- do_close_post (ctx );
842
- assert (error == 0 );
814
+ goto vm_fail ;
843
815
}
844
816
845
817
error = acrn_sw_load (ctx );
846
818
if (error )
847
- do_close_post (ctx );
848
- assert (error == 0 );
819
+ goto vm_fail ;
849
820
850
821
/*
851
822
* Change the proc title to include the VM name.
@@ -865,16 +836,34 @@ main(int argc, char *argv[])
865
836
*/
866
837
mevent_dispatch ();
867
838
868
- monitor_close ();
869
839
vm_pause (ctx );
870
840
fbsdrun_deletecpu (ctx , BSP );
871
- vm_unsetup_memory (ctx );
872
- do_close_post (ctx );
873
- _ctx = 0 ;
874
841
875
842
if (vm_get_suspend_mode () != VM_SUSPEND_RESET )
876
843
break ;
844
+
845
+ pci_irq_deinit (ctx );
846
+ deinit_pci (ctx );
847
+ monitor_close ();
848
+ vrtc_deinit (ctx );
849
+ atkbdc_deinit (ctx );
850
+ vm_unsetup_memory (ctx );
851
+ vm_destroy (ctx );
852
+ vm_close (ctx );
853
+ _ctx = 0 ;
854
+
877
855
vm_set_suspend_mode (VM_SUSPEND_NONE );
878
856
}
857
+ vm_fail :
858
+ pci_irq_deinit (ctx );
859
+ deinit_pci (ctx );
860
+ pci_fail :
861
+ monitor_close ();
862
+ vrtc_deinit (ctx );
863
+ atkbdc_deinit (ctx );
864
+ vm_unsetup_memory (ctx );
865
+ fail :
866
+ vm_destroy (ctx );
867
+ vm_close (ctx );
879
868
exit (0 );
880
869
}
0 commit comments