misc: clippy: add needless_pass_by_value

This is a follow-up of [0].

# Advantages

- This saves dozens of unneeded clone()s across the whole code base
- Makes it much easier to reason about how parameters are used
  (often we passed owned Arc/Rc versions without actually needing
  ownership)

# Exceptions

For certain code paths, the alternatives would require awkward or overly
complex code, and in some cases the functions are the logical owners of
the values they take. In those cases, I've added
#[allow(clippy::needless_pass_by_value)].

This does not mean that one should not improve this in the future.

[0] 6a86c157af

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-11-26 14:00:44 +01:00
committed by Rob Bradford
parent ed4af3a005
commit c53781bf5f
53 changed files with 273 additions and 231 deletions

View File

@@ -297,7 +297,7 @@ impl VirtioDevice for Blk {
let mut handler = self.vu_common.activate(
mem,
queues,
&queues,
interrupt_cb,
self.common.acked_features,
backend_req_handler,
@@ -316,7 +316,7 @@ impl VirtioDevice for Blk {
Thread::VirtioVhostBlock,
&mut epoll_threads,
&self.exit_evt,
move || handler.run(paused, paused_sync.unwrap()),
move || handler.run(&paused, paused_sync.as_ref().unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@@ -277,7 +277,7 @@ impl VirtioDevice for Fs {
let mut handler = self.vu_common.activate(
mem,
queues,
&queues,
interrupt_cb,
self.common.acked_features,
backend_req_handler,
@@ -295,7 +295,7 @@ impl VirtioDevice for Fs {
Thread::VirtioVhostFs,
&mut epoll_threads,
&self.exit_evt,
move || handler.run(paused, paused_sync.unwrap()),
move || handler.run(&paused, paused_sync.as_ref().unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@@ -183,8 +183,8 @@ pub struct VhostUserEpollHandler<S: VhostUserFrontendReqHandler> {
impl<S: VhostUserFrontendReqHandler> VhostUserEpollHandler<S> {
pub fn run(
&mut self,
paused: Arc<AtomicBool>,
paused_sync: Arc<Barrier>,
paused: &AtomicBool,
paused_sync: &Barrier,
) -> std::result::Result<(), EpollHelperError> {
let mut helper = EpollHelper::new(&self.kill_evt, &self.pause_evt)?;
helper.add_event_custom(
@@ -221,14 +221,16 @@ impl<S: VhostUserFrontendReqHandler> VhostUserEpollHandler<S> {
)))
})?;
let queues = self
.queues
.iter()
.map(|(i, q, e)| (*i, vm_virtio::clone_queue(q), e.try_clone().unwrap()))
.collect::<Vec<_>>();
// Initialize the backend
vhost_user
.reinitialize_vhost_user(
self.mem.memory().deref(),
self.queues
.iter()
.map(|(i, q, e)| (*i, vm_virtio::clone_queue(q), e.try_clone().unwrap()))
.collect(),
&queues,
self.virtio_interrupt.as_ref(),
self.acked_features,
self.acked_protocol_features,
@@ -305,7 +307,7 @@ impl VhostUserCommon {
pub fn activate<T: VhostUserFrontendReqHandler>(
&mut self,
mem: GuestMemoryAtomic<GuestMemoryMmap>,
queues: Vec<(usize, Queue, EventFd)>,
queues: &[(usize, Queue, EventFd)],
interrupt_cb: Arc<dyn VirtioInterrupt>,
acked_features: u64,
backend_req_handler: Option<FrontendReqHandler<T>>,
@@ -325,14 +327,15 @@ impl VhostUserCommon {
return Err(ActivateError::BadActivate);
}
let vu = self.vu.as_ref().unwrap();
let queues = queues
.iter()
.map(|(i, q, e)| (*i, vm_virtio::clone_queue(q), e.try_clone().unwrap()))
.collect::<Vec<_>>();
vu.lock()
.unwrap()
.setup_vhost_user(
&mem.memory(),
queues
.iter()
.map(|(i, q, e)| (*i, vm_virtio::clone_queue(q), e.try_clone().unwrap()))
.collect(),
&queues,
interrupt_cb.as_ref(),
acked_features,
&backend_req_handler,

View File

@@ -336,7 +336,7 @@ impl VirtioDevice for Net {
Thread::VirtioVhostNetCtl,
&mut epoll_threads,
&self.exit_evt,
move || ctrl_handler.run_ctrl(paused, paused_sync.unwrap()),
move || ctrl_handler.run_ctrl(&paused, paused_sync.as_ref().unwrap()),
)?;
self.ctrl_queue_epoll_thread = Some(epoll_threads.remove(0));
}
@@ -353,7 +353,7 @@ impl VirtioDevice for Net {
let mut handler = self.vu_common.activate(
mem,
queues,
&queues,
interrupt_cb,
backend_acked_features,
backend_req_handler,
@@ -371,7 +371,7 @@ impl VirtioDevice for Net {
Thread::VirtioVhostNet,
&mut epoll_threads,
&self.exit_evt,
move || handler.run(paused, paused_sync.unwrap()),
move || handler.run(&paused, paused_sync.as_ref().unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@@ -156,7 +156,7 @@ impl VhostUserHandle {
pub fn setup_vhost_user<S: VhostUserFrontendReqHandler>(
&mut self,
mem: &GuestMemoryMmap,
queues: Vec<(usize, Queue, EventFd)>,
queues: &[(usize, Queue, EventFd)],
virtio_interrupt: &dyn VirtioInterrupt,
acked_features: u64,
backend_req_handler: &Option<FrontendReqHandler<S>>,
@@ -340,7 +340,7 @@ impl VhostUserHandle {
pub fn reinitialize_vhost_user<S: VhostUserFrontendReqHandler>(
&mut self,
mem: &GuestMemoryMmap,
queues: Vec<(usize, Queue, EventFd)>,
queues: &[(usize, Queue, EventFd)],
virtio_interrupt: &dyn VirtioInterrupt,
acked_features: u64,
acked_protocol_features: u64,