getsize_unix.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // +build linux freebsd solaris
  2. package daemon
  3. import (
  4. "github.com/Sirupsen/logrus"
  5. "github.com/docker/docker/container"
  6. )
  7. // getSize returns the real size & virtual size of the container.
  8. func (daemon *Daemon) getSize(container *container.Container) (int64, int64) {
  9. var (
  10. sizeRw, sizeRootfs int64
  11. err error
  12. )
  13. if err := daemon.Mount(container); err != nil {
  14. logrus.Errorf("Failed to compute size of container rootfs %s: %s", container.ID, err)
  15. return sizeRw, sizeRootfs
  16. }
  17. defer daemon.Unmount(container)
  18. sizeRw, err = container.RWLayer.Size()
  19. if err != nil {
  20. logrus.Errorf("Driver %s couldn't return diff size of container %s: %s",
  21. daemon.GraphDriverName(), container.ID, err)
  22. // FIXME: GetSize should return an error. Not changing it now in case
  23. // there is a side-effect.
  24. sizeRw = -1
  25. }
  26. if parent := container.RWLayer.Parent(); parent != nil {
  27. sizeRootfs, err = parent.Size()
  28. if err != nil {
  29. sizeRootfs = -1
  30. } else if sizeRw != -1 {
  31. sizeRootfs += sizeRw
  32. }
  33. }
  34. return sizeRw, sizeRootfs
  35. }