mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-21 23:41:15 +00:00
virtio-devices: Make EpollHandler more generic
Instead of passing only the event type through the handle_event() callback, we make the trait slightly more generic by providing the epoll event to each virtio device implementation. This is particularly useful for vsock as it will need the event set. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
1e0b516a84
commit
01e7bd7276
@ -241,8 +241,9 @@ impl BalloonEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for BalloonEpollHandler {
|
impl EpollHelperHandler for BalloonEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
RESIZE_EVENT => {
|
RESIZE_EVENT => {
|
||||||
if let Err(e) = self.resize_receiver.evt.read() {
|
if let Err(e) = self.resize_receiver.evt.read() {
|
||||||
error!("Failed to get resize event: {:?}", e);
|
error!("Failed to get resize event: {:?}", e);
|
||||||
@ -275,7 +276,7 @@ impl EpollHelperHandler for BalloonEpollHandler {
|
|||||||
if let Err(e) = self.inflate_queue_evt.read() {
|
if let Err(e) = self.inflate_queue_evt.read() {
|
||||||
error!("Failed to get inflate queue event: {:?}", e);
|
error!("Failed to get inflate queue event: {:?}", e);
|
||||||
return true;
|
return true;
|
||||||
} else if let Err(e) = self.process_queue(event) {
|
} else if let Err(e) = self.process_queue(ev_type) {
|
||||||
error!("Failed to signal used inflate queue: {:?}", e);
|
error!("Failed to signal used inflate queue: {:?}", e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -284,7 +285,7 @@ impl EpollHelperHandler for BalloonEpollHandler {
|
|||||||
if let Err(e) = self.deflate_queue_evt.read() {
|
if let Err(e) = self.deflate_queue_evt.read() {
|
||||||
error!("Failed to get deflate queue event: {:?}", e);
|
error!("Failed to get deflate queue event: {:?}", e);
|
||||||
return true;
|
return true;
|
||||||
} else if let Err(e) = self.process_queue(event) {
|
} else if let Err(e) = self.process_queue(ev_type) {
|
||||||
error!("Failed to signal used deflate queue: {:?}", e);
|
error!("Failed to signal used deflate queue: {:?}", e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,9 @@ impl<T: DiskFile> BlockEpollHandler<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: DiskFile> EpollHelperHandler for BlockEpollHandler<T> {
|
impl<T: DiskFile> EpollHelperHandler for BlockEpollHandler<T> {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
QUEUE_AVAIL_EVENT => {
|
QUEUE_AVAIL_EVENT => {
|
||||||
if let Err(e) = self.queue_evt.read() {
|
if let Err(e) = self.queue_evt.read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
@ -244,7 +245,7 @@ impl<T: DiskFile> EpollHelperHandler for BlockEpollHandler<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,8 +240,9 @@ impl BlockIoUringEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for BlockIoUringEpollHandler {
|
impl EpollHelperHandler for BlockIoUringEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
QUEUE_AVAIL_EVENT => {
|
QUEUE_AVAIL_EVENT => {
|
||||||
if let Err(e) = self.queue_evt.read() {
|
if let Err(e) = self.queue_evt.read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
@ -285,7 +286,7 @@ impl EpollHelperHandler for BlockIoUringEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,8 +193,9 @@ impl ConsoleEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for ConsoleEpollHandler {
|
impl EpollHelperHandler for ConsoleEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
INPUT_QUEUE_EVENT => {
|
INPUT_QUEUE_EVENT => {
|
||||||
if let Err(e) = self.input_queue_evt.read() {
|
if let Err(e) = self.input_queue_evt.read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
|
@ -33,7 +33,7 @@ pub const EPOLL_HELPER_EVENT_LAST: u16 = 15;
|
|||||||
|
|
||||||
pub trait EpollHelperHandler {
|
pub trait EpollHelperHandler {
|
||||||
// Return true if execution of the loop should be stopped
|
// Return true if execution of the loop should be stopped
|
||||||
fn handle_event(&mut self, helper: &mut EpollHelper, event: u16) -> bool;
|
fn handle_event(&mut self, helper: &mut EpollHelper, event: &epoll::Event) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelper {
|
impl EpollHelper {
|
||||||
@ -122,8 +122,8 @@ impl EpollHelper {
|
|||||||
// and every thread related to this virtio device.
|
// and every thread related to this virtio device.
|
||||||
let _ = self.pause_evt.read();
|
let _ = self.pause_evt.read();
|
||||||
}
|
}
|
||||||
id => {
|
_ => {
|
||||||
if handler.handle_event(self, id) {
|
if handler.handle_event(self, event) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -657,8 +657,9 @@ impl IommuEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for IommuEpollHandler {
|
impl EpollHelperHandler for IommuEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
REQUEST_Q_EVENT => {
|
REQUEST_Q_EVENT => {
|
||||||
if let Err(e) = self.queue_evts[0].read() {
|
if let Err(e) = self.queue_evts[0].read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
@ -682,7 +683,7 @@ impl EpollHelperHandler for IommuEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,8 +600,9 @@ impl MemEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for MemEpollHandler {
|
impl EpollHelperHandler for MemEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
RESIZE_EVENT => {
|
RESIZE_EVENT => {
|
||||||
if let Err(e) = self.resize.evt.read() {
|
if let Err(e) = self.resize.evt.read() {
|
||||||
error!("Failed to get resize event: {:?}", e);
|
error!("Failed to get resize event: {:?}", e);
|
||||||
@ -663,7 +664,7 @@ impl EpollHelperHandler for MemEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,9 @@ impl NetEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for NetEpollHandler {
|
impl EpollHelperHandler for NetEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
RX_QUEUE_EVENT => {
|
RX_QUEUE_EVENT => {
|
||||||
self.driver_awake = true;
|
self.driver_awake = true;
|
||||||
if let Err(e) = self.handle_rx_event() {
|
if let Err(e) = self.handle_rx_event() {
|
||||||
@ -183,7 +184,7 @@ impl EpollHelperHandler for NetEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unknown event: {}", event);
|
error!("Unknown event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,8 +253,9 @@ impl PmemEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for PmemEpollHandler {
|
impl EpollHelperHandler for PmemEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
QUEUE_AVAIL_EVENT => {
|
QUEUE_AVAIL_EVENT => {
|
||||||
if let Err(e) = self.queue_evt.read() {
|
if let Err(e) = self.queue_evt.read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
@ -267,7 +268,7 @@ impl EpollHelperHandler for PmemEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,9 @@ impl RngEpollHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EpollHelperHandler for RngEpollHandler {
|
impl EpollHelperHandler for RngEpollHandler {
|
||||||
fn handle_event(&mut self, _helper: &mut EpollHelper, event: u16) -> bool {
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
||||||
match event {
|
let ev_type = event.data as u16;
|
||||||
|
match ev_type {
|
||||||
QUEUE_AVAIL_EVENT => {
|
QUEUE_AVAIL_EVENT => {
|
||||||
if let Err(e) = self.queue_evt.read() {
|
if let Err(e) = self.queue_evt.read() {
|
||||||
error!("Failed to get queue event: {:?}", e);
|
error!("Failed to get queue event: {:?}", e);
|
||||||
@ -112,7 +113,7 @@ impl EpollHelperHandler for RngEpollHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Unexpected event: {}", event);
|
error!("Unexpected event: {}", ev_type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user