MCPcopy
hub / github.com/containerd/containerd / TestAutoclearTrueLoop

Function TestAutoclearTrueLoop

core/mount/losetup_linux_test.go:104–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestAutoclearTrueLoop(t *testing.T) {
105 testutil.RequiresRoot(t)
106
107 backingFile := createTempFile(t)
108 bInfo, err := os.Stat(backingFile)
109 require.NoError(t, err)
110 bInode := bInfo.Sys().(*syscall.Stat_t).Ino
111
112 file, err := SetupLoop(backingFile, LoopParams{Autoclear: true})
113 require.NoError(t, err)
114 dev := file.Name()
115 file.Close()
116
117 var checkFn = func(loopDev string, expectedInode uint64) (_shouldRetry bool, _ error) {
118 loop, err := os.Open(loopDev)
119 if err != nil {
120 if os.IsNotExist(err) {
121 return false, nil
122 }
123 return false, fmt.Errorf("failed to open loop device: %w", err)
124 }
125 info, err := unix.IoctlLoopGetStatus64(int(loop.Fd()))
126 loop.Close()
127 if err != nil {
128 if errors.Is(err, unix.ENXIO) {
129 return false, nil
130 }
131 return false, fmt.Errorf("failed to get loop device info: %w", err)
132 }
133
134 if info.Inode != expectedInode {
135 return false, nil
136 }
137
138 t.Logf("loop device %s still present with backing inode %d", loopDev, expectedInode)
139 return true, nil
140 }
141
142 for range 10 {
143 retry, err := checkFn(dev, bInode)
144 require.NoError(t, err)
145 if !retry {
146 return
147 }
148 time.Sleep(100 * time.Millisecond)
149 }
150 t.Fatalf("loop device %s still present after autoclear", dev)
151}
152
153func TestAutoclearFalseLoop(t *testing.T) {
154 testutil.RequiresRoot(t)

Callers

nothing calls this directly

Calls 7

SetupLoopFunction · 0.85
createTempFileFunction · 0.70
StatMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
SysMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…