Skip to content

Commit

Permalink
quota lookup by ref in decomposedfs
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Oct 8, 2021
1 parent 9c42bee commit 1d35619
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20211006080433-1c957dea0f30
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/gdexlab/go-render v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20211006080433-1c957dea0f30 h1:pbropYqSquVy4hWqKEhbVnITo0hJxdfl5Cew8zuiwkI=
github.com/cs3org/go-cs3apis v0.0.0-20211006080433-1c957dea0f30/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11 h1:cc/8fdzWdr/wAZOXb29J8bnXjo1poCMCLwhlFBlvhfI=
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/owncloud/owncloud_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"strings"
"syscall"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *ocfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
func (fs *ocfs) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/owncloud/owncloud_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"golang.org/x/sys/windows"
)
Expand All @@ -55,7 +56,7 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *ocfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
func (fs *ocfs) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/owncloudsql/owncloudsql_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"strings"
"syscall"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
return strings.Trim(etag, "\"")
}

func (fs *owncloudsqlfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
func (fs *owncloudsqlfs) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/owncloudsql/owncloudsql_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os"
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"golang.org/x/sys/windows"
)
Expand All @@ -54,7 +55,7 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *owncloudsqlfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
func (fs *owncloudsqlfs) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
Expand Down
10 changes: 8 additions & 2 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ func (fs *Decomposedfs) Shutdown(ctx context.Context) error {
// TODO Document in the cs3 should we return quota or free space?
func (fs *Decomposedfs) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (total uint64, inUse uint64, err error) {
var n *node.Node
if n, err = fs.lu.HomeOrRootNode(ctx); err != nil {
return 0, 0, err
if req.Ref != nil {
if n, err = fs.lu.NodeFromResource(ctx, req.Ref); err != nil {
return 0, 0, err
}
} else {
if n, err = fs.lu.HomeOrRootNode(ctx); err != nil {
return 0, 0, err
}
}

if !n.Exists {
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/utils/decomposedfs/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func (lu *Lookup) NodeFromResource(ctx context.Context, ref *provider.Reference)
if ref.ResourceId != nil {
// check if a storage space reference is used
// currently, the decomposed fs uses the root node id as the space id
n, err := lu.NodeFromID(ctx, ref.ResourceId)
spaceRoot, err := lu.NodeFromID(ctx, ref.ResourceId)
if err != nil {
return nil, err
}

n := spaceRoot
p := filepath.Clean(ref.Path)
if p != "." {
// walk the relative path
Expand All @@ -59,6 +60,8 @@ func (lu *Lookup) NodeFromResource(ctx context.Context, ref *provider.Reference)
if err != nil {
return nil, err
}
// use reference id as space root for relative references
n.SpaceRoot = spaceRoot
return n, nil
}

Expand All @@ -78,11 +81,12 @@ func (lu *Lookup) NodeFromPath(ctx context.Context, fn string, followReferences
log := appctx.GetLogger(ctx)
log.Debug().Interface("fn", fn).Msg("NodeFromPath()")

n, err := lu.HomeOrRootNode(ctx)
root, err := lu.HomeOrRootNode(ctx)
if err != nil {
return nil, err
}

n := root
// TODO collect permissions of the current user on every segment
fn = filepath.Clean(fn)
if fn != "/" && fn != "." {
Expand All @@ -94,7 +98,7 @@ func (lu *Lookup) NodeFromPath(ctx context.Context, fn string, followReferences
return nil, err
}
}

n.SpaceRoot = root
return n, nil
}

Expand Down
24 changes: 13 additions & 11 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ const (

// Node represents a node in the tree and provides methods to get a Parent or Child instance
type Node struct {
ParentID string
ID string
Name string
Blobsize int64
BlobID string
owner *userpb.UserId
Exists bool
ParentID string
ID string
Name string
Blobsize int64
BlobID string
owner *userpb.UserId
Exists bool
SpaceRoot *Node

lu PathLookup
}
Expand Down Expand Up @@ -608,12 +609,13 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
// quota
if _, ok := mdKeysMap[QuotaKey]; (nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER) && returnAllKeys || ok {
var quotaPath string
if r, err := n.lu.HomeOrRootNode(ctx); err == nil {
quotaPath = r.InternalPath()
readQuotaIntoOpaque(ctx, quotaPath, ri)
if n.SpaceRoot != nil {
quotaPath = n.SpaceRoot.InternalPath()
} else {
sublog.Error().Err(err).Msg("error determining home or root node for quota")
sublog.Error().Err(err).Msg("error determining the space root node for quota")
}
quotaPath = n.InternalPath()
readQuotaIntoOpaque(ctx, quotaPath, ri)
}

// only read the requested metadata attributes
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,8 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo
}

func checkQuota(ctx context.Context, fs *Decomposedfs, fileSize uint64) (quotaSufficient bool, err error) {
total, inUse, err := fs.GetQuota(ctx)
req := &provider.GetQuotaRequest{}
total, inUse, err := fs.GetQuota(ctx, req)
if err != nil {
switch err.(type) {
case errtypes.NotFound:
Expand Down

0 comments on commit 1d35619

Please sign in to comment.