diff options
author | Dylan Reid <dgreid@chromium.org> | 2020-04-08 01:18:16 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-10 00:13:06 +0000 |
commit | 40d0e01de6246c9787bd3019681419c0c13a8f97 (patch) | |
tree | fd77a277c6fe62747ee7ce68fb4b608edf0e529a | |
parent | e1980a9c360b04705a16434bdaf1a56161dafb56 (diff) | |
download | crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar.gz crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar.bz2 crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar.lz crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar.xz crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.tar.zst crosvm-40d0e01de6246c9787bd3019681419c0c13a8f97.zip |
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 <chirantan@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Tested-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org>
-rw-r--r-- | io_uring/src/uring.rs | 22 |
1 files 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<impl Iterator<Item = (UserData, std::io::Result<i32>)> + 'a> { + ) -> Result<impl Iterator<Item = (UserData, std::io::Result<u32>)> + '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<i32>); + type Item = (UserData, std::io::Result<u32>); fn next(&mut self) -> Option<Self::Item> { // 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); } } |