image_unix.go 1.5 KB

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