From 620687c9dc136b841a08df48c7c22a8d0c4eb609 Mon Sep 17 00:00:00 2001 From: Frederick Mayle Date: Tue, 28 Nov 2023 12:52:22 -0800 Subject: [PATCH] vmm_vhost: remove more unnecessary `&mut self` Follow up to https://crrev.com/c/5064382. Change-Id: I0d723f765be4b846b0feb679d8e86d423d56345a Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5068396 Reviewed-by: Daniel Verkamp Commit-Queue: Frederick Mayle --- third_party/vmm_vhost/src/connection.rs | 7 ++----- third_party/vmm_vhost/src/connection/socket.rs | 6 +++--- third_party/vmm_vhost/src/connection/tube.rs | 6 +++--- third_party/vmm_vhost/src/master.rs | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/third_party/vmm_vhost/src/connection.rs b/third_party/vmm_vhost/src/connection.rs index 81b8e7de7f..bc80fa8c18 100644 --- a/third_party/vmm_vhost/src/connection.rs +++ b/third_party/vmm_vhost/src/connection.rs @@ -287,10 +287,7 @@ impl Endpoint { /// * - (number of bytes received, buf, [received files]) on success. /// * - backend specific errors #[cfg(test)] - pub fn recv_into_buf( - &mut self, - buf_size: usize, - ) -> Result<(usize, Vec, Option>)> { + pub fn recv_into_buf(&self, buf_size: usize) -> Result<(usize, Vec, Option>)> { let mut buf = vec![0u8; buf_size]; let mut slices = [IoSliceMut::new(buf.as_mut_slice())]; let (bytes, files) = self.0.recv_into_bufs(&mut slices, true /* allow_fd */)?; @@ -307,7 +304,7 @@ impl Endpoint { /// * - PartialMessage: received a partial message. /// * - InvalidMessage: received a invalid message. /// * - backend specific errors - pub fn recv_header(&mut self) -> Result<(VhostUserMsgHeader, Option>)> { + pub fn recv_header(&self) -> Result<(VhostUserMsgHeader, Option>)> { let mut hdr = VhostUserMsgHeader::default(); let (bytes, files) = self.0.recv_into_bufs( &mut [IoSliceMut::new(hdr.as_bytes_mut())], diff --git a/third_party/vmm_vhost/src/connection/socket.rs b/third_party/vmm_vhost/src/connection/socket.rs index 906037e902..f611085f0f 100644 --- a/third_party/vmm_vhost/src/connection/socket.rs +++ b/third_party/vmm_vhost/src/connection/socket.rs @@ -285,7 +285,7 @@ mod tests { let mut listener = SocketListener::new(&path, true).unwrap(); listener.set_nonblocking(true).unwrap(); let master = Endpoint::::connect(&path).unwrap(); - let mut slave = listener.accept().unwrap().unwrap(); + let slave = listener.accept().unwrap().unwrap(); let buf1 = [0x1, 0x2, 0x3, 0x4]; let mut len = master.send_slice(IoSlice::new(&buf1[..]), None).unwrap(); @@ -312,7 +312,7 @@ mod tests { let mut listener = SocketListener::new(&path, true).unwrap(); listener.set_nonblocking(true).unwrap(); let master = Endpoint::::connect(&path).unwrap(); - let mut slave = listener.accept().unwrap().unwrap(); + let slave = listener.accept().unwrap().unwrap(); let mut fd = tempfile().unwrap(); write!(fd, "test").unwrap(); @@ -485,7 +485,7 @@ mod tests { let mut listener = SocketListener::new(&path, true).unwrap(); listener.set_nonblocking(true).unwrap(); let master = Endpoint::::connect(&path).unwrap(); - let mut slave = listener.accept().unwrap().unwrap(); + let slave = listener.accept().unwrap().unwrap(); let mut hdr1 = VhostUserMsgHeader::new(MasterReq::GET_FEATURES, 0, mem::size_of::() as u32); diff --git a/third_party/vmm_vhost/src/connection/tube.rs b/third_party/vmm_vhost/src/connection/tube.rs index cd27d3219c..b6e7d1e8f2 100644 --- a/third_party/vmm_vhost/src/connection/tube.rs +++ b/third_party/vmm_vhost/src/connection/tube.rs @@ -204,7 +204,7 @@ mod tests { #[test] fn send_data() { - let (master, mut slave) = create_pair(); + let (master, slave) = create_pair(); let buf1 = vec![0x1, 0x2, 0x3, 0x4]; let len = master.send_slice(IoSlice::new(&buf1[..]), None).unwrap(); @@ -216,7 +216,7 @@ mod tests { #[test] fn send_fd() { - let (master, mut slave) = create_pair(); + let (master, slave) = create_pair(); let mut file = tempfile().unwrap(); write!(file, "test").unwrap(); @@ -301,7 +301,7 @@ mod tests { #[test] fn send_recv() { - let (master, mut slave) = create_pair(); + let (master, slave) = create_pair(); let mut hdr1 = VhostUserMsgHeader::new(MasterReq::GET_FEATURES, 0, mem::size_of::() as u32); diff --git a/third_party/vmm_vhost/src/master.rs b/third_party/vmm_vhost/src/master.rs index 5d87809818..8bf19975e6 100644 --- a/third_party/vmm_vhost/src/master.rs +++ b/third_party/vmm_vhost/src/master.rs @@ -713,7 +713,7 @@ mod tests { #[test] fn create_master() { - let (master, mut slave) = create_pair(); + let (master, slave) = create_pair(); assert!(master.main_sock.as_raw_descriptor() != INVALID_DESCRIPTOR); // Send two messages continuously @@ -735,7 +735,7 @@ mod tests { #[test] fn test_features() { - let (mut master, mut peer) = create_pair(); + let (mut master, peer) = create_pair(); master.set_owner().unwrap(); let (hdr, rfds) = peer.recv_header().unwrap(); @@ -769,7 +769,7 @@ mod tests { #[test] fn test_protocol_features() { - let (mut master, mut peer) = create_pair(); + let (mut master, peer) = create_pair(); master.set_owner().unwrap(); let (hdr, rfds) = peer.recv_header().unwrap();