2016-06-07 03:45:21 -04:00
|
|
|
// +build linux freebsd solaris
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-05-16 19:56:56 -04:00
|
|
|
"runtime"
|
|
|
|
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-07 03:45:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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-05-16 19:56:56 -04:00
|
|
|
rwlayer, err := daemon.stores[runtime.GOOS].layerStore.GetRWLayer(containerID)
|
2017-02-18 21:11:48 -05:00
|
|
|
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-05-16 19:56:56 -04:00
|
|
|
defer daemon.stores[runtime.GOOS].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-05-16 19:56:56 -04:00
|
|
|
daemon.GraphDriverName(runtime.GOOS), 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
|
|
|
|
}
|