Skip to content

Commit

Permalink
Consolidate all metadata Get's and Set's to central functions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Klaas Freitag committed Feb 7, 2022
1 parent 325f1b1 commit 1eb197c
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 128 deletions.
15 changes: 6 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 @@ -223,14 +222,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.WriteNodeMetadata(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 @@ -324,9 +322,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")
return
}
Expand Down Expand Up @@ -391,11 +388,11 @@ func (fs *Decomposedfs) CreateReference(ctx context.Context, p string, targetURI
return err
}

internal := n.InternalPath()
if err := xattr.Set(internal, xattrs.ReferenceAttr, []byte(targetURI.String())); err != nil {
if err := n.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(),
internal,
n.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 @@ -62,10 +62,9 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return errtypes.PermissionDenied(filepath.Join(node.ParentID, node.Name))
}

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 @@ -169,15 +168,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

0 comments on commit 1eb197c

Please sign in to comment.