Skip to content

Commit

Permalink
fix volume reporting in system df
Browse files Browse the repository at this point in the history
currently, podman system df incorrectly calculates the reclaimable storage for
volumes, using a cumulative reclaimable variable that is incremented and placed into each
report entry causing values to rise above 100%.

Switch this variables to be in the context of the loop, so it resets per volume just like the size variable does.

resolves #13516

Signed-off-by: Charlie Doern <[email protected]>
  • Loading branch information
cdoern committed Jun 28, 2022
1 parent 4274906 commit 6c4c050
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/domain/infra/abi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
}

dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols))
var reclaimableSize uint64
for _, v := range vols {
var reclaimableSize uint64
var consInUse int
mountPoint, err := v.MountPoint()
if err != nil {
Expand All @@ -341,7 +341,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
return nil, err
}
if len(inUse) == 0 {
reclaimableSize += volSize
reclaimableSize = volSize
}
for _, viu := range inUse {
if cutil.StringInSlice(viu, runningContainers) {
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/system_df_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ var _ = Describe("podman system df", func() {
Expect(containers[1]).To(Equal("2"), "total containers expected")
Expect(volumes[2]).To(Equal("2"), "total volumes expected")
Expect(volumes[6]).To(Equal("(50%)"), "percentage usage expected")

session = podmanTest.Podman([]string{"rm", "container1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"system", "df"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
volumes = strings.Fields(session.OutputToStringArray()[3])
// percentages on volumes were being calculated incorrectly. Make sure we only report 100% and not above
Expect(volumes[6]).To(Equal("(100%)"), "percentage usage expected")

})

It("podman system df image with no tag", func() {
Expand Down

0 comments on commit 6c4c050

Please sign in to comment.