github.com/rawahars/moby@v24.0.4+incompatible/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 "context" 8 9 "github.com/docker/docker/image" 10 "github.com/docker/docker/layer" 11 "github.com/sirupsen/logrus" 12 ) 13 14 // GetLayerFolders returns the layer folders from an image RootFS 15 func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer) ([]string, error) { 16 // Windows specific 17 panic("not implemented") 18 } 19 20 // GetContainerLayerSize returns the real size & virtual size of the container. 21 func (i *ImageService) GetContainerLayerSize(ctx context.Context, containerID string) (int64, int64, error) { 22 var ( 23 sizeRw, sizeRootfs int64 24 err error 25 ) 26 27 // Safe to index by runtime.GOOS as Unix hosts don't support multiple 28 // container operating systems. 29 rwlayer, err := i.layerStore.GetRWLayer(containerID) 30 if err != nil { 31 logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err) 32 return sizeRw, sizeRootfs, nil 33 } 34 defer i.layerStore.ReleaseRWLayer(rwlayer) 35 36 sizeRw, err = rwlayer.Size() 37 if err != nil { 38 logrus.Errorf("Driver %s couldn't return diff size of container %s: %s", 39 i.layerStore.DriverName(), containerID, err) 40 // FIXME: GetSize should return an error. Not changing it now in case 41 // there is a side-effect. 42 sizeRw = -1 43 } 44 45 if parent := rwlayer.Parent(); parent != nil { 46 sizeRootfs = parent.Size() 47 if sizeRw != -1 { 48 sizeRootfs += sizeRw 49 } 50 } 51 return sizeRw, sizeRootfs, nil 52 }