diff --git a/containerd/shim.go b/containerd/shim.go index dd7d848..818fdbe 100644 --- a/containerd/shim.go +++ b/containerd/shim.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "strconv" + "strings" "sync" "syscall" "time" @@ -19,7 +20,6 @@ import ( tasktypes "github.com/containerd/containerd/api/types/task" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" - "github.com/containerd/containerd/mount" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/process" "github.com/containerd/containerd/runtime" @@ -31,6 +31,7 @@ import ( "github.com/containerd/typeurl" "github.com/gogo/protobuf/types" ptypes "github.com/gogo/protobuf/types" + "github.com/moby/sys/mount" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -338,7 +339,7 @@ func (s *service) delete(ctx context.Context, bundlePath string) (*task.DeleteRe log.G(ctx).WithError(err).Error("failed to run runj delete") return nil, err } - if err := mount.UnmountAll(filepath.Join(bundlePath, "rootfs"), 0); err != nil { + if err := mount.RecursiveUnmount(filepath.Join(bundlePath, "rootfs")); err != nil { log.G(ctx).WithError(err).Warn("failed to cleanup rootfs mount") } return &taskAPI.DeleteResponse{ @@ -405,20 +406,15 @@ func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (*tas defer func() { if err != nil { log.G(ctx).WithField("rootfs", rootfs).WithError(err).Error("failed to create,unmounting rootfs") - if err2 := mount.UnmountAll(rootfs, 0); err2 != nil { + if err2 := mount.RecursiveUnmount(rootfs); err2 != nil { log.G(ctx).WithError(err2).Warn("failed to cleanup rootfs mount") } } }() for _, rm := range mounts { - m := &mount.Mount{ - Type: rm.Type, - Source: rm.Source, - Options: rm.Options, - } - log.G(ctx).WithField("mount", m).WithField("rootfs", rootfs).Warn("mount") - if err := m.Mount(rootfs); err != nil { - return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m) + log.G(ctx).WithField("mount", rm).WithField("rootfs", rootfs).Warn("mount") + if err := mount.Mount(rm.Source, rootfs, rm.Type, strings.Join(rm.Options, ",")); err != nil { + return nil, errors.Wrapf(err, "failed to mount rootfs component %v", rm) } } diff --git a/go.mod b/go.mod index 4952ae9..e00e8cf 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/containerd/typeurl v1.0.2 github.com/gogo/protobuf v1.3.2 github.com/hashicorp/go-multierror v1.1.0 // indirect + github.com/moby/sys/mount v0.3.3 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.0.2 github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 @@ -18,6 +19,6 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.0.0 github.com/stretchr/testify v1.7.0 - golang.org/x/sys v0.0.0-20220412211240-33da011f77ad + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a google.golang.org/grpc v1.34.0 // indirect ) diff --git a/go.sum b/go.sum index 4e393f7..94620cb 100644 --- a/go.sum +++ b/go.sum @@ -434,9 +434,12 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A= github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc= +github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs= +github.com/moby/sys/mount v0.3.3/go.mod h1:PBaEorSNTLG5t/+4EgukEQVlAvVEc6ZjTySwKdqp5K0= github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= -github.com/moby/sys/mountinfo v0.4.1 h1:1O+1cHA1aujwEwwVMa2Xm2l+gIpUHyd3+D+d7LZh1kM= github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= +github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78= +github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI= github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ= github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -784,8 +787,9 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=