From 40d0e01de6246c9787bd3019681419c0c13a8f97 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Wed, 8 Apr 2020 01:18:16 +0000 Subject: io_uring: operation results are unsigned Switch from returning an i32 to a u32. This will make handling the number easier for users, as they can assume it is >= 0. Any value < 0 would not be returned as Ok(value) anyways as ret < 0 is used for error conditions. Change-Id: I609ce55d3c6be6e28f4d7aadf7148b2ac3b18878 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2140913 Reviewed-by: Chirantan Ekbote Tested-by: kokoro Tested-by: Dylan Reid Commit-Queue: Dylan Reid --- io_uring/src/uring.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/io_uring/src/uring.rs b/io_uring/src/uring.rs index 0a51df1..5c00129 100644 --- a/io_uring/src/uring.rs +++ b/io_uring/src/uring.rs @@ -374,7 +374,7 @@ impl URingContext { /// returns as soon an one or more is ready. pub fn wait<'a>( &'a mut self, - ) -> Result)> + 'a> { + ) -> Result)> + 'a> { let completed = self.complete_ring.num_completed(); self.stats.total_complete = self.stats.total_complete.wrapping_add(completed as u64); self.in_flight -= completed; @@ -508,7 +508,7 @@ impl CompleteQueueState { // Return the completed ops with their result. impl Iterator for CompleteQueueState { - type Item = (UserData, std::io::Result); + type Item = (UserData, std::io::Result); fn next(&mut self) -> Option { // Safe because the pointers to the atomics are valid and the cqe must be in range @@ -532,8 +532,8 @@ impl Iterator for CompleteQueueState { self.pointers.set_head(new_head); let io_res = match res { - r if r < 0 => Err(std::io::Error::from_raw_os_error(r)), - r => Ok(r), + r if r < 0 => Err(std::io::Error::from_raw_os_error(-r)), + r => Ok(r as u32), }; Some((user_data, io_res)) } @@ -628,7 +628,7 @@ mod tests { .unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, i as UserData); - assert_eq!(res.unwrap(), buf.len() as i32); + assert_eq!(res.unwrap(), buf.len() as u32); } } } @@ -657,7 +657,7 @@ mod tests { .unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 55 as UserData); - assert_eq!(res.unwrap(), buf.len() as i32); + assert_eq!(res.unwrap(), buf.len() as u32); } } @@ -697,7 +697,7 @@ mod tests { assert_eq!(event.token(), 1); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 55 as UserData); - assert_eq!(res.unwrap(), buf.len() as i32); + assert_eq!(res.unwrap(), buf.len() as u32); } } #[test] @@ -732,12 +732,12 @@ mod tests { .unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 66 as UserData); - assert_eq!(res.unwrap(), 0 as i32); + assert_eq!(res.unwrap(), 0 as u32); uring.add_fsync(f.as_raw_fd(), 67).unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 67 as UserData); - assert_eq!(res.unwrap(), 0 as i32); + assert_eq!(res.unwrap(), 0 as u32); uring .add_fallocate( @@ -750,7 +750,7 @@ mod tests { .unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 68 as UserData); - assert_eq!(res.unwrap(), 0 as i32); + assert_eq!(res.unwrap(), 0 as u32); drop(f); // Close to ensure directory entires for metadata are updated. @@ -767,6 +767,6 @@ mod tests { .unwrap(); let (user_data, res) = uring.wait().unwrap().next().unwrap(); assert_eq!(user_data, 454 as UserData); - assert_eq!(res.unwrap(), 1 as i32); + assert_eq!(res.unwrap(), 1 as u32); } } -- cgit 1.4.1