Skip to content

Commit

Permalink
fix: ignore unsafe preconditions on debug
Browse files Browse the repository at this point in the history
Latest rust from_raw_parts now ensures the ptr is valid.
This causes issues on write_zeroes where the iovec is actually
not valid and not used.
For now let's simply ignore this precondition check since the
iovec is not used but probably we ought to use fix this for
release as well, just in case.

Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Nov 4, 2024
1 parent b9e3655 commit 60648c1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/bdev_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
fmt::{Debug, Formatter},
marker::PhantomData,
os::raw::c_void,
ptr,
ptr::NonNull,
slice::{from_raw_parts, from_raw_parts_mut},
};
Expand Down Expand Up @@ -40,7 +41,6 @@ pub trait AsIoVecs {
/// # Generic Arguments
///
/// * `BdevData`: TODO
#[derive(Copy)]
pub struct BdevIo<BdevData>
where
BdevData: BdevOps,
Expand All @@ -49,6 +49,8 @@ where
inner: NonNull<spdk_bdev_io>,
/// TODO
_data: PhantomData<BdevData>,
#[cfg(debug_assertions)]
_no_iov: Vec<IoVec>,
}

impl<BdevData> BdevIo<BdevData>
Expand Down Expand Up @@ -114,10 +116,11 @@ where
pub fn iovs(&self) -> &[IoVec] {
unsafe {
let bdev = self.as_ref().u.bdev;
std::slice::from_raw_parts(
bdev.iovs as *const IoVec,
bdev.iovcnt as usize,
)
#[cfg(debug_assertions)]
if bdev.iovs.is_null() {
return &self._no_iov;
}
from_raw_parts(bdev.iovs as *const IoVec, bdev.iovcnt as usize)
}
}

Expand All @@ -126,10 +129,7 @@ where
pub fn iovs_mut(&self) -> &mut [IoVec] {
unsafe {
let bdev = self.as_ref().u.bdev;
std::slice::from_raw_parts_mut(
bdev.iovs as *mut IoVec,
bdev.iovcnt as usize,
)
from_raw_parts_mut(bdev.iovs as *mut IoVec, bdev.iovcnt as usize)
}
}

Expand Down Expand Up @@ -254,6 +254,8 @@ where
BdevIo {
inner: NonNull::new(bio).unwrap(),
_data: Default::default(),
#[cfg(debug_assertions)]
_no_iov: vec![],
}
}

Expand Down Expand Up @@ -321,6 +323,8 @@ where
Self {
inner: self.inner,
_data: Default::default(),
#[cfg(debug_assertions)]
_no_iov: vec![],
}
}
}

0 comments on commit 60648c1

Please sign in to comment.