Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions alioth/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use std::error::Error;
use std::fmt;

use snafu::{ErrorCompat, IntoError, ResultExt};

pub use macros::{DebugTrace, trace_error};

pub trait DebugTrace: Error {
Expand All @@ -27,8 +29,22 @@ impl Error for Box<dyn DebugTrace + Send + Sync + 'static> {
}
}

pub fn boxed_debug_trace<E: DebugTrace + Send + Sync + 'static>(
e: E,
) -> Box<dyn DebugTrace + Send + Sync + 'static> {
Box::new(e)
pub trait BoxTrace<'a, T> {
fn box_trace<C, E>(self, context: C) -> Result<T, E>
where
C: IntoError<E, Source = Box<dyn DebugTrace + Send + Sync + 'a>>,
E: Error + ErrorCompat;
}

impl<'a, T, E1> BoxTrace<'a, T> for Result<T, E1>
where
E1: DebugTrace + Send + Sync + 'a,
{
fn box_trace<C, E>(self, context: C) -> Result<T, E>
where
C: IntoError<E, Source = Box<dyn DebugTrace + Send + Sync + 'a>>,
E: Error + ErrorCompat,
{
self.map_err(|e| Box::new(e) as _).context(context)
}
}
8 changes: 3 additions & 5 deletions alioth/src/vfio/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use parking_lot::Mutex;
use snafu::ResultExt;

use crate::errors::boxed_debug_trace;
use crate::errors::BoxTrace;
use crate::mem::mapped::ArcMemPages;
use crate::mem::{self, LayoutChanged};
use crate::vfio::bindings::{
Expand Down Expand Up @@ -110,15 +110,13 @@ pub struct UpdateContainerMapping {
impl LayoutChanged for UpdateContainerMapping {
fn ram_added(&self, gpa: u64, pages: &ArcMemPages) -> mem::Result<()> {
let ret = self.container.map(pages.addr(), gpa, pages.size());
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
Ok(())
}

fn ram_removed(&self, gpa: u64, pages: &ArcMemPages) -> mem::Result<()> {
let ret = self.container.unmap(gpa, pages.size());
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
Ok(())
}
}
8 changes: 3 additions & 5 deletions alioth/src/vfio/iommu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;

use snafu::ResultExt;

use crate::errors::boxed_debug_trace;
use crate::errors::BoxTrace;
use crate::mem::mapped::ArcMemPages;
use crate::mem::{self, LayoutChanged};
use crate::vfio::bindings::{
Expand Down Expand Up @@ -128,15 +128,13 @@ pub struct UpdateIommuIoas {
impl LayoutChanged for UpdateIommuIoas {
fn ram_added(&self, gpa: u64, pages: &ArcMemPages) -> mem::Result<()> {
let ret = self.ioas.map(pages.addr(), gpa, pages.size());
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
Ok(())
}

fn ram_removed(&self, gpa: u64, pages: &ArcMemPages) -> mem::Result<()> {
let ret = self.ioas.unmap(gpa, pages.size());
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
Ok(())
}
}
12 changes: 4 additions & 8 deletions alioth/src/vfio/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ use std::sync::atomic::AtomicU64;
use libc::{PROT_READ, PROT_WRITE};
use macros::Layout;
use parking_lot::{Mutex, RwLock};
use snafu::ResultExt;
use zerocopy::{FromBytes, Immutable, IntoBytes, transmute};

use crate::errors::boxed_debug_trace;
use crate::errors::BoxTrace;
use crate::hv::{IrqFd, MsiSender};
use crate::mem::emulated::{Action, Mmio, MmioBus};
use crate::mem::mapped::ArcMemPages;
Expand Down Expand Up @@ -341,7 +340,7 @@ where

fn reset(&self) -> pci::Result<()> {
let ret = VfioPciDev::reset(self);
ret.map_err(boxed_debug_trace).context(pci::error::Reset)?;
ret.box_trace(pci::error::Reset)?;
Ok(())
}
}
Expand Down Expand Up @@ -696,8 +695,7 @@ where
let offset = offset - self.table_range.start;
if self.table.write_val(offset as u64, size, val)? {
self.enable_irqfd(offset / size_of::<MsixTableEntry>())
.map_err(boxed_debug_trace)
.context(mem::error::Mmio)?;
.box_trace(mem::error::Mmio)?;
}
} else if self.pba_range.contains(&offset) {
log::error!(
Expand Down Expand Up @@ -825,9 +823,7 @@ where
}
drop(cap);
if need_update {
self.update_msi()
.map_err(boxed_debug_trace)
.context(mem::error::Mmio)?;
self.update_msi().box_trace(mem::error::Mmio)?;
}
Ok(Action::None)
}
Expand Down
5 changes: 2 additions & 3 deletions alioth/src/virtio/vhost/vhost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::sync::Arc;

use snafu::{ResultExt, Snafu};

use crate::errors::{DebugTrace, boxed_debug_trace, trace_error};
use crate::errors::{BoxTrace, DebugTrace, trace_error};
use crate::mem::mapped::Ram;
use crate::mem::{self, LayoutUpdated};

Expand Down Expand Up @@ -158,8 +158,7 @@ impl LayoutUpdated for UpdateVsockMem {
table.regions[index].size = user_mem.size();
}
let ret = self.dev.set_mem_table(&table);
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
log::trace!(
"vhost-{}: updated mem table to {:x?}",
self.dev.fd.as_raw_fd(),
Expand Down
8 changes: 3 additions & 5 deletions alioth/src/virtio/vu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use parking_lot::Mutex;
use snafu::{ResultExt, Snafu};
use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes};

use crate::errors::{DebugTrace, boxed_debug_trace, trace_error};
use crate::errors::{BoxTrace, DebugTrace, trace_error};
use crate::mem::LayoutChanged;
use crate::mem::mapped::ArcMemPages;
use crate::{ffi, mem};
Expand Down Expand Up @@ -542,8 +542,7 @@ impl LayoutChanged for UpdateVuMem {
},
};
let ret = self.dev.add_mem_region(&region, fd.as_raw_fd());
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
log::trace!(
"vu-{}: added memory region {:x?}",
self.dev.conn.lock().as_raw_fd(),
Expand All @@ -566,8 +565,7 @@ impl LayoutChanged for UpdateVuMem {
},
};
let ret = self.dev.remove_mem_region(&region);
ret.map_err(boxed_debug_trace)
.context(mem::error::ChangeLayout)?;
ret.box_trace(mem::error::ChangeLayout)?;
log::trace!(
"vu-{}: removed memory region {:x?}",
self.dev.conn.lock().as_raw_fd(),
Expand Down