2021-08-23 13:14:53 +00:00
|
|
|
//go:build linux || freebsd
|
2016-06-07 07:45:21 +00:00
|
|
|
|
2018-02-07 20:52:47 +00:00
|
|
|
package images // import "github.com/docker/docker/daemon/images"
|
2016-06-07 07:45:21 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-06 15:02:37 +00:00
|
|
|
"context"
|
|
|
|
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
2022-06-28 12:09:10 +00:00
|
|
|
"github.com/docker/docker/image"
|
|
|
|
"github.com/docker/docker/layer"
|
2016-06-07 07:45:21 +00:00
|
|
|
)
|
|
|
|
|
2022-06-28 12:09:10 +00:00
|
|
|
// GetLayerFolders returns the layer folders from an image RootFS
|
2023-09-23 11:06:20 +00:00
|
|
|
func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer, containerID string) ([]string, error) {
|
2022-06-28 12:09:10 +00:00
|
|
|
// Windows specific
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2018-02-07 20:52:47 +00:00
|
|
|
// GetContainerLayerSize returns the real size & virtual size of the container.
|
2023-03-06 15:02:37 +00:00
|
|
|
func (i *ImageService) GetContainerLayerSize(ctx context.Context, containerID string) (int64, int64, error) {
|
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.
|
2021-03-19 14:34:08 +00:00
|
|
|
rwlayer, err := i.layerStore.GetRWLayer(containerID)
|
2017-02-19 02:11:48 +00:00
|
|
|
if err != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Errorf("Failed to compute size of container rootfs %v: %v", containerID, err)
|
2023-03-06 15:02:37 +00:00
|
|
|
return sizeRw, sizeRootfs, nil
|
2016-06-07 07:45:21 +00:00
|
|
|
}
|
2021-03-19 14:34:08 +00:00
|
|
|
defer i.layerStore.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 {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).Errorf("Driver %s couldn't return diff size of container %s: %s",
|
2021-03-19 14:34:08 +00:00
|
|
|
i.layerStore.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 {
|
2022-01-21 18:01:34 +00:00
|
|
|
sizeRootfs = parent.Size()
|
|
|
|
if sizeRw != -1 {
|
2016-06-07 07:45:21 +00:00
|
|
|
sizeRootfs += sizeRw
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 15:02:37 +00:00
|
|
|
return sizeRw, sizeRootfs, nil
|
2016-06-07 07:45:21 +00:00
|
|
|
}
|