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

Enhance FUSE implementation to support RAFS in TARFS mode #1158

Merged
merged 2 commits into from
Mar 20, 2023
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: 1 addition & 5 deletions rafs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use nydus_utils::{
};

use crate::metadata::{
Inode, RafsInode, RafsInodeWalkAction, RafsSuper, RafsSuperFlags, RafsSuperMeta, DOT, DOTDOT,
Inode, RafsInode, RafsInodeWalkAction, RafsSuper, RafsSuperMeta, DOT, DOTDOT,
};
use crate::{RafsError, RafsIoReader, RafsResult};

Expand Down Expand Up @@ -616,10 +616,6 @@ impl FileSystem for Rafs {
}

let real_size = cmp::min(size as u64, inode_size - offset);
if self.sb.meta.flags.contains(RafsSuperFlags::TARTFS_MODE) {
return Err(enosys!("rafs: `TARFS` mode is not supported by FUSE yet"));
}

let mut result = 0;
let mut descs = inode.alloc_bio_vecs(&self.device, offset, real_size as usize, true)?;
assert!(!descs.is_empty() && !descs[0].is_empty());
Expand Down
6 changes: 3 additions & 3 deletions rafs/src/metadata/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use nydus_utils::digest::RafsDigest;

use crate::metadata::cached_v5::CachedChunkInfoV5;
use crate::metadata::direct_v5::DirectChunkInfoV5;
use crate::metadata::direct_v6::{DirectChunkInfoV6, TarfsChunkInfo};
use crate::metadata::direct_v6::{DirectChunkInfoV6, PlainChunkInfoV6};
use crate::metadata::layout::v5::RafsV5ChunkInfo;
use crate::metadata::{RafsStore, RafsVersion};
use crate::RafsIoWrite;
Expand Down Expand Up @@ -331,7 +331,7 @@ impl ChunkWrapper {
*self = Self::V6(to_rafs_v5_chunk_info(cki_v6));
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<DirectChunkInfoV6>() {
*self = Self::V6(to_rafs_v5_chunk_info(cki_v6));
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<TarfsChunkInfo>() {
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<PlainChunkInfoV6>() {
*self = Self::V6(to_rafs_v5_chunk_info(cki_v6));
} else if let Some(cki_v5) = cki.as_any().downcast_ref::<CachedChunkInfoV5>() {
*self = Self::V5(to_rafs_v5_chunk_info(cki_v5));
Expand All @@ -349,7 +349,7 @@ fn as_blob_v5_chunk_info(cki: &dyn BlobChunkInfo) -> &dyn BlobV5ChunkInfo {
cki_v6
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<DirectChunkInfoV6>() {
cki_v6
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<TarfsChunkInfo>() {
} else if let Some(cki_v6) = cki.as_any().downcast_ref::<PlainChunkInfoV6>() {
cki_v6
} else if let Some(cki_v5) = cki.as_any().downcast_ref::<CachedChunkInfoV5>() {
cki_v5
Expand Down
66 changes: 52 additions & 14 deletions rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use crate::metadata::layout::v5::RafsV5ChunkInfo;
use crate::metadata::layout::v6::{
rafsv6_load_blob_extra_info, recover_namespace, RafsV6BlobTable, RafsV6Dirent,
RafsV6InodeChunkAddr, RafsV6InodeCompact, RafsV6InodeExtended, RafsV6OndiskInode,
RafsV6XattrEntry, RafsV6XattrIbodyHeader, EROFS_BLOCK_SIZE_4096, EROFS_BLOCK_SIZE_512,
EROFS_INODE_CHUNK_BASED, EROFS_INODE_FLAT_INLINE, EROFS_INODE_FLAT_PLAIN,
RafsV6XattrEntry, RafsV6XattrIbodyHeader, EROFS_BLOCK_BITS_9, EROFS_BLOCK_SIZE_4096,
EROFS_BLOCK_SIZE_512, EROFS_INODE_CHUNK_BASED, EROFS_INODE_FLAT_INLINE, EROFS_INODE_FLAT_PLAIN,
EROFS_INODE_SLOT_SIZE, EROFS_I_DATALAYOUT_BITS, EROFS_I_VERSION_BIT, EROFS_I_VERSION_BITS,
};
use crate::metadata::layout::{bytes_to_os_str, MetaRange, XattrName, XattrValue};
Expand Down Expand Up @@ -525,6 +525,7 @@ impl OndiskInodeWrapper {
i.mode() as u32 & libc::S_IFMT as u32
}

#[allow(clippy::too_many_arguments)]
fn make_chunk_io(
&self,
state: &Guard<Arc<DirectMappingState>>,
Expand All @@ -533,6 +534,8 @@ impl OndiskInodeWrapper {
content_offset: u32,
content_len: u32,
user_io: bool,
is_tarfs_mode: bool,
is_tail: bool,
) -> Option<BlobIoDesc> {
let blob_index = chunk_addr.blob_index();
let chunk_index = chunk_addr.blob_ci_index();
Expand All @@ -545,9 +548,29 @@ impl OndiskInodeWrapper {
);
None
}
Ok(blob) => device
.create_io_chunk(blob.blob_index(), chunk_index)
.map(|v| BlobIoDesc::new(blob, v, content_offset, content_len, user_io)),
Ok(blob) => {
if is_tarfs_mode {
let offset = (chunk_addr.block_addr() as u64) << EROFS_BLOCK_BITS_9;
let size = if is_tail {
(self.size() % self.chunk_size() as u64) as u32
} else {
self.chunk_size()
};
let chunk = PlainChunkInfoV6::new(blob_index, chunk_index, offset, size);
let chunk = Arc::new(chunk) as Arc<dyn BlobChunkInfo>;
Some(BlobIoDesc::new(
blob,
chunk.into(),
content_offset,
content_len,
user_io,
))
} else {
device
.create_io_chunk(blob.blob_index(), chunk_index)
.map(|v| BlobIoDesc::new(blob, v, content_offset, content_len, user_io))
}
}
}
}

Expand Down Expand Up @@ -777,6 +800,9 @@ impl RafsInode for OndiskInodeWrapper {
return Ok(vec);
}

let mut curr_chunk_index = head_chunk_index as u32;
let tail_chunk_index = self.get_chunk_count() - 1;
let is_tarfs_mode = state.is_tarfs();
let content_offset = (offset % chunk_size as u64) as u32;
let mut left = std::cmp::min(self.size() - offset, size as u64) as u32;
let mut content_len = std::cmp::min(chunk_size - content_offset, left);
Expand All @@ -788,6 +814,8 @@ impl RafsInode for OndiskInodeWrapper {
content_offset,
content_len,
user_io,
is_tarfs_mode,
curr_chunk_index == tail_chunk_index,
)
.ok_or_else(|| einval!("failed to get chunk information"))?;

Expand All @@ -797,9 +825,19 @@ impl RafsInode for OndiskInodeWrapper {
if left != 0 {
// Handle the rest of chunks since they shares the same content length = 0.
for c in chunks.iter().skip(1) {
curr_chunk_index += 1;
content_len = std::cmp::min(chunk_size, left);
let desc = self
.make_chunk_io(&state, device, c, 0, content_len, user_io)
.make_chunk_io(
&state,
device,
c,
0,
content_len,
user_io,
is_tarfs_mode,
curr_chunk_index == tail_chunk_index,
)
.ok_or_else(|| einval!("failed to get chunk information"))?;
if desc.blob.blob_index() != descs.blob_index() {
vec.push(descs);
Expand Down Expand Up @@ -1286,13 +1324,13 @@ impl RafsInodeExt for OndiskInodeWrapper {
} else if state.is_tarfs() {
let blob_index = chunk_addr.blob_index();
let chunk_index = chunk_addr.blob_ci_index();
let offset = (chunk_addr.block_addr() as u64) << 9;
let offset = (chunk_addr.block_addr() as u64) << EROFS_BLOCK_BITS_9;
let size = if idx == self.get_chunk_count() - 1 {
(self.size() % self.chunk_size() as u64) as u32
} else {
self.chunk_size()
};
let chunk = TarfsChunkInfo::new(blob_index, chunk_index, offset, size);
let chunk = PlainChunkInfoV6::new(blob_index, chunk_index, offset, size);
Ok(Arc::new(chunk))
} else {
let mut chunk_map = self.mapping.info.chunk_map.lock().unwrap();
Expand Down Expand Up @@ -1408,17 +1446,17 @@ impl BlobV5ChunkInfo for DirectChunkInfoV6 {
}

/// Rafs v6 fake ChunkInfo for Tarfs.
pub(crate) struct TarfsChunkInfo {
pub(crate) struct PlainChunkInfoV6 {
blob_index: u32,
chunk_index: u32,
offset: u64,
size: u32,
}

impl TarfsChunkInfo {
/// Create a new instance of [TarfsChunkInfo].
impl PlainChunkInfoV6 {
/// Create a new instance of [PlainChunkInfoV6].
pub fn new(blob_index: u32, chunk_index: u32, offset: u64, size: u32) -> Self {
TarfsChunkInfo {
PlainChunkInfoV6 {
blob_index,
chunk_index,
offset,
Expand All @@ -1429,7 +1467,7 @@ impl TarfsChunkInfo {

const TARFS_DIGEST: RafsDigest = RafsDigest { data: [0u8; 32] };

impl BlobChunkInfo for TarfsChunkInfo {
impl BlobChunkInfo for PlainChunkInfoV6 {
fn chunk_id(&self) -> &RafsDigest {
&TARFS_DIGEST
}
Expand Down Expand Up @@ -1467,7 +1505,7 @@ impl BlobChunkInfo for TarfsChunkInfo {
}
}

impl BlobV5ChunkInfo for TarfsChunkInfo {
impl BlobV5ChunkInfo for PlainChunkInfoV6 {
fn index(&self) -> u32 {
self.chunk_index
}
Expand Down