mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
disk: Switch to ThisError
`ThisError` is now used as the standard across crosvm Change-Id: I5e888c3af0bf98d6d00487ce48c92c929571bd6d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2947799 Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
parent
6a1c64e1df
commit
2eaabfd2c1
3 changed files with 22 additions and 31 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -347,6 +347,7 @@ dependencies = [
|
||||||
"protos",
|
"protos",
|
||||||
"remain",
|
"remain",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"thiserror",
|
||||||
"vm_memory",
|
"vm_memory",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ libc = "*"
|
||||||
protobuf = { version = "2.3", optional = true }
|
protobuf = { version = "2.3", optional = true }
|
||||||
remain = "*"
|
remain = "*"
|
||||||
tempfile = "*"
|
tempfile = "*"
|
||||||
|
thiserror = "*"
|
||||||
cros_async = { path = "../cros_async" }
|
cros_async = { path = "../cros_async" }
|
||||||
data_model = { path = "../data_model" }
|
data_model = { path = "../data_model" }
|
||||||
protos = { path = "../protos", optional = true }
|
protos = { path = "../protos", optional = true }
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::fmt::{self, Debug, Display};
|
use std::fmt::Debug;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -16,6 +16,7 @@ use base::{
|
||||||
use cros_async::Executor;
|
use cros_async::Executor;
|
||||||
use libc::EINVAL;
|
use libc::EINVAL;
|
||||||
use remain::sorted;
|
use remain::sorted;
|
||||||
|
use thiserror::Error as ThisError;
|
||||||
use vm_memory::GuestMemory;
|
use vm_memory::GuestMemory;
|
||||||
|
|
||||||
mod qcow;
|
mod qcow;
|
||||||
|
@ -30,25 +31,42 @@ mod android_sparse;
|
||||||
use android_sparse::{AndroidSparse, SPARSE_HEADER_MAGIC};
|
use android_sparse::{AndroidSparse, SPARSE_HEADER_MAGIC};
|
||||||
|
|
||||||
#[sorted]
|
#[sorted]
|
||||||
#[derive(Debug)]
|
#[derive(ThisError, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
#[error("failed to create block device: {0}")]
|
||||||
BlockDeviceNew(base::Error),
|
BlockDeviceNew(base::Error),
|
||||||
|
#[error("requested file conversion not supported")]
|
||||||
ConversionNotSupported,
|
ConversionNotSupported,
|
||||||
|
#[error("failure in android sparse disk: {0}")]
|
||||||
CreateAndroidSparseDisk(android_sparse::Error),
|
CreateAndroidSparseDisk(android_sparse::Error),
|
||||||
#[cfg(feature = "composite-disk")]
|
#[cfg(feature = "composite-disk")]
|
||||||
|
#[error("failure in composite disk: {0}")]
|
||||||
CreateCompositeDisk(composite::Error),
|
CreateCompositeDisk(composite::Error),
|
||||||
|
#[error("failure creating single file disk: {0}")]
|
||||||
CreateSingleFileDisk(cros_async::AsyncError),
|
CreateSingleFileDisk(cros_async::AsyncError),
|
||||||
|
#[error("failure with fallocate: {0}")]
|
||||||
Fallocate(cros_async::AsyncError),
|
Fallocate(cros_async::AsyncError),
|
||||||
|
#[error("failure with fsync: {0}")]
|
||||||
Fsync(cros_async::AsyncError),
|
Fsync(cros_async::AsyncError),
|
||||||
|
#[error("failure in qcow: {0}")]
|
||||||
QcowError(qcow::Error),
|
QcowError(qcow::Error),
|
||||||
|
#[error("failed to read data: {0}")]
|
||||||
ReadingData(io::Error),
|
ReadingData(io::Error),
|
||||||
|
#[error("failed to read header: {0}")]
|
||||||
ReadingHeader(io::Error),
|
ReadingHeader(io::Error),
|
||||||
|
#[error("failed to read to memory: {0}")]
|
||||||
ReadToMem(cros_async::AsyncError),
|
ReadToMem(cros_async::AsyncError),
|
||||||
|
#[error("failed to seek file: {0}")]
|
||||||
SeekingFile(io::Error),
|
SeekingFile(io::Error),
|
||||||
|
#[error("failed to set file size: {0}")]
|
||||||
SettingFileSize(io::Error),
|
SettingFileSize(io::Error),
|
||||||
|
#[error("unknown disk type")]
|
||||||
UnknownType,
|
UnknownType,
|
||||||
|
#[error("failed to write from memory: {0}")]
|
||||||
WriteFromMem(cros_async::AsyncError),
|
WriteFromMem(cros_async::AsyncError),
|
||||||
|
#[error("failed to write from vec: {0}")]
|
||||||
WriteFromVec(cros_async::AsyncError),
|
WriteFromVec(cros_async::AsyncError),
|
||||||
|
#[error("failed to write data: {0}")]
|
||||||
WritingData(io::Error),
|
WritingData(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,35 +134,6 @@ impl ToAsyncDisk for File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
|
||||||
#[remain::check]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
use self::Error::*;
|
|
||||||
|
|
||||||
#[sorted]
|
|
||||||
match self {
|
|
||||||
BlockDeviceNew(e) => write!(f, "failed to create block device: {}", e),
|
|
||||||
ConversionNotSupported => write!(f, "requested file conversion not supported"),
|
|
||||||
CreateAndroidSparseDisk(e) => write!(f, "failure in android sparse disk: {}", e),
|
|
||||||
#[cfg(feature = "composite-disk")]
|
|
||||||
CreateCompositeDisk(e) => write!(f, "failure in composite disk: {}", e),
|
|
||||||
CreateSingleFileDisk(e) => write!(f, "failure creating single file disk: {}", e),
|
|
||||||
Fallocate(e) => write!(f, "failure with fallocate: {}", e),
|
|
||||||
Fsync(e) => write!(f, "failure with fsync: {}", e),
|
|
||||||
QcowError(e) => write!(f, "failure in qcow: {}", e),
|
|
||||||
ReadingData(e) => write!(f, "failed to read data: {}", e),
|
|
||||||
ReadingHeader(e) => write!(f, "failed to read header: {}", e),
|
|
||||||
ReadToMem(e) => write!(f, "failed to read to memory: {}", e),
|
|
||||||
SeekingFile(e) => write!(f, "failed to seek file: {}", e),
|
|
||||||
SettingFileSize(e) => write!(f, "failed to set file size: {}", e),
|
|
||||||
UnknownType => write!(f, "unknown disk type"),
|
|
||||||
WriteFromMem(e) => write!(f, "failed to write from memory: {}", e),
|
|
||||||
WriteFromVec(e) => write!(f, "failed to write from vec: {}", e),
|
|
||||||
WritingData(e) => write!(f, "failed to write data: {}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The variants of image files on the host that can be used as virtual disks.
|
/// The variants of image files on the host that can be used as virtual disks.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum ImageType {
|
pub enum ImageType {
|
||||||
|
|
Loading…
Reference in a new issue