Sync and stat btrfs loopback in tests
Fixes #3676 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		| @@ -26,6 +26,7 @@ import ( | |||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/containerd/containerd/mount" | 	"github.com/containerd/containerd/mount" | ||||||
| 	"github.com/containerd/containerd/pkg/testutil" | 	"github.com/containerd/containerd/pkg/testutil" | ||||||
| @@ -62,11 +63,26 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap | |||||||
| 			loop.Close() | 			loop.Close() | ||||||
| 			return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out) | 			return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out) | ||||||
| 		} | 		} | ||||||
|  | 		// sync after a mkfs on the loopback before trying to mount the device | ||||||
|  | 		unix.Sync() | ||||||
|  |  | ||||||
|  | 		for i := 0; i < 5; i++ { | ||||||
| 			if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil { | 			if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil { | ||||||
| 				loop.Close() | 				loop.Close() | ||||||
| 				return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out) | 				return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out) | ||||||
| 			} | 			} | ||||||
|  | 			var stat unix.Statfs_t | ||||||
|  | 			if err := unix.Statfs(root, &stat); err != nil { | ||||||
|  | 				unix.Unmount(root, 0) | ||||||
|  | 				return nil, nil, errors.Wrapf(err, "unable to statfs btrfs mount %s", root) | ||||||
|  | 			} | ||||||
|  | 			if stat.Type == unix.BTRFS_SUPER_MAGIC { | ||||||
|  | 				break | ||||||
|  | 			} | ||||||
|  | 			// unmount and try again | ||||||
|  | 			unix.Unmount(root, 0) | ||||||
|  | 			time.Sleep(100 * time.Millisecond) | ||||||
|  | 		} | ||||||
| 		snapshotter, err := NewSnapshotter(root) | 		snapshotter, err := NewSnapshotter(root) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			loop.Close() | 			loop.Close() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby