From 7d29aefea5329d99c2bd9f42572f9c5583da1ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 2 May 2023 10:01:37 +0200 Subject: [PATCH] Send quota when listing spaces in decomposedfs (#3828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Send quota when listing spaces in decomposedfs Signed-off-by: Jörn Friedrich Dreyer * Improve reading the quota from the opaque * Remove unused opaque map --------- Signed-off-by: Jörn Friedrich Dreyer Co-authored-by: André Duffeck --- .../send-quota-when-listing-spaces.md | 5 ++++ .../utils/decomposedfs/decomposedfs.go | 14 +++++++--- pkg/storage/utils/decomposedfs/spaces.go | 26 ++++++++++++++++++- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/send-quota-when-listing-spaces.md diff --git a/changelog/unreleased/send-quota-when-listing-spaces.md b/changelog/unreleased/send-quota-when-listing-spaces.md new file mode 100644 index 0000000000..186a26c6ec --- /dev/null +++ b/changelog/unreleased/send-quota-when-listing-spaces.md @@ -0,0 +1,5 @@ +Bugfix: Send quota when listing spaces in decomposedfs + +We now include free, used and remaining quota when listing spaces + +https://github.com/cs3org/reva/pull/3828 \ No newline at end of file diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index 4a8d0d0a5f..66234fb35e 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -438,11 +438,18 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) ( quotaStr = string(ri.Opaque.Map["quota"].Value) } + // FIXME this reads remaining disk size from the local disk, not the blobstore remaining, err = node.GetAvailableSize(n.InternalPath()) if err != nil { return 0, 0, 0, err } + return fs.calculateTotalUsedRemaining(quotaStr, ri.Size, remaining) +} + +func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse, remaining uint64) (uint64, uint64, uint64, error) { + var err error + var total uint64 switch quotaStr { case node.QuotaUncalculated, node.QuotaUnknown: // best we can do is return current total @@ -457,15 +464,14 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) ( if total <= remaining { // Prevent overflowing - if ri.Size >= total { + if inUse >= total { remaining = 0 } else { - remaining = total - ri.Size + remaining = total - inUse } } } - - return total, ri.Size, remaining, nil + return total, inUse, remaining, nil } // CreateHome creates a new home node for the given user diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index f39fc4bc98..fc49ef60ca 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -25,6 +25,7 @@ import ( "math" "os" "path/filepath" + "strconv" "strings" "time" @@ -38,6 +39,7 @@ import ( "github.com/cs3org/reva/v2/pkg/errtypes" "github.com/cs3org/reva/v2/pkg/rgrpc/status" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + sdk "github.com/cs3org/reva/v2/pkg/sdk/common" "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup" "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes" "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node" @@ -988,6 +990,7 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node, QuotaMaxBytes: uint64(q), QuotaMaxFiles: math.MaxUint64, // TODO MaxUInt64? = unlimited? why even max files? 0 = unlimited? } + } if si := spaceAttributes.String(prefixes.SpaceImageAttr); si != "" { space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "image", storagespace.FormatResourceID( @@ -1008,7 +1011,28 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node, // add rootinfo ps, _ := n.SpaceRoot.PermissionSet(ctx) - space.RootInfo, _ = n.SpaceRoot.AsResourceInfo(ctx, &ps, nil, nil, false) + space.RootInfo, _ = n.SpaceRoot.AsResourceInfo(ctx, &ps, []string{"quota"}, nil, false) + + // we cannot put free, used and remaining into the quota, as quota, when set would always imply a quota limit + // for now we use opaque properties with a 'quota.' prefix + quotaStr := node.QuotaUnknown + if quotaInOpaque := sdk.DecodeOpaqueMap(space.RootInfo.Opaque)["quota"]; quotaInOpaque != "" { + quotaStr = quotaInOpaque + } + + // FIXME this reads remaining disk size from the local disk, not the blobstore + remaining, err := node.GetAvailableSize(n.InternalPath()) + if err != nil { + return nil, err + } + total, used, remaining, err := fs.calculateTotalUsedRemaining(quotaStr, space.GetRootInfo().GetSize(), remaining) + if err != nil { + return nil, err + } + space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "quota.total", strconv.FormatUint(total, 10)) + space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "quota.used", strconv.FormatUint(used, 10)) + space.Opaque = utils.AppendPlainToOpaque(space.Opaque, "quota.remaining", strconv.FormatUint(remaining, 10)) + return space, nil }