From 2a39635d30a5ecbf3f8020dcb272cd8ae939fe06 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 15 Aug 2014 00:43:12 +0000 Subject: [PATCH] Cleanup: move image depth checks in image/ Signed-off-by: Solomon Hykes --- daemon/create.go | 2 +- daemon/daemon.go | 18 ------------------ image/image.go | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/daemon/create.go b/daemon/create.go index c3aa9ee58e..3c6827eeec 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -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 { diff --git a/daemon/daemon.go b/daemon/daemon.go index 04d3327546..811cb3391e 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -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_.-]` @@ -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 { diff --git a/image/image.go b/image/image.go index 94c6462011..702782c892 100644 --- a/image/image.go +++ b/image/image.go @@ -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"` @@ -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{}