Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send quota when listing spaces in decomposedfs #3828

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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