cros_async: convert to ThisError and sort

BUG=b:197143586
TEST=cargo check

Cq-Depend: chromium:3105313
Change-Id: Ic9757b7e1947970910245fe954e47e4a2b7aa28e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105074
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-08-18 14:19:22 -07:00 committed by Commit Bot
parent 9aeb925b30
commit ddcf7bd2ab
8 changed files with 29 additions and 30 deletions

1
Cargo.lock generated
View file

@ -196,6 +196,7 @@ dependencies = [
"once_cell",
"paste",
"pin-utils",
"remain",
"slab",
"sync",
"sys_util",

View file

@ -14,6 +14,7 @@ libc = "*"
once_cell = "1.7.2"
paste = "1.0"
pin-utils = "0.1.0-alpha.4"
remain = "0.2"
slab = "0.4"
sync = { path = "../sync" } # provided by ebuild
sys_util = { path = "../sys_util" } # provided by ebuild

View file

@ -22,6 +22,7 @@ use std::task::{Context, Poll, Waker};
use async_task::Task;
use futures::task::noop_waker;
use pin_utils::pin_mut;
use remain::sorted;
use slab::Slab;
use sync::Mutex;
use sys_util::{add_fd_flags, warn, EpollContext, EpollEvents, EventFd, WatchingEvents};
@ -30,6 +31,7 @@ use thiserror::Error as ThisError;
use crate::waker::{new_waker, WakerToken, WeakWake};
use crate::{queue::RunnableQueue, BlockingPool};
#[sorted]
#[derive(Debug, ThisError)]
pub enum Error {
/// Failed to clone the EventFd for waking the executor.
@ -38,15 +40,15 @@ pub enum Error {
/// Failed to create the EventFd for waking the executor.
#[error("Failed to create the EventFd for waking the executor: {0}")]
CreateEventFd(sys_util::Error),
/// Creating a context to wait on FDs failed.
#[error("An error creating the fd waiting context: {0}")]
CreatingContext(sys_util::Error),
/// Failed to copy the FD for the polling context.
#[error("Failed to copy the FD for the polling context: {0}")]
DuplicatingFd(sys_util::Error),
/// The Executor is gone.
#[error("The FDExecutor is gone")]
ExecutorGone,
/// Creating a context to wait on FDs failed.
#[error("An error creating the fd waiting context: {0}")]
CreatingContext(sys_util::Error),
/// PollContext failure.
#[error("PollContext failure: {0}")]
PollContextError(sys_util::Error),

View file

@ -22,11 +22,13 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::Arc;
use async_trait::async_trait;
use remain::sorted;
use sys_util::net::UnixSeqpacket;
use thiserror::Error as ThisError;
use crate::{BackingMemory, MemRegion};
#[sorted]
#[derive(ThisError, Debug)]
pub enum Error {
/// An error with a polled(FD) source.

View file

@ -96,22 +96,24 @@ use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use remain::sorted;
use thiserror::Error as ThisError;
#[sorted]
#[derive(ThisError, Debug)]
pub enum Error {
/// Error from the FD executor.
#[error("Failure in the FD executor: {0}")]
FdExecutor(fd_executor::Error),
/// Error from the uring executor.
#[error("Failure in the uring executor: {0}")]
URingExecutor(uring_executor::Error),
/// Error from TimerFd.
#[error("Failure in TimerFd: {0}")]
TimerFd(sys_util::Error),
/// Error from TimerFd.
#[error("Failure in TimerAsync: {0}")]
TimerAsync(AsyncError),
/// Error from TimerFd.
#[error("Failure in TimerFd: {0}")]
TimerFd(sys_util::Error),
/// Error from the uring executor.
#[error("Failure in the uring executor: {0}")]
URingExecutor(uring_executor::Error),
}
pub type Result<T> = std::result::Result<T, Error>;

View file

@ -2,32 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::fmt::{self, Display};
use data_model::VolatileSlice;
use remain::sorted;
use thiserror::Error as ThisError;
#[derive(Debug)]
#[sorted]
#[derive(ThisError, Debug)]
pub enum Error {
/// Invalid offset or length given for an iovec in backing memory.
#[error("Invalid offset/len for getting a slice from {0} with len {1}.")]
InvalidOffset(u64, usize),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
InvalidOffset(base, len) => write!(
f,
"Invalid offset/len for getting a slice from {} with len {}.",
base, len
),
}
}
}
impl std::error::Error for Error {}
/// Used to index subslices of backing memory. Like an iovec, but relative to the start of the
/// memory region instead of an absolute pointer.
/// The backing memory referenced by the region can be an array, an mmapped file, or guest memory.

View file

@ -12,6 +12,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use data_model::VolatileSlice;
use remain::sorted;
use thiserror::Error as ThisError;
use crate::fd_executor::{self, FdExecutor, RegisteredSource};
@ -19,6 +20,7 @@ use crate::mem::{BackingMemory, MemRegion};
use crate::{AsyncError, AsyncResult};
use crate::{IoSourceExt, ReadAsync, WriteAsync};
#[sorted]
#[derive(ThisError, Debug)]
pub enum Error {
/// An error occurred attempting to register a waker with the executor.

View file

@ -70,6 +70,7 @@ use futures::task::noop_waker;
use io_uring::URingContext;
use once_cell::sync::Lazy;
use pin_utils::pin_mut;
use remain::sorted;
use slab::Slab;
use sync::Mutex;
use sys_util::{warn, WatchingEvents};
@ -82,8 +83,12 @@ use crate::{
BlockingPool,
};
#[sorted]
#[derive(Debug, ThisError)]
pub enum Error {
/// Creating a context to wait on FDs failed.
#[error("Error creating the fd waiting context: {0}")]
CreatingContext(io_uring::Error),
/// Failed to copy the FD for the polling context.
#[error("Failed to copy the FD for the polling context: {0}")]
DuplicatingFd(sys_util::Error),
@ -99,9 +104,6 @@ pub enum Error {
/// Error doing the IO.
#[error("Error during IO: {0}")]
Io(io::Error),
/// Creating a context to wait on FDs failed.
#[error("Error creating the fd waiting context: {0}")]
CreatingContext(io_uring::Error),
/// Failed to remove the waker remove the polling context.
#[error("Error removing from the URing context: {0}")]
RemovingWaker(io_uring::Error),