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>
This commit is contained in:
Yu Li 2023-07-12 12:43:58 +08:00 committed by Bo Chen
parent d0dbc7fb4d
commit 63226e2b80
2 changed files with 6 additions and 5 deletions

View File

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

View File

@ -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<Receiver<ApiRequest>>,
#[cfg(feature = "guest_debug")] gdb_receiver: Arc<Receiver<gdb::GdbRequest>>,
api_receiver: Rc<Receiver<ApiRequest>>,
#[cfg(feature = "guest_debug")] gdb_receiver: Rc<Receiver<gdb::GdbRequest>>,
) -> Result<()> {
const EPOLL_EVENTS_LEN: usize = 100;