Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 17 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 4 additions & 5 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return err
}

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

Expand Down Expand Up @@ -179,15 +178,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 @@ -148,9 +147,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