mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-10 14:47:42 +00:00
virtio-devices: Add helper to VirtioCommon for EventFd duplication
Add a helper to VirtioCommon which returns duplicates of the EventFds for kill and pause event. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
df92495e31
commit
280bef834b
@ -404,26 +404,7 @@ impl VirtioDevice for Balloon {
|
|||||||
mut queue_evts: Vec<EventFd>,
|
mut queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut handler = BalloonEpollHandler {
|
let mut handler = BalloonEpollHandler {
|
||||||
config: self.config.clone(),
|
config: self.config.clone(),
|
||||||
|
@ -554,26 +554,7 @@ impl VirtioDevice for Block {
|
|||||||
let queue_evt = queue_evts.remove(0);
|
let queue_evt = queue_evts.remove(0);
|
||||||
let queue = queues.remove(0);
|
let queue = queues.remove(0);
|
||||||
let queue_size = queue.size;
|
let queue_size = queue.size;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let rate_limiter: Option<RateLimiter> = self
|
let rate_limiter: Option<RateLimiter> = self
|
||||||
.rate_limiter_config
|
.rate_limiter_config
|
||||||
|
@ -402,26 +402,7 @@ impl VirtioDevice for Console {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut handler = ConsoleEpollHandler {
|
let mut handler = ConsoleEpollHandler {
|
||||||
queues,
|
queues,
|
||||||
|
@ -319,6 +319,13 @@ impl VirtioCommon {
|
|||||||
// Return the interrupt
|
// Return the interrupt
|
||||||
Some(self.interrupt_cb.take().unwrap())
|
Some(self.interrupt_cb.take().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dup_eventfds(&self) -> (EventFd, EventFd) {
|
||||||
|
(
|
||||||
|
self.kill_evt.as_ref().unwrap().try_clone().unwrap(),
|
||||||
|
self.pause_evt.as_ref().unwrap().try_clone().unwrap(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pausable for VirtioCommon {
|
impl Pausable for VirtioCommon {
|
||||||
|
@ -911,26 +911,7 @@ impl VirtioDevice for Iommu {
|
|||||||
queue_evts: Vec<EventFd>,
|
queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let mut handler = IommuEpollHandler {
|
let mut handler = IommuEpollHandler {
|
||||||
queues,
|
queues,
|
||||||
mem,
|
mem,
|
||||||
|
@ -926,27 +926,7 @@ impl VirtioDevice for Mem {
|
|||||||
mut queue_evts: Vec<EventFd>,
|
mut queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let config = self.config.lock().unwrap();
|
let config = self.config.lock().unwrap();
|
||||||
let mut handler = MemEpollHandler {
|
let mut handler = MemEpollHandler {
|
||||||
host_addr: self.host_addr,
|
host_addr: self.host_addr,
|
||||||
|
@ -544,27 +544,7 @@ impl VirtioDevice for Net {
|
|||||||
let cvq_queue = queues.remove(queue_num - 1);
|
let cvq_queue = queues.remove(queue_num - 1);
|
||||||
let cvq_queue_evt = queue_evts.remove(queue_num - 1);
|
let cvq_queue_evt = queue_evts.remove(queue_num - 1);
|
||||||
|
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut ctrl_handler = NetCtrlEpollHandler {
|
let mut ctrl_handler = NetCtrlEpollHandler {
|
||||||
mem: mem.clone(),
|
mem: mem.clone(),
|
||||||
kill_evt,
|
kill_evt,
|
||||||
@ -616,26 +596,7 @@ impl VirtioDevice for Net {
|
|||||||
|
|
||||||
let queue_evt_pair = vec![queue_evts.remove(0), queue_evts.remove(0)];
|
let queue_evt_pair = vec![queue_evts.remove(0), queue_evts.remove(0)];
|
||||||
|
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let rx_rate_limiter: Option<rate_limiter::RateLimiter> = self
|
let rx_rate_limiter: Option<rate_limiter::RateLimiter> = self
|
||||||
.rate_limiter_config
|
.rate_limiter_config
|
||||||
|
@ -370,26 +370,7 @@ impl VirtioDevice for Pmem {
|
|||||||
mut queue_evts: Vec<EventFd>,
|
mut queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
if let Some(disk) = self.disk.as_ref() {
|
if let Some(disk) = self.disk.as_ref() {
|
||||||
let disk = disk.try_clone().map_err(|e| {
|
let disk = disk.try_clone().map_err(|e| {
|
||||||
error!("failed cloning pmem disk: {}", e);
|
error!("failed cloning pmem disk: {}", e);
|
||||||
|
@ -215,26 +215,7 @@ impl VirtioDevice for Rng {
|
|||||||
mut queue_evts: Vec<EventFd>,
|
mut queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if let Some(file) = self.random_file.as_ref() {
|
if let Some(file) = self.random_file.as_ref() {
|
||||||
let random_file = file.try_clone().map_err(|e| {
|
let random_file = file.try_clone().map_err(|e| {
|
||||||
|
@ -410,30 +410,9 @@ impl VirtioDevice for Fs {
|
|||||||
queue_evts: Vec<EventFd>,
|
queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
self.guest_memory = Some(mem.clone());
|
self.guest_memory = Some(mem.clone());
|
||||||
|
|
||||||
let kill_evt = self
|
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
setup_vhost_user(
|
setup_vhost_user(
|
||||||
&mut self.vu,
|
&mut self.vu,
|
||||||
&mem.memory(),
|
&mem.memory(),
|
||||||
|
@ -246,26 +246,7 @@ impl VirtioDevice for Net {
|
|||||||
let cvq_queue = queues.remove(num_queues - 1);
|
let cvq_queue = queues.remove(num_queues - 1);
|
||||||
let cvq_queue_evt = queue_evts.remove(num_queues - 1);
|
let cvq_queue_evt = queue_evts.remove(num_queues - 1);
|
||||||
|
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut ctrl_handler = NetCtrlEpollHandler {
|
let mut ctrl_handler = NetCtrlEpollHandler {
|
||||||
mem: mem.clone(),
|
mem: mem.clone(),
|
||||||
@ -322,26 +303,7 @@ impl VirtioDevice for Net {
|
|||||||
|
|
||||||
// Run a dedicated thread for handling potential reconnections with
|
// Run a dedicated thread for handling potential reconnections with
|
||||||
// the backend.
|
// the backend.
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut reconnect_handler = ReconnectEpollHandler {
|
let mut reconnect_handler = ReconnectEpollHandler {
|
||||||
vu: self.vhost_user_net.clone(),
|
vu: self.vhost_user_net.clone(),
|
||||||
|
@ -418,26 +418,7 @@ where
|
|||||||
queue_evts: Vec<EventFd>,
|
queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut handler = VsockEpollHandler {
|
let mut handler = VsockEpollHandler {
|
||||||
mem,
|
mem,
|
||||||
|
@ -290,26 +290,7 @@ impl VirtioDevice for Watchdog {
|
|||||||
mut queue_evts: Vec<EventFd>,
|
mut queue_evts: Vec<EventFd>,
|
||||||
) -> ActivateResult {
|
) -> ActivateResult {
|
||||||
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
||||||
let kill_evt = self
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
||||||
.common
|
|
||||||
.kill_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("Failed to clone kill_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
let pause_evt = self
|
|
||||||
.common
|
|
||||||
.pause_evt
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.try_clone()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("Failed to clone pause_evt eventfd: {}", e);
|
|
||||||
ActivateError::BadActivate
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let reset_evt = self.reset_evt.try_clone().map_err(|e| {
|
let reset_evt = self.reset_evt.try_clone().map_err(|e| {
|
||||||
error!("Failed to clone reset_evt eventfd: {}", e);
|
error!("Failed to clone reset_evt eventfd: {}", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user