Skip to content

Commit

Permalink
nydus: generate blob id for v5 images with inlined meta
Browse files Browse the repository at this point in the history
Generate blob id for v5 images with inlined meta, instead of use the
special blob id "xxxxx...".

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Dec 27, 2022
1 parent ebd132d commit c4090c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 8 additions & 6 deletions rafs/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,19 +671,19 @@ impl RafsSuper {

if let Err(e) = rs.load(&mut reader) {
let id = BlobInfo::get_blob_id_from_meta_path(path.as_ref())?;
let path = match TocEntryList::extract_rafs_meta(&id, config.clone()) {
let new_path = match TocEntryList::extract_rafs_meta(&id, config.clone()) {
Ok(v) => v,
Err(_e) => {
debug!("failed to load inlined RAFS meta, {}", _e);
return Err(e);
}
};
let file = OpenOptions::new().read(true).write(false).open(path)?;
let file = OpenOptions::new().read(true).write(false).open(new_path)?;
reader = Box::new(file) as RafsIoReader;
rs.load(&mut reader)?;
rs.set_blob_id_from_meta_path(path.as_ref())?;
}

rs.set_blob_meta_path(path.as_ref())?;
if (validate_digest || config.is_chunk_validation_enabled())
&& rs.meta.has_inlined_chunk_digest()
{
Expand All @@ -710,12 +710,14 @@ impl RafsSuper {
/// Set meta blob file path from which the `RafsSuper` object is loaded from.
///
/// It's used to support inlined-meta and ZRan blobs.
pub fn set_blob_meta_path(&self, meta_path: &Path) -> Result<()> {
pub fn set_blob_id_from_meta_path(&self, meta_path: &Path) -> Result<()> {
let blobs = self.superblock.get_blob_infos();
for blob in blobs.iter() {
if blob.has_feature(BlobFeatures::ZRAN) || blob.has_feature(BlobFeatures::INLINED_META)
if blob.has_feature(BlobFeatures::ZRAN)
|| blob.has_feature(BlobFeatures::INLINED_META)
|| !blob.meta_ci_is_valid()
{
blob.set_meta_path(meta_path)?;
blob.set_blob_id_from_meta_path(meta_path)?;
}
}
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions storage/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ impl BlobInfo {

/// Get the id of the blob, with special handling of `inlined-meta` case.
pub fn blob_id(&self) -> String {
if self.has_feature(BlobFeatures::INLINED_META) && !self.has_feature(BlobFeatures::ZRAN) {
if self.has_feature(BlobFeatures::INLINED_META) && !self.has_feature(BlobFeatures::ZRAN)
|| !self.meta_ci_is_valid()
{
let guard = self.meta_path.lock().unwrap();
if !guard.is_empty() {
return guard.deref().clone();
Expand Down Expand Up @@ -405,12 +407,13 @@ impl BlobInfo {
}

/// Set path for meta blob file, which will be used by `get_blob_id()` and `get_rafs_blob_id()`.
pub fn set_meta_path(&self, path: &Path) -> Result<(), Error> {
pub fn set_blob_id_from_meta_path(&self, path: &Path) -> Result<(), Error> {
*self.meta_path.lock().unwrap() = Self::get_blob_id_from_meta_path(path)?;
Ok(())
}

pub fn get_blob_id_from_meta_path(path: &Path) -> Result<String, Error> {
// Manual implementation of Path::file_prefix().
let mut id = path.file_name().ok_or_else(|| {
einval!(format!(
"failed to get blob id from meta file path {}",
Expand Down

0 comments on commit c4090c9

Please sign in to comment.