1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move remount as private to the graph drivers

If this is at the root directory for the daemon you could unmount
somones filesystem when you stop docker and this is actually only needed
for the palces that the graph drivers mount the container's root
    filesystems.
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-06-05 12:50:53 -07:00
parent 9329c0d2e0
commit 3609b051b8
5 changed files with 51 additions and 29 deletions

View file

@ -27,7 +27,6 @@ import (
"github.com/dotcloud/docker/image" "github.com/dotcloud/docker/image"
"github.com/dotcloud/docker/pkg/graphdb" "github.com/dotcloud/docker/pkg/graphdb"
"github.com/dotcloud/docker/pkg/label" "github.com/dotcloud/docker/pkg/label"
"github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/pkg/namesgenerator" "github.com/dotcloud/docker/pkg/namesgenerator"
"github.com/dotcloud/docker/pkg/networkfs/resolvconf" "github.com/dotcloud/docker/pkg/networkfs/resolvconf"
"github.com/dotcloud/docker/pkg/selinux" "github.com/dotcloud/docker/pkg/selinux"
@ -102,21 +101,6 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
return eng.Register("container_inspect", daemon.ContainerInspect) return eng.Register("container_inspect", daemon.ContainerInspect)
} }
// Mountpoints should be private to the container
func remountPrivate(mountPoint string) error {
mounted, err := mount.Mounted(mountPoint)
if err != nil {
return err
}
if !mounted {
if err := mount.Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
return err
}
}
return mount.ForceMount("", mountPoint, "none", "private")
}
// List returns an array of all containers registered in the daemon. // List returns an array of all containers registered in the daemon.
func (daemon *Daemon) List() []*Container { func (daemon *Daemon) List() []*Container {
return daemon.containers.List() return daemon.containers.List()
@ -786,10 +770,6 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
} }
utils.Debugf("Using graph driver %s", driver) utils.Debugf("Using graph driver %s", driver)
if err := remountPrivate(config.Root); err != nil {
return nil, err
}
daemonRepo := path.Join(config.Root, "containers") daemonRepo := path.Join(config.Root, "containers")
if err := os.MkdirAll(daemonRepo, 0700); err != nil && !os.IsExist(err) { if err := os.MkdirAll(daemonRepo, 0700); err != nil && !os.IsExist(err) {
@ -938,10 +918,6 @@ func (daemon *Daemon) Close() error {
utils.Errorf("daemon.containerGraph.Close(): %s", err.Error()) utils.Errorf("daemon.containerGraph.Close(): %s", err.Error())
errorsStrings = append(errorsStrings, err.Error()) errorsStrings = append(errorsStrings, err.Error())
} }
if err := mount.Unmount(daemon.config.Root); err != nil {
utils.Errorf("daemon.Umount(%s): %s", daemon.config.Root, err.Error())
errorsStrings = append(errorsStrings, err.Error())
}
if len(errorsStrings) > 0 { if len(errorsStrings) > 0 {
return fmt.Errorf("%s", strings.Join(errorsStrings, ", ")) return fmt.Errorf("%s", strings.Join(errorsStrings, ", "))
} }

View file

@ -97,6 +97,10 @@ func Init(root string, options []string) (graphdriver.Driver, error) {
return nil, err return nil, err
} }
if err := graphdriver.MakePrivate(root); err != nil {
return nil, err
}
for _, p := range paths { for _, p := range paths {
if err := os.MkdirAll(path.Join(root, p), 0755); err != nil { if err := os.MkdirAll(path.Join(root, p), 0755); err != nil {
return nil, err return nil, err
@ -371,12 +375,14 @@ func (a *Driver) Cleanup() error {
if err != nil { if err != nil {
return err return err
} }
for _, id := range ids { for _, id := range ids {
if err := a.unmount(id); err != nil { if err := a.unmount(id); err != nil {
utils.Errorf("Unmounting %s: %s", utils.TruncateID(id), err) utils.Errorf("Unmounting %s: %s", utils.TruncateID(id), err)
} }
} }
return nil
return mountpk.Unmount(a.root)
} }
func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err error) { func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err error) {

View file

@ -11,11 +11,13 @@ import "C"
import ( import (
"fmt" "fmt"
"github.com/dotcloud/docker/daemon/graphdriver"
"os" "os"
"path" "path"
"syscall" "syscall"
"unsafe" "unsafe"
"github.com/dotcloud/docker/daemon/graphdriver"
"github.com/dotcloud/docker/pkg/mount"
) )
func init() { func init() {
@ -34,6 +36,14 @@ func Init(home string, options []string) (graphdriver.Driver, error) {
return nil, graphdriver.ErrPrerequisites return nil, graphdriver.ErrPrerequisites
} }
if err := os.MkdirAll(home, 0700); err != nil {
return nil, err
}
if err := graphdriver.MakePrivate(home); err != nil {
return nil, err
}
return &Driver{ return &Driver{
home: home, home: home,
}, nil }, nil
@ -52,7 +62,7 @@ func (d *Driver) Status() [][2]string {
} }
func (d *Driver) Cleanup() error { func (d *Driver) Cleanup() error {
return nil return mount.Unmount(d.home)
} }
func free(p *C.char) { func free(p *C.char) {

View file

@ -9,6 +9,7 @@ import (
"path" "path"
"github.com/dotcloud/docker/daemon/graphdriver" "github.com/dotcloud/docker/daemon/graphdriver"
"github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/utils" "github.com/dotcloud/docker/utils"
) )
@ -31,10 +32,16 @@ func Init(home string, options []string) (graphdriver.Driver, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := graphdriver.MakePrivate(home); err != nil {
return nil, err
}
d := &Driver{ d := &Driver{
DeviceSet: deviceSet, DeviceSet: deviceSet,
home: home, home: home,
} }
return d, nil return d, nil
} }
@ -58,7 +65,13 @@ func (d *Driver) Status() [][2]string {
} }
func (d *Driver) Cleanup() error { func (d *Driver) Cleanup() error {
return d.DeviceSet.Shutdown() err := d.DeviceSet.Shutdown()
if err2 := mount.Unmount(d.home); err == nil {
err = err2
}
return err
} }
func (d *Driver) Create(id, parent string) error { func (d *Driver) Create(id, parent string) error {

View file

@ -3,9 +3,11 @@ package graphdriver
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/dotcloud/docker/archive"
"os" "os"
"path" "path"
"github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/pkg/mount"
) )
type FsMagic uint64 type FsMagic uint64
@ -107,3 +109,18 @@ func New(root string, options []string) (driver Driver, err error) {
} }
return nil, fmt.Errorf("No supported storage backend found") return nil, fmt.Errorf("No supported storage backend found")
} }
func MakePrivate(mountPoint string) error {
mounted, err := mount.Mounted(mountPoint)
if err != nil {
return err
}
if !mounted {
if err := mount.Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
return err
}
}
return mount.ForceMount("", mountPoint, "none", "private")
}