Skip to main content

DsmRange

Struct DsmRange 

Source
pub struct DsmRange {
    pub context: u32,
    pub length: u32,
    pub slba: u64,
}
Expand description

One DSM range entry. NVMe spec: each entry covers up to 4 GiB of LBAs.

Fields§

§context: u32

Context attributes (frequency / latency / access-pattern hints — see NVMe spec figure on DSM context attributes).

§length: u32

Length in logical blocks. 0-based per spec: 0 = 1 LBA, 1 = 2, etc. We keep the spec encoding here because it’s a 32-bit field and 1-basing it would silently truncate.

§slba: u64

Starting LBA.

Implementations§

Source§

impl DsmRange

Source

pub fn new(slba: u64, length: u32) -> Self

Construct a range with no context hints. length is 1-based for convenience (1 = a single LBA); decremented to spec form on send.

Examples found in repository?
examples/io_smoke.rs (line 73)
19fn main() -> Result<(), Box<dyn std::error::Error>> {
20    let root = Root::scan()?;
21    let mut exercised = 0;
22
23    for host in root.hosts() {
24        for subsys in host.subsystems() {
25            for ctrl in subsys.controllers() {
26                let model = ctrl.model().unwrap_or("?").trim();
27                if model != QEMU_MODEL {
28                    println!(
29                        "skipping {}: model {model:?} != {QEMU_MODEL:?} (refusing on real hardware)",
30                        ctrl.name()?
31                    );
32                    continue;
33                }
34
35                for ns in ctrl.namespaces() {
36                    let lba_size = ns.lba_size();
37                    println!(
38                        "exercising {} (NSID {}, {} B LBAs)",
39                        ns.name()?,
40                        ns.nsid(),
41                        lba_size
42                    );
43
44                    // ---- Write one LBA with a recognizable pattern -----
45                    let mut pattern = vec![0u8; lba_size as usize];
46                    for (i, b) in pattern.iter_mut().enumerate() {
47                        *b = (i & 0xFF) as u8;
48                    }
49                    ns.write(0, 1, &pattern).fua().execute()?;
50                    println!("  write ok");
51
52                    // ---- Read it back ---------------------------------
53                    let got = ns.read_to_vec(0, 1)?;
54                    assert_eq!(got, pattern, "read did not return the bytes we wrote");
55                    println!("  read ok (round-trip matches)");
56
57                    // ---- Compare (should succeed) ---------------------
58                    ns.compare(0, 1, &pattern).execute()?;
59                    println!("  compare ok");
60
61                    // ---- Verify (controller-side integrity check) -----
62                    ns.verify(0, 1).execute()?;
63                    println!("  verify ok");
64
65                    // ---- Write zeroes over the LBA --------------------
66                    ns.write_zeroes(0, 1).execute()?;
67                    let zeroed = ns.read_to_vec(0, 1)?;
68                    assert!(zeroed.iter().all(|&b| b == 0), "expected all-zero LBA");
69                    println!("  write_zeroes ok");
70
71                    // ---- DSM deallocate (TRIM) ------------------------
72                    ns.dsm(DsmAttr::DEALLOCATE)
73                        .ranges(&[DsmRange::new(0, 1)])
74                        .execute()?;
75                    println!("  dsm(deallocate) ok");
76
77                    // ---- Flush ----------------------------------------
78                    ns.flush()?;
79                    println!("  flush ok");
80
81                    exercised += 1;
82                }
83            }
84        }
85    }
86
87    if exercised == 0 {
88        println!("(no QEMU virtual NVMe controllers found)");
89    } else {
90        println!("\nall I/O commands exercised on {exercised} namespace(s)");
91    }
92    Ok(())
93}
Source

pub fn with_context(self, context: u32) -> Self

Attach context-attribute bits.

Trait Implementations§

Source§

impl Clone for DsmRange

Source§

fn clone(&self) -> DsmRange

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DsmRange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for DsmRange

Auto Trait Implementations§

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.