Skip to content

Commit

Permalink
Merge pull request #798 from jiangliu/nydus-image-default
Browse files Browse the repository at this point in the history
Change default value of nydus-image and optimize output
  • Loading branch information
jiangliu authored Nov 6, 2022
2 parents ae0cf4c + 49d7dd8 commit 9e49996
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 101 deletions.
69 changes: 67 additions & 2 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ use std::io::Result;
use std::path::PathBuf;

use flexi_logger::{
self, colored_opt_format, opt_format, Cleanup, Criterion, FileSpec, Logger, Naming,
self, style, Cleanup, Criterion, DeferredNow, FileSpec, Logger, Naming,
TS_DASHES_BLANK_COLONS_DOT_BLANK,
};
use log::LevelFilter;
use log::{Level, LevelFilter, Record};

pub mod signal;

Expand Down Expand Up @@ -114,6 +115,70 @@ impl BuildTimeInfo {
}
}

fn get_file_name<'a>(record: &'a Record) -> Option<&'a str> {
record.file().map(|v| match v.rfind("/src/") {
None => v,
Some(pos) => match v[..pos].rfind('/') {
None => &v[pos..],
Some(p) => &v[p..],
},
})
}

fn opt_format(
w: &mut dyn std::io::Write,
now: &mut DeferredNow,
record: &Record,
) -> std::result::Result<(), std::io::Error> {
let level = record.level();
if level == Level::Info {
write!(
w,
"[{}] {} {}",
now.format(TS_DASHES_BLANK_COLONS_DOT_BLANK),
record.level(),
&record.args()
)
} else {
write!(
w,
"[{}] {} [{}:{}] {}",
now.format(TS_DASHES_BLANK_COLONS_DOT_BLANK),
record.level(),
get_file_name(record).unwrap_or("<unnamed>"),
record.line().unwrap_or(0),
&record.args()
)
}
}

fn colored_opt_format(
w: &mut dyn std::io::Write,
now: &mut DeferredNow,
record: &Record,
) -> std::result::Result<(), std::io::Error> {
let level = record.level();
if level == Level::Info {
write!(
w,
"[{}] {} {}",
style(level).paint(now.format(TS_DASHES_BLANK_COLONS_DOT_BLANK)),
style(level).paint(level.to_string()),
style(level).paint(&record.args().to_string())
)
} else {
write!(
w,
"[{}] {} [{}:{}] {}",
style(level).paint(now.format(TS_DASHES_BLANK_COLONS_DOT_BLANK)),
style(level).paint(level.to_string()),
get_file_name(record).unwrap_or("<unnamed>"),
record.line().unwrap_or(0),
style(level).paint(&record.args().to_string())
)
}
}

