Browse code

Cleanup: move image depth checks in image/

Signed-off-by: Solomon Hykes <solomon@docker.com>

Solomon Hykes authored on 2014/08/15 09:43:12
Showing 3 changed files
... ...
@@ -64,7 +64,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, name string) (*Container,
64 64
 	if err != nil {
65 65
 		return nil, nil, err
66 66
 	}
67
-	if err := daemon.checkImageDepth(img); err != nil {
67
+	if err := img.CheckDepth(); err != nil {
68 68
 		return nil, nil, err
69 69
 	}
70 70
 	if warnings, err = daemon.mergeAndVerifyConfig(config, img); err != nil {
... ...
@@ -39,11 +39,6 @@ import (
39 39
 	"github.com/docker/docker/utils"
40 40
 )
41 41
 
42
-// Set the max depth to the aufs default that most
43
-// kernels are compiled with
44
-// For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk
45
-const MaxImageDepth = 127
46
-
47 42
 var (
48 43
 	DefaultDns                = []string{"8.8.8.8", "8.8.4.4"}
49 44
 	validContainerNameChars   = `[a-zA-Z0-9_.-]`
... ...
@@ -388,19 +383,6 @@ func (daemon *Daemon) restore() error {
388 388
 	return nil
389 389
 }
390 390
 
391
-func (daemon *Daemon) checkImageDepth(img *image.Image) error {
392
-	// We add 2 layers to the depth because the container's rw and
393
-	// init layer add to the restriction
394
-	depth, err := img.Depth()
395
-	if err != nil {
396
-		return err
397
-	}
398
-	if depth+2 >= MaxImageDepth {
399
-		return fmt.Errorf("Cannot create container with more than %d parents", MaxImageDepth)
400
-	}
401
-	return nil
402
-}
403
-
404 391
 func (daemon *Daemon) checkDeprecatedExpose(config *runconfig.Config) bool {
405 392
 	if config != nil {
406 393
 		if config.PortSpecs != nil {
... ...
@@ -16,6 +16,11 @@ import (
16 16
 	"github.com/docker/docker/utils"
17 17
 )
18 18
 
19
+// Set the max depth to the aufs default that most
20
+// kernels are compiled with
21
+// For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk
22
+const MaxImageDepth = 127
23
+
19 24
 type Image struct {
20 25
 	ID              string            `json:"id"`
21 26
 	Parent          string            `json:"parent,omitempty"`
... ...
@@ -297,6 +302,22 @@ func (img *Image) Depth() (int, error) {
297 297
 	return count, nil
298 298
 }
299 299
 
300
+// CheckDepth returns an error if the depth of an image, as returned
301
+// by ImageDepth, is too large to support creating a container from it
302
+// on this daemon.
303
+func (img *Image) CheckDepth() error {
304
+	// We add 2 layers to the depth because the container's rw and
305
+	// init layer add to the restriction
306
+	depth, err := img.Depth()
307
+	if err != nil {
308
+		return err
309
+	}
310
+	if depth+2 >= MaxImageDepth {
311
+		return fmt.Errorf("Cannot create container with more than %d parents", MaxImageDepth)
312
+	}
313
+	return nil
314
+}
315
+
300 316
 // Build an Image object from raw json data
301 317
 func NewImgJSON(src []byte) (*Image, error) {
302 318
 	ret := &Image{}