Skip to content

Commit d36810d

Browse files
committed
overlay: use index=off to fix EBUSY on mount
kernel version > 4.13rc1 support index=on feature, it will be failed with EBUSY when trying to mount. Related: moby/moby#37993 Signed-off-by: Rudy Zhang <[email protected]>
1 parent 38cb1c1 commit d36810d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

snapshots/overlay/overlay.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type snapshotter struct {
7070
root string
7171
ms *storage.MetaStore
7272
asyncRemove bool
73+
indexOff bool
7374
}
7475

7576
// NewSnapshotter returns a Snapshotter which uses overlayfs. The overlayfs
@@ -102,10 +103,17 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
102103
return nil, err
103104
}
104105

106+
// figure out whether "index=off" option is recognized by the kernel
107+
var indexOff bool
108+
if _, err = os.Stat("/sys/module/overlay/parameters/index"); err == nil {
109+
indexOff = true
110+
}
111+
105112
return &snapshotter{
106113
root: root,
107114
ms: ms,
108115
asyncRemove: config.asyncRemove,
116+
indexOff: indexOff,
109117
}, nil
110118
}
111119

@@ -465,6 +473,11 @@ func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
465473
}
466474
var options []string
467475

476+
// set index=off when mount overlayfs
477+
if o.indexOff {
478+
options = append(options, "index=off")
479+
}
480+
468481
if s.Kind == snapshots.KindActive {
469482
options = append(options,
470483
fmt.Sprintf("workdir=%s", o.workPath(s.ID)),

0 commit comments

Comments
 (0)