diff --git a/mount/mount.go b/mount/mount.go index 6a982824b..c7865b3c8 100644 --- a/mount/mount.go +++ b/mount/mount.go @@ -23,6 +23,8 @@ func (m *Mount) Mount(rootfs, mountLabel string) error { switch m.Type { case "bind": return m.bindMount(rootfs, mountLabel) + case "tmpfs": + return m.tmpfsMount(rootfs, mountLabel) default: return fmt.Errorf("unsupported mount type %s for %s", m.Type, m.Destination) } @@ -43,14 +45,14 @@ func (m *Mount) bindMount(rootfs, mountLabel string) error { return err } - // FIXME: (crosbymichael) This is not belong here and should be done a layer above + // FIXME: (crosbymichael) This does not belong here and should be done a layer above dest, err = symlink.FollowSymlinkInScope(dest, rootfs) if err != nil { return err } if err := createIfNotExists(dest, stat.IsDir()); err != nil { - return fmt.Errorf("creating new bind-mount target, %s", err) + return fmt.Errorf("creating new bind mount target %s", err) } if err := syscall.Mount(m.Source, dest, "bind", uintptr(flags), ""); err != nil { @@ -77,3 +79,26 @@ func (m *Mount) bindMount(rootfs, mountLabel string) error { return nil } + +func (m *Mount) tmpfsMount(rootfs, mountLabel string) error { + var ( + err error + l = label.FormatMountLabel("", mountLabel) + dest = filepath.Join(rootfs, m.Destination) + ) + + // FIXME: (crosbymichael) This does not belong here and should be done a layer above + if dest, err = symlink.FollowSymlinkInScope(dest, rootfs); err != nil { + return err + } + + if err := createIfNotExists(dest, true); err != nil { + return fmt.Errorf("creating new tmpfs mount target %s", err) + } + + if err := syscall.Mount("tmpfs", dest, "tmpfs", uintptr(defaultMountFlags), l); err != nil { + return fmt.Errorf("%s mounting %s in tmpfs", err, dest) + } + + return nil +} diff --git a/sample_configs/minimal.json b/sample_configs/minimal.json index c08c99679..8d85ddf7d 100644 --- a/sample_configs/minimal.json +++ b/sample_configs/minimal.json @@ -166,6 +166,12 @@ "path": "/dev/random", "type": 99 } + ], + "mounts": [ + { + "type": "tmpfs", + "destination": "/tmp" + } ] }, "environment": [