|
@@ -4,8 +4,15 @@ package overlayutils // import "github.com/docker/docker/daemon/graphdriver/over
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "os"
|
|
|
+ "path"
|
|
|
+ "path/filepath"
|
|
|
|
|
|
"github.com/docker/docker/daemon/graphdriver"
|
|
|
+ "github.com/pkg/errors"
|
|
|
+ "github.com/sirupsen/logrus"
|
|
|
+ "golang.org/x/sys/unix"
|
|
|
)
|
|
|
|
|
|
// ErrDTypeNotSupported denotes that the backing filesystem doesn't support d_type.
|
|
@@ -23,3 +30,36 @@ func ErrDTypeNotSupported(driver, backingFs string) error {
|
|
|
|
|
|
return graphdriver.NotSupportedError(msg)
|
|
|
}
|
|
|
+
|
|
|
+// SupportsMultipleLowerDir checks if the system supports multiple lowerdirs,
|
|
|
+// which is required for the overlay2 driver. On 4.x kernels, multiple lowerdirs
|
|
|
+// are always available (so this check isn't needed), and backported to RHEL and
|
|
|
+// CentOS 3.x kernels (3.10.0-693.el7.x86_64 and up). This function is to detect
|
|
|
+// support on those kernels, without doing a kernel version compare.
|
|
|
+func SupportsMultipleLowerDir(d string) error {
|
|
|
+ td, err := ioutil.TempDir(d, "multiple-lowerdir-check")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err := os.RemoveAll(td); err != nil {
|
|
|
+ logrus.Warnf("Failed to remove check directory %v: %v", td, err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ for _, dir := range []string{"lower1", "lower2", "upper", "work", "merged"} {
|
|
|
+ if err := os.Mkdir(filepath.Join(td, dir), 0755); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mnt := filepath.Join(td, "merged")
|
|
|
+ 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"))
|
|
|
+ if err := unix.Mount("overlay", mnt, "overlay", 0, opts); err != nil {
|
|
|
+ return errors.Wrap(err, "failed to mount overlay")
|
|
|
+ }
|
|
|
+ if err := unix.Unmount(mnt, 0); err != nil {
|
|
|
+ logrus.Warnf("Failed to unmount check directory %v: %v", mnt, err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|