mounts: Add check for system volumes

We handle system directories differently, if its a bind mount
we mount the guest system directory to the container mount and
skip the 9p share mount.
However, we should not do this for docker volumes which are directories
created by Docker.

This introduces a Docker specific check, but that is the only
information available to us at the OCI layer.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2019-03-22 16:45:27 -07:00
parent 814e5de224
commit 70c193132d
3 changed files with 31 additions and 1 deletions

View File

@ -477,7 +477,11 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
var sharedDirMounts []Mount
var ignoredMounts []Mount
for idx, m := range c.mounts {
if isSystemMount(m.Destination) || m.Type != "bind" {
if isSystemMount(m.Destination) && !IsDockerVolume(m.Source) {
continue
}
if m.Type != "bind" {
continue
}

View File

@ -326,3 +326,19 @@ func bindUnmountAllRootfs(ctx context.Context, sharedDir string, sandbox *Sandbo
}
}
}
const (
dockerVolumePrefix = "/var/lib/docker/volumes"
dockerVolumeSuffix = "_data"
)
// IsDockerVolume returns true if the given source path is
// a docker volume.
// This uses a very specific path that is used by docker.
func IsDockerVolume(path string) bool {
if strings.HasPrefix(path, dockerVolumePrefix) && filepath.Base(path) == dockerVolumeSuffix {
return true
}
return false
}

View File

@ -282,3 +282,13 @@ func TestIsDeviceMapper(t *testing.T) {
t.Fatal()
}
}
func TestIsDockerVolume(t *testing.T) {
path := "/var/lib/docker/volumes/00da1347c7cf4f15db35f/_data"
isDockerVolume := IsDockerVolume(path)
assert.True(t, isDockerVolume)
path = "/var/lib/testdir"
isDockerVolume := IsDockerVolume(path)
assert.False(t, isDockerVolume)
}