Skip to content

Commit

Permalink
Merge pull request #4708 from aduffeck/decomposed-based-posixfs
Browse files Browse the repository at this point in the history
Improve posixfs storage driver
  • Loading branch information
aduffeck authored Jun 4, 2024
2 parents 634bf10 + 5fb0518 commit e4229f1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.revad-ceph
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ FROM quay.io/ceph/ceph:v18

# replace repo url with one that allows downloading the repo metadata
# if http://download.ceph.com/rpm-reef/el8/x86_64/repodata/repomd.xml works again this can be dropped
RUN sed -i 's/download.ceph.com/fr.ceph.com/' /etc/yum.repos.d/ceph.repo
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN mkdir -p /etc/selinux/config

RUN dnf update --exclude=ceph-iscsi,chrony -y && dnf install -y \
Expand Down
1 change: 1 addition & 0 deletions changelog/unreleased/improve-posixfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Enhancement: Improve posixfs storage driver

Improve the posixfs storage driver by fixing several issues and adding missing features.

https://github.com/cs3org/reva/pull/4708
https://github.com/cs3org/reva/pull/4562
48 changes: 22 additions & 26 deletions pkg/storage/fs/posix/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,21 @@ func (lu *Lookup) GetCachedID(ctx context.Context, spaceID, nodeID string) (stri
func (lu *Lookup) WarmupIDCache(root string) error {
spaceID := []byte("")

var gid int
scopeSpace := func(spaceCandidate string) error {
if !lu.Options.UseSpaceGroups {
return nil
}

// set the uid and gid for the space
fi, err := os.Stat(spaceCandidate)
if err != nil {
return err
}
sys := fi.Sys().(*syscall.Stat_t)
gid := int(sys.Gid)
_, err = lu.userMapper.ScopeUserByIds(-1, gid)
return err
}

return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand All @@ -107,41 +121,23 @@ func (lu *Lookup) WarmupIDCache(root string) error {

attribs, err := lu.metadataBackend.All(context.Background(), path)
if err == nil {
nodeSpaceID, ok := attribs[prefixes.SpaceIDAttr]
if ok {
nodeSpaceID := attribs[prefixes.SpaceIDAttr]
if len(nodeSpaceID) > 0 {
spaceID = nodeSpaceID

// set the uid and gid for the space
fi, err := os.Stat(path)
err = scopeSpace(path)
if err != nil {
return err
}
sys := fi.Sys().(*syscall.Stat_t)
gid = int(sys.Gid)
_, err = lu.userMapper.ScopeUserByIds(-1, gid)
if err != nil {
return err
}
}

if len(spaceID) == 0 {
} else {
// try to find space
spaceCandidate := path
for strings.HasPrefix(spaceCandidate, lu.Options.Root) {
spaceID, err = lu.MetadataBackend().Get(context.Background(), spaceCandidate, prefixes.SpaceIDAttr)
if err == nil {
if lu.Options.UseSpaceGroups {
// set the uid and gid for the space
fi, err := os.Stat(spaceCandidate)
if err != nil {
return err
}
sys := fi.Sys().(*syscall.Stat_t)
gid := int(sys.Gid)
_, err = lu.userMapper.ScopeUserByIds(-1, gid)
if err != nil {
return err
}
err = scopeSpace(path)
if err != nil {
return err
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/posix/lookup/store_idcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *StoreIDCache) Set(_ context.Context, spaceID, nodeID, val string) error
// Get returns the value for a given key
func (c *StoreIDCache) Get(_ context.Context, spaceID, nodeID string) (string, bool) {
records, err := c.cache.Read(cacheKey(spaceID, nodeID))
if err != nil {
if err != nil || len(records) == 0 {
return "", false
}
return string(records[0].Value), true
Expand Down
12 changes: 8 additions & 4 deletions pkg/storage/fs/posix/tree/assimilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,19 @@ assimilate:
return nil, errors.Wrap(err, "failed to stat item")
}

previousAttribs, err := t.lookup.MetadataBackend().All(context.Background(), path)
attrs, err := t.lookup.MetadataBackend().All(context.Background(), path)
if err != nil && !metadata.IsAttrUnset(err) {
return nil, errors.Wrap(err, "failed to get item attribs")
}
previousAttribs := node.Attributes(attrs)

attributes := node.Attributes{
prefixes.IDAttr: []byte(id),
prefixes.NameAttr: []byte(filepath.Base(path)),
prefixes.MTimeAttr: []byte(fi.ModTime().Format(time.RFC3339)),
prefixes.IDAttr: []byte(id),
prefixes.NameAttr: []byte(filepath.Base(path)),
}
prevMtime, err := previousAttribs.Time(prefixes.MTimeAttr)
if err != nil || prevMtime.Before(fi.ModTime()) {
attributes[prefixes.MTimeAttr] = []byte(fi.ModTime().Format(time.RFC3339Nano))
}
if len(parentID) > 0 {
attributes[prefixes.ParentidAttr] = []byte(parentID)
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/fs/posix/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ var _ = SynchronizedBeforeSuite(func() {
}

if strings.Contains(name, "inotifywait") {
// Give it some time to setup the watches
time.Sleep(2 * time.Second)
return true
}
}

// Give it some time to setup the watches
time.Sleep(2 * time.Second)
return false
}).Should(BeTrue())
}, func() {})
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"io"
"strconv"
"time"

"github.com/pkg/xattr"
)
Expand Down Expand Up @@ -59,6 +60,11 @@ func (md Attributes) SetUInt64(key string, val uint64) {
md[key] = []byte(strconv.FormatUint(val, 10))
}

// Time reads a time value
func (md Attributes) Time(key string) (time.Time, error) {
return time.Parse(time.RFC3339Nano, string(md[key]))
}

// SetXattrs sets multiple extended attributes on the write-through cache/node
func (n *Node) SetXattrsWithContext(ctx context.Context, attribs map[string][]byte, acquireLock bool) (err error) {
if n.xattrsCache != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -181,12 +180,10 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere
session.SetStorageValue("SpaceRoot", n.SpaceRoot.ID) // TODO SpaceRoot -> SpaceID
session.SetStorageValue("SpaceOwnerOrManager", n.SpaceOwnerOrManager(ctx).GetOpaqueId()) // TODO needed for what?

// remember the gid of the space
fi, err := os.Stat(n.SpaceRoot.InternalPath())
if err != nil {
return nil, err
spaceGID, ok := ctx.Value(CtxKeySpaceGID).(uint32)
if ok {
session.SetStorageValue("SpaceGid", fmt.Sprintf("%d", spaceGID))
}
session.SetStorageValue("SpaceGid", fmt.Sprintf("%d", (fi.Sys().(*syscall.Stat_t).Gid)))

iid, _ := ctxpkg.ContextGetInitiator(ctx)
session.SetMetadata("initiatorid", iid)
Expand Down

0 comments on commit e4229f1

Please sign in to comment.