Skip to content

Commit 3e6ba3c

Browse files
Erik Schillingstefano-garzarella
authored andcommitted
vhost-user-backend: de-duplicate match branches
No need to repeat the struct definition here. The only purpose is to register an event_fd at epoll if one exists. Signed-off-by: Erik Schilling <[email protected]>
1 parent 3cbdcea commit 3e6ba3c

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

crates/vhost-user-backend/src/event_loop.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,27 @@ where
8585
/// Create a `VringEpollHandler` instance.
8686
pub(crate) fn new(backend: S, vrings: Vec<V>, thread_id: usize) -> VringEpollResult<Self> {
8787
let epoll = Epoll::new().map_err(VringEpollError::EpollCreateFd)?;
88+
let exit_event_fd = backend.exit_event(thread_id);
89+
90+
if let Some(exit_event_fd) = &exit_event_fd {
91+
let id = backend.num_queues();
92+
epoll
93+
.ctl(
94+
ControlOperation::Add,
95+
exit_event_fd.as_raw_fd(),
96+
EpollEvent::new(EventSet::IN, id as u64),
97+
)
98+
.map_err(VringEpollError::RegisterExitEvent)?;
99+
}
88100

89-
let handler = match backend.exit_event(thread_id) {
90-
Some(exit_event_fd) => {
91-
let id = backend.num_queues();
92-
epoll
93-
.ctl(
94-
ControlOperation::Add,
95-
exit_event_fd.as_raw_fd(),
96-
EpollEvent::new(EventSet::IN, id as u64),
97-
)
98-
.map_err(VringEpollError::RegisterExitEvent)?;
99-
100-
VringEpollHandler {
101-
epoll,
102-
backend,
103-
vrings,
104-
thread_id,
105-
exit_event_fd: Some(exit_event_fd),
106-
phantom: PhantomData,
107-
}
108-
}
109-
None => VringEpollHandler {
110-
epoll,
111-
backend,
112-
vrings,
113-
thread_id,
114-
exit_event_fd: None,
115-
phantom: PhantomData,
116-
},
117-
};
118-
119-
Ok(handler)
101+
Ok(VringEpollHandler {
102+
epoll,
103+
backend,
104+
vrings,
105+
thread_id,
106+
exit_event_fd,
107+
phantom: PhantomData,
108+
})
120109
}
121110

122111
/// Register an event into the epoll fd.

0 commit comments

Comments
 (0)