github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/images/image_unix.go (about) 1 // +build linux freebsd 2 3 package images // import "github.com/docker/docker/daemon/images" 4 5 import ( 6 "runtime" 7 8 "github.com/sirupsen/logrus" 9 ) 10 11 // GetContainerLayerSize returns the real size & virtual size of the container. 12 func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) { 13 var ( 14 sizeRw, sizeRootfs int64 15 err error 16 ) 17 18 // Safe to index by runtime.GOOS as Unix hosts don't support multiple 19 // container operating systems. 20 rwlayer, err := i.layerStores[runtime.GOOS].GetRWLayer(containerID) 21 if err != nil { 22 logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err) 23 return sizeRw, sizeRootfs 24 } 25 defer i.layerStores[runtime.GOOS].ReleaseRWLayer(rwlayer) 26 27 sizeRw, err = rwlayer.Size() 28 if err != nil { 29 logrus.Errorf("Driver %s couldn't return diff size of container %s: %s", 30 i.layerStores[runtime.GOOS].DriverName(), containerID, err) 31 // FIXME: GetSize should return an error. Not changing it now in case 32 // there is a side-effect. 33 sizeRw = -1 34 } 35 36 if parent := rwlayer.Parent(); parent != nil { 37 sizeRootfs, err = parent.Size() 38 if err != nil { 39 sizeRootfs = -1 40 } else if sizeRw != -1 { 41 sizeRootfs += sizeRw 42 } 43 } 44 return sizeRw, sizeRootfs 45 }