Skip to content

Commit 138400e

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 <[email protected]>
1 parent cfff91e commit 138400e

File tree

7 files changed

+182
-89
lines changed

7 files changed

+182
-89
lines changed

vhost-user-backend/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Added
66
### Changed
7+
- [[316]](https://github.com/rust-vmm/vhost/pull/316) Use mio to replace Epoll. Expose event_loop::EventSet.
8+
79
### Deprecated
810
### Fixed
911

vhost-user-backend/Cargo.toml

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

1515
[dependencies]
16+
bitflags = "2.9.1"
1617
libc = "0.2.39"
1718
log = "0.4.17"
19+
mio = { version = "1.0.4", features = ["os-poll", "os-ext"] }
1820
userfaultfd = { version = "0.8.1", optional = true }
1921
vhost = { path = "../vhost", version = "0.14.0", features = ["vhost-user-backend"] }
2022
virtio-bindings = { workspace = true }

vhost-user-backend/src/backend.rs

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

26+
use mio::Interest;
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;
@@ -144,7 +144,7 @@ pub trait VhostUserBackend: Send + Sync {
144144
fn handle_event(
145145
&self,
146146
device_event: u16,
147-
evset: EventSet,
147+
evset: Interest,
148148
vrings: &[Self::Vring],
149149
thread_id: usize,
150150
) -> Result<()>;
@@ -287,7 +287,7 @@ pub trait VhostUserBackendMut: Send + Sync {
287287
fn handle_event(
288288
&mut self,
289289
device_event: u16,
290-
evset: EventSet,
290+
evset: Interest,
291291
vrings: &[Self::Vring],
292292
thread_id: usize,
293293
) -> Result<()>;
@@ -389,7 +389,7 @@ impl<T: VhostUserBackend> VhostUserBackend for Arc<T> {
389389
fn handle_event(
390390
&self,
391391
device_event: u16,
392-
evset: EventSet,
392+
evset: Interest,
393393
vrings: &[Self::Vring],
394394
thread_id: usize,
395395
) -> Result<()> {
@@ -478,7 +478,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T> {
478478
fn handle_event(
479479
&self,
480480
device_event: u16,
481-
evset: EventSet,
481+
evset: Interest,
482482
vrings: &[Self::Vring],
483483
thread_id: usize,
484484
) -> Result<()> {
@@ -570,7 +570,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
570570
fn handle_event(
571571
&self,
572572
device_event: u16,
573-
evset: EventSet,
573+
evset: Interest,
574574
vrings: &[Self::Vring],
575575
thread_id: usize,
576576
) -> Result<()> {
@@ -600,6 +600,7 @@ pub mod tests {
600600
use super::*;
601601
use crate::VringRwLock;
602602
use libc::EFD_NONBLOCK;
603+
use mio::Interest;
603604
use std::sync::Mutex;
604605
use uuid::Uuid;
605606
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryMmap};
@@ -707,7 +708,7 @@ pub mod tests {
707708
fn handle_event(
708709
&mut self,
709710
_device_event: u16,
710-
_evset: EventSet,
711+
_evset: Interest,
711712
_vrings: &[VringRwLock],
712713
_thread_id: usize,
713714
) -> Result<()> {
@@ -793,7 +794,7 @@ pub mod tests {
793794

794795
let vring = VringRwLock::new(mem, 0x1000).unwrap();
795796
backend
796-
.handle_event(0x1, EventSet::IN, &[vring], 0)
797+
.handle_event(0x1, Interest::READABLE, &[vring], 0)
797798
.unwrap();
798799

799800
backend.reset_device();

0 commit comments

Comments
 (0)