Skip to content

Commit

Permalink
feat: add --expected-fs-version option for nydusify merge
Browse files Browse the repository at this point in the history
If nydus merge all hit  remote cache,but the fs version is not correct, this will leads to the merge is fine but the fs version maybe not user want.So add --expected-fs-version option for nydusify merge and user can specify fs version

Signed-off-by: YuQiang <[email protected]>
  • Loading branch information
PerseidMeteor committed Sep 20, 2023
1 parent 859d050 commit ef67eb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 17 additions & 2 deletions builder/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::Arc;
use anyhow::{anyhow, bail, ensure, Context, Result};
use hex::FromHex;
use nydus_api::ConfigV2;
use nydus_rafs::metadata::{RafsSuper, RafsVersion};
use nydus_rafs::metadata::{MergeError, RafsSuper, RafsVersion};
use nydus_storage::device::{BlobFeatures, BlobInfo};
use nydus_utils::crypt;

Expand Down Expand Up @@ -83,6 +83,7 @@ impl Merger {
target: ArtifactStorage,
chunk_dict: Option<PathBuf>,
config_v2: Arc<ConfigV2>,
expected_fs_version: Option<u32>,
) -> Result<BuildOutput> {
if sources.is_empty() {
bail!("source bootstrap list is empty , at least one bootstrap is required");
Expand Down Expand Up @@ -127,7 +128,13 @@ impl Merger {
sources.len(),
);
}

if let Some(expected_version) = expected_fs_version {
ensure!(
expected_version == 5 || expected_version == 6,
"invalid fs version, expected v5 or v6, found {}",
expected_version
)
}
let mut tree: Option<Tree> = None;
let mut blob_mgr = BlobManager::new(ctx.digester);
let mut blob_idx_map = HashMap::new();
Expand Down Expand Up @@ -171,6 +178,14 @@ impl Merger {
.check_compatibility(&rs.meta)?;
fs_version = RafsVersion::try_from(rs.meta.version)
.context("failed to get RAFS version number")?;
if let Some(expected_version) = expected_fs_version {
if expected_version != u32::from(fs_version) {
bail!(MergeError::InconsisentFsVersion(format!(
"Unexpected fs version, expected {:?}, actual {:?}",
expected_fs_version, fs_version
)))
}
}
ctx.compressor = rs.meta.get_compressor();
ctx.digester = rs.meta.get_digester();
// If any RAFS filesystems are encrypted, the merged boostrap will be marked as encrypted.
Expand Down
9 changes: 9 additions & 0 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,14 @@ impl Command {
.map(|item| item.trim().to_string())
.collect()
});
let expected_fs_version: Option<u32> = matches
.get_one::<String>("expected-fs-version")
.map(|value| {
value
.parse::<u32>()
.expect("invalid number in --expected-fs-version option")
});

let target_bootstrap_path = Self::get_bootstrap_storage(matches)?;
let chunk_dict_path = if let Some(arg) = matches.get_one::<String>("chunk-dict") {
Some(parse_chunk_dict_arg(arg)?)
Expand Down Expand Up @@ -1259,6 +1267,7 @@ impl Command {
target_bootstrap_path,
chunk_dict_path,
config,
expected_fs_version,
)?;
OutputSerializer::dump(matches, output, build_info)
}
Expand Down

0 comments on commit ef67eb7

Please sign in to comment.