Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nydus image #350

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/bin/nydus-image/builder/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,13 @@ impl DiffBuilder {
let ctx = Arc::new(ctx.clone());
let hint_path_idx = idx + base;
let hint_path = paths[hint_path_idx].clone();
let snapshot_path = paths[idx].clone();
let chunk_dict = chunk_dict.clone();
let worker = thread::spawn(move || -> Result<(Option<BlobContext>, ChunkMap)> {
info!("[{}] diff building with hint {:?}", idx, hint_path);
info!(
"[{}: {:?}] diff building with hint {:?}",
idx, snapshot_path, hint_path
);

let snapshot_idx = idx as u32;
let mut blob_nodes = walk_all(ctx.as_ref(), hint_path.clone(), hint_path)?;
Expand Down
40 changes: 32 additions & 8 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::fs::{self, metadata, DirEntry, File, OpenOptions};
use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};
use clap::{App, Arg, SubCommand};
use clap::{App, Arg, ArgMatches, SubCommand};
use nix::unistd::{getegid, geteuid};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -132,11 +132,9 @@ impl OutputSerializer {
}
}

fn main() -> Result<()> {
let (bti_string, build_info) = BuildTimeInfo::dump(crate_version!());

fn prepare_cmd_args(bti_string: String) -> ArgMatches<'static> {
// TODO: Try to use yaml to define below options
let cmd = App::new("")
App::new("")
.version(bti_string.as_str())
.author(crate_authors!())
.about("Build or inspect RAFS filesystems for nydus accelerated container images.")
Expand Down Expand Up @@ -459,6 +457,15 @@ fn main() -> Result<()> {
.help("path to JSON output file")
.takes_value(true))
)
.arg(
Arg::with_name("log-file")
.long("log-file")
.short("o")
.help("Specify log file name")
.takes_value(true)
.required(false)
.global(true),
)
.arg(
Arg::with_name("log-level")
.long("log-level")
Expand All @@ -470,11 +477,28 @@ fn main() -> Result<()> {
.required(false)
.global(true),
)
.get_matches();
.get_matches()
}

fn init_log(matches: &ArgMatches) -> Result<()> {
let mut log_file = None;
if let Some(file) = matches.value_of("log-file") {
let path = PathBuf::from(file);
log_file = Some(path);
}

// Safe to unwrap because it has a default value and possible values are defined.
let level = cmd.value_of("log-level").unwrap().parse().unwrap();
setup_logging(None, level)?;
let level = matches.value_of("log-level").unwrap().parse().unwrap();

setup_logging(log_file, level).context("failed to setup logging")
}

fn main() -> Result<()> {
let (bti_string, build_info) = BuildTimeInfo::dump(crate_version!());

let cmd = prepare_cmd_args(bti_string);

init_log(&cmd)?;

register_tracer!(TraceClass::Timing, TimingTracerClass);
register_tracer!(TraceClass::Event, EventTracerClass);
Expand Down