diff --git a/lxd/storage/drivers/driver_powerflex_volumes.go b/lxd/storage/drivers/driver_powerflex_volumes.go index bbfbd7717a81..4ecd63302cdc 100644 --- a/lxd/storage/drivers/driver_powerflex_volumes.go +++ b/lxd/storage/drivers/driver_powerflex_volumes.go @@ -385,7 +385,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 }