summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorJakub Staron <jstaron@google.com>2019-04-11 12:49:29 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-25 00:59:51 -0700
commit1f828d7cd738a0bd38eb5342130510e2acb24afd (patch)
tree5f5f26558fa54c4585a1b87011193d6443c69a56 /src/linux.rs
parentd6945a09b8aa4ea03abac7a1adc0d2990ca8a5e7 (diff)
downloadcrosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar.gz
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar.bz2
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar.lz
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar.xz
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.tar.zst
crosvm-1f828d7cd738a0bd38eb5342130510e2acb24afd.zip
Extracts BalloonAdjust from VmRequest.
Extracts BalloonAdjust from VmRequest into BalloonControlCommand.

BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: Ia9f5778c37c8fd4fa560df413134d1b441142f64
Reviewed-on: https://chromium-review.googlesource.com/1565298
Commit-Ready: Jakub StaroĊ„ <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 6e2c2c9..07cb5a9 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -9,7 +9,6 @@ use std::ffi::CStr;
 use std::fmt::{self, Display};
 use std::fs::{File, OpenOptions};
 use std::io::{self, stdin, Read};
-use std::mem;
 use std::net::Ipv4Addr;
 use std::os::unix::io::{FromRawFd, RawFd};
 use std::os::unix::net::UnixStream;
@@ -23,7 +22,6 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
 use libc::{self, c_int, gid_t, uid_t};
 
 use audio_streams::DummyStreamSource;
-use byteorder::{ByteOrder, LittleEndian};
 use devices::virtio::{self, VirtioDevice};
 use devices::{self, HostBackendDeviceProvider, PciDevice, VirtioPciDevice, XhciController};
 use io_jail::{self, Minijail};
@@ -37,7 +35,7 @@ use remain::sorted;
 #[cfg(feature = "gpu-forward")]
 use resources::Alloc;
 use sync::{Condvar, Mutex};
-use sys_util::net::{UnixSeqpacket, UnixSeqpacketListener, UnlinkUnixSeqpacketListener};
+use sys_util::net::{UnixSeqpacketListener, UnlinkUnixSeqpacketListener};
 use sys_util::{
     self, block_signal, clear_signal, drop_capabilities, error, flock, get_blocked_signals,
     get_group_id, get_user_id, getegid, geteuid, info, register_signal_handler, set_cpu_affinity,
@@ -48,6 +46,7 @@ use sys_util::{
 use sys_util::{GuestAddress, MemoryMapping, Protection};
 use vhost;
 use vm_control::{
+    BalloonControlCommand, BalloonControlRequestSocket, BalloonControlResponseSocket,
     DiskControlCommand, DiskControlRequestSocket, DiskControlResponseSocket, DiskControlResult,
     UsbControlSocket, VmControlRequestSocket, VmControlResponseSocket, VmRequest, VmResponse,
     VmRunMode,
@@ -457,7 +456,7 @@ fn create_vinput_device(cfg: &Config, dev_path: &Path) -> DeviceResult {
     })
 }
 
-fn create_balloon_device(cfg: &Config, socket: UnixSeqpacket) -> DeviceResult {
+fn create_balloon_device(cfg: &Config, socket: BalloonControlResponseSocket) -> DeviceResult {
     let dev = virtio::Balloon::new(socket).map_err(Error::BalloonDeviceNew)?;
 
     Ok(VirtioDeviceStub {
@@ -673,7 +672,7 @@ fn create_virtio_devices(
     mem: &GuestMemory,
     _exit_evt: &EventFd,
     wayland_device_socket: VmControlRequestSocket,
-    balloon_device_socket: UnixSeqpacket,
+    balloon_device_socket: BalloonControlResponseSocket,
     disk_device_sockets: &mut Vec<DiskControlResponseSocket>,
 ) -> DeviceResult<Vec<VirtioDeviceStub>> {
     let mut devs = Vec::new();
@@ -773,7 +772,7 @@ fn create_devices(
     mem: &GuestMemory,
     exit_evt: &EventFd,
     wayland_device_socket: VmControlRequestSocket,
-    balloon_device_socket: UnixSeqpacket,
+    balloon_device_socket: BalloonControlResponseSocket,
     disk_device_sockets: &mut Vec<DiskControlResponseSocket>,
     usb_provider: HostBackendDeviceProvider,
 ) -> DeviceResult<Vec<(Box<dyn PciDevice>, Option<Minijail>)>> {
@@ -1131,7 +1130,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
     control_sockets.push(wayland_host_socket);
     // Balloon gets a special socket so balloon requests can be forwarded from the main process.
     let (balloon_host_socket, balloon_device_socket) =
-        UnixSeqpacket::pair().map_err(Error::CreateSocket)?;
+        msg_socket::pair::<BalloonControlCommand, ()>().map_err(Error::CreateSocket)?;
 
     // Create one control socket per disk.
     let mut disk_device_sockets = Vec::new();
@@ -1215,7 +1214,7 @@ fn run_control(
     mut linux: RunnableLinuxVm,
     control_server_socket: Option<UnlinkUnixSeqpacketListener>,
     mut control_sockets: Vec<VmControlResponseSocket>,
-    balloon_host_socket: UnixSeqpacket,
+    balloon_host_socket: BalloonControlRequestSocket,
     disk_host_sockets: &[DiskControlRequestSocket],
     usb_control_socket: UsbControlSocket,
     sigchld_fd: SignalFd,
@@ -1416,9 +1415,10 @@ fn run_control(
                             } else {
                                 0
                             };
-                        let mut buf = [0u8; mem::size_of::<u64>()];
-                        LittleEndian::write_u64(&mut buf, current_balloon_memory);
-                        if let Err(e) = balloon_host_socket.send(&buf) {
+                        let command = BalloonControlCommand::Adjust {
+                            num_bytes: current_balloon_memory,
+                        };
+                        if let Err(e) = balloon_host_socket.send(&command) {
                             warn!("failed to send memory value to balloon device: {}", e);
                         }
                     }
@@ -1431,9 +1431,10 @@ fn run_control(
                             max_balloon_memory,
                         );
                         if current_balloon_memory != old_balloon_memory {
-                            let mut buf = [0u8; mem::size_of::<u64>()];
-                            LittleEndian::write_u64(&mut buf, current_balloon_memory);
-                            if let Err(e) = balloon_host_socket.send(&buf) {
+                            let command = BalloonControlCommand::Adjust {
+                                num_bytes: current_balloon_memory,
+                            };
+                            if let Err(e) = balloon_host_socket.send(&command) {
                                 warn!("failed to send memory value to balloon device: {}", e);
                             }
                         }