From 63226e2b80947258bf4dc35a8d78474023602dda Mon Sep 17 00:00:00 2001 From: Yu Li Date: Wed, 12 Jul 2023 12:43:58 +0800 Subject: [PATCH] build: Fix beta clippy issue (arc_with_non_send_sync) warning: usage of `Arc` where `T` is not `Send` or `Sync` --> virtio-devices/src/vsock/device.rs:376:22 | 376 | backend: Arc::new(RwLock::new(backend)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `Rc` instead or wrapping `T` in a std::sync type like `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `#[warn(clippy::arc_with_non_send_sync)]` on by default The vsock backend may be shared between threads, so the type `B` in `Vsock` should be `VsockBackend` and `Sync`. Considering that `api_receiver` and `gdb_receiver` are only used in vmm threads, the `Arc` can be replaced by `Rc`. Signed-off-by: Yu Li --- virtio-devices/src/vsock/device.rs | 2 +- vmm/src/lib.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/virtio-devices/src/vsock/device.rs b/virtio-devices/src/vsock/device.rs index b0d425ec3..fa793295c 100644 --- a/virtio-devices/src/vsock/device.rs +++ b/virtio-devices/src/vsock/device.rs @@ -333,7 +333,7 @@ impl VersionMapped for VsockState {} impl Vsock where - B: VsockBackend, + B: VsockBackend + Sync, { /// Create a new virtio-vsock device with the given VM CID and vsock /// backend. diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 407e590fd..264037a9d 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -43,6 +43,7 @@ use std::os::unix::net::UnixListener; use std::os::unix::net::UnixStream; use std::panic::AssertUnwindSafe; use std::path::PathBuf; +use std::rc::Rc; use std::sync::mpsc::{Receiver, RecvError, SendError, Sender}; use std::sync::{Arc, Mutex}; use std::time::Instant; @@ -347,9 +348,9 @@ pub fn start_vmm_thread( vmm.setup_signal_handler()?; vmm.control_loop( - Arc::new(api_receiver), + Rc::new(api_receiver), #[cfg(feature = "guest_debug")] - Arc::new(gdb_receiver), + Rc::new(gdb_receiver), ) }) .map_err(Error::VmmThreadSpawn)? @@ -1791,8 +1792,8 @@ impl Vmm { fn control_loop( &mut self, - api_receiver: Arc>, - #[cfg(feature = "guest_debug")] gdb_receiver: Arc>, + api_receiver: Rc>, + #[cfg(feature = "guest_debug")] gdb_receiver: Rc>, ) -> Result<()> { const EPOLL_EVENTS_LEN: usize = 100;