Skip to content

Commit

Permalink
libublk: remove UBLK_QUEUE_POLL
Browse files Browse the repository at this point in the history
Remove UBLK_QUEUE_POLL and pass 'to_wait'.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
  • Loading branch information
ming1 committed Oct 6, 2023
1 parent c1a3ff2 commit 9965c86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ impl UblkCtrl {
let mut started = false;
let token = self.__start_dev(dev, true)?;

q.set_poll(true);
while !started {
std::thread::sleep(std::time::Duration::from_millis(10));
if let Ok(res) = self.poll_cmd(token) {
Expand All @@ -758,12 +757,11 @@ impl UblkCtrl {
return Err(UblkError::UringIOError(res));
}
}
match q.process_ios(&mut ops) {
match q.process_ios(&mut ops, 0) {
Err(r) => return Err(r),
_ => continue,
}
}
q.set_poll(false);

Ok(0)
}
Expand Down
26 changes: 7 additions & 19 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ impl UblkQueueCtx {

const UBLK_QUEUE_STOPPING: u32 = 1_u32 << 0;
const UBLK_QUEUE_IDLE: u32 = 1_u32 << 1;
const UBLK_QUEUE_POLL: u32 = 1_u32 << 2;

/// UBLK queue abstraction
///
Expand Down Expand Up @@ -536,18 +535,6 @@ impl UblkQueue<'_> {
self.flags & super::UBLK_DEV_F_COMP_BATCH != 0
}

pub fn set_poll(&mut self, val: bool) {
if val {
self.q_state |= UBLK_QUEUE_POLL;
} else {
self.q_state &= !UBLK_QUEUE_POLL;
}
}

pub fn get_poll(&mut self) -> bool {
self.q_state & UBLK_QUEUE_POLL != 0
}

#[inline(always)]
#[allow(unused_assignments)]
fn queue_io_cmd(&mut self, tag: u16, cmd_op: u32, buf_addr: u64, res: i32) -> i32 {
Expand Down Expand Up @@ -736,9 +723,7 @@ impl UblkQueue<'_> {
}

#[inline(always)]
fn process_io(&mut self) -> Result<i32, UblkError> {
let to_wait = if self.get_poll() { 0 } else { 1 };

fn process_io(&mut self, to_wait: usize) -> Result<i32, UblkError> {
info!(
"dev{}-q{}: to_submit {} inflight cmd {} stopping {}",
self.dev.dev_info.dev_id,
Expand Down Expand Up @@ -774,6 +759,9 @@ impl UblkQueue<'_> {
///
/// * `ops`: IO handling Closure
///
/// * `to_wait`: passed to io_uring_enter(), wait until how many events are
/// available
///
/// When either io command or target io is coming, we are called for
/// handling both. Basically the IO handling closure is called for
/// every incoming io_uring CQE.
Expand Down Expand Up @@ -815,11 +803,11 @@ impl UblkQueue<'_> {
/// provided, and target code can return UblkFatRes::BatchRes(batch) to
/// cover each completed IO(tag, result) in io closure. Then, all these
/// added IOs will be completed automatically.
pub fn process_ios<F>(&mut self, mut ops: F) -> Result<i32, UblkError>
pub fn process_ios<F>(&mut self, mut ops: F, to_wait: usize) -> Result<i32, UblkError>
where
F: FnMut(&mut UblkIOCtx) -> Result<UblkIORes, UblkError>,
{
match self.process_io() {
match self.process_io(to_wait) {
Err(r) => Err(r),
Ok(done) => {
for idx in 0..done {
Expand All @@ -844,7 +832,7 @@ impl UblkQueue<'_> {
F: FnMut(&mut UblkIOCtx) -> Result<UblkIORes, UblkError>,
{
loop {
match self.process_ios(&mut ops) {
match self.process_ios(&mut ops, 1) {
Err(_) => break,
_ => continue,
}
Expand Down

0 comments on commit 9965c86

Please sign in to comment.