Skip to content

Commit be19e30

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 be19e30

File tree

7 files changed

+150
-101
lines changed

7 files changed

+150
-101
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ 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

35-
use vhost::vhost_user::GpuBackend;
36-
3734
use super::vring::VringT;
3835
use super::GM;
36+
use vhost::vhost_user::GpuBackend;
37+
38+
use crate::EventSet;
3939

4040
/// Trait with interior mutability for vhost user backend servers to implement concrete services.
4141
///
@@ -144,7 +144,7 @@ pub trait VhostUserBackend: Send + Sync {
144144
/// do with events happening on custom listeners.
145145
fn handle_event(
146146
&self,
147-
device_event: u16,
147+
device_event: usize,
148148
evset: EventSet,
149149
vrings: &[Self::Vring],
150150
thread_id: usize,
@@ -288,7 +288,7 @@ pub trait VhostUserBackendMut: Send + Sync {
288288
/// do with events happening on custom listeners.
289289
fn handle_event(
290290
&mut self,
291-
device_event: u16,
291+
device_event: usize,
292292
evset: EventSet,
293293
vrings: &[Self::Vring],
294294
thread_id: usize,
@@ -390,7 +390,7 @@ impl<T: VhostUserBackend> VhostUserBackend for Arc<T> {
390390

391391
fn handle_event(
392392
&self,
393-
device_event: u16,
393+
device_event: usize,
394394
evset: EventSet,
395395
vrings: &[Self::Vring],
396396
thread_id: usize,
@@ -479,7 +479,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T> {
479479

480480
fn handle_event(
481481
&self,
482-
device_event: u16,
482+
device_event: usize,
483483
evset: EventSet,
484484
vrings: &[Self::Vring],
485485
thread_id: usize,
@@ -571,7 +571,7 @@ impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
571571

572572
fn handle_event(
573573
&self,
574-
device_event: u16,
574+
device_event: usize,
575575
evset: EventSet,
576576
vrings: &[Self::Vring],
577577
thread_id: usize,
@@ -711,7 +711,7 @@ pub mod tests {
711711

712712
fn handle_event(
713713
&mut self,
714-
_device_event: u16,
714+
_device_event: usize,
715715
_evset: EventSet,
716716
_vrings: &[VringRwLock],
717717
_thread_id: usize,
@@ -798,7 +798,7 @@ pub mod tests {
798798

799799
let vring = VringRwLock::new(mem, 0x1000).unwrap();
800800
backend
801-
.handle_event(0x1, EventSet::IN, &[vring], 0)
801+
.handle_event(0x1, EventSet::Readable, &[vring], 0)
802802
.unwrap();
803803

804804
backend.reset_device();

0 commit comments

Comments
 (0)