Skip to content

Commit

Permalink
libublk: add UblkIOCtx::set_zone_append_lab()
Browse files Browse the repository at this point in the history
Add UblkIOCtx::set_zone_append_lab() for zoned target to pass back sector
allocated for UBLK_IO_ZONE_APPEND.

Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Aug 21, 2023
1 parent b5018f8 commit fc26a0b
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ fn is_target_io(user_data: u64) -> bool {
}

impl<'a, 'b, 'd> UblkIOCtx<'a, 'b, 'd> {
/// Set LBA for UBLK_IO_ZONE_APPEND
#[inline(always)]
pub fn set_zone_append_lab(&mut self, lba: u64) {
self.1.set_buf_addr(lba)
}

/// Return io_uring instance which is shared in queue wide.
///
/// Target IO often needs to handle IO command by io_uring further,
Expand Down Expand Up @@ -377,15 +383,25 @@ const UBLK_IO_FREE: u32 = 1u32 << 2;
const UBLK_IO_TO_QUEUE: u32 = 1u32 << 3;

struct UblkIO {
buf_addr: *mut u8,
// for holding the allocated buffer
__buf_addr: *mut u8,

//for sending as io command
buf_addr: u64,
flags: u32,
result: i32,
}

impl UblkIO {
#[inline(always)]
fn get_buf_addr(&self) -> *mut u8 {
self.buf_addr
self.__buf_addr
}

/// for zoned append command only
#[inline(always)]
fn set_buf_addr(&mut self, addr: u64) {
self.buf_addr = addr;
}

/// Complete this io command
Expand Down Expand Up @@ -487,7 +503,7 @@ impl Drop for UblkQueue<'_> {
for i in 0..depth {
let io = &self.ios[i as usize];
super::ublk_dealloc_buf(
io.buf_addr,
io.__buf_addr,
dev.dev_info.max_io_buf_bytes as usize,
unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize },
);
Expand Down Expand Up @@ -580,16 +596,21 @@ impl UblkQueue<'_> {

// extra io slot needn't to allocate buffer
if i < depth {
io.buf_addr =
super::ublk_alloc_buf(dev.dev_info.max_io_buf_bytes as usize, unsafe {
libc::sysconf(libc::_SC_PAGESIZE) as usize
});
if (dev.dev_info.flags & (super::sys::UBLK_F_USER_COPY as u64)) == 0 {
io.__buf_addr =
super::ublk_alloc_buf(dev.dev_info.max_io_buf_bytes as usize, unsafe {
libc::sysconf(libc::_SC_PAGESIZE).try_into().unwrap()
});
} else {
io.__buf_addr = std::ptr::null_mut();
}
io.flags = UBLK_IO_NEED_FETCH_RQ | UBLK_IO_FREE;
} else {
io.buf_addr = std::ptr::null_mut();
io.__buf_addr = std::ptr::null_mut();
io.flags = 0;
}
io.result = -1;
io.buf_addr = io.__buf_addr as u64;
}

let mut q = UblkQueue {
Expand Down

0 comments on commit fc26a0b

Please sign in to comment.