Skip to content

Commit 2aa2517

Browse files
committed
Change device_event in handle_event() from u16 to usize
When register_event we pass in the value of u32/u64, so we don't need to convert it to u16 and then pass it to handle_event. Signed-off-by: Wenyu Huang <[email protected]>
1 parent 266854e commit 2aa2517

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

vhost-user-backend/src/backend.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

vhost-user-backend/src/event_loop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ where
184184
}
185185
};
186186

187-
let ev_type = event.data() as u16;
187+
let ev_type = event.data();
188188

189189
// handle_event() returns true if an event is received from the exit event fd.
190-
if self.handle_event(ev_type, evset)? {
190+
if self.handle_event(ev_type as usize, evset)? {
191191
break 'epoll;
192192
}
193193
}
@@ -196,13 +196,13 @@ where
196196
Ok(())
197197
}
198198

199-
fn handle_event(&self, device_event: u16, evset: EventSet) -> VringEpollResult<bool> {
200-
if self.exit_event_fd.is_some() && device_event as usize == self.backend.num_queues() {
199+
fn handle_event(&self, device_event: usize, evset: EventSet) -> VringEpollResult<bool> {
200+
if self.exit_event_fd.is_some() && device_event == self.backend.num_queues() {
201201
return Ok(true);
202202
}
203203

204-
if (device_event as usize) < self.vrings.len() {
205-
let vring = &self.vrings[device_event as usize];
204+
if device_event < self.vrings.len() {
205+
let vring = &self.vrings[device_event];
206206
let enabled = vring
207207
.read_kick()
208208
.map_err(VringEpollError::HandleEventReadKick)?;

vhost-user-backend/tests/vhost-user-server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl VhostUserBackendMut for MockVhostBackend {
117117

118118
fn handle_event(
119119
&mut self,
120-
_device_event: u16,
120+
_device_event: usize,
121121
_evset: EventSet,
122122
_vrings: &[VringRwLock],
123123
_thread_id: usize,

0 commit comments

Comments
 (0)