diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index f9e34483c0..6da1f25a34 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -112,6 +112,8 @@ var ( useNaiveDiffLock sync.Once useNaiveDiffOnly bool + + indexOff string ) func init() { @@ -227,7 +229,18 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap return nil, fmt.Errorf("Storage Option overlay2.size only supported for backingFS XFS. Found %v", backingFs) } - logger.Debugf("backingFs=%s, projectQuotaSupported=%v", backingFs, projectQuotaSupported) + // figure out whether "index=off" option is recognized by the kernel + _, err = os.Stat("/sys/module/overlay/parameters/index") + switch { + case err == nil: + indexOff = "index=off," + case os.IsNotExist(err): + // old kernel, no index -- do nothing + default: + logger.Warnf("Unable to detect whether overlay kernel module supports index parameter: %s", err) + } + + logger.Debugf("backingFs=%s, projectQuotaSupported=%v, indexOff=%q", backingFs, projectQuotaSupported, indexOff) return d, nil } @@ -576,7 +589,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e for i, s := range splitLowers { absLowers[i] = path.Join(d.home, s) } - opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(absLowers, ":"), path.Join(dir, "diff"), path.Join(dir, "work")) + opts := indexOff + "lowerdir=" + strings.Join(absLowers, ":") + ",upperdir=" + path.Join(dir, "diff") + ",workdir=" + path.Join(dir, "work") mountData := label.FormatMountLabel(opts, mountLabel) mount := unix.Mount mountTarget := mergedDir @@ -605,7 +618,7 @@ func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr e // fit within a page and relative links make the mount data much // smaller at the expense of requiring a fork exec to chroot. if len(mountData) > pageSize { - opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", string(lowers), path.Join(id, "diff"), path.Join(id, "work")) + opts = indexOff + "lowerdir=" + string(lowers) + ",upperdir=" + path.Join(id, "diff") + ",workdir=" + path.Join(id, "work") mountData = label.FormatMountLabel(opts, mountLabel) if len(mountData) > pageSize { return nil, fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))