github.com/rumpl/bof@v23.0.0-rc.2+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  	"github.com/sirupsen/logrus"
     8  )
     9  
    10  // GetContainerLayerSize returns the real size & virtual size of the container.
    11  func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) {
    12  	var (
    13  		sizeRw, sizeRootfs int64
    14  		err                error
    15  	)
    16  
    17  	// Safe to index by runtime.GOOS as Unix hosts don't support multiple
    18  	// container operating systems.
    19  	rwlayer, err := i.layerStore.GetRWLayer(containerID)
    20  	if err != nil {
    21  		logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err)
    22  		return sizeRw, sizeRootfs
    23  	}
    24  	defer i.layerStore.ReleaseRWLayer(rwlayer)
    25  
    26  	sizeRw, err = rwlayer.Size()
    27  	if err != nil {
    28  		logrus.Errorf("Driver %s couldn't return diff size of container %s: %s",
    29  			i.layerStore.DriverName(), containerID, err)
    30  		// FIXME: GetSize should return an error. Not changing it now in case
    31  		// there is a side-effect.
    32  		sizeRw = -1
    33  	}
    34  
    35  	if parent := rwlayer.Parent(); parent != nil {
    36  		sizeRootfs = parent.Size()
    37  		if sizeRw != -1 {
    38  			sizeRootfs += sizeRw
    39  		}
    40  	}
    41  	return sizeRw, sizeRootfs
    42  }