pub enum BufDesc<'a> {
Slice(&'a [u8]),
AutoReg(ublk_auto_buf_reg),
ZonedAppendLba(u64),
RawAddress(*const u8),
}Expand description
Unified buffer descriptor supporting both copy and zero-copy operations
Variants§
Slice(&'a [u8])
Buffer slice for copy-based operations
Contains a reference to a buffer slice in userspace memory. Data is copied
between this buffer and kernel buffers. Compatible with devices that have
UBLK_F_USER_COPY enabled or devices without auto buffer registration.
AutoReg(ublk_auto_buf_reg)
Auto buffer registration for zero-copy operations
Contains auto buffer registration data that allows the kernel to directly
access userspace buffers without copying. Requires devices with
UBLK_F_AUTO_BUF_REG enabled for optimal performance.
ZonedAppendLba(u64)
Zoned append LBA for zoned storage operations
Contains a zoned append LBA value for UBLK_F_ZONED devices.
Only used for zone append operations and passed through the addr field
of ublksrv_io_desc when using submit_io_prep_cmd(), submit_io_commit_cmd(), or complete_io_cmd_unified().
RawAddress(*const u8)
Raw memory address for unsafe low-level operations
WARNING: This variant should be avoided whenever possible.
Contains a raw pointer to memory that will be used directly without safety checks or lifetime guarantees. This is an escape hatch for cases where only a raw address is available and other buffer types cannot be used.
§Safety
- The caller must ensure the memory pointed to by this address is valid
- The memory must remain valid for the entire duration of the I/O operation
- The memory must be properly aligned for the intended operations
- No bounds checking is performed - buffer overruns are possible
§When to Use
This variant should only be used as a last resort when:
- Interfacing with C libraries that only provide raw pointers
- Working with memory-mapped regions where slice creation is impractical
- Performance-critical code where slice overhead must be avoided
§Preferred Alternatives
- Use
Slice(&[u8])when you have a safe slice reference - Use
AutoReg(ublk_auto_buf_reg)for zero-copy operations - Consider creating a safe slice using
std::slice::from_raw_parts()if length is known
Implementations§
Source§impl<'a> BufDesc<'a>
impl<'a> BufDesc<'a>
Sourcepub fn validate_compatibility(&self, device_flags: u64) -> Result<(), UblkError>
pub fn validate_compatibility(&self, device_flags: u64) -> Result<(), UblkError>
Validate buffer descriptor compatibility with device capabilities
§Arguments
device_flags: Device flags fromdev_info.flags
§Returns
Ok(())if the buffer descriptor is compatible with device capabilitiesErr(UblkError::OtherError(-libc::ENOTSUP))if the buffer type is not supportedErr(UblkError::OtherError(-libc::EINVAL))if the configuration is invalid
§Validation Rules
BufDesc::Slicerequires either no special flags orUBLK_F_USER_COPYBufDesc::AutoRegrequiresUBLK_F_AUTO_BUF_REGto be enabledBufDesc::ZonedAppendLbarequiresUBLK_F_ZONEDto be enabledBufDesc::RawAddressis compatible with all device configurations (unsafe)UBLK_F_AUTO_BUF_REGandUBLK_F_USER_COPYcannot be used together
Sourcepub fn from_io_buf(io_buf: &'a IoBuf<u8>) -> Self
pub fn from_io_buf(io_buf: &'a IoBuf<u8>) -> Self
Create a BufDesc from an IoBuf for migration compatibility
§Arguments
io_buf: Reference to an IoBuf instance
§Returns
A BufDesc::Slice containing a reference to the IoBuf’s data
This helper method facilitates migration from existing IoBuf-based code to the new unified buffer descriptor system while maintaining zero-cost abstraction principles.