From fc26a0b01920f42212404c2cd985d43fd5030f8f Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Tue, 11 Jul 2023 11:50:54 +0000 Subject: [PATCH] libublk: add UblkIOCtx::set_zone_append_lab() Add UblkIOCtx::set_zone_append_lab() for zoned target to pass back sector allocated for UBLK_IO_ZONE_APPEND. Signed-off-by: Ming Lei --- src/io.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/io.rs b/src/io.rs index 03b87a0..ff0c617 100644 --- a/src/io.rs +++ b/src/io.rs @@ -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, @@ -377,7 +383,11 @@ 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, } @@ -385,7 +395,13 @@ struct UblkIO { 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 @@ -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 }, ); @@ -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 {