瀏覽代碼

Merge pull request #37031 from kolyshkin/getmnt

Fix daemon.getSourceMount() for /
Sebastiaan van Stijn 7 年之前
父節點
當前提交
379845ec20
共有 2 個文件被更改,包括 15 次插入7 次删除
  1. 1 7
      daemon/oci_linux.go
  2. 14 0
      daemon/oci_linux_test.go

+ 1 - 7
daemon/oci_linux.go

@@ -405,13 +405,7 @@ func getSourceMount(source string) (string, string, error) {
 			idx = i
 		}
 	}
-	// and return it unless it's "/"
-	if mi[idx].Mountpoint != "/" {
-		return mi[idx].Mountpoint, mi[idx].Optional, nil
-	}
-
-	// If we are here, we did not find parent mount. Something is wrong.
-	return "", "", fmt.Errorf("Could not find source mount of %s", source)
+	return mi[idx].Mountpoint, mi[idx].Optional, nil
 }
 
 const (

+ 14 - 0
daemon/oci_linux_test.go

@@ -1,6 +1,7 @@
 package daemon // import "github.com/docker/docker/daemon"
 
 import (
+	"os"
 	"testing"
 
 	containertypes "github.com/docker/docker/api/types/container"
@@ -86,3 +87,16 @@ func TestIpcPrivateVsReadonly(t *testing.T) {
 		assert.Check(t, is.Equal(false, inSlice(m.Options, "ro")))
 	}
 }
+
+func TestGetSourceMount(t *testing.T) {
+	// must be able to find source mount for /
+	mnt, _, err := getSourceMount("/")
+	assert.NilError(t, err)
+	assert.Equal(t, mnt, "/")
+
+	// must be able to find source mount for current directory
+	cwd, err := os.Getwd()
+	assert.NilError(t, err)
+	_, _, err = getSourceMount(cwd)
+	assert.NilError(t, err)
+}