mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-21 20:15:21 +00:00
vm-virtio: Further factorization
The trait bound and non trait bound virtio devices can use the same inner implementation. Also, the virtio pausable trait definiton can also be factorized. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
bce76271c5
commit
c4b3ed7223
@ -112,6 +112,15 @@ pub trait DmaRemapping: Send + Sync {
|
||||
fn translate(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! virtio_pausable_trait_definition {
|
||||
() => {
|
||||
trait VirtioPausable {
|
||||
fn virtio_pause(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
fn virtio_resume(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
}
|
||||
};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! virtio_pausable_trait_inner {
|
||||
() => {
|
||||
@ -151,10 +160,7 @@ macro_rules! virtio_pausable_trait_inner {
|
||||
#[macro_export]
|
||||
macro_rules! virtio_pausable_trait {
|
||||
($type:ident) => {
|
||||
trait VirtioPausable {
|
||||
fn virtio_pause(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
fn virtio_resume(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
}
|
||||
virtio_pausable_trait_definition!();
|
||||
|
||||
impl VirtioPausable for $type {
|
||||
virtio_pausable_trait_inner!();
|
||||
@ -162,10 +168,7 @@ macro_rules! virtio_pausable_trait {
|
||||
};
|
||||
|
||||
($type:ident, T: $($bounds:tt)+) => {
|
||||
trait VirtioPausable {
|
||||
fn virtio_pause(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
fn virtio_resume(&mut self) -> std::result::Result<(), MigratableError>;
|
||||
}
|
||||
virtio_pausable_trait_definition!();
|
||||
|
||||
impl<T: $($bounds)+ > VirtioPausable for $type<T> {
|
||||
virtio_pausable_trait_inner!();
|
||||
@ -173,19 +176,26 @@ macro_rules! virtio_pausable_trait {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! virtio_pausable_inner {
|
||||
($type:ident) => {
|
||||
fn pause(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_pause()
|
||||
}
|
||||
|
||||
fn resume(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_resume()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! virtio_pausable {
|
||||
($type:ident) => {
|
||||
virtio_pausable_trait!($type);
|
||||
|
||||
impl Pausable for $type {
|
||||
fn pause(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_pause()
|
||||
}
|
||||
|
||||
fn resume(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_resume()
|
||||
}
|
||||
virtio_pausable_inner!($type);
|
||||
}
|
||||
};
|
||||
|
||||
@ -194,13 +204,7 @@ macro_rules! virtio_pausable {
|
||||
virtio_pausable_trait!($type, T: $($bounds)+);
|
||||
|
||||
impl<T: $($bounds)+ > Pausable for $type<T> {
|
||||
fn pause(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_pause()
|
||||
}
|
||||
|
||||
fn resume(&mut self) -> result::Result<(), MigratableError> {
|
||||
self.virtio_resume()
|
||||
}
|
||||
virtio_pausable_inner!($type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user