Skip to content

Commit

Permalink
fix(core): fixing passing read mode flags to block devices
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Savitskiy <[email protected]>
  • Loading branch information
dsavitskiy committed Jul 10, 2023
1 parent afe2e16 commit e514fe4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
9 changes: 3 additions & 6 deletions io-engine/src/bdev/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,13 @@ impl BlockDeviceHandle for SpdkBlockDeviceHandle {
DmaBuf::new(size, self.device.alignment())
}

async fn read_at(
async fn read_at_ex(
&self,
offset: u64,
buffer: &mut DmaBuf,
mode: Option<ReadMode>,
) -> Result<u64, CoreError> {
self.handle.read_at(offset, buffer).await
}

fn set_read_mode(&mut self, mode: ReadMode) {
self.handle.set_read_mode(mode);
self.handle.read_at_ex(offset, buffer, mode).await
}

async fn write_at(
Expand Down
18 changes: 8 additions & 10 deletions io-engine/src/bdev/nvmx/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,11 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
DmaBuf::new(size, self.ns.alignment())
}

async fn read_at(
async fn read_at_ex(
&self,
offset: u64,
buffer: &mut DmaBuf,
mode: Option<ReadMode>,
) -> Result<u64, CoreError> {
let (valid, offset_blocks, num_blocks) =
self.bytes_to_blocks(offset, buffer.len());
Expand All @@ -576,6 +577,11 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
});
}

let flags = mode.map_or(self.prchk_flags, |m| match m {
ReadMode::Normal => 0,
ReadMode::UnwrittenFail => SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL,
});

let inner = NvmeIoChannel::inner_from_channel(self.io_channel.as_ptr());

// Make sure channel allows I/O.
Expand All @@ -592,7 +598,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
num_blocks as u32,
Some(nvme_async_io_completion),
cb_arg(s),
self.prchk_flags,
flags,
)
};

Expand Down Expand Up @@ -631,14 +637,6 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
ret
}

/// TODO
fn set_read_mode(&mut self, mode: ReadMode) {
self.prchk_flags = match mode {
ReadMode::Normal => 0,
ReadMode::UnwrittenFail => SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL,
};
}

async fn write_at(
&self,
offset: u64,
Expand Down
11 changes: 9 additions & 2 deletions io-engine/src/core/block_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,17 @@ pub trait BlockDeviceHandle {
&self,
offset: u64,
buffer: &mut DmaBuf,
) -> Result<u64, CoreError>;
) -> Result<u64, CoreError> {
self.read_at_ex(offset, buffer, None).await
}

/// TODO
fn set_read_mode(&mut self, mode: ReadMode);
async fn read_at_ex(
&self,
offset: u64,
buffer: &mut DmaBuf,
mode: Option<ReadMode>,
) -> Result<u64, CoreError>;

/// TODO
async fn write_at(
Expand Down
28 changes: 16 additions & 12 deletions io-engine/src/core/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub struct BdevHandle<T: BdevOps> {
channel: IoChannelGuard<T::ChannelData>,
/// TODO
desc: Arc<DescriptorGuard<T>>,
/// TODO
io_flags: u32,
}

pub type UntypedBdevHandle = BdevHandle<()>;
Expand Down Expand Up @@ -167,13 +165,27 @@ impl<T: BdevOps> BdevHandle<T> {
}),
}
}

/// read at given offset into the ['DmaBuf']
pub async fn read_at(
&self,
offset: u64,
buffer: &mut DmaBuf,
) -> Result<u64, CoreError> {
self.read_at_ex(offset, buffer, None).await
}

/// read at given offset into the ['DmaBuf']
pub(crate) async fn read_at_ex(
&self,
offset: u64,
buffer: &mut DmaBuf,
mode: Option<ReadMode>,
) -> Result<u64, CoreError> {
let flags = mode.map_or(0, |m| match m {
ReadMode::Normal => 0,
ReadMode::UnwrittenFail => SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL,
});

let (s, r) = oneshot::channel::<NvmeStatus>();
let errno = unsafe {
spdk_bdev_read_with_flags(
Expand All @@ -184,7 +196,7 @@ impl<T: BdevOps> BdevHandle<T> {
buffer.len(),
Some(Self::io_completion_cb),
cb_arg(s),
self.io_flags,
flags,
)
};

Expand Down Expand Up @@ -212,13 +224,6 @@ impl<T: BdevOps> BdevHandle<T> {
}
}

pub fn set_read_mode(&mut self, mode: ReadMode) {
self.io_flags = match mode {
ReadMode::Normal => 0,
ReadMode::UnwrittenFail => SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL,
};
}

pub async fn reset(&self) -> Result<(), CoreError> {
let (s, r) = oneshot::channel::<NvmeStatus>();
let errno = unsafe {
Expand Down Expand Up @@ -388,7 +393,6 @@ impl<T: BdevOps> TryFrom<Arc<DescriptorGuard<T>>> for BdevHandle<T> {
return Ok(Self {
channel,
desc,
io_flags: 0,
});
}

Expand Down
9 changes: 6 additions & 3 deletions io-engine/src/rebuild/rebuild_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl RebuildTask {
descriptor: &RebuildDescriptor,
) -> Result<(), RebuildError> {
let mut copy_buffer: DmaBuf;
let mut source_hdl = descriptor.src_io_handle().await?;
let source_hdl = descriptor.src_io_handle().await?;
let destination_hdl = descriptor.dst_io_handle().await?;

let copy_buffer = if descriptor.get_segment_size_blks(blk)
Expand All @@ -136,9 +136,12 @@ impl RebuildTask {
&mut copy_buffer
};

source_hdl.set_read_mode(ReadMode::UnwrittenFail);
let res = source_hdl
.read_at(blk * descriptor.block_size, copy_buffer)
.read_at_ex(
blk * descriptor.block_size,
copy_buffer,
Some(ReadMode::UnwrittenFail),
)
.await;

if let Err(CoreError::ReadingUnallocatedBlock {
Expand Down

0 comments on commit e514fe4

Please sign in to comment.