Skip to content

Commit 158ca1d

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 18bf2a5 commit 158ca1d

File tree

7 files changed

+149
-99
lines changed

7 files changed

+149
-99
lines changed

vhost-user-backend/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66
### Changed
77
- [[#308](https://github.com/rust-vmm/vhost/pull/308)] Replace Eventfd with EventNotifier/EventConsumer.
8+
- [[316]](https://github.com/rust-vmm/vhost/pull/316) Use mio to replace Epoll. Expose event_loop::EventSet.
89

910
### Deprecated
1011
### Fixed

vhost-user-backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ postcopy = ["vhost/postcopy", "userfaultfd"]
1515
[dependencies]
1616
libc = "0.2.39"
1717
log = "0.4.17"
18+
mio = { version = "1.0.4", features = ["os-poll", "os-ext"] }
1819
userfaultfd = { version = "0.8.1", optional = true }
1920
vhost = { path = "../vhost", version = "0.14.0", features = ["vhost-user-backend"] }
2021
virtio-bindings = { workspace = true }

vhost-user-backend/src/backend.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ use vhost::vhost_user::message::{
2929
};
3030
use vhost::vhost_user::Backend;
3131
use vm_memory::bitmap::Bitmap;
32-
use vmm_sys_util::epoll::EventSet;
3332
use vmm_sys_util::event::{EventConsumer, EventNotifier};
3433

3534
use vhost::vhost_user::GpuBackend;
3635

3736
use super::vring::VringT;
3837
use super::GM;
3938

39+
use crate::EventSet;
40+
4041
/// Trait with interior mutability for vhost user backend servers to implement concrete services.
4142
///
4243
/// To support multi-threading and asynchronous IO, we enforce `Send + Sync` bound.
@@ -144,7 +145,7 @@ pub trait VhostUserBackend: Send + Sync {
144145
/// do with events happening on custom listeners.
145146
fn handle_event(
146147
&self,
147-
device_event: u16,
148+
device_event: usize,
148149
evset: EventSet,
149150
vrings: &[Self::Vring],
150151
thread_id: usize,
@@ -288,7 +289,7 @@ pub trait VhostUserBackendMut: Send + Sync {
288289
/// do with events happening on custom listeners.
289290
fn handle_event(
290291
&mut self,
291-
device_event: u16,
292+
device_event: usize,
292293
evset: EventSet,
293294
vrings: &[Self::Vring],
294295
thread_id: usize,
@@ -390,7 +391,7 @@ impl<T: VhostUserBackend> VhostUserBackend for Arc<T> {
390391

391392
fn handle_event(
392393
&self,
393-
device_event: u16,
394+
device_event: usize,
394395
evset: EventSet,
395396
vrings: &[Self::Vring],
396397
thread_id: usize,
@@ -479,7 +480,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T> {
479480

480481
fn handle_event(
481482
&self,
482-
device_event: u16,
483+
device_event: usize,
483484
evset: EventSet,
484485
vrings: &[Self::Vring],
485486
thread_id: usize,
@@ -571,7 +572,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
571572

572573
fn handle_event(
573574
&self,
574-
device_event: u16,
575+
device_event: usize,
575576
evset: EventSet,
576577
vrings: &[Self::Vring],
577578
thread_id: usize,
@@ -711,7 +712,7 @@ pub mod tests {
711712

712713
fn handle_event(
713714
&mut self,
714-
_device_event: u16,
715+
_device_event: usize,
715716
_evset: EventSet,
716717
_vrings: &[VringRwLock],
717718
_thread_id: usize,
@@ -798,7 +799,7 @@ pub mod tests {
798799

799800
let vring = VringRwLock::new(mem, 0x1000).unwrap();
800801
backend
801-
.handle_event(0x1, EventSet::IN, &[vring], 0)
802+
.handle_event(0x1, EventSet::Readable, &[vring], 0)
802803
.unwrap();
803804

804805
backend.reset_device();

0 commit comments

Comments
 (0)