The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7141
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Makes snapshot usage reporting as consistent in meaning as possible (CoW usage as opposed to volume size) and if not possible returns -1/ErrNotSupported.
From b82245272be3e0f4b853e61ca70f8c097b556841 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Fri, 3 Apr 2020 17:57:51 +0100 Subject: [PATCH 1/6] lxd/storage/drivers/driver/zfs/volumes: Comment Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_zfs_volumes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go index b8f1426b7e..864b293675 100644 --- a/lxd/storage/drivers/driver_zfs_volumes.go +++ b/lxd/storage/drivers/driver_zfs_volumes.go @@ -778,7 +778,7 @@ func (d *zfs) GetVolumeUsage(vol Volume) (int64, error) { key = "referenced" } - // Shortcut for refquota filesystems. + // Shortcut for mounted refquota filesystems. if key == "referenced" && vol.contentType == ContentTypeFS && shared.IsMountPoint(vol.MountPath()) { var stat unix.Statfs_t err := unix.Statfs(vol.MountPath(), &stat) From 32b3587b439d0378eb397c14119589f97a582b7b Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 6 Apr 2020 13:24:59 +0100 Subject: [PATCH 2/6] lxd/storage/drivers/driver/lvm/volumes: Always return -1/ErrNotSupported for snapshot usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_lvm_volumes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lxd/storage/drivers/driver_lvm_volumes.go b/lxd/storage/drivers/driver_lvm_volumes.go index 49cc983ed7..710abebbc9 100644 --- a/lxd/storage/drivers/driver_lvm_volumes.go +++ b/lxd/storage/drivers/driver_lvm_volumes.go @@ -283,6 +283,11 @@ func (d *lvm) UpdateVolume(vol Volume, changedConfig map[string]string) error { // GetVolumeUsage returns the disk space used by the volume (this is not currently supported). func (d *lvm) GetVolumeUsage(vol Volume) (int64, error) { + // Snapshot usage not supported for LVM. + if vol.IsSnapshot() { + return -1, ErrNotSupported + } + // If volume has a filesystem and is mounted we can ask the filesystem for usage. if vol.contentType == ContentTypeFS && shared.IsMountPoint(vol.MountPath()) { var stat unix.Statfs_t From abd6e41a87fefe68c811837cf53cbfa6535612ea Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 6 Apr 2020 13:35:04 +0100 Subject: [PATCH 3/6] lxd/storage/drivers/driver/dir/volumes: Always return -1/ErrNotSupported for snapshot usage Also if project quotas not supported return ErrNotSupported. Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_dir_volumes.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go index d79ce2b155..acdae14e59 100644 --- a/lxd/storage/drivers/driver_dir_volumes.go +++ b/lxd/storage/drivers/driver_dir_volumes.go @@ -213,10 +213,15 @@ func (d *dir) UpdateVolume(vol Volume, changedConfig map[string]string) error { // GetVolumeUsage returns the disk space used by the volume. func (d *dir) GetVolumeUsage(vol Volume) (int64, error) { + // Snapshot usage not supported for Dir. + if vol.IsSnapshot() { + return -1, ErrNotSupported + } + volPath := vol.MountPath() ok, err := quota.Supported(volPath) if err != nil || !ok { - return 0, nil + return -1, ErrNotSupported } // Get the volume ID for the volume to access quota. From 1adea3bb753bebef2a5045a3b9087b7552902423 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 6 Apr 2020 13:44:19 +0100 Subject: [PATCH 4/6] lxd/storage/drivers/driver/zfs/volumes: Always used 'used' property for ZFS snapshot usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_zfs_volumes.go | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go index 864b293675..14dbcd7453 100644 --- a/lxd/storage/drivers/driver_zfs_volumes.go +++ b/lxd/storage/drivers/driver_zfs_volumes.go @@ -774,19 +774,25 @@ func (d *zfs) UpdateVolume(vol Volume, changedConfig map[string]string) error { func (d *zfs) GetVolumeUsage(vol Volume) (int64, error) { // Determine what key to use. key := "used" - if shared.IsTrue(vol.ExpandedConfig("zfs.use_refquota")) { - key = "referenced" - } - // Shortcut for mounted refquota filesystems. - if key == "referenced" && vol.contentType == ContentTypeFS && shared.IsMountPoint(vol.MountPath()) { - var stat unix.Statfs_t - err := unix.Statfs(vol.MountPath(), &stat) - if err != nil { - return -1, err + // If volume isn't snapshot then we can take into account the zfs.use_refquota setting. + // Snapshots should also use the "used" ZFS property because the snapshot usage size represents the CoW + // usage not the size of the snapshot volume. + if !vol.IsSnapshot() { + if shared.IsTrue(vol.ExpandedConfig("zfs.use_refquota")) { + key = "referenced" } - return int64(stat.Blocks-stat.Bfree) * int64(stat.Bsize), nil + // Shortcut for mounted refquota filesystems. + if key == "referenced" && vol.contentType == ContentTypeFS && shared.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 + } } // Get the current value. From 7eb513c6a88783821ce16d3f8f0b33ff3271b263 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 6 Apr 2020 13:48:28 +0100 Subject: [PATCH 5/6] lxd/storage/drivers/driver/cephfs/volumes: Always return -1/ErrNotSupported for snapshot usage Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_cephfs_volumes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go index 0e5b720c62..f3337d84e8 100644 --- a/lxd/storage/drivers/driver_cephfs_volumes.go +++ b/lxd/storage/drivers/driver_cephfs_volumes.go @@ -288,6 +288,11 @@ func (d *cephfs) UpdateVolume(vol Volume, changedConfig map[string]string) error // GetVolumeUsage returns the disk space usage of a volume. func (d *cephfs) GetVolumeUsage(vol Volume) (int64, error) { + // Snapshot usage not supported for CephFS. + if vol.IsSnapshot() { + return -1, ErrNotSupported + } + out, err := shared.RunCommand("getfattr", "-n", "ceph.quota.max_bytes", "--only-values", GetVolumeMountPath(d.name, vol.volType, vol.name)) if err != nil { return -1, err From b4f57af0ceee29efe71a3ee72080ce90dd06f187 Mon Sep 17 00:00:00 2001 From: Thomas Parrott <thomas.parr...@canonical.com> Date: Mon, 6 Apr 2020 13:55:33 +0100 Subject: [PATCH 6/6] lxd/storage/drivers/driver/btrfs/volumes: Return -1/ErrNotSupported when no quota available Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com> --- lxd/storage/drivers/driver_btrfs_volumes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_btrfs_volumes.go b/lxd/storage/drivers/driver_btrfs_volumes.go index 4841be48e3..123df4c106 100644 --- a/lxd/storage/drivers/driver_btrfs_volumes.go +++ b/lxd/storage/drivers/driver_btrfs_volumes.go @@ -419,7 +419,7 @@ func (d *btrfs) GetVolumeUsage(vol Volume) (int64, error) { _, usage, err := d.getQGroup(vol.MountPath()) if err != nil { if err == errBtrfsNoQuota { - return 0, nil + return -1, ErrNotSupported } return -1, err
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel