Skip to content

Commit

Permalink
introduce new layout
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 Feb 16, 2022
1 parent dfd5eb3 commit e4c1191
Showing 6 changed files with 214 additions and 217 deletions.
54 changes: 8 additions & 46 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ import (
"syscall"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
@@ -204,57 +205,18 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {
return errtypes.NotSupported("Decomposedfs: CreateHome() home supported disabled")
}

var n, h *node.Node
if n, err = fs.lu.RootNode(ctx); err != nil {
return
}
h, err = fs.lu.WalkPath(ctx, n, fs.lu.mustGetUserLayout(ctx), false, func(ctx context.Context, n *node.Node) error {
if !n.Exists {
if err := fs.tp.CreateDir(ctx, n); err != nil {
return err
}
}
return nil
u := ctxpkg.ContextMustGetUser(ctx)
res, err := fs.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{
Type: spaceTypePersonal,
Owner: u,
})

// make sure to delete the created directory if things go wrong
defer func() {
if err != nil {
// do not catch the error to not shadow the original error
if tmpErr := fs.tp.Delete(ctx, n); tmpErr != nil {
appctx.GetLogger(ctx).Error().Err(tmpErr).Msg("Can not revert file system change after error")
}
}
}()

if err != nil {
return
}

// update the owner
u := ctxpkg.ContextMustGetUser(ctx)
if err = h.WriteAllNodeMetadata(u.Id); err != nil {
return
}

if fs.o.TreeTimeAccounting || fs.o.TreeSizeAccounting {
// mark the home node as the end of propagation
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
}
}

if err := h.SetMetadata(xattrs.SpaceNameAttr, u.DisplayName); err != nil {
return err
}

// add storage space
if err := fs.createStorageSpace(ctx, spaceTypePersonal, h.ID); err != nil {
return err
if res.Status.Code != rpcv1beta1.Code_CODE_OK {
return errtypes.NewErrtypeFromStatus(res.Status)
}

return
return nil
}

// The os not exists error is buried inside the xattr error,
10 changes: 1 addition & 9 deletions pkg/storage/utils/decomposedfs/lookup.go
Original file line number Diff line number Diff line change
@@ -76,18 +76,10 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
// The Resource references the root of a space
return lu.NodeFromSpaceID(ctx, id)
}
var spaceID string
// If the ids are the same then both are the spaceID
if id.StorageId == id.OpaqueId {
spaceID = node.NoSpaceID
} else {
spaceID = id.StorageId
}
n, err = node.ReadNode(ctx, lu, spaceID, id.OpaqueId)
n, err = node.ReadNode(ctx, lu, id.StorageId, id.OpaqueId)
if err != nil {
return nil, err
}
n.SpaceID = spaceID

return n, n.FindStorageSpaceRoot()
}
39 changes: 16 additions & 23 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
@@ -241,6 +241,16 @@ func isNotDir(err error) bool {
return false
}

func readChildNodeFromLink(path string) (string, error) {
link, err := os.Readlink(path)
if err != nil {
return "", err
}
nodeID := strings.TrimLeft(link, "/.")
nodeID = strings.ReplaceAll(nodeID, "/", "")
return nodeID, nil
}

// Child returns the child node with the given name
func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
spaceID := n.SpaceID
@@ -249,7 +259,7 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
} else if n.SpaceRoot != nil {
spaceID = n.SpaceRoot.ID
}
link, err := os.Readlink(filepath.Join(n.InternalPath(), filepath.Join("/", name)))
nodeID, err := readChildNodeFromLink(filepath.Join(n.InternalPath(), name))
if err != nil {
if os.IsNotExist(err) || isNotDir(err) {

@@ -267,17 +277,11 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
}

var c *Node
if strings.HasPrefix(link, "../") {
c, err = ReadNode(ctx, n.lu, spaceID, filepath.Base(link))
if err != nil {
return nil, errors.Wrap(err, "could not read child node")
}
c.SpaceRoot = n.SpaceRoot
} else {
return nil, fmt.Errorf("decomposedfs: expected '../ prefix, got' %+v", link)
c, err = ReadNode(ctx, n.lu, spaceID, nodeID)
if err != nil {
return nil, errors.Wrap(err, "could not read child node")
}
c.SpaceRoot = n.SpaceRoot
c.SpaceID = spaceID

return c, nil
}
@@ -287,14 +291,8 @@ func (n *Node) Parent() (p *Node, err error) {
if n.ParentID == "" {
return nil, fmt.Errorf("decomposedfs: root has no parent")
}
var spaceID string
if n.SpaceRoot != nil && n.SpaceRoot.ID != n.ParentID {
spaceID = n.SpaceID
} else {
spaceID = ""
}
p = &Node{
SpaceID: spaceID,
SpaceID: n.SpaceID,
lu: n.lu,
ID: n.ParentID,
SpaceRoot: n.SpaceRoot,
@@ -401,12 +399,7 @@ func (n *Node) InternalPath() string {
}

func (n *Node) ParentInternalPath() string {
spaceID := n.SpaceID
// If the parent is the space root then we don't need the extra spaceID part in the path.
if n.SpaceID == n.ParentID {
spaceID = ""
}
return n.lu.InternalPath(spaceID, n.ParentID)
return n.lu.InternalPath(n.SpaceID, n.ParentID)
}

// LockFilePath returns the internal path of the lock file of the node
Loading

0 comments on commit e4c1191

Please sign in to comment.