BufDesc

Enum BufDesc 

Source
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>

Source

pub fn validate_compatibility(&self, device_flags: u64) -> Result<(), UblkError>

Validate buffer descriptor compatibility with device capabilities

§Arguments
  • device_flags: Device flags from dev_info.flags
§Returns
  • Ok(()) if the buffer descriptor is compatible with device capabilities
  • Err(UblkError::OtherError(-libc::ENOTSUP)) if the buffer type is not supported
  • Err(UblkError::OtherError(-libc::EINVAL)) if the configuration is invalid
§Validation Rules
  • BufDesc::Slice requires either no special flags or UBLK_F_USER_COPY
  • BufDesc::AutoReg requires UBLK_F_AUTO_BUF_REG to be enabled
  • BufDesc::ZonedAppendLba requires UBLK_F_ZONED to be enabled
  • BufDesc::RawAddress is compatible with all device configurations (unsafe)
  • UBLK_F_AUTO_BUF_REG and UBLK_F_USER_COPY cannot be used together
Source

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.

Trait Implementations§

Source§

impl<'a> Clone for BufDesc<'a>

Source§

fn clone(&self) -> BufDesc<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BufDesc<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BufDesc<'a>

§

impl<'a> RefUnwindSafe for BufDesc<'a>

§

impl<'a> !Send for BufDesc<'a>

§

impl<'a> !Sync for BufDesc<'a>

§

impl<'a> Unpin for BufDesc<'a>

§

impl<'a> UnwindSafe for BufDesc<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.