github.com/moby/docker@v26.1.3+incompatible/daemon/images/image_unix.go (about)

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