Skip to content

Commit

Permalink
Try #1405:
Browse files Browse the repository at this point in the history
  • Loading branch information
mayastor-bors committed Jun 8, 2023
2 parents e7bbe27 + 40c887e commit 19d5473
Show file tree
Hide file tree
Showing 9 changed files with 878 additions and 469 deletions.
502 changes: 59 additions & 443 deletions io-engine/src/bdev/nvmx/channel.rs

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions io-engine/src/bdev/nvmx/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl NvmeDeviceHandle {
fn connect_sync(&mut self) {
let inner = NvmeIoChannel::inner_from_channel(self.io_channel.as_ptr());

match inner.qpair.as_mut() {
match inner.qpair_mut() {
Some(q) => {
q.connect();
}
Expand All @@ -198,7 +198,7 @@ impl NvmeDeviceHandle {
pub(crate) async fn connect_async(&mut self) -> Result<(), CoreError> {
let inner = NvmeIoChannel::inner_from_channel(self.io_channel.as_ptr());

match inner.qpair.as_mut() {
match inner.qpair_mut() {
Some(q) => q.connect_async().await,
None => {
error!("No I/O qpair in NvmeDeviceHandle, can't connect()");
Expand Down Expand Up @@ -489,7 +489,7 @@ fn check_channel_for_io(

// Check against concurrent controller reset, which results in valid
// I/O channel but deactivated I/O pair.
if inner.qpair.is_none() {
if inner.qpair().is_none() {
errno = libc::ENODEV;
}

Expand Down Expand Up @@ -566,7 +566,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let rc = unsafe {
spdk_nvme_ns_cmd_read(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
**buffer,
offset_blocks,
num_blocks as u32,
Expand Down Expand Up @@ -656,7 +656,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let rc = unsafe {
spdk_nvme_ns_cmd_write(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
**buffer,
offset_blocks,
num_blocks as u32,
Expand Down Expand Up @@ -734,7 +734,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
unsafe {
spdk_nvme_ns_cmd_read(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
(*iov).iov_base,
offset_blocks,
num_blocks as u32,
Expand All @@ -747,7 +747,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
unsafe {
spdk_nvme_ns_cmd_readv(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
offset_blocks,
num_blocks as u32,
Some(nvme_io_done),
Expand Down Expand Up @@ -809,7 +809,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
unsafe {
spdk_nvme_ns_cmd_write(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
(*iov).iov_base,
offset_blocks,
num_blocks as u32,
Expand All @@ -822,7 +822,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
unsafe {
spdk_nvme_ns_cmd_writev(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
offset_blocks,
num_blocks as u32,
Some(nvme_writev_done),
Expand Down Expand Up @@ -905,7 +905,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let rc = unsafe {
spdk_nvme_ns_cmd_flush(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
Some(nvme_flush_completion),
bio as *mut c_void,
)
Expand Down Expand Up @@ -1003,7 +1003,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {

spdk_nvme_ns_cmd_dataset_management(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
utils::NvmeDsmAttribute::Deallocate as u32,
dsm_ranges,
num_ranges as u16,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let rc = unsafe {
spdk_nvme_ns_cmd_write_zeroes(
self.ns.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
offset_blocks,
num_blocks as u32,
Some(nvme_io_done),
Expand Down Expand Up @@ -1126,7 +1126,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let inner = NvmeIoChannel::inner_from_channel(self.io_channel.as_ptr());

// Make sure channel allows I/O.
if inner.qpair.is_none() {
if inner.qpair().is_none() {
return Err(CoreError::NvmeAdminDispatch {
source: Errno::ENODEV,
opcode: cmd.opc(),
Expand Down Expand Up @@ -1309,7 +1309,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
let inner = NvmeIoChannel::inner_from_channel(self.io_channel.as_ptr());

// Make sure channel allows I/O.
if inner.qpair.is_none() {
if inner.qpair().is_none() {
return Err(CoreError::NvmeIoPassthruDispatch {
source: Errno::ENODEV,
opcode: nvme_cmd.opc(),
Expand All @@ -1326,7 +1326,7 @@ impl BlockDeviceHandle for NvmeDeviceHandle {
unsafe {
spdk_nvme_ctrlr_cmd_io_raw(
self.ctrlr.as_ptr(),
inner.qpair.as_mut().unwrap().as_ptr(),
inner.qpair_ptr(),
&mut pcmd,
ptr,
size as u32,
Expand Down
5 changes: 5 additions & 0 deletions io-engine/src/bdev/nvmx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};

pub use channel::{NvmeControllerIoChannel, NvmeIoChannel, NvmeIoChannelInner};
pub use controller::NvmeController;
use controller_inner::SpdkNvmeController;
pub use controller_state::NvmeControllerState;
pub use device::{lookup_by_name, open_by_name, NvmeBlockDevice};
pub use handle::{nvme_io_ctx_pool_init, NvmeDeviceHandle};
pub use namespace::NvmeNamespace;
use poll_group::PollGroup;
pub use qpair::{QPair, QPairState};
pub use snapshot::{NvmeSnapshotMessage, NvmeSnapshotMessageV1};
pub(crate) use uri::NvmfDeviceTemplate;

Expand All @@ -24,6 +27,8 @@ mod controller_state;
mod device;
mod handle;
mod namespace;
mod poll_group;
mod qpair;
mod snapshot;
mod uri;
pub mod utils;
Expand Down
62 changes: 62 additions & 0 deletions io-engine/src/bdev/nvmx/poll_group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::{os::raw::c_void, ptr::NonNull};

use spdk_rs::libspdk::{
spdk_nvme_poll_group,
spdk_nvme_poll_group_add,
spdk_nvme_poll_group_create,
spdk_nvme_poll_group_destroy,
spdk_nvme_poll_group_remove,
};

use crate::core::CoreError;

use super::QPair;

/// Wrapper for NVMe SPDK poll group structure.
pub(super) struct PollGroup(NonNull<spdk_nvme_poll_group>);

impl PollGroup {
/// Creates a poll group.
pub(super) fn create(
ctx: *mut c_void,
ctrlr_name: &str,
) -> Result<Self, CoreError> {
let poll_group: *mut spdk_nvme_poll_group =
unsafe { spdk_nvme_poll_group_create(ctx, std::ptr::null_mut()) };

if poll_group.is_null() {
Err(CoreError::GetIoChannel {
name: ctrlr_name.to_string(),
})
} else {
Ok(Self(NonNull::new(poll_group).unwrap()))
}
}

/// Adds I/O qpair to poll group.
pub(super) fn add_qpair(&mut self, qpair: &QPair) -> i32 {
unsafe { spdk_nvme_poll_group_add(self.0.as_ptr(), qpair.as_ptr()) }
}

/// Removes I/O qpair to poll group.
pub(super) fn remove_qpair(&mut self, qpair: &QPair) -> i32 {
unsafe { spdk_nvme_poll_group_remove(self.0.as_ptr(), qpair.as_ptr()) }
}

/// Gets SPDK handle for poll group.
#[inline(always)]
pub(super) fn as_ptr(&self) -> *mut spdk_nvme_poll_group {
self.0.as_ptr()
}
}

impl Drop for PollGroup {
fn drop(&mut self) {
trace!("dropping poll group {:p}", self.0.as_ptr());
let rc = unsafe { spdk_nvme_poll_group_destroy(self.0.as_ptr()) };
if rc < 0 {
error!("Error on poll group destroy: {}", rc);
}
trace!("poll group {:p} successfully dropped", self.0.as_ptr());
}
}
Loading

0 comments on commit 19d5473

Please sign in to comment.