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

Fix Stat() for eos storage provider #2074

Merged
merged 3 commits into from
Sep 16, 2021
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
8 changes: 8 additions & 0 deletions changelog/unreleased/stat-eos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Fix Stat() for EOS storage provider

This change fixes the convertion between the eosclient.FileInfo
to ResourceInfo, in which the field ArbitraryMetadata was missing.
Moreover, to be consistent with SetArbitraryMetadata() EOS implementation,
all the "user." prefix are stripped out from the xattrs.

https://github.com/cs3org/reva/pull/2074
15 changes: 8 additions & 7 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
name := line[0:length]

kv := make(map[string]string)
attrs := make(map[string]string)
// strip trailing slash
kv["file"] = strings.TrimSuffix(name, "/")

Expand All @@ -948,17 +949,17 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
// handle xattrn and xattrv special cases
switch {
case partsByEqual[0] == "xattrn":
previousXAttr = partsByEqual[1]
previousXAttr = strings.Replace(partsByEqual[1], "user.", "", 1)
case partsByEqual[0] == "xattrv":
kv[previousXAttr] = partsByEqual[1]
attrs[previousXAttr] = partsByEqual[1]
previousXAttr = ""
default:
kv[partsByEqual[0]] = partsByEqual[1]

}
}
}
fi, err := c.mapToFileInfo(kv)
fi, err := c.mapToFileInfo(kv, attrs)
if err != nil {
return nil, err
}
Expand All @@ -968,7 +969,7 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
// mapToFileInfo converts the dictionary to an usable structure.
// The kv has format:
// map[sys.forced.space:default files:0 mode:42555 ino:5 sys.forced.blocksize:4k sys.forced.layout:replica uid:0 fid:5 sys.forced.blockchecksum:crc32c sys.recycle:/eos/backup/proc/recycle/ fxid:00000005 pid:1 etag:5:0.000 keylength.file:4 file:/eos treesize:1931593933849913 container:3 gid:0 mtime:1498571294.108614409 ctime:1460121992.294326762 pxid:00000001 sys.forced.checksum:adler sys.forced.nstripes:2]
func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error) {
func (c *Client) mapToFileInfo(kv, attrs map[string]string) (*eosclient.FileInfo, error) {
inode, err := strconv.ParseUint(kv["ino"], 10, 64)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1055,11 +1056,11 @@ func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error
}
}

sysACL, err := acl.Parse(kv["sys.acl"], acl.ShortTextForm)
sysACL, err := acl.Parse(attrs["sys.acl"], acl.ShortTextForm)
if err != nil {
return nil, err
}
lwACLStr, ok := kv[lwShareAttrKey]
lwACLStr, ok := attrs[lwShareAttrKey]
if ok {
lwAcls, err := acl.Parse(lwACLStr, acl.ShortTextForm)
if err != nil {
Expand Down Expand Up @@ -1088,7 +1089,7 @@ func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error
Instance: c.opt.URL,
SysACL: sysACL,
TreeCount: treeCount,
Attrs: kv,
Attrs: attrs,
XS: xs,
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,14 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
}
}

// filter 'sys' attrs
filteredAttrs := make(map[string]string)
for k, v := range eosFileInfo.Attrs {
if !strings.HasPrefix(k, "sys") {
filteredAttrs[k] = v
}
}

info := &provider.ResourceInfo{
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Expand All @@ -1697,6 +1705,9 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
},
},
},
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: filteredAttrs,
},
gmgigi96 marked this conversation as resolved.
Show resolved Hide resolved
}

if eosFileInfo.IsDir {
Expand Down