From 3f1628c4ff3f2608091483bb13dd8f22502a5121 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Wed, 1 Dec 2021 18:04:36 +0800 Subject: [PATCH] Fix a bug in SubmissionQueue::sync() The uring driver may update queue.head, so SubmissionQueue::sync() should read queue.head instead of queue.tail. Signed-off-by: Liu Jiang --- io-uring-test/src/tests/queue.rs | 8 ++++++++ src/squeue.rs | 1 + 2 files changed, 9 insertions(+) diff --git a/io-uring-test/src/tests/queue.rs b/io-uring-test/src/tests/queue.rs index 5a37ff86..758df697 100644 --- a/io-uring-test/src/tests/queue.rs +++ b/io-uring-test/src/tests/queue.rs @@ -12,7 +12,9 @@ pub fn test_nop(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { unsafe { let mut queue = ring.submission(); + assert_eq!(queue.len(), 0); queue.push(&nop_e).expect("queue is full"); + assert_eq!(queue.len(), 1); } ring.submit_and_wait(1)?; @@ -23,6 +25,12 @@ pub fn test_nop(ring: &mut IoUring, test: &Test) -> anyhow::Result<()> { assert_eq!(cqes[0].user_data(), 0x42); assert_eq!(cqes[0].result(), 0); + unsafe { + let mut queue = ring.submission(); + queue.sync(); + assert_eq!(queue.len(), 0); + } + Ok(()) } diff --git a/src/squeue.rs b/src/squeue.rs index 0b6edb64..d88feb3d 100644 --- a/src/squeue.rs +++ b/src/squeue.rs @@ -178,6 +178,7 @@ impl SubmissionQueue<'_> { unsafe { (*self.queue.tail).store(self.tail, atomic::Ordering::Release); self.tail = (*self.queue.tail).load(atomic::Ordering::Acquire); + //self.head = (*self.queue.head).load(atomic::Ordering::Acquire); } }