virtio-mem: mem: Simplify 'process_queue'

No functional change.

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-10-06 14:58:10 -07:00 committed by Bo Chen
parent 756aebafda
commit fd9fa2a681

View File

@ -596,28 +596,22 @@ impl MemEpollHandler {
while let Some(mut desc_chain) = self.queue.pop_descriptor_chain(self.mem.memory()) { while let Some(mut desc_chain) = self.queue.pop_descriptor_chain(self.mem.memory()) {
let r = Request::parse(&mut desc_chain)?; let r = Request::parse(&mut desc_chain)?;
let len = match r.req.req_type { let (resp_type, resp_state) = match r.req.req_type {
VIRTIO_MEM_REQ_PLUG => { VIRTIO_MEM_REQ_PLUG => (
let resp_type = self.state_change_request(r.req.addr, r.req.nb_blocks, true); self.state_change_request(r.req.addr, r.req.nb_blocks, true),
r.send_response(desc_chain.memory(), resp_type, 0u16)? 0u16,
} ),
VIRTIO_MEM_REQ_UNPLUG => { VIRTIO_MEM_REQ_UNPLUG => (
let resp_type = self.state_change_request(r.req.addr, r.req.nb_blocks, false); self.state_change_request(r.req.addr, r.req.nb_blocks, false),
r.send_response(desc_chain.memory(), resp_type, 0u16)? 0u16,
} ),
VIRTIO_MEM_REQ_UNPLUG_ALL => { VIRTIO_MEM_REQ_UNPLUG_ALL => (self.unplug_all(), 0u16),
let resp_type = self.unplug_all(); VIRTIO_MEM_REQ_STATE => self.state_request(r.req.addr, r.req.nb_blocks),
r.send_response(desc_chain.memory(), resp_type, 0u16)?
}
VIRTIO_MEM_REQ_STATE => {
let (resp_type, resp_state) = self.state_request(r.req.addr, r.req.nb_blocks);
r.send_response(desc_chain.memory(), resp_type, resp_state)?
}
_ => { _ => {
return Err(Error::UnkownRequestType(r.req.req_type)); return Err(Error::UnkownRequestType(r.req.req_type));
} }
}; };
let len = r.send_response(desc_chain.memory(), resp_type, resp_state)?;
self.queue self.queue
.add_used(desc_chain.memory(), desc_chain.head_index(), len) .add_used(desc_chain.memory(), desc_chain.head_index(), len)
.unwrap(); .unwrap();