From 56f03db69c458e036adeba3a34bd1f5498d2762d Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 3 Sep 2020 16:39:13 +0100 Subject: [PATCH] virtio-devices: net: Simplify activate function Move the if-let for the taps later which makes the earlier activation code identical to other devices. Signed-off-by: Rob Bradford --- virtio-devices/src/net.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/virtio-devices/src/net.rs b/virtio-devices/src/net.rs index d2265412c..9969014e9 100644 --- a/virtio-devices/src/net.rs +++ b/virtio-devices/src/net.rs @@ -388,22 +388,21 @@ impl VirtioDevice for Net { })?; self.pause_evt = Some(self_pause_evt); - if let Some(mut taps) = self.taps.clone() { - // Save the interrupt EventFD as we need to return it on reset + // Save the interrupt EventFD as we need to return it on reset + // but clone it to pass into the thread. + self.interrupt_cb = Some(interrupt_cb.clone()); + let mut tmp_queue_evts: Vec = Vec::new(); + for queue_evt in queue_evts.iter() { + // Save the queue EventFD as we need to return it on reset // but clone it to pass into the thread. - self.interrupt_cb = Some(interrupt_cb.clone()); - - let mut tmp_queue_evts: Vec = Vec::new(); - for queue_evt in queue_evts.iter() { - // Save the queue EventFD as we need to return it on reset - // but clone it to pass into the thread. - tmp_queue_evts.push(queue_evt.try_clone().map_err(|e| { - error!("failed to clone queue EventFd: {}", e); - ActivateError::BadActivate - })?); - } - self.queue_evts = Some(tmp_queue_evts); + tmp_queue_evts.push(queue_evt.try_clone().map_err(|e| { + error!("failed to clone queue EventFd: {}", e); + ActivateError::BadActivate + })?); + } + self.queue_evts = Some(tmp_queue_evts); + if let Some(mut taps) = self.taps.clone() { let queue_num = queues.len(); if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && queue_num % 2 != 0 { let cvq_queue = queues.remove(queue_num - 1);