Skip to content

Commit

Permalink
feat: add fs_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 like 5 or 6.
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 <y_q_email@163.com>
  • Loading branch information
PerseidMeteor committed Feb 27, 2024
1 parent 7b3cc50 commit 7282bd2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
74 changes: 69 additions & 5 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ use nydus_builder::{
Feature, Features, HashChunkDict, Merger, Prefetch, PrefetchPolicy, StargzBuilder,
TarballBuilder, WhiteoutSpec,
};
use nydus_rafs::metadata::layout::{
RAFS_SUPER_MIN_VERSION, RAFS_SUPER_VERSION_V5, RAFS_SUPER_VERSION_V6,
};
use nydus_rafs::metadata::{MergeError, RafsSuper, RafsSuperConfig, RafsVersion};
use nydus_storage::backend::localfs::LocalFs;
use nydus_storage::backend::BlobBackend;
Expand Down Expand Up @@ -74,13 +77,19 @@ pub struct OutputSerializer {
blobs: Vec<String>,
/// Performance trace info for current build.
trace: serde_json::Map<String, serde_json::Value>,
/// Rafs version(v5 or v6).
fs_version: u32,
/// compress algorithm.
compressor: String,
}

impl OutputSerializer {
fn dump(
matches: &ArgMatches,
build_output: BuildOutput,
build_info: &BuildTimeInfo,
compressor: String,
fs_version: u32,
) -> Result<()> {
let output_json: Option<PathBuf> = matches
.get_one::<String>("output-json")
Expand All @@ -95,11 +104,19 @@ impl OutputSerializer {
.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 out_fs_version: u32 = match fs_version {
RAFS_SUPER_VERSION_V5 => 5,
RAFS_SUPER_VERSION_V6 => 6,
RAFS_SUPER_MIN_VERSION => 4,
_ => bail!("Invalid fs version: {}", fs_version),
};
let output = Self {
version,
bootstrap: build_output.bootstrap_path.unwrap_or_default(),
blobs: build_output.blobs,
trace,
fs_version: out_fs_version,
compressor,
};

serde_json::to_writer_pretty(w, &output)
Expand All @@ -114,6 +131,8 @@ impl OutputSerializer {
build_info: &BuildTimeInfo,
blob_ids: Vec<String>,
bootstrap: &Path,
compressor: String,
fs_version: u32,
) -> Result<()> {
let output_json: Option<PathBuf> = matches
.get_one::<String>("output-json")
Expand All @@ -128,11 +147,19 @@ impl OutputSerializer {
.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 out_fs_version: u32 = match fs_version {
RAFS_SUPER_VERSION_V5 => 5,
RAFS_SUPER_VERSION_V6 => 6,
RAFS_SUPER_MIN_VERSION => 4,
_ => bail!("Invalid fs version: {}", fs_version),
};
let output = Self {
version,
bootstrap: bootstrap.display().to_string(),
blobs: blob_ids,
trace,
fs_version: out_fs_version,
compressor,
};

serde_json::to_writer(w, &output).context("failed to write result to output file")?;
Expand Down Expand Up @@ -1179,7 +1206,20 @@ impl Command {
event_tracer!("euid", "{}", geteuid());
event_tracer!("egid", "{}", getegid());
info!("successfully built RAFS filesystem: \n{}", build_output);
OutputSerializer::dump(matches, build_output, build_info)
let fs_version = if version.is_v6() {
RAFS_SUPER_VERSION_V6
} else if version.is_v5() {
RAFS_SUPER_VERSION_V5
} else {
RAFS_SUPER_MIN_VERSION
};
OutputSerializer::dump(
matches,
build_output,
build_info,
compressor.to_string(),
fs_version,
)
}

fn chunkdict_save(matches: &ArgMatches) -> Result<()> {
Expand Down Expand Up @@ -1271,6 +1311,9 @@ impl Command {
ctx.configuration = config.clone();

let parent_bootstrap_path = Self::get_parent_bootstrap(matches)?;
let meta = RafsSuper::load_from_file(&source_bootstrap_paths[0], config.clone(), false)?
.0
.meta;

let output = Merger::merge(
&mut ctx,
Expand All @@ -1285,7 +1328,13 @@ impl Command {
chunk_dict_path,
config,
)?;
OutputSerializer::dump(matches, output, build_info)
OutputSerializer::dump(
matches,
output,
build_info,
meta.get_compressor().to_string(),
meta.version,
)
}

fn compact(matches: &ArgMatches, build_info: &BuildTimeInfo) -> Result<()> {
Expand Down Expand Up @@ -1319,10 +1368,18 @@ impl Command {
let config = serde_json::from_reader(file)
.with_context(|| format!("invalid config file {}", config_file_path))?;

let version = rs.meta.version;
let compressor = rs.meta.get_compressor();
if let Some(build_output) =
BlobCompactor::compact(rs, dst_bootstrap, chunk_dict, backend, &config)?
{
OutputSerializer::dump(matches, build_output, build_info)?;
OutputSerializer::dump(
matches,
build_output,
build_info,
compressor.to_string(),
version,
)?;
}
Ok(())
}
Expand Down Expand Up @@ -1380,7 +1437,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, fs_version) = validator
.check(verbose)
.with_context(|| format!("failed to check bootstrap {:?}", bootstrap_path))?;

Expand All @@ -1400,7 +1457,14 @@ 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,
fs_version,
)?;

Ok(())
}
Expand Down
11 changes: 8 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,12 @@ 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 7282bd2

Please sign in to comment.