mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
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:
parent
85f818421f
commit
1b0f35e42d
@ -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."
|
||||
|
Loading…
Reference in New Issue
Block a user