2016-06-07 03:45:21 -04:00
|
|
|
// +build linux freebsd solaris
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// getSize returns the real size & virtual size of the container.
|
2017-02-18 21:11:48 -05:00
|
|
|
func (daemon *Daemon) getSize(containerID string) (int64, int64) {
|
2016-06-07 03:45:21 -04:00
|
|
|
var (
|
|
|
|
sizeRw, sizeRootfs int64
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2017-02-18 21:11:48 -05:00
|
|
|
rwlayer, err := daemon.layerStore.GetRWLayer(containerID)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err)
|
2016-06-07 03:45:21 -04:00
|
|
|
return sizeRw, sizeRootfs
|
|
|
|
}
|
2017-02-18 21:11:48 -05:00
|
|
|
defer daemon.layerStore.ReleaseRWLayer(rwlayer)
|
2016-06-07 03:45:21 -04:00
|
|
|
|
2017-02-18 21:11:48 -05:00
|
|
|
sizeRw, err = rwlayer.Size()
|
2016-06-07 03:45:21 -04:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Driver %s couldn't return diff size of container %s: %s",
|
2017-02-18 21:11:48 -05:00
|
|
|
daemon.GraphDriverName(), containerID, err)
|
2016-06-07 03:45:21 -04:00
|
|
|
// FIXME: GetSize should return an error. Not changing it now in case
|
|
|
|
// there is a side-effect.
|
|
|
|
sizeRw = -1
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:11:48 -05:00
|
|
|
if parent := rwlayer.Parent(); parent != nil {
|
2016-06-07 03:45:21 -04:00
|
|
|
sizeRootfs, err = parent.Size()
|
|
|
|
if err != nil {
|
|
|
|
sizeRootfs = -1
|
|
|
|
} else if sizeRw != -1 {
|
|
|
|
sizeRootfs += sizeRw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sizeRw, sizeRootfs
|
|
|
|
}
|