Skip to content

Commit

Permalink
Ensure that the DF endpoint updated volume refcount
Browse files Browse the repository at this point in the history
The field was already exposed already in the `system df` output
so this just required a bit of plumbing and testing.

Fixes #15720

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
  • Loading branch information
mheon committed Sep 12, 2022
1 parent 94864cb commit 6c698d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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
20 changes: 20 additions & 0 deletions test/apiv2/45-system.at
Expand Up @@ -25,6 +25,26 @@ 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 '.Volumes[0].RefCount=0'
t GET libpod/system/df '.Volumes[0].RefCount=0'

# Make a container using the volume
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 '.Volumes[0].RefCount=1'
t GET libpod/system/df '.Volumes[0].RefCount=1'

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

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

# Create two more volumes to test pruneing
t POST libpod/volumes/create \
Name=foo2 \
Expand Down

0 comments on commit 6c698d6

Please sign in to comment.