From d36810d66d87f08b09003b2e2455bcabe116ab08 Mon Sep 17 00:00:00 2001 From: Rudy Zhang Date: Mon, 8 Jun 2020 15:16:17 +0800 Subject: [PATCH] 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: https://github.com/moby/moby/pull/37993 Signed-off-by: Rudy Zhang --- snapshots/overlay/overlay.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/snapshots/overlay/overlay.go b/snapshots/overlay/overlay.go index 2222207a6..153e7aa81 100644 --- a/snapshots/overlay/overlay.go +++ b/snapshots/overlay/overlay.go @@ -70,6 +70,7 @@ type snapshotter struct { root string ms *storage.MetaStore asyncRemove bool + indexOff bool } // NewSnapshotter returns a Snapshotter which uses overlayfs. The overlayfs @@ -102,10 +103,17 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { return nil, err } + // figure out whether "index=off" option is recognized by the kernel + var indexOff bool + if _, err = os.Stat("/sys/module/overlay/parameters/index"); err == nil { + indexOff = true + } + return &snapshotter{ root: root, ms: ms, asyncRemove: config.asyncRemove, + indexOff: indexOff, }, nil } @@ -465,6 +473,11 @@ func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount { } var options []string + // set index=off when mount overlayfs + if o.indexOff { + options = append(options, "index=off") + } + if s.Kind == snapshots.KindActive { options = append(options, fmt.Sprintf("workdir=%s", o.workPath(s.ID)),