mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
plugins: container-rootfs-relative paths
Legacy plugins expect host-relative paths (such as for Volume.Mount). However, a containerized plugin cannot respond with a host-relative path. Therefore, this commit modifies new volume plugins' paths in Mount and List to prepend the container's rootfs path. This introduces a new PropagatedMount field in the Plugin Config. When it is set for volume plugins, RootfsPropagation is set to rshared and the path specified by PropagatedMount is bind-mounted with rshared prior to launching the container. This is so that the daemon code can access the paths returned by the plugin from the host mount namespace. Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
@@ -186,7 +187,6 @@ func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
||||
testRequires(c, Network, IsAmd64)
|
||||
|
||||
volName := "plugin-volume"
|
||||
volRoot := "/data"
|
||||
destDir := "/tmp/data/"
|
||||
destFile := "foo"
|
||||
|
||||
@@ -197,13 +197,25 @@ func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
||||
if err != nil {
|
||||
c.Fatalf("Could not install plugin: %v %s", err, out)
|
||||
}
|
||||
pluginID, err := s.d.Cmd("plugin", "inspect", "-f", "{{.Id}}", pName)
|
||||
pluginID = strings.TrimSpace(pluginID)
|
||||
if err != nil {
|
||||
c.Fatalf("Could not retrieve plugin ID: %v %s", err, pluginID)
|
||||
}
|
||||
mountpointPrefix := filepath.Join(s.d.RootDir(), "plugins", pluginID, "rootfs")
|
||||
defer func() {
|
||||
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
||||
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
||||
}
|
||||
|
||||
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
||||
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
||||
}
|
||||
|
||||
exists, err := existsMountpointWithPrefix(mountpointPrefix)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(exists, checker.Equals, false)
|
||||
|
||||
}()
|
||||
|
||||
out, err = s.d.Cmd("volume", "create", "-d", pName, volName)
|
||||
@@ -231,11 +243,24 @@ func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
||||
|
||||
out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "touch", destDir+destFile)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
path := filepath.Join(mountPoint, destFile)
|
||||
path := filepath.Join(s.d.RootDir(), "plugins", pluginID, "rootfs", mountPoint, destFile)
|
||||
_, err = os.Lstat(path)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// tiborvass/no-remove is a volume plugin that persists data on disk at /data,
|
||||
// even after the volume is removed. So perform an explicit filesystem cleanup.
|
||||
os.RemoveAll(volRoot)
|
||||
exists, err := existsMountpointWithPrefix(mountpointPrefix)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(exists, checker.Equals, true)
|
||||
}
|
||||
|
||||
func existsMountpointWithPrefix(mountpointPrefix string) (bool, error) {
|
||||
mounts, err := mount.GetMounts()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, mnt := range mounts {
|
||||
if strings.HasPrefix(mnt.Mountpoint, mountpointPrefix) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user