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

Do not read empty node metadata #3902

Merged
merged 3 commits into from
May 19, 2023
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
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-cache-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Do not try to use the cache for empty node

We fixed a problem where nodes that did not have an ID set were still trying to use the cache for their metadata resulting in clashing cache keys.

https://github.com/cs3org/reva/pull/3902
14 changes: 13 additions & 1 deletion pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (n *Node) RemoveXattr(key string) error {
// XattrsWithReader returns the extended attributes of the node. If the attributes have already
// been cached they are not read from disk again.
func (n *Node) XattrsWithReader(r io.Reader) (Attributes, error) {
if n.ID == "" {
// Do not try to read the attribute of an empty node. The InternalPath points to the
// base nodes directory in this case.
return Attributes{}, &xattr.Error{Op: "node.XattrsWithReader", Path: n.InternalPath(), Err: xattr.ENOATTR}
}

if n.xattrsCache != nil {
return n.xattrsCache, nil
}
Expand Down Expand Up @@ -116,6 +122,12 @@ func (n *Node) Xattrs() (Attributes, error) {
// Xattr returns an extended attribute of the node. If the attributes have already
// been cached it is not read from disk again.
func (n *Node) Xattr(key string) ([]byte, error) {
if n.ID == "" {
// Do not try to read the attribute of an empty node. The InternalPath points to the
// base nodes directory in this case.
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: n.InternalPath(), Name: key, Err: xattr.ENOATTR}
}

if n.xattrsCache == nil {
attrs, err := n.lu.MetadataBackend().All(n.InternalPath())
if err != nil {
Expand All @@ -128,7 +140,7 @@ func (n *Node) Xattr(key string) ([]byte, error) {
return val, nil
}
// wrap the error as xattr does
return []byte{}, &xattr.Error{Op: "xattr.get", Path: n.InternalPath(), Name: key, Err: xattr.ENOATTR}
return []byte{}, &xattr.Error{Op: "node.Xattr", Path: n.InternalPath(), Name: key, Err: xattr.ENOATTR}
}

// XattrString returns the string representation of an attribute
Expand Down