MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / main

Function main

cloud-hypervisor/src/main.rs:853–914  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

851}
852
853fn main() {
854 #[cfg(all(feature = "tdx", feature = "sev_snp"))]
855 compile_error!("Feature 'tdx' and 'sev_snp' are mutually exclusive.");
856 #[cfg(all(feature = "sev_snp", not(target_arch = "x86_64")))]
857 compile_error!("Feature 'sev_snp' needs target 'x86_64'");
858 #[cfg(all(feature = "fw_cfg", target_arch = "riscv64"))]
859 compile_error!("Feature 'fw_cfg' needs targets 'x86_64' or 'aarch64'");
860
861 #[cfg(feature = "dhat-heap")]
862 let _profiler = dhat::Profiler::new_heap();
863
864 // Ensure all created files (.e.g sockets) are only accessible by this user
865 // SAFETY: trivially safe
866 let _ = unsafe { libc::umask(0o077) };
867
868 let (default_vcpus, default_memory, default_rng) = prepare_default_values();
869 let cmd_arguments = create_app(default_vcpus, default_memory, default_rng).get_matches();
870
871 if cmd_arguments.get_flag("version") {
872 println!("{} {}", env!("CARGO_BIN_NAME"), env!("BUILD_VERSION"));
873
874 if cmd_arguments.get_count("v") != 0 {
875 println!("Enabled features: {:?}", vmm::feature_list());
876 }
877
878 return;
879 }
880
881 if let Err(e) = expand_fdtable() {
882 warn!("Error expanding FD table: {e}");
883 }
884
885 let (api_socket_path, api_socket_fd) = match parse_api_socket(&cmd_arguments) {
886 Ok(p) => p,
887 Err(top_error) => {
888 cloud_hypervisor::cli_print_error_chain(&top_error, "Cloud Hypervisor", |_, _, _| None);
889 std::process::exit(1);
890 }
891 };
892
893 let vmm_result = start_vmm(&cmd_arguments, &api_socket_path, api_socket_fd);
894
895 if let Some(ref p) = api_socket_path {
896 let _ = std::fs::remove_file(p);
897 }
898
899 let exit_code = match vmm_result {
900 Ok(()) => {
901 info!("Cloud Hypervisor exited successfully");
902 0
903 }
904 Err(top_error) => {
905 cloud_hypervisor::cli_print_error_chain(&top_error, "Cloud Hypervisor", |_, _, _| None);
906 1
907 }
908 };
909
910 #[cfg(feature = "dhat-heap")]

Callers

nothing calls this directly

Calls 6

prepare_default_valuesFunction · 0.85
create_appFunction · 0.85
expand_fdtableFunction · 0.85
parse_api_socketFunction · 0.85
cli_print_error_chainFunction · 0.85
start_vmmFunction · 0.85

Tested by

no test coverage detected