diff --git a/lxd/storage/drivers/driver_powerflex_volumes.go b/lxd/storage/drivers/driver_powerflex_volumes.go index c8e0d3bd92b9..56ce1d3cb9d7 100644 --- a/lxd/storage/drivers/driver_powerflex_volumes.go +++ b/lxd/storage/drivers/driver_powerflex_volumes.go @@ -388,7 +388,22 @@ func (d *powerflex) UpdateVolume(vol Volume, changedConfig map[string]string) er } // GetVolumeUsage returns the disk space used by the volume. +// TODO: Query statistics from PowerFlex if not mounted. func (d *powerflex) GetVolumeUsage(vol Volume) (int64, error) { + isSnap := vol.IsSnapshot() + + // If mounted, use the filesystem stats for pretty accurate usage information. + if !isSnap && vol.contentType == ContentTypeFS && filesystem.IsMountPoint(vol.MountPath()) { + var stat unix.Statfs_t + + err := unix.Statfs(vol.MountPath(), &stat) + if err != nil { + return -1, err + } + + return int64(stat.Blocks-stat.Bfree) * int64(stat.Bsize), nil + } + return 0, ErrNotSupported }