Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit a5c9db1

Browse files
kolyshkinAkihiroSuda
authored andcommitted
overlay: move supportsMultipleLowerDir to utils
This moves supportsMultipleLowerDir() to overlayutils so it can be used from both overlay and overlay2. The only changes made were: * replace logger with logrus * don't use workDirName mergedDirName constants * add mnt var to improve readability a bit This is a preparation for the next commit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> (cherry picked from commit d5687079ad8ad27c467ef5c8758a73c519b45d9b) Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp> Upstream-commit: 5571ceb5aca90ac702e0d3a02b38dd95416f3da5 Component: engine
1 parent 806947e commit a5c9db1

3 files changed

Lines changed: 41 additions & 33 deletions

File tree

components/engine/daemon/graphdriver/overlay2/check.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,35 +99,3 @@ func doesSupportNativeDiff(d string) error {
9999

100100
return nil
101101
}
102-
103-
// supportsMultipleLowerDir checks if the system supports multiple lowerdirs,
104-
// which is required for the overlay2 driver. On 4.x kernels, multiple lowerdirs
105-
// are always available (so this check isn't needed), and backported to RHEL and
106-
// CentOS 3.x kernels (3.10.0-693.el7.x86_64 and up). This function is to detect
107-
// support on those kernels, without doing a kernel version compare.
108-
func supportsMultipleLowerDir(d string) error {
109-
td, err := ioutil.TempDir(d, "multiple-lowerdir-check")
110-
if err != nil {
111-
return err
112-
}
113-
defer func() {
114-
if err := os.RemoveAll(td); err != nil {
115-
logger.Warnf("Failed to remove check directory %v: %v", td, err)
116-
}
117-
}()
118-
119-
for _, dir := range []string{"lower1", "lower2", "upper", workDirName, mergedDirName} {
120-
if err := os.Mkdir(filepath.Join(td, dir), 0755); err != nil {
121-
return err
122-
}
123-
}
124-
125-
opts := fmt.Sprintf("lowerdir=%s:%s,upperdir=%s,workdir=%s", path.Join(td, "lower2"), path.Join(td, "lower1"), path.Join(td, "upper"), path.Join(td, workDirName))
126-
if err := unix.Mount("overlay", filepath.Join(td, mergedDirName), "overlay", 0, opts); err != nil {
127-
return errors.Wrap(err, "failed to mount overlay")
128-
}
129-
if err := unix.Unmount(filepath.Join(td, mergedDirName), 0); err != nil {
130-
logger.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, mergedDirName), err)
131-
}
132-
return nil
133-
}

components/engine/daemon/graphdriver/overlay2/overlay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
180180
if opts.overrideKernelCheck {
181181
logger.Warn("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update")
182182
} else {
183-
if err := supportsMultipleLowerDir(testdir); err != nil {
183+
if err := overlayutils.SupportsMultipleLowerDir(testdir); err != nil {
184184
logger.Debugf("Multiple lower dirs not supported: %v", err)
185185
return nil, graphdriver.ErrNotSupported
186186
}

components/engine/daemon/graphdriver/overlayutils/overlayutils.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ package overlayutils // import "github.com/docker/docker/daemon/graphdriver/over
44

55
import (
66
"fmt"
7+
"io/ioutil"
8+
"os"
9+
"path"
10+
"path/filepath"
711

812
"github.com/docker/docker/daemon/graphdriver"
13+
"github.com/pkg/errors"
14+
"github.com/sirupsen/logrus"
15+
"golang.org/x/sys/unix"
916
)
1017

1118
// ErrDTypeNotSupported denotes that the backing filesystem doesn't support d_type.
@@ -23,3 +30,36 @@ func ErrDTypeNotSupported(driver, backingFs string) error {
2330

2431
return graphdriver.NotSupportedError(msg)
2532
}
33+
34+
// SupportsMultipleLowerDir checks if the system supports multiple lowerdirs,
35+
// which is required for the overlay2 driver. On 4.x kernels, multiple lowerdirs
36+
// are always available (so this check isn't needed), and backported to RHEL and
37+
// CentOS 3.x kernels (3.10.0-693.el7.x86_64 and up). This function is to detect
38+
// support on those kernels, without doing a kernel version compare.
39+
func SupportsMultipleLowerDir(d string) error {
40+
td, err := ioutil.TempDir(d, "multiple-lowerdir-check")
41+
if err != nil {
42+
return err
43+
}
44+
defer func() {
45+
if err := os.RemoveAll(td); err != nil {
46+
logrus.Warnf("Failed to remove check directory %v: %v", td, err)
47+
}
48+
}()
49+
50+
for _, dir := range []string{"lower1", "lower2", "upper", "work", "merged"} {
51+
if err := os.Mkdir(filepath.Join(td, dir), 0755); err != nil {
52+
return err
53+
}
54+
}
55+
56+
mnt := filepath.Join(td, "merged")
57+
opts := fmt.Sprintf("lowerdir=%s:%s,upperdir=%s,workdir=%s", path.Join(td, "lower2"), path.Join(td, "lower1"), path.Join(td, "upper"), path.Join(td, "work"))
58+
if err := unix.Mount("overlay", mnt, "overlay", 0, opts); err != nil {
59+
return errors.Wrap(err, "failed to mount overlay")
60+
}
61+
if err := unix.Unmount(mnt, 0); err != nil {
62+
logrus.Warnf("Failed to unmount check directory %v: %v", mnt, err)
63+
}
64+
return nil
65+
}

0 commit comments

Comments
 (0)