Skip to content

Commit

Permalink
Consolidate all metadata Get's and Set's to central functions. (cs3or…
Browse files Browse the repository at this point in the history
…g#2512)

* Consolidate all metadata Get's and Set's to central functions.

In the decomposed FS, access to xattr was spread all over. This
patch consolidates that to use either the Node.SetMetadata() or
xattrs.Set(). This allows us to hook in indexing for example.

* hound and typos

* Add changelog.

* Some more fixes to use xattrs functions.

* Fix function name in tests.

* Fix some linting hints.

* Even more linter warning fixes

* Even more linting issues

* And another iteration

* Linter I hate you

* Use proper Int formatting

Co-authored-by: David Christofas <dchristofas@owncloud.com>

* Update pkg/storage/utils/decomposedfs/node/node.go

Co-authored-by: David Christofas <dchristofas@owncloud.com>

* Update pkg/storage/utils/decomposedfs/node/node.go

Co-authored-by: David Christofas <dchristofas@owncloud.com>

* Update pkg/storage/utils/decomposedfs/xattrs/xattrs.go

Co-authored-by: David Christofas <dchristofas@owncloud.com>

* again linting

* use correct variable in decomposedfs

Co-authored-by: Jörn Friedrich Dreyer <jfd@butonic.de>
Co-authored-by: David Christofas <dchristofas@owncloud.com>
  • Loading branch information
3 people committed Feb 14, 2022
1 parent f283b98 commit 65bb12a
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 162 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/consolidate-xattr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Consolidate xattr setter and getter

- Consolidate all metadata Get's and Set's to central functions.
- Cleaner code by reduction of casts
- Easier to hook functionality like indexing

https://github.com/cs3org/reva/pull/2512
14 changes: 5 additions & 9 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
rtrace "github.com/cs3org/reva/pkg/trace"
"github.com/cs3org/reva/pkg/utils"
"github.com/pkg/errors"
"github.com/pkg/xattr"
"go.opentelemetry.io/otel/codes"
)

Expand Down Expand Up @@ -234,14 +233,13 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {

// update the owner
u := ctxpkg.ContextMustGetUser(ctx)
if err = h.WriteMetadata(u.Id); err != nil {
if err = h.WriteAllNodeMetadata(u.Id); err != nil {
return
}

if fs.o.TreeTimeAccounting || fs.o.TreeSizeAccounting {
homePath := h.InternalPath()
// mark the home node as the end of propagation
if err = xattr.Set(homePath, xattrs.PropagationAttr, []byte("1")); err != nil {
if err = h.SetMetadata(xattrs.PropagationAttr, "1"); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("node", h).Msg("could not mark home as propagation root")
return
}
Expand Down Expand Up @@ -340,9 +338,8 @@ func (fs *Decomposedfs) CreateDir(ctx context.Context, ref *provider.Reference)
}

if fs.o.TreeTimeAccounting || fs.o.TreeSizeAccounting {
nodePath := n.InternalPath()
// mark the home node as the end of propagation
if err = xattr.Set(nodePath, xattrs.PropagationAttr, []byte("1")); err != nil {
if err = n.SetMetadata(xattrs.PropagationAttr, "1"); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("node", n).Msg("could not mark node to propagate")

// FIXME: This does not return an error at all, but results in a severe situation that the
Expand Down Expand Up @@ -433,12 +430,11 @@ func (fs *Decomposedfs) CreateReference(ctx context.Context, p string, targetURI
}
childCreated = true

internalPath := childNode.InternalPath()
if err := xattr.Set(internalPath, xattrs.ReferenceAttr, []byte(targetURI.String())); err != nil {
if err := childNode.SetMetadata(xattrs.ReferenceAttr, targetURI.String()); err != nil {
// the reference could not be set - that would result in an lost reference?
err := errors.Wrapf(err, "Decomposedfs: error setting the target %s on the reference file %s",
targetURI.String(),
internalPath,
childNode.InternalPath(),
)
span.SetStatus(codes.Error, err.Error())
return err
Expand Down
13 changes: 9 additions & 4 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return errtypes.PermissionDenied(filepath.Join(node.ParentID, node.Name))
}

// check lock
if err := node.CheckLock(ctx); err != nil {
return err
}

e := ace.FromGrant(g)
principal, value := e.Marshal()
if err := xattr.Set(node.InternalPath(), xattrs.GrantPrefix+principal, value); err != nil {
if err := node.SetMetadata(xattrs.GrantPrefix+principal, string(value)); err != nil {
return err
}

Expand Down Expand Up @@ -172,15 +177,15 @@ func extractACEsFromAttrs(ctx context.Context, fsfn string, attrs []string) (ent
entries = []*ace.ACE{}
for i := range attrs {
if strings.HasPrefix(attrs[i], xattrs.GrantPrefix) {
var value []byte
var value string
var err error
if value, err = xattr.Get(fsfn, attrs[i]); err != nil {
if value, err = xattrs.Get(fsfn, attrs[i]); err != nil {
log.Error().Err(err).Str("attr", attrs[i]).Msg("could not read attribute")
continue
}
var e *ace.ACE
principal := attrs[i][len(xattrs.GrantPrefix):]
if e, err = ace.Unmarshal(principal, value); err != nil {
if e, err = ace.Unmarshal(principal, []byte(value)); err != nil {
log.Error().Err(err).Str("principal", principal).Str("attr", attrs[i]).Msg("could not unmarshal ace")
continue
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/utils/decomposedfs/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/options"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/storage/utils/templates"
"github.com/pkg/xattr"
)

// Lookup implements transformations from filepath to node and back
Expand Down Expand Up @@ -157,9 +156,9 @@ func (lu *Lookup) WalkPath(ctx context.Context, r *node.Node, p string, followRe
}

if followReferences {
if attrBytes, err := xattr.Get(r.InternalPath(), xattrs.ReferenceAttr); err == nil {
if attrBytes, err := r.GetMetadata(xattrs.ReferenceAttr); err == nil {
realNodeID := attrBytes
ref, err := xattrs.ReferenceFromAttr(realNodeID)
ref, err := xattrs.ReferenceFromAttr([]byte(realNodeID))
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 65bb12a

Please sign in to comment.