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

feat: notifying incosistent fs version problem with exit code #1424

Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rafs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde = { version = "1.0.110", features = ["serde_derive", "rc"] }
serde_json = "1.0.53"
vm-memory = "0.10"
fuse-backend-rs = "^0.10.3"
thiserror = "1"

nydus-api = { version = "0.3", path = "../api" }
nydus-storage = { version = "0.6", path = "../storage", features = ["backend-localfs"] }
Expand Down
67 changes: 40 additions & 27 deletions rafs/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use std::path::{Component, Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use thiserror::Error;

use anyhow::bail;
use anyhow::{bail, ensure};
use fuse_backend_rs::abi::fuse_abi::Attr;
use fuse_backend_rs::api::filesystem::Entry;
use nydus_api::{ConfigV2, RafsConfigV2};
Expand Down Expand Up @@ -409,44 +410,56 @@ pub struct RafsSuperConfig {
pub is_tarfs_mode: bool,
}

#[derive(Error, Debug)]
pub enum MergeError {
PerseidMeteor marked this conversation as resolved.
Show resolved Hide resolved
#[error("Inconsistent RAFS Filesystem: {0}")]
InconsistentFilesystem(String),
#[error(transparent)]
Other(#[from] anyhow::Error),
}

impl RafsSuperConfig {
/// Check compatibility for two RAFS filesystems.
pub fn check_compatibility(&self, meta: &RafsSuperMeta) -> Result<()> {
if self.chunk_size != meta.chunk_size {
return Err(einval!(format!(
pub fn check_compatibility(&self, meta: &RafsSuperMeta) -> anyhow::Result<()> {
ensure!(
self.chunk_size == meta.chunk_size,
MergeError::InconsistentFilesystem(format!(
"Inconsistent configuration of chunk_size: {} vs {}",
self.chunk_size, meta.chunk_size
)));
}
))
);

if self.explicit_uidgid != meta.explicit_uidgid() {
return Err(einval!(format!(
"Using inconsistent explicit_uidgid setting {:?}, target explicit_uidgid setting {:?}",
self.explicit_uidgid,
meta.explicit_uidgid()
)));
}
ensure!(
self.explicit_uidgid == meta.explicit_uidgid(),
MergeError::InconsistentFilesystem(format!(
"Using inconsistent explicit_uidgid setting {:?}, target explicit_uidgid setting {:?}",
self.explicit_uidgid,
meta.explicit_uidgid()
))
);

if u32::from(self.version) != meta.version {
return Err(einval!(format!(
let meta_version = RafsVersion::try_from(meta.version);
ensure!(
u32::from(self.version) == meta.version,
MergeError::InconsistentFilesystem(format!(
"Using inconsistent RAFS version {:?}, target RAFS version {:?}",
self.version,
RafsVersion::try_from(meta.version)?
)));
}
self.version, meta_version
))
);

if self.version == RafsVersion::V5 && self.digester != meta.get_digester() {
return Err(einval!(format!(
ensure!(
self.version != RafsVersion::V5 || self.digester == meta.get_digester(),
MergeError::InconsistentFilesystem(format!(
"RAFS v5 can not support different digest algorithm due to inode digest, {} vs {}",
self.digester,
meta.get_digester()
)));
}

))
);
let is_tarfs_mode = meta.flags.contains(RafsSuperFlags::TARTFS_MODE);
if is_tarfs_mode != self.is_tarfs_mode {
return Err(einval!(format!("Using inconsistent RAFS TARFS mode")));
}
ensure!(
is_tarfs_mode == self.is_tarfs_mode,
MergeError::InconsistentFilesystem("Using inconsistent RAFS TARFS mode".to_string(),)
);

Ok(())
}
Expand Down
11 changes: 9 additions & 2 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use nydus_builder::{
BuildContext, BuildOutput, Builder, ConversionType, DirectoryBuilder, Feature, Features,
HashChunkDict, Merger, Prefetch, PrefetchPolicy, StargzBuilder, TarballBuilder, WhiteoutSpec,
};
use nydus_rafs::metadata::{RafsSuper, RafsSuperConfig, RafsVersion};
use nydus_rafs::metadata::{MergeError, RafsSuper, RafsSuperConfig, RafsVersion};
use nydus_storage::backend::localfs::LocalFs;
use nydus_storage::backend::BlobBackend;
use nydus_storage::device::BlobFeatures;
Expand Down Expand Up @@ -758,7 +758,14 @@ fn main() -> Result<()> {
}
}
} else if let Some(matches) = cmd.subcommand_matches("merge") {
Command::merge(matches, &build_info)
let result = Command::merge(matches, &build_info);
if let Err(ref err) = result {
if let Some(MergeError::InconsistentFilesystem(_)) = err.downcast_ref::<MergeError>() {
error!("message:{}", err);
std::process::exit(2);
}
}
result
} else if let Some(matches) = cmd.subcommand_matches("check") {
Command::check(matches, &build_info)
} else if let Some(matches) = cmd.subcommand_matches("inspect") {
Expand Down