diff --git a/src/main.rs b/src/main.rs index e53e3642c..3acd89127 100644 --- a/src/main.rs +++ b/src/main.rs @@ -511,7 +511,7 @@ fn start_vmm(toplevel: TopLevel) -> Result, Error> { let vm_debug_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateDebugEventFd)?; let vmm_thread = vmm::start_vmm_thread( - env!("CARGO_PKG_VERSION").to_string(), + vmm::VmmVersionInfo::new(env!("BUILD_VERSION"), env!("CARGO_PKG_VERSION")), &api_socket_path, api_socket_fd, api_evt.try_clone().unwrap(), diff --git a/vmm/src/api/mod.rs b/vmm/src/api/mod.rs index c1b5ef0dd..42b04871d 100644 --- a/vmm/src/api/mod.rs +++ b/vmm/src/api/mod.rs @@ -165,7 +165,9 @@ pub struct VmInfo { #[derive(Clone, Deserialize, Serialize)] pub struct VmmPingResponse { + pub build_version: String, pub version: String, + pub pid: i64, } #[derive(Clone, Deserialize, Serialize, Default, Debug)] diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index a2392f988..0300d4022 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -438,8 +438,13 @@ components: - version type: object properties: + build_version: + type: string version: type: string + pid: + type: integer + format: int64 description: Virtual Machine Monitor information VmInfo: diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index a25cab35d..c881cfd24 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -281,7 +281,7 @@ impl Serialize for PciDeviceInfo { #[allow(unused_variables)] #[allow(clippy::too_many_arguments)] pub fn start_vmm_thread( - vmm_version: String, + vmm_version: VmmVersionInfo, http_path: &Option, http_fd: Option, api_event: EventFd, @@ -322,7 +322,7 @@ pub fn start_vmm_thread( } let mut vmm = Vmm::new( - vmm_version.to_string(), + vmm_version, api_event, #[cfg(feature = "guest_debug")] debug_event, @@ -390,6 +390,21 @@ struct VmMigrationConfig { memory_manager_data: MemoryManagerSnapshotData, } +#[derive(Debug, Clone)] +pub struct VmmVersionInfo { + pub build_version: String, + pub version: String, +} + +impl VmmVersionInfo { + pub fn new(build_version: &str, version: &str) -> Self { + Self { + build_version: build_version.to_owned(), + version: version.to_owned(), + } + } +} + pub struct Vmm { epoll: EpollContext, exit_evt: EventFd, @@ -399,7 +414,7 @@ pub struct Vmm { debug_evt: EventFd, #[cfg(feature = "guest_debug")] vm_debug_evt: EventFd, - version: String, + version: VmmVersionInfo, vm: Option, vm_config: Option>>, seccomp_action: SeccompAction, @@ -482,7 +497,7 @@ impl Vmm { } fn new( - vmm_version: String, + vmm_version: VmmVersionInfo, api_evt: EventFd, #[cfg(feature = "guest_debug")] debug_evt: EventFd, #[cfg(feature = "guest_debug")] vm_debug_evt: EventFd, @@ -802,8 +817,15 @@ impl Vmm { } fn vmm_ping(&self) -> VmmPingResponse { + let VmmVersionInfo { + build_version, + version, + } = self.version.clone(); + VmmPingResponse { - version: self.version.clone(), + build_version, + version, + pid: std::process::id() as i64, } } @@ -2057,7 +2079,7 @@ mod unit_tests { fn create_dummy_vmm() -> Vmm { Vmm::new( - "dummy".to_string(), + VmmVersionInfo::new("dummy", "dummy"), EventFd::new(EFD_NONBLOCK).unwrap(), #[cfg(feature = "guest_debug")] EventFd::new(EFD_NONBLOCK).unwrap(),