Skip to content

Commit

Permalink
WIP: Add a xattr cache for node objects
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Oct 28, 2022
1 parent 6669390 commit bf4a13e
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 180 deletions.
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (fs *Decomposedfs) CreateDir(ctx context.Context, ref *provider.Reference)

if fs.o.TreeTimeAccounting || fs.o.TreeSizeAccounting {
// mark the home node as the end of propagation
if err = n.SetMetadata(xattrs.PropagationAttr, "1"); err != nil {
if err = n.SetXattr(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 @@ -467,7 +467,7 @@ func (fs *Decomposedfs) CreateReference(ctx context.Context, p string, targetURI
}
childCreated = true

if err := childNode.SetMetadata(xattrs.ReferenceAttr, targetURI.String()); err != nil {
if err := childNode.SetXattr(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(),
Expand Down
16 changes: 11 additions & 5 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,21 @@ func (fs *Decomposedfs) ListGrants(ctx context.Context, ref *provider.Reference)
}
log := appctx.GetLogger(ctx)
np := node.InternalPath()
var attrs []string
if attrs, err = xattrs.List(np); err != nil {
var attrs map[string]string
if attrs, err = node.Xattrs(); err != nil {
log.Error().Err(err).Msg("error listing attributes")
return nil, err
}
attrNames := make([]string, len(attrs))
i := 0
for attr := range attrs {
attrNames[i] = attr
i++
}

log.Debug().Interface("attrs", attrs).Msg("read attributes")
log.Debug().Interface("attrs", attrNames).Msg("read attributes")

aces := extractACEsFromAttrs(ctx, np, attrs)
aces := extractACEsFromAttrs(ctx, np, attrNames)

uid := ctxpkg.ContextMustGetUser(ctx).GetId()
grants = make([]*provider.Grant, 0, len(aces))
Expand Down Expand Up @@ -272,7 +278,7 @@ func (fs *Decomposedfs) storeGrant(ctx context.Context, n *node.Node, g *provide
// set the grant
e := ace.FromGrant(g)
principal, value := e.Marshal()
if err := n.SetMetadata(xattrs.GrantPrefix+principal, string(value)); err != nil {
if err := n.SetXattr(xattrs.GrantPrefix+principal, string(value)); err != nil {
appctx.GetLogger(ctx).Error().Err(err).
Str("principal", principal).Msg("Could not set grant for principal")
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (lu *Lookup) WalkPath(ctx context.Context, r *node.Node, p string, followRe
}

if followReferences {
if attrBytes, err := r.GetMetadata(xattrs.ReferenceAttr); err == nil {
if attrBytes, err := r.Xattr(xattrs.ReferenceAttr); err == nil {
realNodeID := attrBytes
ref, err := xattrs.ReferenceFromAttr([]byte(realNodeID))
if err != nil {
Expand All @@ -147,7 +147,7 @@ func (lu *Lookup) WalkPath(ctx context.Context, r *node.Node, p string, followRe
}
}
}
if node.IsSpaceRoot(r) {
if r.IsSpaceRoot() {
r.SpaceRoot = r
}

Expand Down
10 changes: 3 additions & 7 deletions pkg/storage/utils/decomposedfs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/pkg/errors"
"github.com/pkg/xattr"
)

// SetArbitraryMetadata sets the metadata on a resource
Expand Down Expand Up @@ -69,8 +68,6 @@ func (fs *Decomposedfs) SetArbitraryMetadata(ctx context.Context, ref *provider.
return err
}

nodePath := n.InternalPath()

errs := []error{}
// TODO should we really continue updating when an error occurs?
if md.Metadata != nil {
Expand Down Expand Up @@ -115,7 +112,7 @@ func (fs *Decomposedfs) SetArbitraryMetadata(ctx context.Context, ref *provider.
}
for k, v := range md.Metadata {
attrName := xattrs.MetadataPrefix + k
if err = xattr.Set(nodePath, attrName, []byte(v)); err != nil {
if err = n.SetXattr(attrName, v); err != nil {
errs = append(errs, errors.Wrap(err, "Decomposedfs: could not set metadata attribute "+attrName+" to "+k))
}
}
Expand Down Expand Up @@ -166,7 +163,6 @@ func (fs *Decomposedfs) UnsetArbitraryMetadata(ctx context.Context, ref *provide
return err
}

nodePath := n.InternalPath()
errs := []error{}
for _, k := range keys {
switch k {
Expand All @@ -189,7 +185,7 @@ func (fs *Decomposedfs) UnsetArbitraryMetadata(ctx context.Context, ref *provide
continue
}
fa := fmt.Sprintf("%s:%s:%s@%s", xattrs.FavPrefix, utils.UserTypeToString(uid.GetType()), uid.GetOpaqueId(), uid.GetIdp())
if err := xattrs.Remove(nodePath, fa); err != nil {
if err := n.RemoveXattr(fa); err != nil {
if xattrs.IsAttrUnset(err) {
continue // already gone, ignore
}
Expand All @@ -200,7 +196,7 @@ func (fs *Decomposedfs) UnsetArbitraryMetadata(ctx context.Context, ref *provide
errs = append(errs, errors.Wrap(err, "could not unset favorite flag"))
}
default:
if err = xattrs.Remove(nodePath, xattrs.MetadataPrefix+k); err != nil {
if err = n.RemoveXattr(xattrs.MetadataPrefix + k); err != nil {
if xattrs.IsAttrUnset(err) {
continue // already gone, ignore
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/storage/utils/decomposedfs/node/locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -81,8 +82,16 @@ var _ = Describe("Node locks", func() {
AppName: "app2",
LockId: uuid.New().String(),
}
n = node.New("u-s-e-r-id", "tobelockedid", "", "tobelocked", 10, "", env.Owner.Id, env.Lookup)
n2 = node.New("u-s-e-r-id", "neverlockedid", "", "neverlocked", 10, "", env.Owner.Id, env.Lookup)
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{
Stat: true,
AddGrant: true,
}, nil).Times(1)
spaceResID, err := env.CreateTestStorageSpace("project", &provider.Quota{QuotaMaxBytes: 2000})
Expect(err).ToNot(HaveOccurred())
n, err = env.CreateTestFile("tobelockedid", "blob", spaceResID.OpaqueId, spaceResID.OpaqueId, 10)
Expect(err).ToNot(HaveOccurred())
n2, err = env.CreateTestFile("neverlockedlockedid", "blob", spaceResID.OpaqueId, spaceResID.OpaqueId, 10)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
Expand Down
Loading

0 comments on commit bf4a13e

Please sign in to comment.