From 9e20bcac5d958365d100a95d57a93996afa85974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Mon, 9 Oct 2023 09:00:34 +0000 Subject: [PATCH] lxd/storage/drivers/powerflex: Add usage information support for mounted volumes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- lxd/storage/drivers/driver_powerflex_volumes.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lxd/storage/drivers/driver_powerflex_volumes.go b/lxd/storage/drivers/driver_powerflex_volumes.go index 4851441d30ed..1ce424dd1ae2 100644 --- a/lxd/storage/drivers/driver_powerflex_volumes.go +++ b/lxd/storage/drivers/driver_powerflex_volumes.go @@ -399,7 +399,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 }