image_unix.go 1.1 KB

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