2017-11-01 19:37:53 -04:00
|
|
|
// +build linux freebsd
|
2016-06-07 03:45:21 -04:00
|
|
|
|
2018-02-07 15:52:47 -05:00
|
|
|
package images // import "github.com/docker/docker/daemon/images"
|
2016-06-07 03:45:21 -04:00
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2018-02-07 15:52:47 -05:00
|
|
|
// GetContainerLayerSize returns the real size & virtual size of the container.
|
|
|
|
func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64) {
|
2016-06-07 03:45:21 -04:00
|
|
|
var (
|
|
|
|
sizeRw, sizeRootfs int64
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2017-09-19 15:14:46 -04:00
|
|
|
// Safe to index by runtime.GOOS as Unix hosts don't support multiple
|
|
|
|
// container operating systems.
|
2018-02-02 17:18:46 -05:00
|
|
|
rwlayer, err := i.layerStores[runtime.GOOS].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
|
|
|
|
}
|
2018-02-02 17:18:46 -05:00
|
|
|
defer i.layerStores[runtime.GOOS].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",
|
2018-02-02 17:18:46 -05:00
|
|
|
i.layerStores[runtime.GOOS].DriverName(), 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
|
|
|
|
}
|