Forráskód Böngészése

Merge pull request #38930 from daym/fewer-modprobes

Use fewer modprobes
Akihiro Suda 5 éve
szülő
commit
610551e039

+ 8 - 2
daemon/graphdriver/devmapper/deviceset.go

@@ -540,8 +540,14 @@ func xfsSupported() error {
 		return err // error text is descriptive enough
 		return err // error text is descriptive enough
 	}
 	}
 
 
-	// Check if kernel supports xfs filesystem or not.
-	exec.Command("modprobe", "xfs").Run()
+	mountTarget, err := ioutil.TempDir("", "supportsXFS")
+	if err != nil {
+		return errors.Wrapf(err, "error checking for xfs support")
+	}
+
+	/* The mounting will fail--after the module has been loaded.*/
+	defer os.RemoveAll(mountTarget)
+	unix.Mount("none", mountTarget, "xfs", 0, "")
 
 
 	f, err := os.Open("/proc/filesystems")
 	f, err := os.Open("/proc/filesystems")
 	if err != nil {
 	if err != nil {

+ 9 - 4
daemon/graphdriver/overlay/overlay.go

@@ -8,7 +8,6 @@ import (
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
-	"os/exec"
 	"path"
 	"path"
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
@@ -201,9 +200,15 @@ func parseOptions(options []string) (*overlayOptions, error) {
 }
 }
 
 
 func supportsOverlay() error {
 func supportsOverlay() error {
-	// We can try to modprobe overlay first before looking at
-	// proc/filesystems for when overlay is supported
-	exec.Command("modprobe", "overlay").Run()
+	// Access overlay filesystem so that Linux loads it (if possible).
+	mountTarget, err := ioutil.TempDir("", "supportsOverlay")
+	if err != nil {
+		logrus.WithError(err).WithField("storage-driver", "overlay2").Error("could not create temporary directory, so assuming that 'overlay' is not supported")
+		return graphdriver.ErrNotSupported
+	}
+	/* The mounting will fail--after the module has been loaded.*/
+	defer os.RemoveAll(mountTarget)
+	unix.Mount("overlay", mountTarget, "overlay", 0, "")
 
 
 	f, err := os.Open("/proc/filesystems")
 	f, err := os.Open("/proc/filesystems")
 	if err != nil {
 	if err != nil {

+ 9 - 4
daemon/graphdriver/overlay2/overlay.go

@@ -10,7 +10,6 @@ import (
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
-	"os/exec"
 	"path"
 	"path"
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
@@ -276,9 +275,15 @@ func parseOptions(options []string) (*overlayOptions, error) {
 }
 }
 
 
 func supportsOverlay() error {
 func supportsOverlay() error {
-	// We can try to modprobe overlay first before looking at
-	// proc/filesystems for when overlay is supported
-	exec.Command("modprobe", "overlay").Run()
+	// Access overlay filesystem so that Linux loads it (if possible).
+	mountTarget, err := ioutil.TempDir("", "supportsOverlay2")
+	if err != nil {
+		logrus.WithError(err).WithField("storage-driver", "overlay2").Error("could not create temporary directory, so assuming that 'overlay' is not supported")
+		return graphdriver.ErrNotSupported
+	}
+	/* The mounting will fail--after the module has been loaded.*/
+	defer os.RemoveAll(mountTarget)
+	unix.Mount("overlay", mountTarget, "overlay", 0, "")
 
 
 	f, err := os.Open("/proc/filesystems")
 	f, err := os.Open("/proc/filesystems")
 	if err != nil {
 	if err != nil {