Skip to content

Commit

Permalink
upgrade: change to use dbs_snapshot crate
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Yin <[email protected]>
  • Loading branch information
Xin Yin committed Dec 7, 2023
1 parent 4eb891c commit abbf2d9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/src/fs_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions service/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct FscacheState {
path: String,
}

#[derive(Versionize, Clone)]
#[derive(Versionize, Clone, Debug)]
struct MountStateWrapper {
cmd: FsBackendMountCmd,
vfs_index: u8,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<u8>,
Expand Down
2 changes: 1 addition & 1 deletion upgrade/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions upgrade/src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 8 additions & 6 deletions upgrade/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -14,7 +15,7 @@ type Versions = Vec<HashMap<TypeId, u16>>;
/// 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;

Expand Down Expand Up @@ -55,11 +56,12 @@ pub trait Snapshotter: Versionize + Sized {

/// Restores the struct from a `Vec<u8>`.
fn restore(buf: &mut Vec<u8>) -> Result<Self> {
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),
)
})
)),
}
}
}

0 comments on commit abbf2d9

Please sign in to comment.