Skip to content

Commit

Permalink
Fix system df inconsistent
Browse files Browse the repository at this point in the history
Use RWSzir as system df verbose containers size to remain consistent with the summery. Volume is reclaimable only if not used by container.

Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Sep 4, 2020
1 parent fa487a6 commit f6a9885
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/podman/system/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {
for _, v := range reports.Volumes {
activeVolumes += v.Links
volumesSize += v.Size
volumesReclaimable += v.Size
volumesReclaimable += v.ReclaimableSize
}
volumeSummary := dfSummary{
Type: "Local Volumes",
Expand Down Expand Up @@ -182,7 +182,7 @@ func printVerbose(reports *entities.SystemDfReport) error {
dfContainers = append(dfContainers, &dfContainer{SystemDfContainerReport: d})
}
containerHeaders := "CONTAINER ID\tIMAGE\tCOMMAND\tLOCAL VOLUMES\tSIZE\tCREATED\tSTATUS\tNAMES\n"
containerRow := "{{.ContainerID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.Created}}\t{{.Status}}\t{{.Names}}\n"
containerRow := "{{.ContainerID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.RWSize}}\t{{.Created}}\t{{.Status}}\t{{.Names}}\n"
format = containerHeaders + "{{range . }}" + containerRow + "{{end}}"
if err := writeTemplate(w, format, dfContainers); err != nil {
return nil
Expand Down Expand Up @@ -257,8 +257,8 @@ func (d *dfContainer) Command() string {
return strings.Join(d.SystemDfContainerReport.Command, " ")
}

func (d *dfContainer) Size() string {
return units.HumanSize(float64(d.SystemDfContainerReport.Size))
func (d *dfContainer) RWSize() string {
return units.HumanSize(float64(d.SystemDfContainerReport.RWSize))
}

func (d *dfContainer) Created() string {
Expand Down
7 changes: 4 additions & 3 deletions pkg/domain/entities/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ type SystemDfContainerReport struct {

// SystemDfVolumeReport describes a volume and its size
type SystemDfVolumeReport struct {
VolumeName string
Links int
Size int64
VolumeName string
Links int
Size int64
ReclaimableSize int64
}

// SystemResetOptions describes the options for resetting your
Expand Down
11 changes: 8 additions & 3 deletions pkg/domain/infra/abi/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
}

dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols))
var reclaimableSize int64
for _, v := range vols {
var consInUse int
volSize, err := sizeOfPath(v.MountPoint())
Expand All @@ -323,15 +324,19 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
if err != nil {
return nil, err
}
if len(inUse) == 0 {
reclaimableSize += volSize
}
for _, viu := range inUse {
if util.StringInSlice(viu, runningContainers) {
consInUse++
}
}
report := entities.SystemDfVolumeReport{
VolumeName: v.Name(),
Links: consInUse,
Size: volSize,
VolumeName: v.Name(),
Links: consInUse,
Size: volSize,
ReclaimableSize: reclaimableSize,
}
dfVolumes = append(dfVolumes, &report)
}
Expand Down

0 comments on commit f6a9885

Please sign in to comment.