Skip to content

Commit

Permalink
eos: fixes for enabling file sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Apr 7, 2021
1 parent a8c6140 commit 1b95080
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/eos-file-sharing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fixes for enabling file sharing in EOS

https://github.com/cs3org/reva/pull/1619
61 changes: 43 additions & 18 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -119,6 +120,9 @@ type Options struct {
// SecProtocol is the comma separated list of security protocols used by xrootd.
// For example: "sss, unix"
SecProtocol string

// The EOS Version.
EOSVersion eosVersion
}

func (opt *Options) init() {
Expand Down Expand Up @@ -263,12 +267,15 @@ func (c *Client) executeEOS(ctx context.Context, cmd *exec.Cmd) (string, string,
}

func (c *Client) getVersion(ctx context.Context, rootUID, rootGID string) (eosVersion, error) {
cmd := exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "version")
stdout, _, err := c.executeEOS(ctx, cmd)
if err != nil {
return "", err
if c.opt.EOSVersion == "" {
cmd := exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "version")
stdout, _, err := c.executeEOS(ctx, cmd)
if err != nil {
return "", err
}
c.opt.EOSVersion = c.parseVersion(ctx, stdout)
}
return c.parseVersion(ctx, stdout), nil
return c.opt.EOSVersion, nil
}

func (c *Client) parseVersion(ctx context.Context, raw string) eosVersion {
Expand Down Expand Up @@ -297,24 +304,44 @@ func (c *Client) AddACL(ctx context.Context, uid, gid, rootUID, rootGID, path st
return err
}

var cmd *exec.Cmd
finfo, err := c.GetFileInfoByPath(ctx, uid, gid, path)
if err != nil {
return err
}

var args []string
if version == versionCitrine {
sysACL := a.CitrineSerialize()
cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "acl", "--sys", "--recursive", sysACL, path)
} else {
acls, err := c.getACLForPath(ctx, uid, gid, path)
if err != nil {
return err
args = []string{"-r", rootUID, rootGID, "acl"}
if finfo.IsDir {
args = append(args, "--sys", "--recursive")
} else {
args = append(args, "--user")
userACLAttr := &eosclient.Attribute{
Type: SystemAttr,
Key: "eval.useracl",
Val: "1",
}
if err = c.SetAttr(ctx, uid, gid, userACLAttr, false, path); err != nil {
return err
}
}

args = append(args, sysACL, path)
} else {
acls := finfo.SysACL
err = acls.SetEntry(a.Type, a.Qualifier, a.Permissions)
if err != nil {
return err
}
sysACL := acls.Serialize()
cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "attr", "-r", "set", fmt.Sprintf("sys.acl=%s", sysACL), path)
args = []string{"-r", rootUID, rootGID, "attr"}
if finfo.IsDir {
args = append(args, "-r")
}
args = append(args, "set", fmt.Sprintf("sys.acl=%s", sysACL), path)
}

cmd := exec.CommandContext(ctx, c.opt.EosBinary, args...)
_, _, err = c.executeEOS(ctx, cmd)
return err

Expand Down Expand Up @@ -437,11 +464,9 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, uid, gid, path string) (
}

if c.opt.VersionInvariant && !isVersionFolder(path) && !info.IsDir {
inode, err := c.getVersionFolderInode(ctx, uid, gid, path)
if err != nil {
return nil, err
if inode, err := c.getVersionFolderInode(ctx, uid, gid, path); err == nil {
info.Inode = inode
}
info.Inode = inode
}

return info, nil
Expand Down Expand Up @@ -791,7 +816,7 @@ func (c *Client) parseQuota(path, raw string) (*eosclient.QuotaInfo, error) {
// map[maxbytes:2000000000000 maxlogicalbytes:1000000000000 percentageusedbytes:0.49 quota:node uid:gonzalhu space:/eos/scratch/user/ usedbytes:9829986500 usedlogicalbytes:4914993250 statusfiles:ok usedfiles:334 maxfiles:1000000 statusbytes:ok]

space := m["space"]
if strings.HasPrefix(path, space) {
if strings.HasPrefix(path, filepath.Clean(space)) {
maxBytesString := m["maxlogicalbytes"]
usedBytesString := m["usedlogicalbytes"]
maxBytes, _ := strconv.ParseUint(maxBytesString, 10, 64)
Expand Down

0 comments on commit 1b95080

Please sign in to comment.