2021-08-23 09:14:53 -04:00
|
|
|
//go:build linux || freebsd
|
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 (
|
2022-06-28 08:09:10 -04:00
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-07 03:45:21 -04:00
|
|
|
)
|
|
|
|
|
2022-06-28 08:09:10 -04:00
|
|
|
// GetLayerFolders returns the layer folders from an image RootFS
|
|
|
|
func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer) ([]string, error) {
|
|
|
|
// Windows specific
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
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.
|
2021-03-19 10:34:08 -04:00
|
|
|
rwlayer, err := i.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
|
|
|
|
}
|
2021-03-19 10:34:08 -04:00
|
|
|
defer i.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",
|
2021-03-19 10:34:08 -04:00
|
|
|
i.layerStore.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 {
|
2022-01-21 13:01:34 -05:00
|
|
|
sizeRootfs = parent.Size()
|
|
|
|
if sizeRw != -1 {
|
2016-06-07 03:45:21 -04:00
|
|
|
sizeRootfs += sizeRw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sizeRw, sizeRootfs
|
|
|
|
}
|