block: Move request code to its own module

There is no reason for most of the Request struct to be writable from
anywhere in the codebase.  Encapsulate it.

Use getter functions for access outside the request module.  Replace the
trivial setter for the writeback field with direct assignment.

No functional change intended.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
Demi Marie Obenour
2026-04-06 20:22:27 -04:00
committed by Bo Chen
parent 8f972567d0
commit 7c44f49293
4 changed files with 628 additions and 576 deletions

View File

@@ -131,14 +131,14 @@ impl VhostUserBlkThread {
let len = match Request::parse(&mut desc_chain, None) {
Ok(mut request) => {
debug!("element is a valid request");
request.set_writeback(self.writeback.load(Ordering::Acquire));
request.writeback = self.writeback.load(Ordering::Acquire);
let (status, len) = match request.execute(
&mut self.disk_image.lock().unwrap().deref_mut(),
self.disk_nsectors,
desc_chain.memory(),
&self.serial,
) {
Ok(_) if request.request_type == RequestType::GetDeviceId => {
Ok(_) if request.request_type() == RequestType::GetDeviceId => {
(VIRTIO_BLK_S_OK as u8, self.serial.len() as u32 + 1)
}
Ok(l) => (VIRTIO_BLK_S_OK as u8, l + 1),
@@ -146,7 +146,7 @@ impl VhostUserBlkThread {
};
desc_chain
.memory()
.write_obj(status, request.status_addr)
.write_obj(status, request.status_addr())
.unwrap();
len
}