Skip to content

Commit

Permalink
Send quota when listing spaces in decomposedfs (#3828)
Browse files Browse the repository at this point in the history
* Send quota when listing spaces in decomposedfs

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* Improve reading the quota from the opaque

* Remove unused opaque map

---------

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Co-authored-by: André Duffeck <[email protected]>
  • Loading branch information
butonic and aduffeck authored May 2, 2023
1 parent 4d1c9f4 commit 7d29aef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/send-quota-when-listing-spaces.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"math"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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
}

Expand Down

0 comments on commit 7d29aef

Please sign in to comment.