Skip to content

Commit d91521f

Browse files
committed
Use mio to replace Epoll
Epoll is linux-specific. So we use mio, which is a cross-platform event notification, to replace Epoll. Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
1 parent eae4f73 commit d91521f

File tree

6 files changed

+180
-77
lines changed

6 files changed

+180
-77
lines changed

vhost-user-backend/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ xen = ["vm-memory/xen", "vhost/xen"]
1313
postcopy = ["vhost/postcopy", "userfaultfd"]
1414

1515
[dependencies]
16+
bitflags = "2.9.1"
17+
dashmap = "6.1.0"
1618
libc = "0.2.39"
1719
log = "0.4.17"
20+
mio = { version = "1.0.4", features = ["os-poll", "os-ext"] }
1821
userfaultfd = { version = "0.8.1", optional = true }
1922
vhost = { path = "../vhost", version = "0.14.0", features = ["vhost-user-backend"] }
2023
virtio-bindings = { workspace = true }

vhost-user-backend/src/backend.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ use std::io::Result;
2323
use std::ops::Deref;
2424
use std::sync::{Arc, Mutex, RwLock};
2525

26+
use mio::event::Event;
2627
use vhost::vhost_user::message::{
2728
VhostTransferStateDirection, VhostTransferStatePhase, VhostUserProtocolFeatures,
2829
VhostUserSharedMsg,
2930
};
3031
use vhost::vhost_user::Backend;
3132
use vm_memory::bitmap::Bitmap;
32-
use vmm_sys_util::epoll::EventSet;
3333
use vmm_sys_util::eventfd::EventFd;
3434

3535
use vhost::vhost_user::GpuBackend;
3636

37+
use crate::event_loop::VringEventSet;
38+
3739
use super::vring::VringT;
3840
use super::GM;
3941

@@ -144,7 +146,7 @@ pub trait VhostUserBackend: Send + Sync {
144146
fn handle_event(
145147
&self,
146148
device_event: u16,
147-
evset: EventSet,
149+
evset: VringEventSet,
148150
vrings: &[Self::Vring],
149151
thread_id: usize,
150152
) -> Result<()>;
@@ -287,7 +289,7 @@ pub trait VhostUserBackendMut: Send + Sync {
287289
fn handle_event(
288290
&mut self,
289291
device_event: u16,
290-
evset: EventSet,
292+
evset: VringEventSet,
291293
vrings: &[Self::Vring],
292294
thread_id: usize,
293295
) -> Result<()>;
@@ -389,7 +391,7 @@ impl<T: VhostUserBackend> VhostUserBackend for Arc<T> {
389391
fn handle_event(
390392
&self,
391393
device_event: u16,
392-
evset: EventSet,
394+
evset: VringEventSet,
393395
vrings: &[Self::Vring],
394396
thread_id: usize,
395397
) -> Result<()> {
@@ -478,7 +480,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T> {
478480
fn handle_event(
479481
&self,
480482
device_event: u16,
481-
evset: EventSet,
483+
evset: VringEventSet,
482484
vrings: &[Self::Vring],
483485
thread_id: usize,
484486
) -> Result<()> {
@@ -570,7 +572,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
570572
fn handle_event(
571573
&self,
572574
device_event: u16,
573-
evset: EventSet,
575+
evset: VringEventSet,
574576
vrings: &[Self::Vring],
575577
thread_id: usize,
576578
) -> Result<()> {
@@ -600,6 +602,7 @@ pub mod tests {
600602
use super::*;
601603
use crate::VringRwLock;
602604
use libc::EFD_NONBLOCK;
605+
use mio::Interest;
603606
use std::sync::Mutex;
604607
use uuid::Uuid;
605608
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryMmap};
@@ -707,7 +710,7 @@ pub mod tests {
707710
fn handle_event(
708711
&mut self,
709712
_device_event: u16,
710-
_evset: EventSet,
713+
_evset: VringEventSet,
711714
_vrings: &[VringRwLock],
712715
_thread_id: usize,
713716
) -> Result<()> {
@@ -793,7 +796,7 @@ pub mod tests {
793796

794797
let vring = VringRwLock::new(mem, 0x1000).unwrap();
795798
backend
796-
.handle_event(0x1, EventSet::IN, &[vring], 0)
799+
.handle_event(0x1, (&Interest::READABLE).into(), &[vring], 0)
797800
.unwrap();
798801

799802
backend.reset_device();

0 commit comments

Comments
 (0)