Skip to content

Commit

Permalink
allow passing reader to read metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed May 12, 2023
1 parent da69ac8 commit e09275d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-deadlock-by-passing-reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: decomposedfs no longer deadlocks when cache is disabled

We now pass a Reader for the locked file to lower level functions so metadata can be read without aquiring a new file lock.

https://github.com/cs3org/reva/pull/3886
12 changes: 10 additions & 2 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
return c, nil
}

// Parent returns the parent node
func (n *Node) Parent() (p *Node, err error) {
// ParentWithReader returns the parent node
func (n *Node) ParentWithReader(r io.Reader) (p *Node, err error) {
if n.ParentID == "" {
return nil, fmt.Errorf("decomposedfs: root has no parent")
}
Expand All @@ -417,6 +417,9 @@ func (n *Node) Parent() (p *Node, err error) {
SpaceRoot: n.SpaceRoot,
}

// fill metadata cache using the reader
_, _ = p.XattrsWithReader(r)

// lookup name and parent id in extended attributes
p.ParentID, _ = p.XattrString(prefixes.ParentidAttr)
p.Name, _ = p.XattrString(prefixes.NameAttr)
Expand All @@ -428,6 +431,11 @@ func (n *Node) Parent() (p *Node, err error) {
return
}

// Parent returns the parent node
func (n *Node) Parent() (p *Node, err error) {
return n.ParentWithReader(nil)
}

// Owner returns the space owner
func (n *Node) Owner() *userpb.UserId {
return n.SpaceRoot.owner
Expand Down
20 changes: 17 additions & 3 deletions pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package node

import (
"io"
"strconv"

"github.com/pkg/xattr"
Expand Down Expand Up @@ -84,21 +85,34 @@ func (n *Node) RemoveXattr(key string) error {
return n.lu.MetadataBackend().Remove(n.InternalPath(), key)
}

// Xattrs returns the extended attributes of the node. If the attributes have already
// 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) Xattrs() (Attributes, error) {
func (n *Node) XattrsWithReader(r io.Reader) (Attributes, error) {
if n.xattrsCache != nil {
return n.xattrsCache, nil
}

attrs, err := n.lu.MetadataBackend().All(n.InternalPath())
var attrs Attributes
var err error
if r != nil {
attrs, err = n.lu.MetadataBackend().AllWithLockedSource(n.InternalPath(), r)
} else {
attrs, err = n.lu.MetadataBackend().All(n.InternalPath())
}
if err != nil {
return nil, err
}

n.xattrsCache = attrs
return n.xattrsCache, nil
}

// Xattrs returns the extended attributes of the node. If the attributes have already
// been cached they are not read from disk again.
func (n *Node) Xattrs() (Attributes, error) {
return n.XattrsWithReader(nil)
}

// 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) {
Expand Down

0 comments on commit e09275d

Please sign in to comment.