Browse code

daemon.getSourceMount(): fix for / mount point

A recent optimization in getSourceMount() made it return an error
in case when the found mount point is "/". This prevented bind-mounted
volumes from working in such cases.

A (rather trivial but adeqate) unit test case is added.

Fixes: 871c957242 ("getSourceMount(): simplify")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/05/11 04:01:50
Showing 2 changed files
... ...
@@ -405,13 +405,7 @@ func getSourceMount(source string) (string, string, error) {
405 405
 			idx = i
406 406
 		}
407 407
 	}
408
-	// and return it unless it's "/"
409
-	if mi[idx].Mountpoint != "/" {
410
-		return mi[idx].Mountpoint, mi[idx].Optional, nil
411
-	}
412
-
413
-	// If we are here, we did not find parent mount. Something is wrong.
414
-	return "", "", fmt.Errorf("Could not find source mount of %s", source)
408
+	return mi[idx].Mountpoint, mi[idx].Optional, nil
415 409
 }
416 410
 
417 411
 const (
... ...
@@ -1,6 +1,7 @@
1 1
 package daemon // import "github.com/docker/docker/daemon"
2 2
 
3 3
 import (
4
+	"os"
4 5
 	"testing"
5 6
 
6 7
 	containertypes "github.com/docker/docker/api/types/container"
... ...
@@ -86,3 +87,16 @@ func TestIpcPrivateVsReadonly(t *testing.T) {
86 86
 		assert.Check(t, is.Equal(false, inSlice(m.Options, "ro")))
87 87
 	}
88 88
 }
89
+
90
+func TestGetSourceMount(t *testing.T) {
91
+	// must be able to find source mount for /
92
+	mnt, _, err := getSourceMount("/")
93
+	assert.NilError(t, err)
94
+	assert.Equal(t, mnt, "/")
95
+
96
+	// must be able to find source mount for current directory
97
+	cwd, err := os.Getwd()
98
+	assert.NilError(t, err)
99
+	_, _, err = getSourceMount(cwd)
100
+	assert.NilError(t, err)
101
+}