From d93405730daf33f10e26855303a94e126378c90f Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 25 Oct 2024 16:14:03 +0900 Subject: [PATCH 1/2] CI: use ubuntu-24.04 Signed-off-by: Akihiro Suda --- .github/workflows/ci.yml | 6 +++--- .github/workflows/codeql.yml | 2 +- fs/copy_linux_test.go | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0541d47..a4be42de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: # project: name: Project Checks - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 timeout-minutes: 5 steps: @@ -42,7 +42,7 @@ jobs: strategy: matrix: - os: [ubuntu-22.04, macos-12, windows-2019, windows-2022] + os: [ubuntu-24.04, macos-12, windows-2019, windows-2022] steps: - name: Set up Go @@ -87,7 +87,7 @@ jobs: working-directory: src/github.com/containerd/continuity cross: name: Cross-compile - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 timeout-minutes: 10 needs: [project] diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6bb0d7c5..25131945 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 timeout-minutes: 30 diff --git a/fs/copy_linux_test.go b/fs/copy_linux_test.go index 20703dfb..0171f346 100644 --- a/fs/copy_linux_test.go +++ b/fs/copy_linux_test.go @@ -86,7 +86,8 @@ func TestCopyReflinkWithXFS(t *testing.T) { t.Fatal(err) } t.Logf("Loopback file size (after copying a %d-byte file): %d", aSize, loopbackSize) - allowedSize := int64(120 << 20) // 120MB + // 170 MiB is needed since Ubuntu 24.04. 120 MiB was enough for Ubuntu 22.04. + allowedSize := int64(170 << 20) if loopbackSize > allowedSize { t.Fatalf("expected <= %d, got %d", allowedSize, loopbackSize) } From 97eff17e2d69acf3724a694badf7eedb1c59684f Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 25 Oct 2024 16:03:20 +0900 Subject: [PATCH 2/2] Fix TestDiffDirChangeWithOverlayfs The test was assuming TMPDIR to be on ext4, not on tmpfs. Fix issue 247 Signed-off-by: Akihiro Suda --- fs/diff_test.go | 73 +++++++++++++++++++++------------------- fs/fstest/mkfs_linux.go | 44 ++++++++++++++++++++++++ fs/fstest/mkfs_others.go | 25 ++++++++++++++ 3 files changed, 108 insertions(+), 34 deletions(-) create mode 100644 fs/fstest/mkfs_linux.go create mode 100644 fs/fstest/mkfs_others.go diff --git a/fs/diff_test.go b/fs/diff_test.go index 191ba21d..0bff5278 100644 --- a/fs/diff_test.go +++ b/fs/diff_test.go @@ -204,50 +204,55 @@ func TestDiffDirChangeWithOverlayfs(t *testing.T) { skipDiffTestOnNonLinux(t) testutil.RequiresRoot(t) - l1 := fstest.Apply( - fstest.CreateDir("/dir1", 0700), - fstest.CreateFile("/dir1/f", []byte("/dir1/f"), 0644), - fstest.CreateDir("/dir1/d", 0700), - fstest.CreateFile("/dir1/d/f", []byte("/dir1/d/f"), 0644), + f := func() { + l1 := fstest.Apply( + fstest.CreateDir("/dir1", 0700), + fstest.CreateFile("/dir1/f", []byte("/dir1/f"), 0644), + fstest.CreateDir("/dir1/d", 0700), + fstest.CreateFile("/dir1/d/f", []byte("/dir1/d/f"), 0644), - fstest.CreateDir("/dir2", 0700), - fstest.CreateDir("/dir2/d", 0700), - fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f"), 0644), + fstest.CreateDir("/dir2", 0700), + fstest.CreateDir("/dir2/d", 0700), + fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f"), 0644), - fstest.CreateDir("/dir3", 0700), - fstest.CreateFile("/dir3/f", []byte("/dir3/f"), 0644), - ) + fstest.CreateDir("/dir3", 0700), + fstest.CreateFile("/dir3/f", []byte("/dir3/f"), 0644), + ) - l2 := fstest.Apply( - fstest.CreateDir("/dir1", 0700), - fstest.CreateFile("/dir1/f", []byte("/dir1/f-diff"), 0644), - fstest.CreateDeviceFile("/dir1/d", os.ModeDevice|os.ModeCharDevice, 0, 0), + l2 := fstest.Apply( + fstest.CreateDir("/dir1", 0700), + fstest.CreateFile("/dir1/f", []byte("/dir1/f-diff"), 0644), + fstest.CreateDeviceFile("/dir1/d", os.ModeDevice|os.ModeCharDevice, 0, 0), - fstest.CreateDir("/dir2", 0700), - fstest.CreateDir("/dir2/d", 0700), - fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f-diff"), 0644), + fstest.CreateDir("/dir2", 0700), + fstest.CreateDir("/dir2/d", 0700), + fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f-diff"), 0644), - fstest.CreateDir("/dir3", 0700), - // TODO(fuweid): check kernel version before apply - fstest.SetXAttr("/dir3", "user.overlay.opaque", "y"), - ) + fstest.CreateDir("/dir3", 0700), + // TODO(fuweid): check kernel version before apply + fstest.SetXAttr("/dir3", "user.overlay.opaque", "y"), + ) - diff := []TestChange{ - Modify("/dir1"), - Modify("/dir1/f"), - Delete("/dir1/d"), + diff := []TestChange{ + Modify("/dir1"), + Modify("/dir1/f"), + Delete("/dir1/d"), - Modify("/dir2"), - Modify("/dir2/d"), - Modify("/dir2/d/f"), + Modify("/dir2"), + Modify("/dir2/d"), + Modify("/dir2/d/f"), - Modify("/dir3"), - Delete("/dir3/.wh..opq"), - } + Modify("/dir3"), + Delete("/dir3/.wh..opq"), + } - if err := testDiffDirChange(l1, l2, DiffSourceOverlayFS, diff); err != nil { - t.Fatalf("failed diff dir change: %+v", err) + if err := testDiffDirChange(l1, l2, DiffSourceOverlayFS, diff); err != nil { + t.Fatalf("failed diff dir change: %+v", err) + } } + // the test assumes ext4 + // https://github.com/containerd/continuity/issues/247#issuecomment-2437014104 + fstest.WithMkfs(t, f, "mkfs.ext4", "-F") } func TestParentDirectoryPermission(t *testing.T) { diff --git a/fs/fstest/mkfs_linux.go b/fs/fstest/mkfs_linux.go new file mode 100644 index 00000000..9510ef1a --- /dev/null +++ b/fs/fstest/mkfs_linux.go @@ -0,0 +1,44 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package fstest + +import ( + "os/exec" + "testing" + + "github.com/containerd/continuity/testutil" + "github.com/containerd/continuity/testutil/loopback" +) + +func WithMkfs(t *testing.T, f func(), mkfs ...string) { + testutil.RequiresRoot(t) + mnt := t.TempDir() + loop, err := loopback.New(100 << 20) // 100 MB + if err != nil { + t.Fatal(err) + } + defer loop.Close() + if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil { + t.Fatalf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out)) + } + if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil { + t.Fatalf("could not mount %s: %v (out: %q)", loop.Device, err, string(out)) + } + defer testutil.Unmount(t, mnt) + t.Setenv("TMPDIR", mnt) + f() +} diff --git a/fs/fstest/mkfs_others.go b/fs/fstest/mkfs_others.go new file mode 100644 index 00000000..5e0bef64 --- /dev/null +++ b/fs/fstest/mkfs_others.go @@ -0,0 +1,25 @@ +//go:build !linux + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package fstest + +import "testing" + +func WithMkfs(t *testing.T, f func(), mkfs ...string) { + t.Fatal("WithMkfs requires Linux") +}