Skip to content

Commit

Permalink
Merge pull request moby#7589 from shykes/cleanup-img-depth
Browse files Browse the repository at this point in the history
Cleanup: move image depth checks in image/
  • Loading branch information
vieux committed Aug 15, 2014
2 parents a20f4ce + 2a39635 commit 101c749
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion daemon/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, name string) (*Container,
if err != nil {
return nil, nil, err
}
if err := daemon.checkImageDepth(img); err != nil {
if err := img.CheckDepth(); err != nil {
return nil, nil, err
}
if warnings, err = daemon.mergeAndVerifyConfig(config, img); err != nil {
Expand Down
18 changes: 0 additions & 18 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ import (
"github.com/docker/docker/utils"
)

// Set the max depth to the aufs default that most
// kernels are compiled with
// For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk
const MaxImageDepth = 127

var (
DefaultDns = []string{"8.8.8.8", "8.8.4.4"}
validContainerNameChars = `[a-zA-Z0-9_.-]`
Expand Down Expand Up @@ -388,19 +383,6 @@ func (daemon *Daemon) restore() error {
return nil
}

func (daemon *Daemon) checkImageDepth(img *image.Image) error {
// We add 2 layers to the depth because the container's rw and
// init layer add to the restriction
depth, err := img.Depth()
if err != nil {
return err
}
if depth+2 >= MaxImageDepth {
return fmt.Errorf("Cannot create container with more than %d parents", MaxImageDepth)
}
return nil
}

func (daemon *Daemon) checkDeprecatedExpose(config *runconfig.Config) bool {
if config != nil {
if config.PortSpecs != nil {
Expand Down
21 changes: 21 additions & 0 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
"github.com/docker/docker/utils"
)

// Set the max depth to the aufs default that most
// kernels are compiled with
// For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk
const MaxImageDepth = 127

type Image struct {
ID string `json:"id"`
Parent string `json:"parent,omitempty"`
Expand Down Expand Up @@ -297,6 +302,22 @@ func (img *Image) Depth() (int, error) {
return count, nil
}

// CheckDepth returns an error if the depth of an image, as returned
// by ImageDepth, is too large to support creating a container from it
// on this daemon.
func (img *Image) CheckDepth() error {
// We add 2 layers to the depth because the container's rw and
// init layer add to the restriction
depth, err := img.Depth()
if err != nil {
return err
}
if depth+2 >= MaxImageDepth {
return fmt.Errorf("Cannot create container with more than %d parents", MaxImageDepth)
}
return nil
}

// Build an Image object from raw json data
func NewImgJSON(src []byte) (*Image, error) {
ret := &Image{}
Expand Down

0 comments on commit 101c749

Please sign in to comment.