pub struct GenericBlockDevice {
disk_name: &'static str,
disk_size: usize,
request_fn: fn(&mut BlockIORequest) -> Result<(), &'static str>,
request_queue: Mutex<Vec<Box<BlockIORequest>>>,
}
Expand description
A generic implementation of a block device
Fields§
§disk_name: &'static str
§disk_size: usize
§request_fn: fn(&mut BlockIORequest) -> Result<(), &'static str>
§request_queue: Mutex<Vec<Box<BlockIORequest>>>
Implementations§
Source§impl GenericBlockDevice
impl GenericBlockDevice
pub fn new( disk_name: &'static str, disk_size: usize, request_fn: fn(&mut BlockIORequest) -> Result<(), &'static str>, ) -> Self
Trait Implementations§
Source§impl BlockDevice for GenericBlockDevice
impl BlockDevice for GenericBlockDevice
Source§fn process_requests(&self) -> Vec<BlockIOResult>
fn process_requests(&self) -> Vec<BlockIOResult>
Process all queued block I/O requests
This method processes all pending requests using a lock-efficient approach:
- Acquires the request_queue lock once
- Extracts all requests at once using mem::replace
- Releases the lock immediately
- Processes all requests without holding any locks
This approach minimizes lock contention and prevents deadlocks by:
- Never holding the lock during request processing
- Allowing other threads to enqueue requests while processing
- Avoiding any circular lock dependencies
§Returns
Vector of BlockIOResult
containing completed requests and their results
Source§fn get_disk_name(&self) -> &'static str
fn get_disk_name(&self) -> &'static str
Get the disk name
Source§fn get_disk_size(&self) -> usize
fn get_disk_size(&self) -> usize
Get the disk size in bytes
Source§fn enqueue_request(&self, request: Box<BlockIORequest>)
fn enqueue_request(&self, request: Box<BlockIORequest>)
Enqueue a block I/O request
Source§impl Device for GenericBlockDevice
impl Device for GenericBlockDevice
fn device_type(&self) -> DeviceType
fn name(&self) -> &'static str
fn as_any(&self) -> &dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Source§fn as_block_device(&self) -> Option<&dyn BlockDevice>
fn as_block_device(&self) -> Option<&dyn BlockDevice>
Cast to BlockDevice if this device is a block device
Source§fn as_char_device(&self) -> Option<&dyn CharDevice>
fn as_char_device(&self) -> Option<&dyn CharDevice>
Cast to CharDevice if this device is a character device