Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the DF endpoint updated volume refcount #15753

Merged
merged 1 commit into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/system.go
Expand Up @@ -76,7 +76,7 @@ func GetDiskUsage(w http.ResponseWriter, r *http.Request) {
Scope: "local",
Status: nil,
UsageData: &docker.VolumeUsageData{
RefCount: 1,
RefCount: int64(o.Links),
Size: o.Size,
},
}
Expand Down
18 changes: 1 addition & 17 deletions pkg/domain/infra/abi/system.go
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/containers/common/pkg/cgroups"
"github.com/containers/common/pkg/config"
cutil "github.com/containers/common/pkg/util"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/entities/reports"
Expand Down Expand Up @@ -321,19 +320,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
return nil, err
}

running, err := ic.Libpod.GetRunningContainers()
if err != nil {
return nil, err
}
runningContainers := make([]string, 0, len(running))
for _, c := range running {
runningContainers = append(runningContainers, c.ID())
}

dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols))
for _, v := range vols {
var reclaimableSize uint64
var consInUse int
mountPoint, err := v.MountPoint()
if err != nil {
return nil, err
Expand All @@ -355,14 +344,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
if len(inUse) == 0 {
reclaimableSize = volSize
}
for _, viu := range inUse {
if cutil.StringInSlice(viu, runningContainers) {
consInUse++
}
}
report := entities.SystemDfVolumeReport{
VolumeName: v.Name(),
Links: consInUse,
Links: len(inUse),
Size: int64(volSize),
ReclaimableSize: int64(reclaimableSize),
}
Expand Down
18 changes: 18 additions & 0 deletions test/apiv2/45-system.at
Expand Up @@ -25,6 +25,24 @@ t GET system/df 200 '.Volumes[0].Name=foo1'

t GET libpod/system/df 200 '.Volumes[0].VolumeName=foo1'

# Verify that no containers reference the volume
t GET system/df 200 '.Volumes[0].UsageData.RefCount=0'

# Make a container using the volume
podman pull $IMAGE &>/dev/null
t POST containers/create Image=$IMAGE Volumes='{"/test":{}}' HostConfig='{"Binds":["foo1:/test"]}' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")

# Verify that one container references the volume
t GET system/df 200 '.Volumes[0].UsageData.RefCount=1'

# Remove the container
t DELETE containers/$cid?v=true 204

# Verify that no containers reference the volume
t GET system/df 200 '.Volumes[0].UsageData.RefCount=0'

# Create two more volumes to test pruneing
t POST libpod/volumes/create \
Name=foo2 \
Expand Down
2 changes: 1 addition & 1 deletion test/system/320-system-df.bats
Expand Up @@ -27,7 +27,7 @@ function teardown() {
run_podman system df --format '{{ .Type }}:{{ .Total }}:{{ .Active }}'
is "${lines[0]}" "Images:1:1" "system df : Images line"
is "${lines[1]}" "Containers:2:1" "system df : Containers line"
is "${lines[2]}" "Local Volumes:2:1" "system df : Volumes line"
is "${lines[2]}" "Local Volumes:2:2" "system df : Volumes line"

# Try -v. (Grrr. No way to specify individual formats)
#
Expand Down