MCPcopy
hub / github.com/containerd/containerd / TestFsmountLoopDevice

Function TestFsmountLoopDevice

plugins/mount/erofs/plugin_linux_test.go:35–103  ·  view source on GitHub ↗

TestFsmountLoopDevice tests fsmount with loop device

(t *testing.T)

Source from the content-addressed store, hash-verified

33
34// TestFsmountLoopDevice tests fsmount with loop device
35func TestFsmountLoopDevice(t *testing.T) {
36 testutil.RequiresRoot(t)
37
38 if _, err := exec.LookPath("mkfs.erofs"); err != nil {
39 t.Skipf("mkfs.erofs not found: %v", err)
40 }
41
42 if !snapshotserofs.FindErofs() {
43 t.Skip("erofs kernel support not available")
44 }
45
46 if !fsmount.SupportsFsmount() {
47 t.Skip("fsmount syscall not available (requires Linux 5.2+)")
48 }
49
50 tempDir := t.TempDir()
51
52 layerPath := filepath.Join(tempDir, "test.erofs")
53 layerDir := filepath.Join(tempDir, "layer_dir")
54 if err := os.MkdirAll(layerDir, 0755); err != nil {
55 t.Fatalf("failed to create layer dir: %v", err)
56 }
57 if err := os.WriteFile(filepath.Join(layerDir, "test.txt"), []byte("hello"), 0644); err != nil {
58 t.Fatalf("failed to write test file: %v", err)
59 }
60
61 cmd := exec.Command("mkfs.erofs", layerPath, layerDir)
62 if output, err := cmd.CombinedOutput(); err != nil {
63 t.Fatalf("failed to create erofs image: %v, output: %s", err, output)
64 }
65
66 loopFile, err := mount.SetupLoop(layerPath, mount.LoopParams{
67 Readonly: true,
68 Autoclear: true,
69 })
70 if err != nil {
71 t.Fatalf("failed to setup loop device: %v", err)
72 }
73 loopDev := loopFile.Name()
74 defer func() {
75 loopFile.Close()
76 mount.DetachLoopDevice(loopDev)
77 }()
78
79 mountPoint := filepath.Join(tempDir, "mnt")
80 if err := os.MkdirAll(mountPoint, 0755); err != nil {
81 t.Fatalf("failed to create mount point: %v", err)
82 }
83
84 m := mount.Mount{
85 Type: "erofs",
86 Source: loopDev,
87 Options: []string{"ro"},
88 }
89
90 err = fsmount.Fsmount(m, mountPoint)
91 if err != nil {
92 t.Fatalf("fsmount with loop device failed: %v", err)

Callers

nothing calls this directly

Calls 10

RequiresRootFunction · 0.92
SupportsFsmountFunction · 0.92
SetupLoopFunction · 0.92
DetachLoopDeviceFunction · 0.92
FsmountFunction · 0.92
UnmountFunction · 0.92
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…