From ae8ec4860e68e945cf6b2c157fa4e243c35c54a5 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 25 Jan 2016 14:48:23 -0800 Subject: [PATCH] Move tar copy-up for tmpfs mounts We cannot rely on the tar command for this type of operation because tar versions, flags, and functionality can very from distro to distro. Since this is in the container execution path it is not safe to have this as a dependency from dockers POV where the user cannot change the fact that docker is adding these pre and post mount commands. Signed-off-by: Michael Crosby --- daemon/execdriver/native/create.go | 3 -- daemon/execdriver/native/tmpfs.go | 56 ------------------------------ man/docker-create.1.md | 5 +-- man/docker-run.1.md | 5 +-- 4 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 daemon/execdriver/native/tmpfs.go diff --git a/daemon/execdriver/native/create.go b/daemon/execdriver/native/create.go index 4f97ed93f8..4cc14532fd 100644 --- a/daemon/execdriver/native/create.go +++ b/daemon/execdriver/native/create.go @@ -436,7 +436,6 @@ func (d *Driver) setupMounts(container *configs.Config, c *execdriver.Command) e flags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV err error ) - fulldest := filepath.Join(c.Rootfs, m.Destination) if m.Data != "" { flags, data, err = mount.ParseTmpfsOptions(m.Data) if err != nil { @@ -449,8 +448,6 @@ func (d *Driver) setupMounts(container *configs.Config, c *execdriver.Command) e Data: data, Device: "tmpfs", Flags: flags, - PremountCmds: genTmpfsPremountCmd(c.TmpDir, fulldest, m.Destination), - PostmountCmds: genTmpfsPostmountCmd(c.TmpDir, fulldest, m.Destination), PropagationFlags: []int{mountPropagationMap[volume.DefaultPropagationMode]}, }) continue diff --git a/daemon/execdriver/native/tmpfs.go b/daemon/execdriver/native/tmpfs.go deleted file mode 100644 index 89f7f4ae7f..0000000000 --- a/daemon/execdriver/native/tmpfs.go +++ /dev/null @@ -1,56 +0,0 @@ -package native - -import ( - "fmt" - "os" - "os/exec" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/opencontainers/runc/libcontainer/configs" -) - -func genTmpfsPremountCmd(tmpDir string, fullDest string, dest string) []configs.Command { - var premount []configs.Command - tarPath, err := exec.LookPath("tar") - if err != nil { - logrus.Warn("tar command is not available for tmpfs mount: %s", err) - return premount - } - if _, err = exec.LookPath("rm"); err != nil { - logrus.Warn("rm command is not available for tmpfs mount: %s", err) - return premount - } - tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1)) - if _, err := os.Stat(fullDest); err == nil { - premount = append(premount, configs.Command{ - Path: tarPath, - Args: []string{"-cf", tarFile, "-C", fullDest, "."}, - }) - } - return premount -} - -func genTmpfsPostmountCmd(tmpDir string, fullDest string, dest string) []configs.Command { - var postmount []configs.Command - tarPath, err := exec.LookPath("tar") - if err != nil { - return postmount - } - rmPath, err := exec.LookPath("rm") - if err != nil { - return postmount - } - if _, err := os.Stat(fullDest); os.IsNotExist(err) { - return postmount - } - tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1)) - postmount = append(postmount, configs.Command{ - Path: tarPath, - Args: []string{"-xf", tarFile, "-C", fullDest, "."}, - }) - return append(postmount, configs.Command{ - Path: rmPath, - Args: []string{"-f", tarFile}, - }) -} diff --git a/man/docker-create.1.md b/man/docker-create.1.md index 08074ac431..acb13498fd 100644 --- a/man/docker-create.1.md +++ b/man/docker-create.1.md @@ -319,10 +319,7 @@ unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image - This command mounts a `tmpfs` at `/tmp` within the container. The mount copies -the underlying content of `my_image` into `/tmp`. For example if there was a -directory `/tmp/content` in the base image, docker will copy this directory and -all of its content on top of the tmpfs mounted on `/tmp`. The supported mount + This command mounts a `tmpfs` at `/tmp` within the container. The supported mount options are the same as the Linux default `mount` flags. If you do not specify any options, the systems uses the following options: `rw,noexec,nosuid,nodev,size=65536k`. diff --git a/man/docker-run.1.md b/man/docker-run.1.md index ea9b0b8168..00103a914f 100644 --- a/man/docker-run.1.md +++ b/man/docker-run.1.md @@ -490,10 +490,7 @@ standard input. $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image - This command mounts a `tmpfs` at `/tmp` within the container. The mount copies -the underlying content of `my_image` into `/tmp`. For example if there was a -directory `/tmp/content` in the base image, docker will copy this directory and -all of its content on top of the tmpfs mounted on `/tmp`. The supported mount + This command mounts a `tmpfs` at `/tmp` within the container. The supported mount options are the same as the Linux default `mount` flags. If you do not specify any options, the systems uses the following options: `rw,noexec,nosuid,nodev,size=65536k`.