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