Skip to content

Commit

Permalink
eos: fixes for enabling file sharing (cs3org#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored and fbx committed Apr 19, 2021
1 parent f53aae9 commit 7d64d6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 63 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
93 changes: 30 additions & 63 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 All @@ -40,13 +41,8 @@ import (
"go.opencensus.io/trace"
)

type eosVersion string

const (
versionPrefix = ".sys.v#."

versionAquamarine = eosVersion("aquamarine")
versionCitrine = eosVersion("citrine")
)

const (
Expand Down Expand Up @@ -262,89 +258,62 @@ func (c *Client) executeEOS(ctx context.Context, cmd *exec.Cmd) (string, string,
return outBuf.String(), errBuf.String(), err
}

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
}
return c.parseVersion(ctx, stdout), nil
}

func (c *Client) parseVersion(ctx context.Context, raw string) eosVersion {
var serverVersion string
rawLines := strings.Split(raw, "\n")
for _, rl := range rawLines {
if rl == "" {
continue
}
if strings.HasPrefix(rl, "EOS_SERVER_VERSION") {
serverVersion = strings.Split(strings.Split(rl, " ")[0], "=")[1]
break
}
}

if strings.HasPrefix(serverVersion, "4.") {
return versionCitrine
}
return versionAquamarine
}

// AddACL adds an new acl to EOS with the given aclType.
func (c *Client) AddACL(ctx context.Context, uid, gid, rootUID, rootGID, path string, a *acl.Entry) error {
version, err := c.getVersion(ctx, rootUID, rootGID)
finfo, err := c.GetFileInfoByPath(ctx, uid, gid, path)
if err != nil {
return err
}
sysACL := a.CitrineSerialize()
args := []string{"-r", rootUID, rootGID, "acl"}

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

err = acls.SetEntry(a.Type, a.Qualifier, a.Permissions)
if err != nil {
if err = c.SetAttr(ctx, uid, gid, userACLAttr, false, path); 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 = append(args, sysACL, path)

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

}

// RemoveACL removes the acl from EOS.
func (c *Client) RemoveACL(ctx context.Context, uid, gid, rootUID, rootGID, path string, a *acl.Entry) error {
version, err := c.getVersion(ctx, rootUID, rootGID)
finfo, err := c.GetFileInfoByPath(ctx, uid, gid, path)
if err != nil {
return err
}

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

acls.DeleteEntry(a.Type, a.Qualifier)
sysACL := acls.Serialize()
cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "attr", "-r", "set", fmt.Sprintf("sys.acl=%s", sysACL), path)
}
args = append(args, sysACL, path)

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

}

// UpdateACL updates the EOS acl.
Expand Down Expand Up @@ -437,11 +406,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 +758,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 7d64d6e

Please sign in to comment.