#![allow(missing_docs)]
#[cfg(feature = "snapshot")]
#[allow(unused_imports)]
use crate::io::Streams;
#[cfg(feature = "snapshot")]
#[allow(unused_imports)]
use crate::runtime::Container;
#[allow(unused_imports)]
use std::path::{Path, PathBuf};
#[cfg(feature = "snapshot")]
#[allow(unused_imports)]
use std::time::Duration;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ContainerSnapshotState {
pub(crate) staging_dir: PathBuf,
pub(crate) machine_identifier: Vec<u8>,
pub(crate) network_macs: Vec<String>,
}
impl ContainerSnapshotState {
#[must_use]
pub fn new(
staging_dir: impl Into<PathBuf>,
machine_identifier: Vec<u8>,
network_macs: Vec<String>,
) -> Self {
Self {
staging_dir: staging_dir.into(),
machine_identifier,
network_macs,
}
}
#[must_use]
pub fn staging_dir(&self) -> &Path {
&self.staging_dir
}
#[must_use]
pub fn machine_identifier(&self) -> &[u8] {
&self.machine_identifier
}
#[must_use]
pub fn network_macs(&self) -> &[String] {
&self.network_macs
}
}
#[cfg(feature = "snapshot")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ContainerRestoreTimings {
pub(crate) staging: Duration,
vm_restore: Duration,
vminitd_connect: Duration,
pub(crate) rootfs_stage: Option<RestoredRootfsStage>,
}
#[cfg(feature = "snapshot")]
impl ContainerRestoreTimings {
#[must_use]
pub const fn new(
staging: Duration,
vm_restore: Duration,
vminitd_connect: Duration,
rootfs_stage: Option<RestoredRootfsStage>,
) -> Self {
Self {
staging,
vm_restore,
vminitd_connect,
rootfs_stage,
}
}
#[must_use]
pub const fn staging(self) -> Duration {
self.staging
}
#[must_use]
pub const fn vm_restore(self) -> Duration {
self.vm_restore
}
#[must_use]
pub const fn vminitd_connect(self) -> Duration {
self.vminitd_connect
}
#[must_use]
pub const fn rootfs_stage(self) -> Option<RestoredRootfsStage> {
self.rootfs_stage
}
}
#[cfg(feature = "snapshot")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum RestoredRootfsStageMethod {
Clone,
#[default]
Copy,
Rebuild,
}
#[cfg(feature = "snapshot")]
impl RestoredRootfsStageMethod {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Clone => "clone",
Self::Copy => "copy",
Self::Rebuild => "rebuild",
}
}
}
#[cfg(feature = "snapshot")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct RestoredRootfsStage {
method: RestoredRootfsStageMethod,
source_bytes: u64,
elapsed: Duration,
}
#[cfg(feature = "snapshot")]
impl RestoredRootfsStage {
#[must_use]
pub const fn new(
method: RestoredRootfsStageMethod,
source_bytes: u64,
elapsed: Duration,
) -> Self {
Self {
method,
source_bytes,
elapsed,
}
}
#[must_use]
pub const fn method(self) -> RestoredRootfsStageMethod {
self.method
}
#[must_use]
pub const fn source_bytes(self) -> u64 {
self.source_bytes
}
#[must_use]
pub const fn elapsed(self) -> Duration {
self.elapsed
}
}
#[cfg(feature = "snapshot")]
#[derive(Debug)]
pub struct TimedContainerRestore {
pub(crate) container: Container<Streams>,
timings: ContainerRestoreTimings,
}
#[cfg(feature = "snapshot")]
impl TimedContainerRestore {
#[must_use]
pub const fn new(container: Container<Streams>, timings: ContainerRestoreTimings) -> Self {
Self { container, timings }
}
#[must_use]
pub const fn timings(&self) -> ContainerRestoreTimings {
self.timings
}
#[must_use]
pub fn into_parts(self) -> (Container<Streams>, ContainerRestoreTimings) {
(self.container, self.timings)
}
}