2017-11-01 23:37:53 +00:00
|
|
|
// +build linux freebsd
|
2016-06-07 07:45:21 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-06-07 07:45:21 +00:00
|
|
|
|
|
|
|
import (
|
2017-05-16 23:56:56 +00:00
|
|
|
"runtime"
|
|
|
|
|
2017-07-26 21:42:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-07 07:45:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// getSize returns the real size & virtual size of the container.
|
2018-02-02 22:18:46 +00:00
|
|
|
func (i *imageService) GetContainerLayerSize(containerID string) (int64, int64) {
|
2016-06-07 07:45:21 +00:00
|
|
|
var (
|
|
|
|
sizeRw, sizeRootfs int64
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2017-09-19 19:14:46 +00:00
|
|
|
// Safe to index by runtime.GOOS as Unix hosts don't support multiple
|
|
|
|
// container operating systems.
|
2018-02-02 22:18:46 +00:00
|
|
|
rwlayer, err := i.layerStores[runtime.GOOS].GetRWLayer(containerID)
|
2017-02-19 02:11:48 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err)
|
2016-06-07 07:45:21 +00:00
|
|
|
return sizeRw, sizeRootfs
|
|
|
|
}
|
2018-02-02 22:18:46 +00:00
|
|
|
defer i.layerStores[runtime.GOOS].ReleaseRWLayer(rwlayer)
|
2016-06-07 07:45:21 +00:00
|
|
|
|
2017-02-19 02:11:48 +00:00
|
|
|
sizeRw, err = rwlayer.Size()
|
2016-06-07 07:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("Driver %s couldn't return diff size of container %s: %s",
|
2018-02-02 22:18:46 +00:00
|
|
|
i.layerStores[runtime.GOOS].DriverName(), containerID, err)
|
2016-06-07 07:45:21 +00:00
|
|
|
// FIXME: GetSize should return an error. Not changing it now in case
|
|
|
|
// there is a side-effect.
|
|
|
|
sizeRw = -1
|
|
|
|
}
|
|
|
|
|
2017-02-19 02:11:48 +00:00
|
|
|
if parent := rwlayer.Parent(); parent != nil {
|
2016-06-07 07:45:21 +00:00
|
|
|
sizeRootfs, err = parent.Size()
|
|
|
|
if err != nil {
|
|
|
|
sizeRootfs = -1
|
|
|
|
} else if sizeRw != -1 {
|
|
|
|
sizeRootfs += sizeRw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sizeRw, sizeRootfs
|
|
|
|
}
|