Browse code

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 <crosbymichael@gmail.com>

Michael Crosby authored on 2016/01/26 07:48:23
Showing 4 changed files
... ...
@@ -436,7 +436,6 @@ func (d *Driver) setupMounts(container *configs.Config, c *execdriver.Command) e
436 436
 				flags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV
437 437
 				err   error
438 438
 			)
439
-			fulldest := filepath.Join(c.Rootfs, m.Destination)
440 439
 			if m.Data != "" {
441 440
 				flags, data, err = mount.ParseTmpfsOptions(m.Data)
442 441
 				if err != nil {
... ...
@@ -449,8 +448,6 @@ func (d *Driver) setupMounts(container *configs.Config, c *execdriver.Command) e
449 449
 				Data:             data,
450 450
 				Device:           "tmpfs",
451 451
 				Flags:            flags,
452
-				PremountCmds:     genTmpfsPremountCmd(c.TmpDir, fulldest, m.Destination),
453
-				PostmountCmds:    genTmpfsPostmountCmd(c.TmpDir, fulldest, m.Destination),
454 452
 				PropagationFlags: []int{mountPropagationMap[volume.DefaultPropagationMode]},
455 453
 			})
456 454
 			continue
457 455
deleted file mode 100644
... ...
@@ -1,56 +0,0 @@
1
-package native
2
-
3
-import (
4
-	"fmt"
5
-	"os"
6
-	"os/exec"
7
-	"strings"
8
-
9
-	"github.com/Sirupsen/logrus"
10
-	"github.com/opencontainers/runc/libcontainer/configs"
11
-)
12
-
13
-func genTmpfsPremountCmd(tmpDir string, fullDest string, dest string) []configs.Command {
14
-	var premount []configs.Command
15
-	tarPath, err := exec.LookPath("tar")
16
-	if err != nil {
17
-		logrus.Warn("tar command is not available for tmpfs mount: %s", err)
18
-		return premount
19
-	}
20
-	if _, err = exec.LookPath("rm"); err != nil {
21
-		logrus.Warn("rm command is not available for tmpfs mount: %s", err)
22
-		return premount
23
-	}
24
-	tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1))
25
-	if _, err := os.Stat(fullDest); err == nil {
26
-		premount = append(premount, configs.Command{
27
-			Path: tarPath,
28
-			Args: []string{"-cf", tarFile, "-C", fullDest, "."},
29
-		})
30
-	}
31
-	return premount
32
-}
33
-
34
-func genTmpfsPostmountCmd(tmpDir string, fullDest string, dest string) []configs.Command {
35
-	var postmount []configs.Command
36
-	tarPath, err := exec.LookPath("tar")
37
-	if err != nil {
38
-		return postmount
39
-	}
40
-	rmPath, err := exec.LookPath("rm")
41
-	if err != nil {
42
-		return postmount
43
-	}
44
-	if _, err := os.Stat(fullDest); os.IsNotExist(err) {
45
-		return postmount
46
-	}
47
-	tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1))
48
-	postmount = append(postmount, configs.Command{
49
-		Path: tarPath,
50
-		Args: []string{"-xf", tarFile, "-C", fullDest, "."},
51
-	})
52
-	return append(postmount, configs.Command{
53
-		Path: rmPath,
54
-		Args: []string{"-f", tarFile},
55
-	})
56
-}
... ...
@@ -319,10 +319,7 @@ unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
319 319
 
320 320
    $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image
321 321
 
322
-   This command mounts a `tmpfs` at `/tmp` within the container. The mount copies
323
-the underlying content of `my_image` into `/tmp`. For example if there was a
324
-directory `/tmp/content` in the base image, docker will copy this directory and
325
-all of its content on top of the tmpfs mounted on `/tmp`.  The supported mount
322
+   This command mounts a `tmpfs` at `/tmp` within the container.  The supported mount
326 323
 options are the same as the Linux default `mount` flags. If you do not specify
327 324
 any options, the systems uses the following options:
328 325
 `rw,noexec,nosuid,nodev,size=65536k`.
... ...
@@ -490,10 +490,7 @@ standard input.
490 490
 
491 491
    $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image
492 492
 
493
-   This command mounts a `tmpfs` at `/tmp` within the container. The mount copies
494
-the underlying content of `my_image` into `/tmp`. For example if there was a
495
-directory `/tmp/content` in the base image, docker will copy this directory and
496
-all of its content on top of the tmpfs mounted on `/tmp`.  The supported mount
493
+   This command mounts a `tmpfs` at `/tmp` within the container.  The supported mount
497 494
 options are the same as the Linux default `mount` flags. If you do not specify
498 495
 any options, the systems uses the following options:
499 496
 `rw,noexec,nosuid,nodev,size=65536k`.