msg_socket: remove MsgOnSocket impl for RawFd, an alias for i32

This implementation makes it impossible to use i32 as ordinary data in a
MsgOnSocket implementation. It is also error prone because i32 is the
default type for integer literals in Rust, and #[derive(MsgOnSocket)] on
structs with an i32 would suddenly be transmitting a RawFd.

This change also replaces the uses of RawFd's MsgOnSocket impl for one
based on File.

TEST=cargo build
BUG=None

Change-Id: I9da392e34e62fe61f773f24d656dbcbf4716f1a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197777
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
diff --git a/msg_socket/src/msg_on_socket.rs b/msg_socket/src/msg_on_socket.rs
index 1172b3d..eeaf1bd 100644
--- a/msg_socket/src/msg_on_socket.rs
+++ b/msg_socket/src/msg_on_socket.rs
@@ -143,30 +143,6 @@
     }
 }
 
-impl MsgOnSocket for RawFd {
-    fn fixed_size() -> Option<usize> {
-        Some(0)
-    }
-
-    fn fd_count(&self) -> usize {
-        1
-    }
-
-    unsafe fn read_from_buffer(_buffer: &[u8], fds: &[RawFd]) -> MsgResult<(Self, usize)> {
-        if fds.is_empty() {
-            return Err(MsgError::ExpectFd);
-        }
-        Ok((fds[0], 1))
-    }
-    fn write_to_buffer(&self, _buffer: &mut [u8], fds: &mut [RawFd]) -> MsgResult<usize> {
-        if fds.is_empty() {
-            return Err(MsgError::WrongFdBufferSize);
-        }
-        fds[0] = *self;
-        Ok(1)
-    }
-}
-
 impl<T: MsgOnSocket> MsgOnSocket for Option<T> {
     fn uses_fd() -> bool {
         T::uses_fd()
@@ -288,7 +264,7 @@
                 Ok(($type::from_raw_fd(fds[0]), 1))
             }
             fn write_to_buffer(&self, _buffer: &mut [u8], fds: &mut [RawFd]) -> MsgResult<usize> {
-                if fds.len() < 1 {
+                if fds.is_empty() {
                     return Err(MsgError::WrongFdBufferSize);
                 }
                 fds[0] = self.as_raw_fd();
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index a8535f8..81a11d3 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -19,7 +19,7 @@
 use libc::{EINVAL, EIO, ENODEV};
 
 use kvm::{IrqRoute, IrqSource, Vm};
-use msg_socket::{MsgOnSocket, MsgReceiver, MsgResult, MsgSender, MsgSocket};
+use msg_socket::{MsgError, MsgOnSocket, MsgReceiver, MsgResult, MsgSender, MsgSocket};
 use resources::{Alloc, GpuMemoryDesc, MmioType, SystemAllocator};
 use sys_util::{error, Error as SysError, EventFd, GuestAddress, MemoryMapping, MmapError, Result};
 
@@ -53,13 +53,16 @@
         1usize
     }
     unsafe fn read_from_buffer(buffer: &[u8], fds: &[RawFd]) -> MsgResult<(Self, usize)> {
-        let (fd, size) = RawFd::read_from_buffer(buffer, fds)?;
-        let file = File::from_raw_fd(fd);
+        let (file, size) = File::read_from_buffer(buffer, fds)?;
         Ok((MaybeOwnedFd::Owned(file), size))
     }
-    fn write_to_buffer(&self, buffer: &mut [u8], fds: &mut [RawFd]) -> MsgResult<usize> {
-        let fd = self.as_raw_fd();
-        fd.write_to_buffer(buffer, fds)
+    fn write_to_buffer(&self, _buffer: &mut [u8], fds: &mut [RawFd]) -> MsgResult<usize> {
+        if fds.is_empty() {
+            return Err(MsgError::WrongFdBufferSize);
+        }
+
+        fds[0] = self.as_raw_fd();
+        Ok(1)
     }
 }