Skip to content

Commit 1caf307

Browse files
committed
#30 Shim: fix the "deadlock avoided" error during the rootfs mount
Currently, the sporadic "mount_nullfs: /path/to/rootfs: resource deadlock avoided" error occurs during containerd shim task creation. The exact reason for this error is unknown, but a mounter that executes the system call instead of running a shell command seems to fix the problem. This change replaces the containerd's mounter with `moby/sys/mount`
1 parent 027fcd7 commit 1caf307

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

containerd/shim.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/exec"
99
"path/filepath"
1010
"strconv"
11+
"strings"
1112
"sync"
1213
"syscall"
1314
"time"
@@ -19,7 +20,6 @@ import (
1920
tasktypes "github.com/containerd/containerd/api/types/task"
2021
"github.com/containerd/containerd/errdefs"
2122
"github.com/containerd/containerd/log"
22-
"github.com/containerd/containerd/mount"
2323
"github.com/containerd/containerd/namespaces"
2424
"github.com/containerd/containerd/pkg/process"
2525
"github.com/containerd/containerd/runtime"
@@ -31,6 +31,7 @@ import (
3131
"github.com/containerd/typeurl"
3232
"github.com/gogo/protobuf/types"
3333
ptypes "github.com/gogo/protobuf/types"
34+
"github.com/moby/sys/mount"
3435
specs "github.com/opencontainers/runtime-spec/specs-go"
3536
"github.com/pkg/errors"
3637
"github.com/sirupsen/logrus"
@@ -338,7 +339,7 @@ func (s *service) delete(ctx context.Context, bundlePath string) (*task.DeleteRe
338339
log.G(ctx).WithError(err).Error("failed to run runj delete")
339340
return nil, err
340341
}
341-
if err := mount.UnmountAll(filepath.Join(bundlePath, "rootfs"), 0); err != nil {
342+
if err := mount.RecursiveUnmount(filepath.Join(bundlePath, "rootfs")); err != nil {
342343
log.G(ctx).WithError(err).Warn("failed to cleanup rootfs mount")
343344
}
344345
return &taskAPI.DeleteResponse{
@@ -405,20 +406,15 @@ func (s *service) Create(ctx context.Context, req *task.CreateTaskRequest) (*tas
405406
defer func() {
406407
if err != nil {
407408
log.G(ctx).WithField("rootfs", rootfs).WithError(err).Error("failed to create,unmounting rootfs")
408-
if err2 := mount.UnmountAll(rootfs, 0); err2 != nil {
409+
if err2 := mount.RecursiveUnmount(rootfs); err2 != nil {
409410
log.G(ctx).WithError(err2).Warn("failed to cleanup rootfs mount")
410411
}
411412
}
412413
}()
413414
for _, rm := range mounts {
414-
m := &mount.Mount{
415-
Type: rm.Type,
416-
Source: rm.Source,
417-
Options: rm.Options,
418-
}
419-
log.G(ctx).WithField("mount", m).WithField("rootfs", rootfs).Warn("mount")
420-
if err := m.Mount(rootfs); err != nil {
421-
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
415+
log.G(ctx).WithField("mount", rm).WithField("rootfs", rootfs).Warn("mount")
416+
if err := mount.Mount(rm.Source, rootfs, rm.Type, strings.Join(rm.Options, ",")); err != nil {
417+
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", rm)
422418
}
423419
}
424420

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ require (
1111
github.com/containerd/typeurl v1.0.2
1212
github.com/gogo/protobuf v1.3.2
1313
github.com/hashicorp/go-multierror v1.1.0 // indirect
14+
github.com/moby/sys/mount v0.3.3
1415
github.com/opencontainers/go-digest v1.0.0
1516
github.com/opencontainers/image-spec v1.0.2
1617
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
1718
github.com/pkg/errors v0.9.1
1819
github.com/sirupsen/logrus v1.8.1
1920
github.com/spf13/cobra v1.0.0
2021
github.com/stretchr/testify v1.7.0
21-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
22+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
2223
google.golang.org/grpc v1.34.0 // indirect
2324
)

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,12 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
434434
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
435435
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
436436
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
437+
github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs=
438+
github.com/moby/sys/mount v0.3.3/go.mod h1:PBaEorSNTLG5t/+4EgukEQVlAvVEc6ZjTySwKdqp5K0=
437439
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
438-
github.com/moby/sys/mountinfo v0.4.1 h1:1O+1cHA1aujwEwwVMa2Xm2l+gIpUHyd3+D+d7LZh1kM=
439440
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
441+
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
442+
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
440443
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
441444
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
442445
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
784787
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
785788
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
786789
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
787-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
788790
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
791+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
792+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
789793
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
790794
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
791795
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 commit comments

Comments
 (0)