Skip to content

Commit

Permalink
Quota (#3671)
Browse files Browse the repository at this point in the history
* add a config options for a max quota

* support setting quota when creating a home space
  • Loading branch information
David Christofas authored Feb 21, 2023
1 parent 573ae44 commit 06fcf4e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/quota.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: add global max quota option and quota for CreateHome

Added a global max quota option to limit how much quota can be assigned to spaces.
Added a quota parameter to CreateHome. This is a prerequisite for setting a default quota per usertypes.

https://github.com/cs3org/reva/pull/3671
15 changes: 15 additions & 0 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/xml"
"fmt"
"net/url"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -111,10 +112,24 @@ func (s *svc) CreateHome(ctx context.Context, req *provider.CreateHomeRequest) (
}, nil

}
quotaStr := utils.ReadPlainFromOpaque(req.Opaque, "quota")
var quota *provider.Quota
if quotaStr != "" {
q, err := strconv.ParseUint(quotaStr, 10, 64)
if err != nil {
return &provider.CreateHomeResponse{
Status: status.NewInvalid(ctx, fmt.Sprintf("can't parse quotaStr: %s", quotaStr)),
}, nil
}
quota = &provider.Quota{
QuotaMaxBytes: q,
}
}
createReq := &provider.CreateStorageSpaceRequest{
Type: "personal",
Owner: u,
Name: u.DisplayName,
Quota: quota,
}

// send the user id as the space id, makes debugging easier
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/utils/decomposedfs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type Options struct {

MaxAcquireLockCycles int `mapstructure:"max_acquire_lock_cycles"`
LockCycleDurationFactor int `mapstructure:"lock_cycle_duration_factor"`

MaxQuota uint64 `mapstructure:"max_quota"`
}

// EventOptions are the configurable options for events
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
spaceTypeAny = "*"
spaceIDAny = "*"
userIDAny = "*"

quotaUnrestricted = 0
)

// CreateStorageSpace creates a storage space
Expand Down Expand Up @@ -139,6 +141,9 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr

if q := req.GetQuota(); q != nil {
// set default space quota
if fs.o.MaxQuota != quotaUnrestricted && q.GetQuotaMaxBytes() > fs.o.MaxQuota {
return nil, errtypes.BadRequest("decompsedFS: requested quota is higher than allowed")
}
metadata[prefixes.QuotaAttr] = strconv.FormatUint(q.QuotaMaxBytes, 10)
}

Expand Down Expand Up @@ -438,6 +443,11 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}

if space.Quota != nil {
if fs.o.MaxQuota != quotaUnrestricted && fs.o.MaxQuota < space.Quota.QuotaMaxBytes {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_INVALID_ARGUMENT, Message: "decompsedFS: requested quota is higher than allowed"},
}, nil
}
metadata[prefixes.QuotaAttr] = strconv.FormatUint(space.Quota.QuotaMaxBytes, 10)
}

Expand Down

0 comments on commit 06fcf4e

Please sign in to comment.