build: Fix beta clippy issue (arc_with_non_send_sync)

warning: usage of `Arc<T>` 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<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = 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 <liyu.yukiteru@bytedance.com>
(cherry picked from commit 63226e2b80)
This commit is contained in:
Yu Li 2023-07-12 12:43:58 +08:00 committed by Bo Chen
parent d08365a131
commit 2cd5b0b5e0
2 changed files with 6 additions and 5 deletions

View File

@ -333,7 +333,7 @@ impl VersionMapped for VsockState {}
impl<B> Vsock<B> impl<B> Vsock<B>
where where
B: VsockBackend, B: VsockBackend + Sync,
{ {
/// Create a new virtio-vsock device with the given VM CID and vsock /// Create a new virtio-vsock device with the given VM CID and vsock
/// backend. /// backend.

View File

@ -43,6 +43,7 @@ use std::os::unix::net::UnixListener;
use std::os::unix::net::UnixStream; use std::os::unix::net::UnixStream;
use std::panic::AssertUnwindSafe; use std::panic::AssertUnwindSafe;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc;
use std::sync::mpsc::{Receiver, RecvError, SendError, Sender}; use std::sync::mpsc::{Receiver, RecvError, SendError, Sender};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Instant; use std::time::Instant;
@ -318,9 +319,9 @@ pub fn start_vmm_thread(
vmm.setup_signal_handler()?; vmm.setup_signal_handler()?;
vmm.control_loop( vmm.control_loop(
Arc::new(api_receiver), Rc::new(api_receiver),
#[cfg(feature = "guest_debug")] #[cfg(feature = "guest_debug")]
Arc::new(gdb_receiver), Rc::new(gdb_receiver),
) )
}) })
.map_err(Error::VmmThreadSpawn)? .map_err(Error::VmmThreadSpawn)?
@ -1698,8 +1699,8 @@ impl Vmm {
fn control_loop( fn control_loop(
&mut self, &mut self,
api_receiver: Arc<Receiver<ApiRequest>>, api_receiver: Rc<Receiver<ApiRequest>>,
#[cfg(feature = "guest_debug")] gdb_receiver: Arc<Receiver<gdb::GdbRequest>>, #[cfg(feature = "guest_debug")] gdb_receiver: Rc<Receiver<gdb::GdbRequest>>,
) -> Result<()> { ) -> Result<()> {
const EPOLL_EVENTS_LEN: usize = 100; const EPOLL_EVENTS_LEN: usize = 100;