Skip to content
New issue

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

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

Already on GitHub? # to your account

Backports two bugfixes from master into stable/v2.1 #1216

Merged
merged 3 commits into from
Apr 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
2 changes: 1 addition & 1 deletion rafs/src/metadata/direct_v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl OndiskInodeWrapper {
let len = if div_round_up(self.size(), EROFS_BLOCK_SIZE) as usize == block_index + 1
{
if self.size() % EROFS_BLOCK_SIZE == 0 {
EROFS_BLOCK_SIZE as usize
(EROFS_BLOCK_SIZE - s) as usize
} else {
(self.size() % EROFS_BLOCK_SIZE - s) as usize
}
Expand Down
50 changes: 37 additions & 13 deletions src/bin/nydus-image/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,20 +1101,44 @@ impl Node {

pub fn v6_dir_d_size(&self, tree: &Tree) -> Result<u64> {
ensure!(self.is_dir(), "{} is not a directory", self);
// Use length in byte, instead of length in character.
let mut d_size: u64 = (".".as_bytes().len()
+ size_of::<RafsV6Dirent>()
+ "..".as_bytes().len()
+ size_of::<RafsV6Dirent>()) as u64;

// Safe as we have check tree above.
for child in tree.children.iter() {
let len = child.node.name().as_bytes().len() + size_of::<RafsV6Dirent>();
// erofs disk format requires dirent to be aligned with 4096.
if (d_size % EROFS_BLOCK_SIZE) + len as u64 > EROFS_BLOCK_SIZE {
d_size = div_round_up(d_size as u64, EROFS_BLOCK_SIZE) * EROFS_BLOCK_SIZE;
let mut d_size = 0;

// Sort all children if "." and ".." are not at the head after sorting.
if !tree.children.is_empty() && tree.children[0].node.name() < ".." {
let mut children = Vec::with_capacity(tree.children.len() + 2);
let dot = OsString::from(".");
let dotdot = OsString::from("..");
children.push(dot.as_os_str());
children.push(dotdot.as_os_str());
for child in tree.children.iter() {
children.push(child.node.name());
}
children.sort_unstable();

for c in children {
// Use length in byte, instead of length in character.
let len = c.as_bytes().len() + size_of::<RafsV6Dirent>();
// erofs disk format requires dirent to be aligned to block size.
if (d_size % EROFS_BLOCK_SIZE) + len as u64 > EROFS_BLOCK_SIZE {
d_size = round_up(d_size as u64, EROFS_BLOCK_SIZE);
}
d_size += len as u64;
}
} else {
// Avoid sorting again if "." and ".." are at the head after sorting due to that
// `tree.children` has already been sorted.
d_size = (".".as_bytes().len()
+ size_of::<RafsV6Dirent>()
+ "..".as_bytes().len()
+ size_of::<RafsV6Dirent>()) as u64;
for child in tree.children.iter() {
let len = child.node.name().as_bytes().len() + size_of::<RafsV6Dirent>();
// erofs disk format requires dirent to be aligned to block size.
if (d_size % EROFS_BLOCK_SIZE) + len as u64 > EROFS_BLOCK_SIZE {
d_size = round_up(d_size as u64, EROFS_BLOCK_SIZE);
}
d_size += len as u64;
}
d_size += len as u64;
}

Ok(d_size)
Expand Down
2 changes: 1 addition & 1 deletion tests/bats/compile_nydus_snapshotter.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setup() {
}

@test "compile nydus snapshotter" {
docker run --rm -v /tmp/nydus-snapshotter:/nydus-snapshotter $compile_image bash -c 'cd /nydus-snapshotter && make clear && make'
docker run --rm -v /tmp/nydus-snapshotter:/nydus-snapshotter $compile_image bash -c 'cd /nydus-snapshotter && make clean && make'
if [ -f "/tmp/nydus-snapshotter/bin/containerd-nydus-grpc" ]; then
/usr/bin/cp -f /tmp/nydus-snapshotter/bin/containerd-nydus-grpc /usr/local/bin/
echo "nydus-snapshotter version"
Expand Down
3 changes: 3 additions & 0 deletions tests/bats/install_bats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ echo "Install BATS from sources"
rm -rf $LOCAL_DIR
mkdir -p $LOCAL_DIR
pushd "${LOCAL_DIR}"
git config pull.rebase false
git config pull.rebase true
git config pull.ff only
git clone "${BATS_REPO}" || true
cd bats-core
sh -c "./install.sh /usr"
Expand Down