...
1
2
3
4
19
20 package fs
21
22 import (
23 "io"
24 "math/rand"
25 "os"
26 "os/exec"
27 "path/filepath"
28 "testing"
29
30 "github.com/containerd/continuity/testutil"
31 "github.com/containerd/continuity/testutil/loopback"
32 )
33
34 func TestCopyReflinkWithXFS(t *testing.T) {
35 testutil.RequiresRoot(t)
36 mnt := t.TempDir()
37
38 loop, err := loopback.New(1 << 30)
39 if err != nil {
40 t.Fatal(err)
41 }
42 mkfs := []string{"mkfs.xfs", "-m", "crc=1", "-n", "ftype=1", "-m", "reflink=1"}
43 if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil {
44
45 t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out))
46 }
47 loopbackSize, err := loop.HardSize()
48 if err != nil {
49 t.Fatal(err)
50 }
51 t.Logf("Loopback file size (after mkfs (%v)): %d", mkfs, loopbackSize)
52 if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil {
53
54 t.Skipf("could not mount %s: %v (out: %q)", loop.Device, err, string(out))
55 }
56 unmounted := false
57 defer func() {
58 if !unmounted {
59 testutil.Unmount(t, mnt)
60 }
61 loop.Close()
62 }()
63
64 aPath := filepath.Join(mnt, "a")
65 aSize := int64(100 << 20)
66 a, err := os.Create(aPath)
67 if err != nil {
68 t.Fatal(err)
69 }
70 randReader := rand.New(rand.NewSource(42))
71 if _, err := io.CopyN(a, randReader, aSize); err != nil {
72 a.Close()
73 t.Fatal(err)
74 }
75 if err := a.Close(); err != nil {
76 t.Fatal(err)
77 }
78 bPath := filepath.Join(mnt, "b")
79 if err := CopyFile(bPath, aPath); err != nil {
80 t.Fatal(err)
81 }
82 testutil.Unmount(t, mnt)
83 unmounted = true
84 loopbackSize, err = loop.HardSize()
85 if err != nil {
86 t.Fatal(err)
87 }
88 t.Logf("Loopback file size (after copying a %d-byte file): %d", aSize, loopbackSize)
89 allowedSize := int64(120 << 20)
90 if loopbackSize > allowedSize {
91 t.Fatalf("expected <= %d, got %d", allowedSize, loopbackSize)
92 }
93 }
94
View as plain text