Skip to content

Commit

Permalink
overlay: public function to check for overlay support
Browse files Browse the repository at this point in the history
add a public function to check whether the kernel supports native
overlay.

If the existing storage was created using a mount_program, refuse to
use the native overlay as they are not fully compatible, e.g. native
overlay uses device whiteout files while a mount_program such as
fuse-overlayfs could be using a different format to accomodate older
kernels where unprivileged users cannot create whiteout devices.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Mar 5, 2021
1 parent 27903e9 commit cf4c912
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,34 @@ func cachedFeatureRecord(runhome, feature string, supported bool, text string) (
return err
}

func SupportsNativeOverlay(graphroot, rundir string) (bool, error) {
if os.Geteuid() != 0 || graphroot == "" || rundir == "" {
return false, nil
}

home := filepath.Join(graphroot, "overlay")
runhome := filepath.Join(rundir, "overlay")

if _, err := os.Stat(getMountProgramFlagFile(home)); err == nil {
logrus.Debugf("overlay storage already configured with a mount-program")
return false, nil
}

for _, dir := range []string{home, runhome} {
if _, err := os.Stat(dir); err != nil {
_ = idtools.MkdirAllAs(dir, 0700, 0, 0)
}
}

fsMagic, err := graphdriver.GetFSMagic(home)
if err != nil {
return false, err
}

supportsDType, _ := checkAndRecordOverlaySupport(fsMagic, home, runhome)
return supportsDType, nil
}

func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGID int) (supportsDType bool, err error) {
// We can try to modprobe overlay first

Expand Down
4 changes: 4 additions & 0 deletions drivers/overlay/overlay_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// +build !linux

package overlay

func SupportsNativeOverlay(graphroot, rundir string) (bool, error) {
return false, nil
}

0 comments on commit cf4c912

Please sign in to comment.