mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-04 04:25:45 +00:00
src: Fix map_err losing the inner error
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
cf25bd74b0
commit
aa5ae7616e
@ -44,7 +44,7 @@ type VhostUserBackendResult<T> = std::result::Result<T, std::io::Error>;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Error {
|
enum Error {
|
||||||
/// Failed to create kill eventfd.
|
/// Failed to create kill eventfd.
|
||||||
CreateKillEventFd,
|
CreateKillEventFd(io::Error),
|
||||||
/// Failed to handle event other than input event.
|
/// Failed to handle event other than input event.
|
||||||
HandleEventNotEpollIn,
|
HandleEventNotEpollIn,
|
||||||
/// Failed to handle unknown event.
|
/// Failed to handle unknown event.
|
||||||
@ -89,7 +89,7 @@ impl<F: FileSystem + Send + Sync + 'static> VhostUserFsBackend<F> {
|
|||||||
fn new(fs: F) -> Result<Self> {
|
fn new(fs: F) -> Result<Self> {
|
||||||
Ok(VhostUserFsBackend {
|
Ok(VhostUserFsBackend {
|
||||||
mem: None,
|
mem: None,
|
||||||
kill_evt: EventFd::new(EFD_NONBLOCK).map_err(|_| Error::CreateKillEventFd)?,
|
kill_evt: EventFd::new(EFD_NONBLOCK).map_err(Error::CreateKillEventFd)?,
|
||||||
server: Arc::new(Server::new(fs)),
|
server: Arc::new(Server::new(fs)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
33
src/main.rs
33
src/main.rs
@ -1918,18 +1918,17 @@ mod tests {
|
|||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
loop {
|
loop {
|
||||||
match (|| -> Result<(), Error> {
|
match (|| -> Result<(), Error> {
|
||||||
let tcp =
|
let tcp = TcpStream::connect(format!("{}:22", ip)).map_err(Error::Connection)?;
|
||||||
TcpStream::connect(format!("{}:22", ip)).map_err(|_| Error::Connection)?;
|
|
||||||
let mut sess = Session::new().unwrap();
|
let mut sess = Session::new().unwrap();
|
||||||
sess.set_tcp_stream(tcp);
|
sess.set_tcp_stream(tcp);
|
||||||
sess.handshake().map_err(|_| Error::Connection)?;
|
sess.handshake().map_err(Error::Handshake)?;
|
||||||
|
|
||||||
sess.userauth_password("cloud", "cloud123")
|
sess.userauth_password("cloud", "cloud123")
|
||||||
.map_err(|_| Error::Authentication)?;
|
.map_err(Error::Authentication)?;
|
||||||
assert!(sess.authenticated());
|
assert!(sess.authenticated());
|
||||||
|
|
||||||
let mut channel = sess.channel_session().map_err(|_| Error::Command)?;
|
let mut channel = sess.channel_session().map_err(Error::ChannelSession)?;
|
||||||
channel.exec(command).map_err(|_| Error::Command)?;
|
channel.exec(command).map_err(Error::Command)?;
|
||||||
|
|
||||||
// Intentionally ignore these results here as their failure
|
// Intentionally ignore these results here as their failure
|
||||||
// does not precipitate a repeat
|
// does not precipitate a repeat
|
||||||
@ -1953,10 +1952,12 @@ mod tests {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Error {
|
enum Error {
|
||||||
Connection,
|
Connection(std::io::Error),
|
||||||
Authentication,
|
Handshake(ssh2::Error),
|
||||||
Command,
|
Authentication(ssh2::Error),
|
||||||
Parsing,
|
ChannelSession(ssh2::Error),
|
||||||
|
Command(ssh2::Error),
|
||||||
|
Parsing(std::num::ParseIntError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
@ -2080,7 +2081,7 @@ mod tests {
|
|||||||
.ssh_command("grep -c processor /proc/cpuinfo")?
|
.ssh_command("grep -c processor /proc/cpuinfo")?
|
||||||
.trim()
|
.trim()
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::Parsing)?)
|
.map_err(Error::Parsing)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_initial_apicid(&self) -> Result<u32, Error> {
|
fn get_initial_apicid(&self) -> Result<u32, Error> {
|
||||||
@ -2088,7 +2089,7 @@ mod tests {
|
|||||||
.ssh_command("grep \"initial apicid\" /proc/cpuinfo | grep -o \"[0-9]*\"")?
|
.ssh_command("grep \"initial apicid\" /proc/cpuinfo | grep -o \"[0-9]*\"")?
|
||||||
.trim()
|
.trim()
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::Parsing)?)
|
.map_err(Error::Parsing)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_total_memory(&self) -> Result<u32, Error> {
|
fn get_total_memory(&self) -> Result<u32, Error> {
|
||||||
@ -2096,7 +2097,7 @@ mod tests {
|
|||||||
.ssh_command("grep MemTotal /proc/meminfo | grep -o \"[0-9]*\"")?
|
.ssh_command("grep MemTotal /proc/meminfo | grep -o \"[0-9]*\"")?
|
||||||
.trim()
|
.trim()
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::Parsing)?)
|
.map_err(Error::Parsing)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_entropy(&self) -> Result<u32, Error> {
|
fn get_entropy(&self) -> Result<u32, Error> {
|
||||||
@ -2104,7 +2105,7 @@ mod tests {
|
|||||||
.ssh_command("cat /proc/sys/kernel/random/entropy_avail")?
|
.ssh_command("cat /proc/sys/kernel/random/entropy_avail")?
|
||||||
.trim()
|
.trim()
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::Parsing)?)
|
.map_err(Error::Parsing)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pci_bridge_class(&self) -> Result<String, Error> {
|
fn get_pci_bridge_class(&self) -> Result<String, Error> {
|
||||||
@ -2189,8 +2190,8 @@ mod tests {
|
|||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let start_addr = u64::from_str_radix(args[0], 16).map_err(|_| Error::Parsing)?;
|
let start_addr = u64::from_str_radix(args[0], 16).map_err(Error::Parsing)?;
|
||||||
let end_addr = u64::from_str_radix(args[1], 16).map_err(|_| Error::Parsing)?;
|
let end_addr = u64::from_str_radix(args[1], 16).map_err(Error::Parsing)?;
|
||||||
|
|
||||||
Ok(cache == (end_addr - start_addr + 1))
|
Ok(cache == (end_addr - start_addr + 1))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user