@@ -48,22 +48,28 @@ use crate::{Result, log_then_return, new_error};
4848/// Return `true` if the KVM API is available, version 12, and has UserMemory capability, or `false` otherwise
4949#[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
5050pub ( crate ) fn is_hypervisor_present ( ) -> bool {
51- if let Ok ( kvm) = Kvm :: new ( ) {
52- let api_version = kvm. get_api_version ( ) ;
53- match api_version {
54- version if version == 12 && kvm. check_extension ( UserMemory ) => true ,
55- 12 => {
56- log:: info!( "KVM does not have KVM_CAP_USER_MEMORY capability" ) ;
57- false
58- }
59- version => {
60- log:: info!( "KVM GET_API_VERSION returned {}, expected 12" , version) ;
61- false
51+ match Kvm :: new ( ) {
52+ Ok ( kvm) => {
53+ let api_version = kvm. get_api_version ( ) ;
54+ match api_version {
55+ version if version == 12 && kvm. check_extension ( UserMemory ) => true ,
56+ 12 => {
57+ println ! ( "KVM does not have KVM_CAP_USER_MEMORY capability" ) ;
58+ log:: info!( "KVM does not have KVM_CAP_USER_MEMORY capability" ) ;
59+ false
60+ }
61+ version => {
62+ println ! ( "KVM GET_API_VERSION returned {}, expected 12" , version) ;
63+ log:: info!( "KVM GET_API_VERSION returned {}, expected 12" , version) ;
64+ false
65+ }
6266 }
6367 }
64- } else {
65- log:: info!( "KVM is not available on this system" ) ;
66- false
68+ Err ( e) => {
69+ log:: info!( "KVM is not available on this system: {:?}" , e) ;
70+ println ! ( "KVM is not available on this system: {:?}" , e) ;
71+ false
72+ }
6773 }
6874}
6975
0 commit comments