/// Setup logging infrastructure for application.
///
/// `log_file_path` is an absolute path to logging files or relative path from current working
Expand Down
3 changes: 1 addition & 2 deletions contrib/nydusify/pkg/checker/tool/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ func NewBuilder(binaryPath string) *Builder {
func (builder *Builder) Check(option BuilderOption) error {
args := []string{
"check",
"--bootstrap",
option.BootstrapPath,
"--log-level",
"warn",
"--output-json",
option.DebugOutputPath,
option.BootstrapPath,
}

cmd := exec.Command(builder.binaryPath, args...)
Expand Down
1 change: 0 additions & 1 deletion contrib/nydusify/pkg/checker/tool/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (p *Inspector) Inspect(option InspectOption) (interface{}, error) {
)
args = []string{
"inspect",
"--bootstrap",
option.Bootstrap,
"--request",
}
Expand Down
36 changes: 18 additions & 18 deletions rafs/src/metadata/layout/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,19 @@ impl RafsV5SuperBlock {
pub fn set_compressor(&mut self, compressor: compress::Algorithm) {
let c: RafsSuperFlags = compressor.into();

self.s_flags &= !RafsSuperFlags::COMPRESS_NONE.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_LZ4_BLOCK.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_GZIP.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_ZSTD.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_NONE.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_LZ4.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_GZIP.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_ZSTD.bits();
self.s_flags |= c.bits();
}

/// Set message digest algorithm to handle chunk of the Rafs filesystem.
pub fn set_digester(&mut self, digester: digest::Algorithm) {
let c: RafsSuperFlags = digester.into();

self.s_flags &= !RafsSuperFlags::DIGESTER_BLAKE3.bits();
self.s_flags &= !RafsSuperFlags::DIGESTER_SHA256.bits();
self.s_flags &= !RafsSuperFlags::HASH_BLAKE3.bits();
self.s_flags &= !RafsSuperFlags::HASH_SHA256.bits();
self.s_flags |= c.bits();
}

Expand Down Expand Up @@ -1726,51 +1726,51 @@ pub mod tests {
fn test_rafsv5_superflags() {
assert_eq!(
RafsSuperFlags::from(digest::Algorithm::Blake3),
RafsSuperFlags::DIGESTER_BLAKE3
RafsSuperFlags::HASH_BLAKE3
);
assert_eq!(
RafsSuperFlags::from(digest::Algorithm::Sha256),
RafsSuperFlags::DIGESTER_SHA256
RafsSuperFlags::HASH_SHA256
);
assert_eq!(
digest::Algorithm::from(RafsSuperFlags::DIGESTER_BLAKE3),
digest::Algorithm::from(RafsSuperFlags::HASH_BLAKE3),
digest::Algorithm::Blake3
);
assert_eq!(
digest::Algorithm::from(RafsSuperFlags::DIGESTER_SHA256),
digest::Algorithm::from(RafsSuperFlags::HASH_SHA256),
digest::Algorithm::Sha256
);

assert_eq!(
RafsSuperFlags::from(compress::Algorithm::Zstd),
RafsSuperFlags::COMPRESS_ZSTD
RafsSuperFlags::COMPRESSION_ZSTD
);
assert_eq!(
RafsSuperFlags::from(compress::Algorithm::GZip),
RafsSuperFlags::COMPRESS_GZIP
RafsSuperFlags::COMPRESSION_GZIP
);
assert_eq!(
RafsSuperFlags::from(compress::Algorithm::Lz4Block),
RafsSuperFlags::COMPRESS_LZ4_BLOCK
RafsSuperFlags::COMPRESSION_LZ4
);
assert_eq!(
RafsSuperFlags::from(compress::Algorithm::None),
RafsSuperFlags::COMPRESS_NONE
RafsSuperFlags::COMPRESSION_NONE
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_ZSTD),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_ZSTD),
compress::Algorithm::Zstd
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_GZIP),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_GZIP),
compress::Algorithm::GZip
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_LZ4_BLOCK),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_LZ4),
compress::Algorithm::Lz4Block
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_NONE),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_NONE),
compress::Algorithm::None
);
}
Expand Down
22 changes: 11 additions & 11 deletions rafs/src/metadata/layout/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ impl RafsV6SuperBlockExt {
/// Validate the Rafs v6 super block.
pub fn validate(&self) -> Result<()> {
let mut flags = self.flags();
flags &= RafsSuperFlags::COMPRESS_NONE.bits()
| RafsSuperFlags::COMPRESS_LZ4_BLOCK.bits()
| RafsSuperFlags::COMPRESS_GZIP.bits()
| RafsSuperFlags::COMPRESS_ZSTD.bits();
flags &= RafsSuperFlags::COMPRESSION_NONE.bits()
| RafsSuperFlags::COMPRESSION_LZ4.bits()
| RafsSuperFlags::COMPRESSION_GZIP.bits()
| RafsSuperFlags::COMPRESSION_ZSTD.bits();
if flags.count_ones() != 1 {
return Err(einval!(format!(
"invalid flags {:#x} related to compression algorithm in Rafs v6 extended superblock",
Expand All @@ -354,7 +354,7 @@ impl RafsV6SuperBlockExt {
}

let mut flags = self.flags();
flags &= RafsSuperFlags::DIGESTER_BLAKE3.bits() | RafsSuperFlags::DIGESTER_SHA256.bits();
flags &= RafsSuperFlags::HASH_BLAKE3.bits() | RafsSuperFlags::HASH_SHA256.bits();
if flags.count_ones() != 1 {
return Err(einval!(format!(
"invalid flags {:#x} related to digest algorithm in Rafs v6 extended superblock",
Expand Down Expand Up @@ -384,10 +384,10 @@ impl RafsV6SuperBlockExt {
pub fn set_compressor(&mut self, compressor: compress::Algorithm) {
let c: RafsSuperFlags = compressor.into();

self.s_flags &= !RafsSuperFlags::COMPRESS_NONE.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_LZ4_BLOCK.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_GZIP.bits();
self.s_flags &= !RafsSuperFlags::COMPRESS_ZSTD.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_NONE.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_LZ4.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_GZIP.bits();
self.s_flags &= !RafsSuperFlags::COMPRESSION_ZSTD.bits();
self.s_flags |= c.bits();
}

Expand All @@ -405,8 +405,8 @@ impl RafsV6SuperBlockExt {
pub fn set_digester(&mut self, digester: digest::Algorithm) {
let c: RafsSuperFlags = digester.into();

self.s_flags &= !RafsSuperFlags::DIGESTER_BLAKE3.bits();
self.s_flags &= !RafsSuperFlags::DIGESTER_SHA256.bits();
self.s_flags &= !RafsSuperFlags::HASH_BLAKE3.bits();
self.s_flags &= !RafsSuperFlags::HASH_SHA256.bits();
self.s_flags |= c.bits();
}

Expand Down
66 changes: 32 additions & 34 deletions rafs/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,24 @@ bitflags! {
/// Rafs filesystem feature flags.
#[derive(Serialize)]
pub struct RafsSuperFlags: u64 {
/// V5: Data chunks are not compressed.
const COMPRESS_NONE = 0x0000_0001;
/// V5: Data chunks are compressed with lz4_block.
const COMPRESS_LZ4_BLOCK = 0x0000_0002;
/// V5: Use blake3 hash algorithm to calculate digest.
const DIGESTER_BLAKE3 = 0x0000_0004;
/// V5: Use sha256 hash algorithm to calculate digest.
const DIGESTER_SHA256 = 0x0000_0008;
/// Data chunks are not compressed.
const COMPRESSION_NONE = 0x0000_0001;
/// Data chunks are compressed with lz4_block.
const COMPRESSION_LZ4 = 0x0000_0002;
/// Use blake3 hash algorithm to calculate digest.
const HASH_BLAKE3 = 0x0000_0004;
/// Use sha256 hash algorithm to calculate digest.
const HASH_SHA256 = 0x0000_0008;
/// Inode has explicit uid gid fields.
///
/// If unset, use nydusd process euid/egid for all inodes at runtime.
const EXPLICIT_UID_GID = 0x0000_0010;
/// Inode may have associated extended attributes.
const HAS_XATTR = 0x0000_0020;
// V5: Data chunks are compressed with gzip
const COMPRESS_GZIP = 0x0000_0040;
// V5: Data chunks are compressed with zstd
const COMPRESS_ZSTD = 0x0000_0080;
// Data chunks are compressed with gzip
const COMPRESSION_GZIP = 0x0000_0040;
// Data chunks are compressed with zstd
const COMPRESSION_ZSTD = 0x0000_0080;
}
}

Expand All @@ -285,8 +285,8 @@ impl Display for RafsSuperFlags {
impl From<RafsSuperFlags> for digest::Algorithm {
fn from(flags: RafsSuperFlags) -> Self {
match flags {
x if x.contains(RafsSuperFlags::DIGESTER_BLAKE3) => digest::Algorithm::Blake3,
x if x.contains(RafsSuperFlags::DIGESTER_SHA256) => digest::Algorithm::Sha256,
x if x.contains(RafsSuperFlags::HASH_BLAKE3) => digest::Algorithm::Blake3,
x if x.contains(RafsSuperFlags::HASH_SHA256) => digest::Algorithm::Sha256,
_ => digest::Algorithm::Blake3,
}
}
Expand All @@ -295,19 +295,19 @@ impl From<RafsSuperFlags> for digest::Algorithm {
impl From<digest::Algorithm> for RafsSuperFlags {
fn from(d: digest::Algorithm) -> RafsSuperFlags {
match d {
digest::Algorithm::Blake3 => RafsSuperFlags::DIGESTER_BLAKE3,
digest::Algorithm::Sha256 => RafsSuperFlags::DIGESTER_SHA256,
digest::Algorithm::Blake3 => RafsSuperFlags::HASH_BLAKE3,
digest::Algorithm::Sha256 => RafsSuperFlags::HASH_SHA256,
}
}
}

impl From<RafsSuperFlags> for compress::Algorithm {
fn from(flags: RafsSuperFlags) -> Self {
match flags {
x if x.contains(RafsSuperFlags::COMPRESS_NONE) => compress::Algorithm::None,
x if x.contains(RafsSuperFlags::COMPRESS_LZ4_BLOCK) => compress::Algorithm::Lz4Block,
x if x.contains(RafsSuperFlags::COMPRESS_GZIP) => compress::Algorithm::GZip,
x if x.contains(RafsSuperFlags::COMPRESS_ZSTD) => compress::Algorithm::Zstd,
x if x.contains(RafsSuperFlags::COMPRESSION_NONE) => compress::Algorithm::None,
x if x.contains(RafsSuperFlags::COMPRESSION_LZ4) => compress::Algorithm::Lz4Block,
x if x.contains(RafsSuperFlags::COMPRESSION_GZIP) => compress::Algorithm::GZip,
x if x.contains(RafsSuperFlags::COMPRESSION_ZSTD) => compress::Algorithm::Zstd,
_ => compress::Algorithm::Lz4Block,
}
}
Expand All @@ -316,10 +316,10 @@ impl From<RafsSuperFlags> for compress::Algorithm {
impl From<compress::Algorithm> for RafsSuperFlags {
fn from(c: compress::Algorithm) -> RafsSuperFlags {
match c {
compress::Algorithm::None => RafsSuperFlags::COMPRESS_NONE,
compress::Algorithm::Lz4Block => RafsSuperFlags::COMPRESS_LZ4_BLOCK,
compress::Algorithm::GZip => RafsSuperFlags::COMPRESS_GZIP,
compress::Algorithm::Zstd => RafsSuperFlags::COMPRESS_ZSTD,
compress::Algorithm::None => RafsSuperFlags::COMPRESSION_NONE,
compress::Algorithm::Lz4Block => RafsSuperFlags::COMPRESSION_LZ4,
compress::Algorithm::GZip => RafsSuperFlags::COMPRESSION_GZIP,
compress::Algorithm::Zstd => RafsSuperFlags::COMPRESSION_ZSTD,
}
}
}
Expand Down Expand Up @@ -917,24 +917,24 @@ mod tests {
#[test]
fn test_rafs_compressor() {
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_NONE),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_NONE),
compress::Algorithm::None
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_GZIP),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_GZIP),
compress::Algorithm::GZip
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_LZ4_BLOCK),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_LZ4),
compress::Algorithm::Lz4Block
);
assert_eq!(
compress::Algorithm::from(RafsSuperFlags::COMPRESS_ZSTD),
compress::Algorithm::from(RafsSuperFlags::COMPRESSION_ZSTD),
compress::Algorithm::Zstd
);
assert_eq!(
compress::Algorithm::from(
RafsSuperFlags::COMPRESS_ZSTD | RafsSuperFlags::COMPRESS_LZ4_BLOCK,
RafsSuperFlags::COMPRESSION_ZSTD | RafsSuperFlags::COMPRESSION_LZ4,
),
compress::Algorithm::Lz4Block
);
Expand All @@ -947,17 +947,15 @@ mod tests {
#[test]
fn test_rafs_digestor() {
assert_eq!(
digest::Algorithm::from(RafsSuperFlags::DIGESTER_BLAKE3),
digest::Algorithm::from(RafsSuperFlags::HASH_BLAKE3),
digest::Algorithm::Blake3
);
assert_eq!(
digest::Algorithm::from(RafsSuperFlags::DIGESTER_SHA256),
digest::Algorithm::from(RafsSuperFlags::HASH_SHA256),
digest::Algorithm::Sha256
);
assert_eq!(
digest::Algorithm::from(
RafsSuperFlags::DIGESTER_SHA256 | RafsSuperFlags::DIGESTER_BLAKE3,
),
digest::Algorithm::from(RafsSuperFlags::HASH_SHA256 | RafsSuperFlags::HASH_BLAKE3,),
digest::Algorithm::Blake3
);
assert_eq!(
Expand Down
Loading

0 comments on commit 9e49996

Please sign in to comment.