mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-04 04:25:45 +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)
|
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> {
|
fn process_queue_complete(&mut self) -> Result<bool> {
|
||||||
let queue = &mut self.queue;
|
let queue = &mut self.queue;
|
||||||
|
|
||||||
@ -318,21 +332,7 @@ 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 {
|
||||||
let needs_notification = self.process_queue_submit().map_err(|e| {
|
self.process_queue_submit_and_signal()?
|
||||||
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
|
|
||||||
))
|
|
||||||
})?
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
COMPLETION_EVENT => {
|
COMPLETION_EVENT => {
|
||||||
@ -367,21 +367,7 @@ impl EpollHelperHandler for BlockEpollHandler {
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let needs_notification = self.process_queue_submit().map_err(|e| {
|
self.process_queue_submit_and_signal()?
|
||||||
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
|
|
||||||
))
|
|
||||||
})?
|
|
||||||
};
|
|
||||||
} 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…
Reference in New Issue
Block a user