diff --git a/Makefile b/Makefile index a32bb5b0d..e33c6c58d 100644 --- a/Makefile +++ b/Makefile @@ -131,8 +131,6 @@ FORCE: # Build a binary from a cmd. bin/%: cmd/% FORCE - @test $$(go list) = "${PKG}" || \ - (echo "$(ONI) Please correctly set up your Go build environment. This project must be located at /src/${PKG}" && false) @echo "$(WHALE) $@${BINARY_SUFFIX}" @go build -i -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ${GO_GCFLAGS} ./$< diff --git a/cmd/ctr/run.go b/cmd/ctr/run.go index aa9286564..8574f827e 100644 --- a/cmd/ctr/run.go +++ b/cmd/ctr/run.go @@ -10,9 +10,9 @@ import ( "github.com/Sirupsen/logrus" "github.com/containerd/console" - "github.com/containerd/containerd" "github.com/containerd/containerd/api/services/execution" "github.com/containerd/containerd/images" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" digest "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/identity" @@ -71,7 +71,7 @@ var runCommand = cli.Command{ Action: func(context *cli.Context) error { var ( err error - mounts []containerd.Mount + mounts []mount.Mount imageConfig ocispec.Image ctx = gocontext.Background() diff --git a/cmd/ctr/run_unix.go b/cmd/ctr/run_unix.go index 9bea14599..55439f240 100644 --- a/cmd/ctr/run_unix.go +++ b/cmd/ctr/run_unix.go @@ -18,10 +18,10 @@ import ( "github.com/Sirupsen/logrus" "github.com/containerd/console" - "github.com/containerd/containerd" "github.com/containerd/containerd/api/services/execution" "github.com/containerd/containerd/api/types/descriptor" "github.com/containerd/containerd/api/types/mount" + mountt "github.com/containerd/containerd/mount" protobuf "github.com/gogo/protobuf/types" ocispec "github.com/opencontainers/image-spec/specs-go/v1" specs "github.com/opencontainers/runtime-spec/specs-go" @@ -277,7 +277,7 @@ func newSpec(context *cli.Context, config *ocispec.ImageConfig, imageRef string) return json.Marshal(s) } -func newCreateRequest(context *cli.Context, id, tmpDir string, checkpoint *ocispec.Descriptor, mounts []containerd.Mount, spec []byte) (*execution.CreateRequest, error) { +func newCreateRequest(context *cli.Context, id, tmpDir string, checkpoint *ocispec.Descriptor, mounts []mountt.Mount, spec []byte) (*execution.CreateRequest, error) { create := &execution.CreateRequest{ ID: id, Spec: &protobuf.Any{ diff --git a/cmd/ctr/run_windows.go b/cmd/ctr/run_windows.go index e028a8bd0..326b13992 100644 --- a/cmd/ctr/run_windows.go +++ b/cmd/ctr/run_windows.go @@ -10,9 +10,9 @@ import ( "github.com/Sirupsen/logrus" "github.com/containerd/console" - "github.com/containerd/containerd" "github.com/containerd/containerd/api/services/execution" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/windows" "github.com/containerd/containerd/windows/hcs" protobuf "github.com/gogo/protobuf/types" @@ -136,7 +136,7 @@ func newSpec(context *cli.Context, config *ocispec.ImageConfig, imageRef string) return json.Marshal(rtSpec) } -func newCreateRequest(context *cli.Context, id, tmpDir string, checkpoint *ocispec.Descriptor, mounts []containerd.Mount, spec []byte) (*execution.CreateRequest, error) { +func newCreateRequest(context *cli.Context, id, tmpDir string, checkpoint *ocispec.Descriptor, mounts []mount.Mount, spec []byte) (*execution.CreateRequest, error) { create := &execution.CreateRequest{ ID: id, Spec: &protobuf.Any{ diff --git a/linux/shim/init.go b/linux/shim/init.go index 6eefa0eb9..d4027982c 100644 --- a/linux/shim/init.go +++ b/linux/shim/init.go @@ -16,9 +16,9 @@ import ( "golang.org/x/sys/unix" "github.com/containerd/console" - "github.com/containerd/containerd" shimapi "github.com/containerd/containerd/api/services/shim" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/fifo" runc "github.com/containerd/go-runc" ) @@ -45,7 +45,7 @@ type initProcess struct { func newInitProcess(context context.Context, path string, r *shimapi.CreateRequest) (*initProcess, error) { for _, rm := range r.Rootfs { - m := &containerd.Mount{ + m := &mount.Mount{ Type: rm.Type, Source: rm.Source, Options: rm.Options, diff --git a/mount.go b/mount/mount.go similarity index 97% rename from mount.go rename to mount/mount.go index 183061b42..94086f178 100644 --- a/mount.go +++ b/mount/mount.go @@ -1,4 +1,4 @@ -package containerd +package mount // Mount is the lingua franca of containerd. A mount represents a // serialized mount syscall. Components either emit or consume mounts. diff --git a/mount_linux.go b/mount/mount_linux.go similarity index 99% rename from mount_linux.go rename to mount/mount_linux.go index 85c652a70..86df8bbc1 100644 --- a/mount_linux.go +++ b/mount/mount_linux.go @@ -1,4 +1,4 @@ -package containerd +package mount import ( "strings" diff --git a/mount_unix.go b/mount/mount_unix.go similarity index 93% rename from mount_unix.go rename to mount/mount_unix.go index 8746424fb..32ea2691a 100644 --- a/mount_unix.go +++ b/mount/mount_unix.go @@ -1,6 +1,6 @@ // +build darwin freebsd -package containerd +package mount import "github.com/pkg/errors" diff --git a/mount_windows.go b/mount/mount_windows.go similarity index 93% rename from mount_windows.go rename to mount/mount_windows.go index d5098b722..35dead411 100644 --- a/mount_windows.go +++ b/mount/mount_windows.go @@ -1,4 +1,4 @@ -package containerd +package mount import "github.com/pkg/errors" diff --git a/mountinfo/mountinfo.go b/mount/mountinfo.go similarity index 98% rename from mountinfo/mountinfo.go rename to mount/mountinfo.go index 4bc11badd..2192cce20 100644 --- a/mountinfo/mountinfo.go +++ b/mount/mountinfo.go @@ -1,4 +1,4 @@ -package mountinfo +package mount // Info reveals information about a particular mounted filesystem. This // struct is populated from the content in the /proc//mountinfo file. diff --git a/mountinfo/mountinfo_freebsd.go b/mount/mountinfo_freebsd.go similarity index 98% rename from mountinfo/mountinfo_freebsd.go rename to mount/mountinfo_freebsd.go index ffb37494c..d2bc075a6 100644 --- a/mountinfo/mountinfo_freebsd.go +++ b/mount/mountinfo_freebsd.go @@ -1,4 +1,4 @@ -package mountinfo +package mount /* #include diff --git a/mountinfo/mountinfo_linux.go b/mount/mountinfo_linux.go similarity index 99% rename from mountinfo/mountinfo_linux.go rename to mount/mountinfo_linux.go index 6cb08fd80..023772264 100644 --- a/mountinfo/mountinfo_linux.go +++ b/mount/mountinfo_linux.go @@ -1,6 +1,6 @@ // +build linux -package mountinfo +package mount import ( "bufio" diff --git a/mountinfo/mountinfo_linux_test.go b/mount/mountinfo_linux_test.go similarity index 99% rename from mountinfo/mountinfo_linux_test.go rename to mount/mountinfo_linux_test.go index 9a74eeb0b..586a43b40 100644 --- a/mountinfo/mountinfo_linux_test.go +++ b/mount/mountinfo_linux_test.go @@ -1,6 +1,6 @@ // +build linux -package mountinfo +package mount import ( "bytes" diff --git a/mountinfo/mountinfo_solaris.go b/mount/mountinfo_solaris.go similarity index 98% rename from mountinfo/mountinfo_solaris.go rename to mount/mountinfo_solaris.go index abf8c71db..9ba5c3d44 100644 --- a/mountinfo/mountinfo_solaris.go +++ b/mount/mountinfo_solaris.go @@ -1,6 +1,6 @@ // +build solaris,cgo -package mountinfo +package mount /* #include diff --git a/mountinfo/mountinfo_unsupported.go b/mount/mountinfo_unsupported.go similarity index 96% rename from mountinfo/mountinfo_unsupported.go rename to mount/mountinfo_unsupported.go index 1ef75dcae..aa659d899 100644 --- a/mountinfo/mountinfo_unsupported.go +++ b/mount/mountinfo_unsupported.go @@ -1,6 +1,6 @@ // +build !linux,!freebsd,!solaris freebsd,!cgo solaris,!cgo -package mountinfo +package mount import ( "fmt" diff --git a/plugin/runtime.go b/plugin/runtime.go index c7902d952..7103e25d4 100644 --- a/plugin/runtime.go +++ b/plugin/runtime.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/containerd/containerd" + "github.com/containerd/containerd/mount" ) type IO struct { @@ -18,7 +18,7 @@ type CreateOpts struct { // Spec is the OCI runtime spec Spec []byte // Rootfs mounts to perform to gain access to the container's filesystem - Rootfs []containerd.Mount + Rootfs []mount.Mount // IO for the container's main process IO IO Checkpoint string diff --git a/rootfs/apply.go b/rootfs/apply.go index bedd16f0d..02a96bf47 100644 --- a/rootfs/apply.go +++ b/rootfs/apply.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "github.com/containerd/containerd" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/identity" @@ -14,7 +14,7 @@ import ( ) type Applier interface { - Apply(context.Context, ocispec.Descriptor, []containerd.Mount) (ocispec.Descriptor, error) + Apply(context.Context, ocispec.Descriptor, []mount.Mount) (ocispec.Descriptor, error) } type Layer struct { diff --git a/rootfs/diff.go b/rootfs/diff.go index a23b84f26..17a31f8c2 100644 --- a/rootfs/diff.go +++ b/rootfs/diff.go @@ -4,14 +4,14 @@ import ( "context" "fmt" - "github.com/containerd/containerd" "github.com/containerd/containerd/content" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) type MountDiffer interface { - DiffMounts(ctx context.Context, lower, upper []containerd.Mount, media, ref string) (ocispec.Descriptor, error) + DiffMounts(ctx context.Context, lower, upper []mount.Mount, media, ref string) (ocispec.Descriptor, error) } type DiffOptions struct { @@ -33,7 +33,7 @@ func Diff(ctx context.Context, snapshotID, contentRef string, sn snapshot.Snapsh } defer sn.Remove(ctx, lowerKey) - var upper []containerd.Mount + var upper []mount.Mount if info.Kind == snapshot.KindActive { upper, err = sn.Mounts(ctx, snapshotID) if err != nil { diff --git a/rootfs/init.go b/rootfs/init.go index 2ef411632..ae3870efe 100644 --- a/rootfs/init.go +++ b/rootfs/init.go @@ -6,8 +6,8 @@ import ( "io/ioutil" "os" - "github.com/containerd/containerd" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" @@ -20,11 +20,11 @@ var ( type initializerFunc func(string) error type Mounter interface { - Mount(target string, mounts ...containerd.Mount) error + Mount(target string, mounts ...mount.Mount) error Unmount(target string) error } -func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]containerd.Mount, error) { +func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]mount.Mount, error) { _, err := snapshotter.Stat(ctx, name) if err == nil { return nil, errors.Errorf("rootfs already exists") diff --git a/services/diff/client.go b/services/diff/client.go index 66a920e50..359e9328d 100644 --- a/services/diff/client.go +++ b/services/diff/client.go @@ -3,10 +3,10 @@ package diff import ( "context" - "github.com/containerd/containerd" diffapi "github.com/containerd/containerd/api/services/diff" "github.com/containerd/containerd/api/types/descriptor" mounttypes "github.com/containerd/containerd/api/types/mount" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/rootfs" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -28,7 +28,7 @@ type remote struct { client diffapi.DiffClient } -func (r *remote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []containerd.Mount) (ocispec.Descriptor, error) { +func (r *remote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) { req := &diffapi.ApplyRequest{ Diff: fromDescriptor(diff), Mounts: fromMounts(mounts), @@ -40,7 +40,7 @@ func (r *remote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []co return toDescriptor(resp.Applied), nil } -func (r *remote) DiffMounts(ctx context.Context, a, b []containerd.Mount, media, ref string) (ocispec.Descriptor, error) { +func (r *remote) DiffMounts(ctx context.Context, a, b []mount.Mount, media, ref string) (ocispec.Descriptor, error) { req := &diffapi.DiffRequest{ Left: fromMounts(a), Right: fromMounts(b), @@ -62,7 +62,7 @@ func fromDescriptor(d ocispec.Descriptor) *descriptor.Descriptor { } } -func fromMounts(mounts []containerd.Mount) []*mounttypes.Mount { +func fromMounts(mounts []mount.Mount) []*mounttypes.Mount { apiMounts := make([]*mounttypes.Mount, len(mounts)) for i, m := range mounts { apiMounts[i] = &mounttypes.Mount{ diff --git a/services/diff/service.go b/services/diff/service.go index 7e722df4d..165a041f2 100644 --- a/services/diff/service.go +++ b/services/diff/service.go @@ -5,13 +5,13 @@ import ( "io/ioutil" "os" - "github.com/containerd/containerd" diffapi "github.com/containerd/containerd/api/services/diff" "github.com/containerd/containerd/api/types/descriptor" mounttypes "github.com/containerd/containerd/api/types/mount" "github.com/containerd/containerd/archive" "github.com/containerd/containerd/archive/compression" "github.com/containerd/containerd/content" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" digest "github.com/opencontainers/go-digest" @@ -59,10 +59,10 @@ func (s *service) Apply(ctx context.Context, er *diffapi.ApplyRequest) (*diffapi } defer os.RemoveAll(dir) - if err := containerd.MountAll(mounts, dir); err != nil { + if err := mount.MountAll(mounts, dir); err != nil { return nil, errors.Wrap(err, "failed to mount") } - defer containerd.Unmount(dir, 0) + defer mount.Unmount(dir, 0) r, err := s.store.Reader(ctx, desc.Digest) if err != nil { @@ -118,15 +118,15 @@ func (s *service) Diff(ctx context.Context, dr *diffapi.DiffRequest) (*diffapi.D } defer os.RemoveAll(bDir) - if err := containerd.MountAll(aMounts, aDir); err != nil { + if err := mount.MountAll(aMounts, aDir); err != nil { return nil, errors.Wrap(err, "failed to mount") } - defer containerd.Unmount(aDir, 0) + defer mount.Unmount(aDir, 0) - if err := containerd.MountAll(bMounts, bDir); err != nil { + if err := mount.MountAll(bMounts, bDir); err != nil { return nil, errors.Wrap(err, "failed to mount") } - defer containerd.Unmount(bDir, 0) + defer mount.Unmount(bDir, 0) cw, err := s.store.Writer(ctx, dr.Ref, 0, "") if err != nil { @@ -190,10 +190,10 @@ func toDescriptor(d *descriptor.Descriptor) ocispec.Descriptor { } } -func toMounts(apim []*mounttypes.Mount) []containerd.Mount { - mounts := make([]containerd.Mount, len(apim)) +func toMounts(apim []*mounttypes.Mount) []mount.Mount { + mounts := make([]mount.Mount, len(apim)) for i, m := range apim { - mounts[i] = containerd.Mount{ + mounts[i] = mount.Mount{ Type: m.Type, Source: m.Source, Options: m.Options, diff --git a/services/execution/service.go b/services/execution/service.go index ea3daded0..eceff06f6 100644 --- a/services/execution/service.go +++ b/services/execution/service.go @@ -9,7 +9,6 @@ import ( "path/filepath" "sync" - "github.com/containerd/containerd" api "github.com/containerd/containerd/api/services/execution" "github.com/containerd/containerd/api/types/container" "github.com/containerd/containerd/api/types/descriptor" @@ -17,6 +16,7 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" protobuf "github.com/gogo/protobuf/types" google_protobuf "github.com/golang/protobuf/ptypes/empty" @@ -108,7 +108,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create Checkpoint: checkpointPath, } for _, m := range r.Rootfs { - opts.Rootfs = append(opts.Rootfs, containerd.Mount{ + opts.Rootfs = append(opts.Rootfs, mount.Mount{ Type: m.Type, Source: m.Source, Options: m.Options, diff --git a/services/snapshot/client.go b/services/snapshot/client.go index ff30cd76c..747aeb6ee 100644 --- a/services/snapshot/client.go +++ b/services/snapshot/client.go @@ -8,8 +8,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - "github.com/containerd/containerd" snapshotapi "github.com/containerd/containerd/api/services/snapshot" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" "github.com/pkg/errors" ) @@ -42,7 +42,7 @@ func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshot.Usa return toUsage(resp), nil } -func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) { +func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { resp, err := r.client.Mounts(ctx, &snapshotapi.MountsRequest{Key: key}) if err != nil { return nil, rewriteGRPCError(err) @@ -50,7 +50,7 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]container return toMounts(resp), nil } -func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { resp, err := r.client.Prepare(ctx, &snapshotapi.PrepareRequest{Key: key, Parent: parent}) if err != nil { return nil, rewriteGRPCError(err) @@ -58,7 +58,7 @@ func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([] return toMounts(resp), nil } -func (r *remoteSnapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (r *remoteSnapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { resp, err := r.client.View(ctx, &snapshotapi.PrepareRequest{Key: key, Parent: parent}) if err != nil { return nil, rewriteGRPCError(err) @@ -145,10 +145,10 @@ func toUsage(resp *snapshotapi.UsageResponse) snapshot.Usage { } } -func toMounts(resp *snapshotapi.MountsResponse) []containerd.Mount { - mounts := make([]containerd.Mount, len(resp.Mounts)) +func toMounts(resp *snapshotapi.MountsResponse) []mount.Mount { + mounts := make([]mount.Mount, len(resp.Mounts)) for i, m := range resp.Mounts { - mounts[i] = containerd.Mount{ + mounts[i] = mount.Mount{ Type: m.Type, Source: m.Source, Options: m.Options, diff --git a/services/snapshot/service.go b/services/snapshot/service.go index 4aff3c4c9..6986bf22b 100644 --- a/services/snapshot/service.go +++ b/services/snapshot/service.go @@ -3,10 +3,10 @@ package snapshot import ( gocontext "context" - "github.com/containerd/containerd" snapshotapi "github.com/containerd/containerd/api/services/snapshot" mounttypes "github.com/containerd/containerd/api/types/mount" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" protoempty "github.com/golang/protobuf/ptypes/empty" @@ -189,7 +189,7 @@ func fromUsage(usage snapshot.Usage) *snapshotapi.UsageResponse { } } -func fromMounts(mounts []containerd.Mount) *snapshotapi.MountsResponse { +func fromMounts(mounts []mount.Mount) *snapshotapi.MountsResponse { resp := &snapshotapi.MountsResponse{ Mounts: make([]*mounttypes.Mount, len(mounts)), } diff --git a/snapshot/btrfs/btrfs.go b/snapshot/btrfs/btrfs.go index a22c48385..422093f0a 100644 --- a/snapshot/btrfs/btrfs.go +++ b/snapshot/btrfs/btrfs.go @@ -11,9 +11,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/containerd/btrfs" - "github.com/containerd/containerd" "github.com/containerd/containerd/log" - "github.com/containerd/containerd/mountinfo" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/storage" @@ -36,7 +35,7 @@ type snapshotter struct { ms *storage.MetaStore } -func getBtrfsDevice(root string, mounts []mountinfo.Info) (string, error) { +func getBtrfsDevice(root string, mounts []mount.Info) (string, error) { device := "" deviceMountpoint := "" for _, info := range mounts { @@ -62,7 +61,7 @@ func getBtrfsDevice(root string, mounts []mountinfo.Info) (string, error) { // a file in the provided root. // root needs to be a mount point of btrfs. func NewSnapshotter(root string) (snapshot.Snapshotter, error) { - mounts, err := mountinfo.Self() + mounts, err := mount.Self() if err != nil { return nil, err } @@ -140,15 +139,15 @@ func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho return storage.WalkInfo(ctx, fn) } -func (b *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (b *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { return b.makeActive(ctx, key, parent, false) } -func (b *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (b *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { return b.makeActive(ctx, key, parent, true) } -func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) { +func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) { ctx, t, err := b.ms.TransactionContext(ctx, true) if err != nil { return nil, err @@ -193,7 +192,7 @@ func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readon return b.mounts(target) } -func (b *snapshotter) mounts(dir string) ([]containerd.Mount, error) { +func (b *snapshotter) mounts(dir string) ([]mount.Mount, error) { var options []string // get the subvolume id back out for the mount @@ -208,7 +207,7 @@ func (b *snapshotter) mounts(dir string) ([]containerd.Mount, error) { options = append(options, "ro") } - return []containerd.Mount{ + return []mount.Mount{ { Type: "btrfs", Source: b.device, @@ -265,7 +264,7 @@ func (b *snapshotter) Commit(ctx context.Context, name, key string) (err error) // called on an read-write or readonly transaction. // // This can be used to recover mounts after calling View or Prepare. -func (b *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) { +func (b *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { ctx, t, err := b.ms.TransactionContext(ctx, false) if err != nil { return nil, err diff --git a/snapshot/btrfs/btrfs_test.go b/snapshot/btrfs/btrfs_test.go index 53245ec15..2a1e9e748 100644 --- a/snapshot/btrfs/btrfs_test.go +++ b/snapshot/btrfs/btrfs_test.go @@ -11,8 +11,7 @@ import ( "strings" "testing" - "github.com/containerd/containerd" - "github.com/containerd/containerd/mountinfo" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/testsuite" "github.com/containerd/containerd/testutil" @@ -86,7 +85,7 @@ func TestBtrfsMounts(t *testing.T) { if err := os.MkdirAll(target, 0755); err != nil { t.Fatal(err) } - if err := containerd.MountAll(mounts, target); err != nil { + if err := mount.MountAll(mounts, target); err != nil { t.Fatal(err) } defer testutil.Unmount(t, target) @@ -116,7 +115,7 @@ func TestBtrfsMounts(t *testing.T) { t.Fatal(err) } - if err := containerd.MountAll(mounts, target); err != nil { + if err := mount.MountAll(mounts, target); err != nil { t.Fatal(err) } defer testutil.Unmount(t, target) @@ -222,12 +221,12 @@ func TestGetBtrfsDevice(t *testing.T) { expectedDevice string expectedError string root string - mounts []mountinfo.Info + mounts []mount.Info }{ { expectedDevice: "/dev/loop0", root: "/var/lib/containerd/snapshot/btrfs", - mounts: []mountinfo.Info{ + mounts: []mount.Info{ {Root: "/", Mountpoint: "/", FSType: "ext4", Source: "/dev/sda1"}, {Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/loop0"}, }, @@ -235,21 +234,21 @@ func TestGetBtrfsDevice(t *testing.T) { { expectedError: "/var/lib/containerd/snapshot/btrfs is not mounted as btrfs", root: "/var/lib/containerd/snapshot/btrfs", - mounts: []mountinfo.Info{ + mounts: []mount.Info{ {Root: "/", Mountpoint: "/", FSType: "ext4", Source: "/dev/sda1"}, }, }, { expectedDevice: "/dev/sda1", root: "/var/lib/containerd/snapshot/btrfs", - mounts: []mountinfo.Info{ + mounts: []mount.Info{ {Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"}, }, }, { expectedDevice: "/dev/sda2", root: "/var/lib/containerd/snapshot/btrfs", - mounts: []mountinfo.Info{ + mounts: []mount.Info{ {Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"}, {Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/sda2"}, }, @@ -257,7 +256,7 @@ func TestGetBtrfsDevice(t *testing.T) { { expectedDevice: "/dev/sda2", root: "/var/lib/containerd/snapshot/btrfs", - mounts: []mountinfo.Info{ + mounts: []mount.Info{ {Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/sda2"}, {Root: "/", Mountpoint: "/var/lib/foooooooooooooooooooo/baaaaaaaaaaaaaaaaaaaar", FSType: "btrfs", Source: "/dev/sda3"}, // mountpoint length longer than /var/lib/containerd/snapshot/btrfs {Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"}, diff --git a/snapshot/naive/naive.go b/snapshot/naive/naive.go index 0a1d88ffd..304409a03 100644 --- a/snapshot/naive/naive.go +++ b/snapshot/naive/naive.go @@ -6,9 +6,9 @@ import ( "os" "path/filepath" - "github.com/containerd/containerd" "github.com/containerd/containerd/fs" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/storage" @@ -92,11 +92,11 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er return usage, nil } -func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { return o.createActive(ctx, key, parent, false) } -func (o *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { return o.createActive(ctx, key, parent, true) } @@ -104,7 +104,7 @@ func (o *snapshotter) View(ctx context.Context, key, parent string) ([]container // called on an read-write or readonly transaction. // // This can be used to recover mounts after calling View or Prepare. -func (o *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) { +func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { ctx, t, err := o.ms.TransactionContext(ctx, false) if err != nil { return nil, err @@ -202,7 +202,7 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho return storage.WalkInfo(ctx, fn) } -func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) { +func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) { var ( err error path, td string @@ -271,7 +271,7 @@ func (o *snapshotter) getSnapshotDir(id string) string { return filepath.Join(o.root, "snapshots", id) } -func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { +func (o *snapshotter) mounts(active storage.Active) []mount.Mount { var ( roFlag string source string @@ -289,7 +289,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { source = o.getSnapshotDir(active.ParentIDs[0]) } - return []containerd.Mount{ + return []mount.Mount{ { Source: source, Type: "bind", diff --git a/snapshot/overlay/overlay.go b/snapshot/overlay/overlay.go index a0b64d3c5..61fd1c1b8 100644 --- a/snapshot/overlay/overlay.go +++ b/snapshot/overlay/overlay.go @@ -10,9 +10,9 @@ import ( "path/filepath" "strings" - "github.com/containerd/containerd" "github.com/containerd/containerd/fs" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/storage" @@ -120,11 +120,11 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er return usage, nil } -func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { return o.createActive(ctx, key, parent, false) } -func (o *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { return o.createActive(ctx, key, parent, true) } @@ -132,7 +132,7 @@ func (o *snapshotter) View(ctx context.Context, key, parent string) ([]container // called on an read-write or readonly transaction. // // This can be used to recover mounts after calling View or Prepare. -func (o *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) { +func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { ctx, t, err := o.ms.TransactionContext(ctx, false) if err != nil { return nil, err @@ -229,7 +229,7 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho return storage.WalkInfo(ctx, fn) } -func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) { +func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) { var ( path string snapshotDir = filepath.Join(o.root, "snapshots") @@ -292,7 +292,7 @@ func (o *snapshotter) createActive(ctx context.Context, key, parent string, read return o.mounts(active), nil } -func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { +func (o *snapshotter) mounts(active storage.Active) []mount.Mount { if len(active.ParentIDs) == 0 { // if we only have one layer/no parents then just return a bind mount as overlay // will not work @@ -301,7 +301,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { roFlag = "ro" } - return []containerd.Mount{ + return []mount.Mount{ { Source: o.upperPath(active.ID), Type: "bind", @@ -320,7 +320,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { fmt.Sprintf("upperdir=%s", o.upperPath(active.ID)), ) } else if len(active.ParentIDs) == 1 { - return []containerd.Mount{ + return []mount.Mount{ { Source: o.upperPath(active.ParentIDs[0]), Type: "bind", @@ -338,7 +338,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount { } options = append(options, fmt.Sprintf("lowerdir=%s", strings.Join(parentPaths, ":"))) - return []containerd.Mount{ + return []mount.Mount{ { Type: "overlay", Source: "overlay", diff --git a/snapshot/overlay/overlay_test.go b/snapshot/overlay/overlay_test.go index a3180d892..f80d11559 100644 --- a/snapshot/overlay/overlay_test.go +++ b/snapshot/overlay/overlay_test.go @@ -11,7 +11,7 @@ import ( "syscall" "testing" - "github.com/containerd/containerd" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot/storage" "github.com/containerd/containerd/snapshot/testsuite" @@ -221,7 +221,7 @@ func TestOverlayOverlayRead(t *testing.T) { t.Error(err) return } - if err := containerd.MountAll(mounts, dest); err != nil { + if err := mount.MountAll(mounts, dest); err != nil { t.Error(err) return } diff --git a/snapshot/snapshotter.go b/snapshot/snapshotter.go index aba5c4a4c..a0e956d79 100644 --- a/snapshot/snapshotter.go +++ b/snapshot/snapshotter.go @@ -3,7 +3,7 @@ package snapshot import ( "context" - "github.com/containerd/containerd" + "github.com/containerd/containerd/mount" ) // Kind identifies the kind of snapshot. @@ -179,7 +179,7 @@ type Snapshotter interface { // available only for active snapshots. // // This can be used to recover mounts after calling View or Prepare. - Mounts(ctx context.Context, key string) ([]containerd.Mount, error) + Mounts(ctx context.Context, key string) ([]mount.Mount, error) // Prepare creates an active snapshot identified by key descending from the // provided parent. The returned mounts can be used to mount the snapshot @@ -195,7 +195,7 @@ type Snapshotter interface { // one is done with the transaction, Remove should be called on the key. // // Multiple calls to Prepare or View with the same key should fail. - Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) + Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) // View behaves identically to Prepare except the result may not be // committed back to the snapshot snapshotter. View returns a readonly view on @@ -210,7 +210,7 @@ type Snapshotter interface { // Commit may not be called on the provided key and will return an error. // To collect the resources associated with key, Remove must be called with // key as the argument. - View(ctx context.Context, key, parent string) ([]containerd.Mount, error) + View(ctx context.Context, key, parent string) ([]mount.Mount, error) // Commit captures the changes between key and its parent into a snapshot // identified by name. The name can then be used with the snapshotter's other diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index d1633506d..a37c925be 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -9,8 +9,8 @@ import ( "syscall" "testing" - "github.com/containerd/containerd" "github.com/containerd/containerd/fs/fstest" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/testutil" "github.com/stretchr/testify/assert" @@ -93,7 +93,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh t.Fatal("expected mounts to have entries") } - if err := containerd.MountAll(mounts, preparing); err != nil { + if err := mount.MountAll(mounts, preparing); err != nil { t.Fatalf("failure reason: %+v", err) } defer testutil.Unmount(t, preparing) @@ -124,7 +124,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh if err != nil { t.Fatalf("failure reason: %+v", err) } - if err := containerd.MountAll(mounts, next); err != nil { + if err := mount.MountAll(mounts, next); err != nil { t.Fatalf("failure reason: %+v", err) } defer testutil.Unmount(t, next) @@ -179,7 +179,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh if err != nil { t.Fatalf("failure reason: %+v", err) } - if err := containerd.MountAll(mounts, nextnext); err != nil { + if err := mount.MountAll(mounts, nextnext); err != nil { t.Fatalf("failure reason: %+v", err) } defer testutil.Unmount(t, nextnext) @@ -211,7 +211,7 @@ func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter s t.Fatal("expected mounts to have entries") } - if err = containerd.MountAll(mounts, preparing); err != nil { + if err = mount.MountAll(mounts, preparing); err != nil { t.Fatal(err) } defer testutil.Unmount(t, preparing) @@ -245,7 +245,7 @@ func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotte t.Fatal("expected mounts to have entries") } - if err = containerd.MountAll(mounts, preparing); err != nil { + if err = mount.MountAll(mounts, preparing); err != nil { t.Fatal(err) } defer testutil.Unmount(t, preparing) @@ -284,7 +284,7 @@ func snapshotterPrepareMount(ctx context.Context, snapshotter snapshot.Snapshott return "", fmt.Errorf("expected mounts to have entries") } - if err = containerd.MountAll(mounts, preparing); err != nil { + if err = mount.MountAll(mounts, preparing); err != nil { return "", err } return preparing, nil diff --git a/snapshot/windows/windows.go b/snapshot/windows/windows.go index 829412525..cb01907b8 100644 --- a/snapshot/windows/windows.go +++ b/snapshot/windows/windows.go @@ -6,7 +6,7 @@ import ( "context" "path/filepath" - "github.com/containerd/containerd" + "github.com/containerd/containerd/mount" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshot" "github.com/pkg/errors" @@ -48,11 +48,11 @@ func (o *Snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er panic("not implemented") } -func (o *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) { panic("not implemented") } -func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) { +func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) { panic("not implemented") } @@ -60,7 +60,7 @@ func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]container // called on an read-write or readonly transaction. // // This can be used to recover mounts after calling View or Prepare. -func (o *Snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) { +func (o *Snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { panic("not implemented") }