Skip to content

Commit

Permalink
feat: add rafs_version and compressor output of nydus image check
Browse files Browse the repository at this point in the history
1.Add rafs_version value, output v5 or v6.
2.Add compressor algorithm value, like ztsd.
Add rafs_version and compressor json output of nydus image check,so that more info can be get if it is necessary.

Signed-off-by: YuQiang <[email protected]>
  • Loading branch information
PerseidMeteor committed Feb 26, 2024
1 parent 7b3cc50 commit c4b1f93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ impl OutputSerializer {
build_info: &BuildTimeInfo,
blob_ids: Vec<String>,
bootstrap: &Path,
compressor: String,
rafs_version: u32,
) -> Result<()> {
let output_json: Option<PathBuf> = matches
.get_one::<String>("output-json")
Expand All @@ -126,16 +128,14 @@ impl OutputSerializer {
.write(true)
.open(f)
.with_context(|| format!("can not open output file {}", f.display()))?;
let trace = root_tracer!().dump_summary_map().unwrap_or_default();
let version = format!("{}-{}", build_info.package_ver, build_info.git_commit);
let output = Self {
version,
bootstrap: bootstrap.display().to_string(),
blobs: blob_ids,
trace,
};

serde_json::to_writer(w, &output).context("failed to write result to output file")?;
let mut out = serde_json::Map::new();
out.insert("version".to_string(), serde_json::Value::from(format!("{}-{}", build_info.package_ver, build_info.git_commit)));
out.insert("bootstrap".to_string(), serde_json::Value::from(bootstrap.display().to_string()));
out.insert("blobs".to_string(), serde_json::Value::from(blob_ids));
out.insert("trace".to_string(), serde_json::Value::from(root_tracer!().dump_summary_map().unwrap_or_default()));
out.insert("compressor".to_string(), serde_json::Value::from(compressor));
out.insert("rafs_version".to_string(), serde_json::Value::from(rafs_version));
serde_json::to_writer(w, &out).context("failed to write result to output file")?;
}

Ok(())
Expand Down Expand Up @@ -1380,7 +1380,7 @@ impl Command {
.set_blob_accessible(matches.get_one::<String>("bootstrap").is_none());

let mut validator = Validator::new(bootstrap_path, config)?;
let blobs = validator
let (blobs, compressor, rafs_version) = validator
.check(verbose)
.with_context(|| format!("failed to check bootstrap {:?}", bootstrap_path))?;

Expand All @@ -1400,7 +1400,7 @@ impl Command {
blob_ids.push(blob.blob_id().to_string());
}

OutputSerializer::dump_for_check(matches, build_info, blob_ids, bootstrap_path)?;
OutputSerializer::dump_for_check(matches, build_info, blob_ids, bootstrap_path, compressor, rafs_version)?;

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions src/bin/nydus-image/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Validator {
Ok(Self { sb })
}

pub fn check(&mut self, verbosity: bool) -> Result<Vec<Arc<BlobInfo>>> {
pub fn check(&mut self, verbosity: bool) -> Result<(Vec<Arc<BlobInfo>>, String, u32)> {
let err = "failed to load bootstrap for validator";
let tree = Tree::from_bootstrap(&self.sb, &mut ()).context(err)?;

Expand All @@ -39,7 +39,8 @@ impl Validator {
Ok(())
};
tree.walk_dfs_pre(pre)?;

Ok(self.sb.superblock.get_blob_infos())
let compressor = self.sb.meta.get_compressor().to_string();
let rafs_version = self.sb.meta.version;
Ok((self.sb.superblock.get_blob_infos(), compressor, rafs_version))
}
}

0 comments on commit c4b1f93

Please sign in to comment.