Add tmpfs support to Mount
Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
parent
daa3a548b9
commit
07212ae6ca
|
@ -23,6 +23,8 @@ func (m *Mount) Mount(rootfs, mountLabel string) error {
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case "bind":
|
case "bind":
|
||||||
return m.bindMount(rootfs, mountLabel)
|
return m.bindMount(rootfs, mountLabel)
|
||||||
|
case "tmpfs":
|
||||||
|
return m.tmpfsMount(rootfs, mountLabel)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported mount type %s for %s", m.Type, m.Destination)
|
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
|
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)
|
dest, err = symlink.FollowSymlinkInScope(dest, rootfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := createIfNotExists(dest, stat.IsDir()); err != nil {
|
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 {
|
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
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -166,6 +166,12 @@
|
||||||
"path": "/dev/random",
|
"path": "/dev/random",
|
||||||
"type": 99
|
"type": 99
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"mounts": [
|
||||||
|
{
|
||||||
|
"type": "tmpfs",
|
||||||
|
"destination": "/tmp"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"environment": [
|
"environment": [
|
||||||
|
|
Loading…
Reference in New Issue