Skip to content

Commit

Permalink
fix(decomposedfs): calculate remaining quota correctly
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Oct 22, 2024
1 parent 0c9e3de commit 54d4ce5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-activitylog-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Fix remaining quota calculation

Remaining quota should only be total - used and not take disk space into account.

https://github.com/cs3org/reva/pull/4897
24 changes: 4 additions & 20 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"fmt"
"io"
"math"
"net/url"
"path"
"path/filepath"
Expand Down Expand Up @@ -602,20 +601,12 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) (
quotaStr = string(ri.Opaque.Map["quota"].Value)
}

remaining, err = fs.bs.GetAvailableSize(n)
switch {
case errors.Is(err, tree.ErrSizeUnlimited):
remaining = math.MaxUint64
case err != nil:
return 0, 0, 0, err
}

return fs.calculateTotalUsedRemaining(quotaStr, ri.Size, remaining)
return fs.calculateTotalUsedRemaining(quotaStr, ri.Size)
}

func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse, remaining uint64) (uint64, uint64, uint64, error) {
func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse uint64) (uint64, uint64, uint64, error) {
var err error
var total uint64
var total, remaining uint64
switch quotaStr {
case node.QuotaUncalculated, node.QuotaUnknown:
// best we can do is return current total
Expand All @@ -628,14 +619,7 @@ func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse, rema
return 0, 0, 0, err
}

if total <= remaining {
// Prevent overflowing
if inUse >= total {
remaining = 0
} else {
remaining = total - inUse
}
}
remaining = total - inUse
}
return total, inUse, remaining, nil
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/permissions"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree"
"github.com/cs3org/reva/v2/pkg/storage/utils/templates"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
Expand Down Expand Up @@ -1030,14 +1029,7 @@ func (fs *Decomposedfs) StorageSpaceFromNode(ctx context.Context, n *node.Node,
quotaStr = quotaInOpaque
}

remaining, err := fs.bs.GetAvailableSize(n)
switch {
case errors.Is(err, tree.ErrSizeUnlimited):
remaining = math.MaxUint64
case err != nil:
return nil, err
}
total, used, remaining, err := fs.calculateTotalUsedRemaining(quotaStr, space.GetRootInfo().GetSize(), remaining)
total, used, remaining, err := fs.calculateTotalUsedRemaining(quotaStr, space.GetRootInfo().GetSize())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 54d4ce5

Please sign in to comment.