diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-04-10 13:44:58 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-04-10 13:45:14 +0000 |
commit | 8404e234c3428a682dfd5ee900936a8032243ba7 (patch) | |
tree | 458d0c9db4e145c1ace3ea7e50c3a50a45f020c3 /vm_control | |
parent | d1ea7fc8d6b750ba75df719fb932984ab1ef5f11 (diff) | |
parent | 4ee9bffbd5722ac6602abaac6f691917add12f48 (diff) | |
download | crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar.gz crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar.bz2 crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar.lz crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar.xz crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.tar.zst crosvm-8404e234c3428a682dfd5ee900936a8032243ba7.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'vm_control')
-rw-r--r-- | vm_control/src/lib.rs | 92 |
1 files changed, 84 insertions, 8 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index 0216a90..b01f4af 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -43,10 +43,13 @@ impl AsRawFd for MaybeOwnedFd { // When sent, it could be owned or borrowed. On the receiver end, it always owned. impl MsgOnSocket for MaybeOwnedFd { - fn msg_size() -> usize { - 0usize + fn uses_fd() -> bool { + true } - fn max_fd_count() -> usize { + fn fixed_size() -> Option<usize> { + Some(0) + } + fn fd_count(&self) -> usize { 1usize } unsafe fn read_from_buffer(buffer: &[u8], fds: &[RawFd]) -> MsgResult<(Self, usize)> { @@ -99,7 +102,33 @@ pub const USB_CONTROL_MAX_PORTS: usize = 16; #[derive(MsgOnSocket, Debug)] pub enum BalloonControlCommand { /// Set the size of the VM's balloon. - Adjust { num_bytes: u64 }, + Adjust { + num_bytes: u64, + }, + Stats, +} + +// BalloonStats holds stats returned from the stats_queue. +#[derive(Default, MsgOnSocket, Debug)] +pub struct BalloonStats { + pub swap_in: Option<u64>, + pub swap_out: Option<u64>, + pub major_faults: Option<u64>, + pub minor_faults: Option<u64>, + pub free_memory: Option<u64>, + pub total_memory: Option<u64>, + pub available_memory: Option<u64>, + pub disk_caches: Option<u64>, + pub hugetlb_allocations: Option<u64>, + pub hugetlb_failures: Option<u64>, +} + +#[derive(MsgOnSocket, Debug)] +pub enum BalloonControlResult { + Stats { + stats: BalloonStats, + balloon_actual: u64, + }, } #[derive(MsgOnSocket, Debug)] @@ -206,7 +235,7 @@ pub enum VmMemoryRequest { RegisterMmapMemory { fd: MaybeOwnedFd, size: usize, - offset: usize, + offset: u64, gpa: u64, }, } @@ -274,7 +303,7 @@ impl VmMemoryRequest { offset, gpa, } => { - let mmap = match MemoryMapping::from_fd_offset(fd, size, offset) { + let mmap = match MemoryMapping::from_fd_offset(fd, size, offset as u64) { Ok(v) => v, Err(_e) => return VmMemoryResponse::Err(SysError::new(EINVAL)), }; @@ -379,8 +408,52 @@ pub enum VmIrqResponse { Err(SysError), } -pub type BalloonControlRequestSocket = MsgSocket<BalloonControlCommand, ()>; -pub type BalloonControlResponseSocket = MsgSocket<(), BalloonControlCommand>; +#[derive(MsgOnSocket, Debug)] +pub enum VmMsyncRequest { + /// Flush the content of a memory mapping to its backing file. + /// `slot` selects the arena (as returned by `Vm::add_mmap_arena`). + /// `offset` is the offset of the mapping to sync within the arena. + MsyncArena { slot: u32, offset: usize }, +} + +#[derive(MsgOnSocket, Debug)] +pub enum VmMsyncResponse { + Ok, + Err(SysError), +} + +impl VmMsyncRequest { + /// Executes this request on the given Vm. + /// + /// # Arguments + /// * `vm` - The `Vm` to perform the request on. + /// + /// This does not return a result, instead encapsulating the success or failure in a + /// `VmMsyncResponse` with the intended purpose of sending the response back over the socket + /// that received this `VmMsyncResponse`. + pub fn execute(&self, vm: &mut Vm) -> VmMsyncResponse { + use self::VmMsyncRequest::*; + match *self { + MsyncArena { slot, offset } => { + if let Some(arena) = vm.get_mmap_arena(slot) { + match arena.msync(offset) { + Ok(true) => VmMsyncResponse::Ok, + Ok(false) => VmMsyncResponse::Err(SysError::new(EINVAL)), + Err(e) => match e { + MmapError::SystemCallFailed(errno) => VmMsyncResponse::Err(errno), + _ => VmMsyncResponse::Err(SysError::new(EINVAL)), + }, + } + } else { + VmMsyncResponse::Err(SysError::new(EINVAL)) + } + } + } + } +} + +pub type BalloonControlRequestSocket = MsgSocket<BalloonControlCommand, BalloonControlResult>; +pub type BalloonControlResponseSocket = MsgSocket<BalloonControlResult, BalloonControlCommand>; pub type DiskControlRequestSocket = MsgSocket<DiskControlCommand, DiskControlResult>; pub type DiskControlResponseSocket = MsgSocket<DiskControlResult, DiskControlCommand>; @@ -393,6 +466,9 @@ pub type VmMemoryControlResponseSocket = MsgSocket<VmMemoryResponse, VmMemoryReq pub type VmIrqRequestSocket = MsgSocket<VmIrqRequest, VmIrqResponse>; pub type VmIrqResponseSocket = MsgSocket<VmIrqResponse, VmIrqRequest>; +pub type VmMsyncRequestSocket = MsgSocket<VmMsyncRequest, VmMsyncResponse>; +pub type VmMsyncResponseSocket = MsgSocket<VmMsyncResponse, VmMsyncRequest>; + pub type VmControlRequestSocket = MsgSocket<VmRequest, VmResponse>; pub type VmControlResponseSocket = MsgSocket<VmResponse, VmRequest>; |