Browse code

Use fewer modprobes

Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org>
(cherry picked from commit 074eca1d796d0863a8c71d4707f6d8767fd19fa9)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>

Danny Milosavljevic authored on 2019/07/31 20:04:03
Showing 3 changed files
... ...
@@ -540,8 +540,14 @@ func xfsSupported() error {
540 540
 		return err // error text is descriptive enough
541 541
 	}
542 542
 
543
-	// Check if kernel supports xfs filesystem or not.
544
-	exec.Command("modprobe", "xfs").Run()
543
+	mountTarget, err := ioutil.TempDir("", "supportsXFS")
544
+	if err != nil {
545
+		return errors.Wrapf(err, "error checking for xfs support")
546
+	}
547
+
548
+	/* The mounting will fail--after the module has been loaded.*/
549
+	defer os.RemoveAll(mountTarget)
550
+	unix.Mount("none", mountTarget, "xfs", 0, "")
545 551
 
546 552
 	f, err := os.Open("/proc/filesystems")
547 553
 	if err != nil {
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"io"
9 9
 	"io/ioutil"
10 10
 	"os"
11
-	"os/exec"
12 11
 	"path"
13 12
 	"path/filepath"
14 13
 	"strconv"
... ...
@@ -201,9 +200,15 @@ func parseOptions(options []string) (*overlayOptions, error) {
201 201
 }
202 202
 
203 203
 func supportsOverlay() error {
204
-	// We can try to modprobe overlay first before looking at
205
-	// proc/filesystems for when overlay is supported
206
-	exec.Command("modprobe", "overlay").Run()
204
+	// Access overlay filesystem so that Linux loads it (if possible).
205
+	mountTarget, err := ioutil.TempDir("", "supportsOverlay")
206
+	if err != nil {
207
+		logrus.WithError(err).WithField("storage-driver", "overlay2").Error("could not create temporary directory, so assuming that 'overlay' is not supported")
208
+		return graphdriver.ErrNotSupported
209
+	}
210
+	/* The mounting will fail--after the module has been loaded.*/
211
+	defer os.RemoveAll(mountTarget)
212
+	unix.Mount("overlay", mountTarget, "overlay", 0, "")
207 213
 
208 214
 	f, err := os.Open("/proc/filesystems")
209 215
 	if err != nil {
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"io"
11 11
 	"io/ioutil"
12 12
 	"os"
13
-	"os/exec"
14 13
 	"path"
15 14
 	"path/filepath"
16 15
 	"strconv"
... ...
@@ -276,9 +275,15 @@ func parseOptions(options []string) (*overlayOptions, error) {
276 276
 }
277 277
 
278 278
 func supportsOverlay() error {
279
-	// We can try to modprobe overlay first before looking at
280
-	// proc/filesystems for when overlay is supported
281
-	exec.Command("modprobe", "overlay").Run()
279
+	// Access overlay filesystem so that Linux loads it (if possible).
280
+	mountTarget, err := ioutil.TempDir("", "supportsOverlay2")
281
+	if err != nil {
282
+		logrus.WithError(err).WithField("storage-driver", "overlay2").Error("could not create temporary directory, so assuming that 'overlay' is not supported")
283
+		return graphdriver.ErrNotSupported
284
+	}
285
+	/* The mounting will fail--after the module has been loaded.*/
286
+	defer os.RemoveAll(mountTarget)
287
+	unix.Mount("overlay", mountTarget, "overlay", 0, "")
282 288
 
283 289
 	f, err := os.Open("/proc/filesystems")
284 290
 	if err != nil {