Merge pull request #37031 from kolyshkin/getmnt

Fix daemon.getSourceMount() for /
This commit is contained in:
Sebastiaan van Stijn 2018-05-11 16:39:57 +02:00 committed by GitHub
commit 379845ec20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View file

@ -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 (

View file

@ -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)
}