libpod/Container.rootFsSize(): use recorded image sizes

In rootFsSize(), instead of calculating the size of the diff for every
layer of the container's base image, ask the storage library for the sum
of the values it recorded when it first wrote those layers.

In a similar fashion, teach rwSize() to use the library's
ContainerSize() method instead of trying to roll its own.

Replace calls to pkg/util.SizeOfPath() with calls to
github.com/containers/storage/pkg/directory.Size(), which does the same
thing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2023-05-08 13:47:28 -04:00
parent d49a537b8f
commit c400cc7ead
5 changed files with 37 additions and 63 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/libpod/lock"
"github.com/containers/podman/v4/libpod/plugin"
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage/pkg/directory"
)
// Volume is a libpod named volume.
@ -109,7 +109,8 @@ func (v *Volume) Name() string {
// Returns the size on disk of volume
func (v *Volume) Size() (uint64, error) {
return util.SizeOfPath(v.config.MountPoint)
size, err := directory.Size(v.config.MountPoint)
return uint64(size), err
}
// Driver retrieves the volume's driver.