diff --git a/api/types/types.go b/api/types/types.go index 57882b84e5..e74d57e509 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -433,6 +433,12 @@ type MountPoint struct { Propagation mount.Propagation } +// VolumeUsageData holds information regarding the volume usage +type VolumeUsageData struct { + Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided. + RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided. +} + // Volume represents the configuration of a volume for the remote API type Volume struct { Name string // Name is the name of the volume @@ -441,8 +447,7 @@ type Volume struct { Status map[string]interface{} `json:",omitempty"` // Status provides low-level status information about the volume Labels map[string]string // Labels is metadata specific to the volume Scope string // Scope describes the level at which the volume exists (e.g. `global` for cluster-wide or `local` for machine level) - Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided. - RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided. + UsageData *VolumeUsageData `json:",omitempty"` } // VolumesListResponse contains the response for the remote API: diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index 866e9bd04a..acb210dbff 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -288,7 +288,7 @@ func (c *diskUsageVolumesContext) Active() string { used := 0 for _, v := range c.volumes { - if v.RefCount > 0 { + if v.UsageData.RefCount > 0 { used++ } } @@ -301,8 +301,8 @@ func (c *diskUsageVolumesContext) Size() string { c.AddHeader(sizeHeader) for _, v := range c.volumes { - if v.Size != -1 { - size += v.Size + if v.UsageData.Size != -1 { + size += v.UsageData.Size } } @@ -315,11 +315,11 @@ func (c *diskUsageVolumesContext) Reclaimable() string { c.AddHeader(reclaimableHeader) for _, v := range c.volumes { - if v.Size != -1 { - if v.RefCount == 0 { - reclaimable += v.Size + if v.UsageData.Size != -1 { + if v.UsageData.RefCount == 0 { + reclaimable += v.UsageData.Size } - totalSize += v.Size + totalSize += v.UsageData.Size } } diff --git a/cli/command/formatter/volume.go b/cli/command/formatter/volume.go index 8fb11732e3..7bc3537573 100644 --- a/cli/command/formatter/volume.go +++ b/cli/command/formatter/volume.go @@ -101,16 +101,16 @@ func (c *volumeContext) Label(name string) string { func (c *volumeContext) Links() string { c.AddHeader(linksHeader) - if c.v.Size == -1 { + if c.v.UsageData == nil { return "N/A" } - return fmt.Sprintf("%d", c.v.RefCount) + return fmt.Sprintf("%d", c.v.UsageData.RefCount) } func (c *volumeContext) Size() string { c.AddHeader(sizeHeader) - if c.v.Size == -1 { + if c.v.UsageData == nil { return "N/A" } - return units.HumanSize(float64(c.v.Size)) + return units.HumanSize(float64(c.v.UsageData.Size)) } diff --git a/daemon/disk_usage.go b/daemon/disk_usage.go index d821470725..a21a761603 100644 --- a/daemon/disk_usage.go +++ b/daemon/disk_usage.go @@ -56,13 +56,12 @@ func (daemon *Daemon) SystemDiskUsage() (*types.DiskUsage, error) { refs := daemon.volumes.Refs(v) tv := volumeToAPIType(v) - tv.RefCount = len(refs) sz, err := directory.Size(v.Path()) if err != nil { logrus.Warnf("failed to determine size of volume %v", name) sz = -1 } - tv.Size = sz + tv.UsageData = &types.VolumeUsageData{Size: sz, RefCount: len(refs)} allVolumes = append(allVolumes, tv) return nil diff --git a/daemon/volumes.go b/daemon/volumes.go index 478938fd0f..dd9292f22c 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -29,10 +29,8 @@ type mounts []container.Mount // volumeToAPIType converts a volume.Volume to the type used by the remote API func volumeToAPIType(v volume.Volume) *types.Volume { tv := &types.Volume{ - Name: v.Name(), - Driver: v.DriverName(), - Size: -1, - RefCount: -1, + Name: v.Name(), + Driver: v.DriverName(), } if v, ok := v.(volume.LabeledVolume); ok { tv.Labels = v.Labels()