diff --git a/Cargo.lock b/Cargo.lock index 83915ecb19e..71d502afb95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,8 +1391,8 @@ dependencies = [ name = "nydus-upgrade" version = "0.1.0" dependencies = [ + "dbs-snapshot", "sendfd", - "snapshot", "thiserror", "versionize", "versionize_derive", @@ -1951,17 +1951,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" -[[package]] -name = "snapshot" -version = "0.1.0" -source = "git+https://github.com/firecracker-microvm/firecracker?tag=v1.4.1#02dd0328589c59ae11b7ad13eaf412410f8e72e1" -dependencies = [ - "libc", - "thiserror", - "versionize", - "versionize_derive", -] - [[package]] name = "socket2" version = "0.4.4" diff --git a/service/src/fs_service.rs b/service/src/fs_service.rs index a834f331206..a1ee0a6b683 100644 --- a/service/src/fs_service.rs +++ b/service/src/fs_service.rs @@ -29,7 +29,7 @@ use crate::upgrade::UpgradeManager; use crate::{Error, FsBackendDescriptor, FsBackendType, Result}; /// Request structure to mount a filesystem instance. -#[derive(Clone, Versionize)] +#[derive(Clone, Versionize, Debug)] pub struct FsBackendMountCmd { /// Filesystem type. pub fs_type: FsBackendType, diff --git a/service/src/upgrade.rs b/service/src/upgrade.rs index 6295ab3d3e2..268c2dda0ab 100644 --- a/service/src/upgrade.rs +++ b/service/src/upgrade.rs @@ -83,7 +83,7 @@ struct FscacheState { path: String, } -#[derive(Versionize, Clone)] +#[derive(Versionize, Clone, Debug)] struct MountStateWrapper { cmd: FsBackendMountCmd, vfs_index: u8, @@ -277,12 +277,12 @@ pub mod fscache_upgrade { use versionize::{VersionMap, Versionize, VersionizeResult}; use versionize_derive::Versionize; - #[derive(Versionize, Clone)] + #[derive(Versionize, Clone, Debug)] pub struct BlobCacheEntryState { json_str: String, } - #[derive(Versionize, Clone, Default)] + #[derive(Versionize, Clone, Default, Debug)] pub struct FscacheBackendState { blob_entry_list: Vec<(String, BlobCacheEntryState)>, threads: usize, @@ -394,7 +394,7 @@ pub mod fusedev_upgrade { use versionize::{VersionMap, Versionize, VersionizeResult}; use versionize_derive::Versionize; - #[derive(Versionize, Clone, Default)] + #[derive(Versionize, Clone, Default, Debug)] pub struct FusedevBackendState { fs_mount_cmd_list: Vec<(String, MountStateWrapper)>, vfs_state_data: Vec, diff --git a/upgrade/Cargo.toml b/upgrade/Cargo.toml index ee78c92cabc..9b13902cae5 100644 --- a/upgrade/Cargo.toml +++ b/upgrade/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" [dependencies] sendfd = "0.4.3" -snapshot = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v1.4.1" } +dbs-snapshot = "1.5.0" thiserror = "1" versionize_derive = "0.1.6" versionize = "0.1.10" diff --git a/upgrade/src/backend/mod.rs b/upgrade/src/backend/mod.rs index 435d91126c8..06dc79ecf50 100644 --- a/upgrade/src/backend/mod.rs +++ b/upgrade/src/backend/mod.rs @@ -1,3 +1,7 @@ +// Copyright 2023 Nydus Developers. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + use std::{io, os::fd::RawFd}; pub mod unix_domain_socket; diff --git a/upgrade/src/persist.rs b/upgrade/src/persist.rs index adced9b1d52..8a86ecb18fe 100644 --- a/upgrade/src/persist.rs +++ b/upgrade/src/persist.rs @@ -2,10 +2,11 @@ // // SPDX-License-Identifier: Apache-2.0 +use std::fmt::Debug; use std::io::{Error as IoError, ErrorKind, Result}; use std::{any::TypeId, collections::HashMap}; -use snapshot::Snapshot; +use dbs_snapshot::Snapshot; use versionize::{VersionMap, Versionize}; /// A list of versions. @@ -14,7 +15,7 @@ type Versions = Vec>; /// A trait for snapshotting. /// This trait is used to save and restore a struct /// which implements `versionize::Versionize`. -pub trait Snapshotter: Versionize + Sized { +pub trait Snapshotter: Versionize + Sized + Debug { /// Returns a list of versions. fn get_versions() -> Versions; @@ -55,11 +56,12 @@ pub trait Snapshotter: Versionize + Sized { /// Restores the struct from a `Vec`. fn restore(buf: &mut Vec) -> Result { - Snapshot::load(&mut buf.as_slice(), buf.len(), Self::new_version_map()).map_err(|e| { - IoError::new( + match Snapshot::load(&mut buf.as_slice(), buf.len(), Self::new_version_map()) { + Ok((o, _)) => Ok(o), + Err(e) => Err(IoError::new( ErrorKind::Other, format!("Failed to load snapshot: {:?}", e), - ) - }) + )), + } } }