virtio-devices: block: Remove duplicated code in handle_event()

There is duplicated code when handlin queue events in handle_event()
refactor and introduce a new helper function.

Signed-off-by: Hao Xu <howeyxu@tencent.com>
This commit is contained in:
Hao Xu 2022-12-15 18:13:51 +08:00 committed by Rob Bradford
parent 85f818421f
commit 1b0f35e42d

View File

@ -199,6 +199,20 @@ impl BlockEpollHandler {
Ok(used_descs)
}
fn process_queue_submit_and_signal(&mut self) -> result::Result<(), EpollHelperError> {
let needs_notification = self.process_queue_submit().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!("Failed to process queue (submit): {:?}", e))
})?;
if needs_notification {
self.signal_used_queue().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!("Failed to signal used queue: {:?}", e))
})?
};
Ok(())
}
fn process_queue_complete(&mut self) -> Result<bool> {
let queue = &mut self.queue;
@ -318,21 +332,7 @@ impl EpollHelperHandler for BlockEpollHandler {
// Process the queue only when the rate limit is not reached
if !rate_limit_reached {
let needs_notification = self.process_queue_submit().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!(
"Failed to process queue (submit): {:?}",
e
))
})?;
if needs_notification {
self.signal_used_queue().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!(
"Failed to signal used queue: {:?}",
e
))
})?
};
self.process_queue_submit_and_signal()?
}
}
COMPLETION_EVENT => {
@ -367,21 +367,7 @@ impl EpollHelperHandler for BlockEpollHandler {
))
})?;
let needs_notification = self.process_queue_submit().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!(
"Failed to process queue (submit): {:?}",
e
))
})?;
if needs_notification {
self.signal_used_queue().map_err(|e| {
EpollHelperError::HandleEvent(anyhow!(
"Failed to signal used queue: {:?}",
e
))
})?
};
self.process_queue_submit_and_signal()?
} else {
return Err(EpollHelperError::HandleEvent(anyhow!(
"Unexpected 'RATE_LIMITER_EVENT' when rate_limiter is not enabled."