From ba6f83d2fad71882d890eb6116af3b0a5757b8f4 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Mon, 17 Apr 2023 10:24:14 +0800 Subject: [PATCH 1/3] bats: fix a failure related git Fix a failure related git ``` Your branch is up to date with 'origin/v2.1-backport'. nothing to commit, working tree clean [tone]Error: The return code of run() in run.sh is not 0 hint: discouraged. You can squelch this message by running one of the following hint: commands sometime before your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. ``` Signed-off-by: Jiang Liu --- tests/bats/compile_nydus_snapshotter.bats | 2 +- tests/bats/install_bats.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/bats/compile_nydus_snapshotter.bats b/tests/bats/compile_nydus_snapshotter.bats index 95208ab26d0..71d855dce84 100644 --- a/tests/bats/compile_nydus_snapshotter.bats +++ b/tests/bats/compile_nydus_snapshotter.bats @@ -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" diff --git a/tests/bats/install_bats.sh b/tests/bats/install_bats.sh index d0e9fac3050..12f69ad5d5a 100755 --- a/tests/bats/install_bats.sh +++ b/tests/bats/install_bats.sh @@ -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" From 715f904ccf109f64e3f14a522f2e417ce3808c80 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Fri, 14 Apr 2023 17:49:33 +0800 Subject: [PATCH 2/3] rafs: fix a possible bug in v6_dirent_size() Function Node::v6_dirent_size() may return wrong result when "." and ".." are not at the first and second entries in the sorted dirent array. Signed-off-by: Jiang Liu --- src/bin/nydus-image/core/node.rs | 50 +++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/bin/nydus-image/core/node.rs b/src/bin/nydus-image/core/node.rs index 5e2a3a32d67..6fb6b7cb32f 100644 --- a/src/bin/nydus-image/core/node.rs +++ b/src/bin/nydus-image/core/node.rs @@ -1101,20 +1101,44 @@ impl Node { pub fn v6_dir_d_size(&self, tree: &Tree) -> Result { 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::() - + "..".as_bytes().len() - + size_of::()) 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::(); - // 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::(); + // 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::() + + "..".as_bytes().len() + + size_of::()) as u64; + for child in tree.children.iter() { + let len = child.node.name().as_bytes().len() + size_of::(); + // 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) From cf024d450c0c82b99cd6f99360ea7994a3692f8f Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Fri, 14 Apr 2023 17:46:44 +0800 Subject: [PATCH 3/3] rafs: fix a regression caused by commit 2616fb2c0502e4 Fix a regression caused by commit 2616fb2c0502e4. Signed-off-by: Jiang Liu --- rafs/src/metadata/direct_v6.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rafs/src/metadata/direct_v6.rs b/rafs/src/metadata/direct_v6.rs index c940cc0e640..20e78d61c7e 100644 --- a/rafs/src/metadata/direct_v6.rs +++ b/rafs/src/metadata/direct_v6.rs @@ -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 }