vmm: Fix map_err losing the inner error

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-01-24 09:34:51 +01:00
parent 0a7bcc9a7d
commit 148a9ed5ce
3 changed files with 25 additions and 17 deletions

View File

@ -109,7 +109,7 @@ pub enum Error {
VcpuUnhandledKvmExit,
/// Failed to join on vCPU threads
ThreadCleanup,
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
/// Cannot add legacy device to Bus.
BusError(devices::BusError),
@ -478,7 +478,7 @@ impl VcpuState {
fn join_thread(&mut self) -> Result<()> {
if let Some(handle) = self.handle.take() {
handle.join().map_err(|_| Error::ThreadCleanup)?
handle.join().map_err(Error::ThreadCleanup)?
}
Ok(())

View File

@ -78,6 +78,9 @@ pub enum Error {
/// The requested hotplug memory addition is not a valid size
InvalidSize,
/// Failed to set the user memory region.
SetUserMemoryRegion(kvm_ioctls::Error),
}
pub fn get_host_cpu_phys_bits() -> u8 {
@ -411,12 +414,8 @@ impl MemoryManager {
};
// Safe because the guest regions are guaranteed not to overlap.
unsafe {
self.fd
.set_user_memory_region(mem_region)
.map_err(|e| io::Error::from_raw_os_error(e.errno()))
}
.map_err(|_: io::Error| Error::GuestMemory(MmapError::NoMemoryRegion))?;
unsafe { self.fd.set_user_memory_region(mem_region) }
.map_err(Error::SetUserMemoryRegion)?;
// Mark the pages as mergeable if explicitly asked for.
if mergeable {

View File

@ -78,7 +78,16 @@ pub enum Error {
KernelLoad(linux_loader::loader::Error),
/// Cannot load the command line in memory
CmdLine,
LoadCmdLine(linux_loader::loader::Error),
/// Cannot modify the command line
CmdLineInsertStr(linux_loader::cmdline::Error),
/// Cannot convert command line into CString
CmdLineCString(std::ffi::NulError),
/// Cannot configure system
ConfigureSystem(arch::Error),
PoisonedState,
@ -110,7 +119,7 @@ pub enum Error {
SignalHandlerSpawn(io::Error),
/// Failed to join on vCPU threads
ThreadCleanup,
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
/// Failed to create a new KVM instance
KvmNew(kvm_ioctls::Error),
@ -363,12 +372,12 @@ impl Vm {
let mut cmdline = Cmdline::new(arch::CMDLINE_MAX_SIZE);
cmdline
.insert_str(self.config.lock().unwrap().cmdline.args.clone())
.map_err(|_| Error::CmdLine)?;
.map_err(Error::CmdLineInsertStr)?;
for entry in self.devices.cmdline_additions() {
cmdline.insert_str(entry).map_err(|_| Error::CmdLine)?;
cmdline.insert_str(entry).map_err(Error::CmdLineInsertStr)?;
}
let cmdline_cstring = CString::new(cmdline).map_err(|_| Error::CmdLine)?;
let cmdline_cstring = CString::new(cmdline).map_err(Error::CmdLineCString)?;
let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory();
let mem = guest_memory.load_full();
let entry_addr = match linux_loader::loader::Elf::load(
@ -395,7 +404,7 @@ impl Vm {
arch::layout::CMDLINE_START,
&cmdline_cstring,
)
.map_err(|_| Error::CmdLine)?;
.map_err(Error::LoadCmdLine)?;
let boot_vcpus = self.cpu_manager.lock().unwrap().boot_vcpus();
let _max_vcpus = self.cpu_manager.lock().unwrap().max_vcpus();
@ -422,7 +431,7 @@ impl Vm {
Some(hdr),
rsdp_addr,
)
.map_err(|_| Error::CmdLine)?;
.map_err(Error::ConfigureSystem)?;
let load_addr = entry_addr
.kernel_load
@ -441,7 +450,7 @@ impl Vm {
None,
rsdp_addr,
)
.map_err(|_| Error::CmdLine)?;
.map_err(Error::ConfigureSystem)?;
Ok(entry_addr.kernel_load)
}
@ -476,7 +485,7 @@ impl Vm {
// Wait for all the threads to finish
for thread in self.threads.drain(..) {
thread.join().map_err(|_| Error::ThreadCleanup)?
thread.join().map_err(Error::ThreadCleanup)?
}
*state = new_state;