diff --git a/changelog/unreleased/quota.md b/changelog/unreleased/quota.md new file mode 100644 index 0000000000..9f6989fb10 --- /dev/null +++ b/changelog/unreleased/quota.md @@ -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 diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 2229d38f73..7c6c6a7205 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -24,6 +24,7 @@ import ( "encoding/xml" "fmt" "net/url" + "strconv" "strings" "time" @@ -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 diff --git a/pkg/storage/utils/decomposedfs/options/options.go b/pkg/storage/utils/decomposedfs/options/options.go index 91f1b5c0d1..3c30246fd0 100644 --- a/pkg/storage/utils/decomposedfs/options/options.go +++ b/pkg/storage/utils/decomposedfs/options/options.go @@ -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 diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index f9b1bddf6b..238ac78db3 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -57,6 +57,8 @@ const ( spaceTypeAny = "*" spaceIDAny = "*" userIDAny = "*" + + quotaUnrestricted = 0 ) // CreateStorageSpace creates a storage space @@ -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) } @@ -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) }