summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-01-03 12:53:04 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-05 20:08:41 -0800
commitf76869d2a62cf662a03c4245ca83456f72f5e813 (patch)
tree2621e32c2ec2e795d3b83afc52ed80d770583567
parent3a794ccb25c599b0f1aac143309e92bd2303f2b0 (diff)
downloadcrosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar.gz
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar.bz2
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar.lz
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar.xz
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.tar.zst
crosvm-f76869d2a62cf662a03c4245ca83456f72f5e813.zip
devices: balloon: fix the 'crosvm balloon' command
The balloon socket interface was changed to take an absolute number of
pages in a u64 in commit 448516e3f9 ("balloon: Implement device
policy"), but the 'crosvm balloon' command wasn't updated to match.  Fix
the crosvm front-end to send a u64 as expected by the command socket
reader instead of the i32 it was sending previously, and change the
parameter to bytes instead of pages to match the receiving end as well.

BUG=None
TEST=crosvm balloon a running VM to various sizes

Change-Id: I265bee55c06809de7559a79a5eb6d0d094533993
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1394157
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
-rw-r--r--src/main.rs10
-rw-r--r--vm_control/src/lib.rs10
2 files changed, 10 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index d901cbf..8e1e452 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -571,13 +571,13 @@ fn stop_vms(args: std::env::Args) -> std::result::Result<(), ()> {
 
 fn balloon_vms(mut args: std::env::Args) -> std::result::Result<(), ()> {
     if args.len() < 2 {
-        print_help("crosvm balloon", "PAGE_ADJUST VM_SOCKET...", &[]);
-        println!("Adjust the ballon size of the crosvm instance by `PAGE_ADJUST` pages, `PAGE_ADJUST` can be negative to shrink the balloon.");
+        print_help("crosvm balloon", "SIZE VM_SOCKET...", &[]);
+        println!("Set the ballon size of the crosvm instance to `SIZE` bytes.");
     }
-    let num_pages: i32 = match args.nth(0).unwrap().parse::<i32>() {
+    let num_bytes = match args.nth(0).unwrap().parse::<u64>() {
         Ok(n) => n,
         Err(_) => {
-            error!("Failed to parse number of pages");
+            error!("Failed to parse number of bytes");
             return Err(());
         }
     };
@@ -590,7 +590,7 @@ fn balloon_vms(mut args: std::env::Args) -> std::result::Result<(), ()> {
         }) {
             Ok(s) => {
                 let sender = Sender::<VmRequest>::new(s);
-                if let Err(e) = sender.send(&VmRequest::BalloonAdjust(num_pages)) {
+                if let Err(e) = sender.send(&VmRequest::BalloonAdjust(num_bytes)) {
                     error!(
                         "failed to send balloon request to socket at '{}': {:?}",
                         socket_path, e
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index ab9af1d..1c28994 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -71,8 +71,8 @@ impl MsgOnSocket for MaybeOwnedFd {
 /// Unless otherwise noted, each request should expect a `VmResponse::Ok` to be received on success.
 #[derive(MsgOnSocket)]
 pub enum VmRequest {
-    /// Try to grow or shrink the VM's balloon.
-    BalloonAdjust(i32),
+    /// Set the size of the VM's balloon in bytes.
+    BalloonAdjust(u64),
     /// Break the VM's run loop and exit.
     Exit,
     /// Register the given ioevent address along with given datamatch to trigger the `EventFd`.
@@ -161,10 +161,10 @@ impl VmRequest {
                 Err(e) => VmResponse::Err(e),
             },
             VmRequest::BalloonAdjust(num_pages) => {
-                let mut buf = [0u8; 4];
-                // write_i32 can't fail as the buffer is 4 bytes long.
+                let mut buf = [0u8; 8];
+                // write_u64 can't fail as the buffer is 8 bytes long.
                 (&mut buf[0..])
-                    .write_i32::<LittleEndian>(num_pages)
+                    .write_u64::<LittleEndian>(num_pages)
                     .unwrap();
                 match balloon_host_socket.send(&buf) {
                     Ok(_) => VmResponse::Ok,