mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 04:25:21 +00:00
virtio-devices: block: Refactor 'handle_event' for readability
Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
0b15e378c7
commit
b4fe41ad0c
@ -295,24 +295,21 @@ impl EpollHelperHandler for BlockEpollHandler {
|
|||||||
|
|
||||||
// Process the queue only when the rate limit is not reached
|
// Process the queue only when the rate limit is not reached
|
||||||
if !rate_limit_reached {
|
if !rate_limit_reached {
|
||||||
match self.process_queue_submit() {
|
let needs_notification = self.process_queue_submit().map_err(|e| {
|
||||||
Ok(needs_notification) => {
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
if needs_notification {
|
"Failed to process queue (submit): {:?}",
|
||||||
if let Err(e) = self.signal_used_queue() {
|
e
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
))
|
||||||
"Failed to signal used queue: {:?}",
|
})?;
|
||||||
e
|
|
||||||
)));
|
if needs_notification {
|
||||||
}
|
self.signal_used_queue().map_err(|e| {
|
||||||
}
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
}
|
"Failed to signal used queue: {:?}",
|
||||||
Err(e) => {
|
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
|
||||||
"Failed to process queue (submit): {:?}",
|
|
||||||
e
|
e
|
||||||
)));
|
))
|
||||||
}
|
})?
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
COMPLETION_EVENT => {
|
COMPLETION_EVENT => {
|
||||||
@ -320,49 +317,48 @@ impl EpollHelperHandler for BlockEpollHandler {
|
|||||||
EpollHelperError::HandleEvent(anyhow!("Failed to get queue event: {:?}", e))
|
EpollHelperError::HandleEvent(anyhow!("Failed to get queue event: {:?}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
match self.process_queue_complete() {
|
let needs_notification = self.process_queue_complete().map_err(|e| {
|
||||||
Ok(needs_notification) => {
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
if needs_notification {
|
"Failed to process queue (complete): {:?}",
|
||||||
if let Err(e) = self.signal_used_queue() {
|
e
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
))
|
||||||
"Failed to signal used queue: {:?}",
|
})?;
|
||||||
e
|
|
||||||
)));
|
if needs_notification {
|
||||||
}
|
self.signal_used_queue().map_err(|e| {
|
||||||
}
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
}
|
"Failed to signal used queue: {:?}",
|
||||||
Err(e) => {
|
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
|
||||||
"Failed to process queue (complete): {:?}",
|
|
||||||
e
|
e
|
||||||
)));
|
))
|
||||||
}
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RATE_LIMITER_EVENT => {
|
RATE_LIMITER_EVENT => {
|
||||||
if let Some(rate_limiter) = &mut self.rate_limiter {
|
if let Some(rate_limiter) = &mut self.rate_limiter {
|
||||||
// Upon rate limiter event, call the rate limiter handler
|
// Upon rate limiter event, call the rate limiter handler
|
||||||
// and restart processing the queue.
|
// and restart processing the queue.
|
||||||
if rate_limiter.event_handler().is_ok() {
|
rate_limiter.event_handler().map_err(|e| {
|
||||||
match self.process_queue_submit() {
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
Ok(needs_notification) => {
|
"Failed to process rate limiter event: {:?}",
|
||||||
if needs_notification {
|
e
|
||||||
if let Err(e) = self.signal_used_queue() {
|
))
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
})?;
|
||||||
"Failed to signal used queue: {:?}",
|
|
||||||
e
|
let needs_notification = self.process_queue_submit().map_err(|e| {
|
||||||
)));
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
}
|
"Failed to process queue (submit): {:?}",
|
||||||
}
|
e
|
||||||
}
|
))
|
||||||
Err(e) => {
|
})?;
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
|
||||||
"Failed to process queue (submit): {:?}",
|
if needs_notification {
|
||||||
e
|
self.signal_used_queue().map_err(|e| {
|
||||||
)));
|
EpollHelperError::HandleEvent(anyhow!(
|
||||||
}
|
"Failed to signal used queue: {:?}",
|
||||||
}
|
e
|
||||||
}
|
))
|
||||||
|
})?
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
return Err(EpollHelperError::HandleEvent(anyhow!(
|
return Err(EpollHelperError::HandleEvent(anyhow!(
|
||||||
"Unexpected 'RATE_LIMITER_EVENT' when rate_limiter is not enabled."
|
"Unexpected 'RATE_LIMITER_EVENT' when rate_limiter is not enabled."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user