Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fixing passing read mode flags to block devices #1454

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 10 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,13 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
});
}

let flags = mode.map_or(self.prchk_flags, |m| match m {
ReadMode::Normal => self.prchk_flags,
ReadMode::UnwrittenFail => {
self.prchk_flags | 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 +600,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 +639,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
6 changes: 3 additions & 3 deletions nix/pkgs/libspdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ let
# 7. Copy SHA256 from 'got' of the error message to 'sha256' field.
# 8. 'nix-shell' build must now succeed.
drvAttrs = rec {
version = "23.01-2620df1";
version = "23.01-4b3b937";

src = fetchFromGitHub {
owner = "openebs";
repo = "spdk";
rev = "45c4b74576f9f45b380ff474ed46635f7596991c";
sha256 = "sha256-JyuP2poHfbUVJ61YT0pDZKGk+QjT5aDpg/rgxyuYPc4=";
rev = "4b3b937d1f0903d41c1252459b7578a2fcb00bee";
sha256 = "sha256-tCc+xFO9w9GmmwfxI8xp8Zs/QI1DqQ7voSGSp3K3Cic=";
fetchSubmodules = true;
};

Expand Down