Skip to content

Commit c5821ba

Browse files
committed
Sync and stat btrfs loopback in tests
Fixes #3676 Signed-off-by: Michael Crosby <[email protected]>
1 parent da66333 commit c5821ba

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

snapshots/btrfs/btrfs_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"path/filepath"
2727
"strings"
2828
"testing"
29+
"time"
2930

3031
"github.com/containerd/containerd/mount"
3132
"github.com/containerd/containerd/pkg/testutil"
@@ -62,11 +63,26 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
6263
loop.Close()
6364
return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out)
6465
}
65-
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
66-
loop.Close()
67-
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
68-
}
66+
// sync after a mkfs on the loopback before trying to mount the device
67+
unix.Sync()
6968

69+
for i := 0; i < 5; i++ {
70+
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
71+
loop.Close()
72+
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
73+
}
74+
var stat unix.Statfs_t
75+
if err := unix.Statfs(root, &stat); err != nil {
76+
unix.Unmount(root, 0)
77+
return nil, nil, errors.Wrapf(err, "unable to statfs btrfs mount %s", root)
78+
}
79+
if stat.Type == unix.BTRFS_SUPER_MAGIC {
80+
break
81+
}
82+
// unmount and try again
83+
unix.Unmount(root, 0)
84+
time.Sleep(100 * time.Millisecond)
85+
}
7086
snapshotter, err := NewSnapshotter(root)
7187
if err != nil {
7288
loop.Close()

0 commit comments

Comments
 (0)