Skip to content

Commit

Permalink
don't include versions in quota check (#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas authored May 13, 2022
1 parent 302c2cd commit 6a0a516
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/versions-quota.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Don't include versions in quota

Fixed the quota check to not count the quota of previous versions.

https://github.com/owncloud/ocis/issues/2829
https://github.com/cs3org/reva/pull/2863
23 changes: 15 additions & 8 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,20 +1108,27 @@ func IsSpaceRoot(r *Node) bool {
}

// CheckQuota checks if both disk space and available quota are sufficient
var CheckQuota = func(spaceRoot *Node, fileSize uint64) (quotaSufficient bool, err error) {
// Overwrite must be set to true if the new file replaces the old file e.g.
// when creating a new file version. In such a case the function will
// reduce the used bytes by the old file size and then add the new size.
// If overwrite is false oldSize will be ignored.
var CheckQuota = func(spaceRoot *Node, overwrite bool, oldSize, newSize uint64) (quotaSufficient bool, err error) {
used, _ := spaceRoot.GetTreeSize()
if !enoughDiskSpace(spaceRoot.InternalPath(), fileSize) {
if !enoughDiskSpace(spaceRoot.InternalPath(), newSize) {
return false, errtypes.InsufficientStorage("disk full")
}
quotaByte, _ := xattrs.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr)
var total uint64
if quotaByte == "" {
quotaByteStr, _ := xattrs.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr)
if quotaByteStr == "" {
// if quota is not set, it means unlimited
return true, nil
}
total, _ = strconv.ParseUint(quotaByte, 10, 64)
// if total is smaller than used, total-used could overflow and be bigger than fileSize
if fileSize > total-used || total < used {
quotaByte, _ := strconv.ParseUint(quotaByteStr, 10, 64)
if overwrite {
if quotaByte < used-oldSize+newSize {
return false, errtypes.InsufficientStorage("quota exceeded")
}
// if total is smaller than used, total-used could overflow and be bigger than fileSize
} else if newSize > quotaByte-used || quotaByte < used {
return false, errtypes.InsufficientStorage("quota exceeded")
}
return true, nil
Expand Down
10 changes: 8 additions & 2 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

log.Debug().Interface("info", info).Interface("node", n).Interface("metadata", metadata).Msg("Decomposedfs: resolved filename")

_, err = node.CheckQuota(n.SpaceRoot, uint64(info.Size))
_, err = node.CheckQuota(n.SpaceRoot, n.Exists, uint64(n.Blobsize), uint64(info.Size))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -481,7 +481,13 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
return err
}

_, err = node.CheckQuota(n.SpaceRoot, uint64(fi.Size()))
var oldSize uint64
if n.ID != "" {
old, _ := node.ReadNode(ctx, upload.fs.lu, spaceID, n.ID)
oldSize = uint64(old.Blobsize)
}
_, err = node.CheckQuota(n.SpaceRoot, n.ID != "", oldSize, uint64(fi.Size()))

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var _ = Describe("File uploads", func() {
When("the user wants to initiate a file upload", func() {
It("fails", func() {
var originalFunc = node.CheckQuota
node.CheckQuota = func(spaceRoot *node.Node, fileSize uint64) (quotaSufficient bool, err error) {
node.CheckQuota = func(spaceRoot *node.Node, overwrite bool, oldSize, newSize uint64) (quotaSufficient bool, err error) {
return false, errtypes.InsufficientStorage("quota exceeded")
}
_, err := fs.InitiateUpload(ctx, ref, 10, map[string]string{})
Expand Down

0 comments on commit 6a0a516

Please sign in to comment.