Skip to content

Commit

Permalink
Propagate lock holder to eos
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Apr 8, 2024
1 parent 0a522b8 commit 530db25
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path st
}

// Write writes a stream to the mgm.
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, metadata map[string]string) error {
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string) error {
fd, err := os.CreateTemp(c.opt.CacheDirectory, "eoswrite-")
if err != nil {
return err
Expand All @@ -723,7 +723,7 @@ func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path s
if err != nil {
return err
}
return c.WriteFile(ctx, auth, path, fd.Name(), metadata["lockholder"])
return c.WriteFile(ctx, auth, path, fd.Name(), app)
}

// WriteFile writes an existing file to the mgm.
Expand All @@ -734,7 +734,7 @@ func (c *Client) WriteFile(ctx context.Context, auth eosclient.Authorization, pa
if auth.Token != "" {
args[4] += "?authz=" + auth.Token
} else if auth.Role.UID != "" && auth.Role.GID != "" {
args = append(args, fmt.Sprintf("-ODeos.ruid=%s&eos.rgid=%s&eos.app=reva_eosclient::write", auth.Role.UID, auth.Role.GID))
args = append(args, fmt.Sprintf("-ODeos.ruid=%s&eos.rgid=%s&eos.app=%s", auth.Role.UID, auth.Role.GID, app))
}

_, _, err := c.executeXRDCopy(ctx, args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/eosclient/eosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type EOSClient interface {
Rename(ctx context.Context, auth Authorization, oldPath, newPath string) error
List(ctx context.Context, auth Authorization, path string) ([]*FileInfo, error)
Read(ctx context.Context, auth Authorization, path string) (io.ReadCloser, error)
Write(ctx context.Context, auth Authorization, path string, stream io.ReadCloser, metadata map[string]string) error
Write(ctx context.Context, auth Authorization, path string, stream io.ReadCloser, app string) error
WriteFile(ctx context.Context, auth Authorization, path, source, app string) error
ListDeletedEntries(ctx context.Context, auth Authorization, maxentries int, from, to time.Time) ([]*DeletedEntry, error)
RestoreDeletedEntry(ctx context.Context, auth Authorization, key string) error
Expand Down
6 changes: 3 additions & 3 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path st

// Write writes a file to the mgm
// Somehow the same considerations as Read apply.
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, metadata map[string]string) error {
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "Write").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")
var length int64
Expand Down Expand Up @@ -1355,10 +1355,10 @@ func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path s
defer wfd.Close()
defer os.RemoveAll(fd.Name())

return c.httpcl.PUTFile(ctx, u.Username, auth, path, wfd, length)
return c.httpcl.PUTFile(ctx, u.Username, auth, path, wfd, length, app)
}

return c.httpcl.PUTFile(ctx, u.Username, auth, path, stream, length)
return c.httpcl.PUTFile(ctx, u.Username, auth, path, stream, length, app)

// return c.httpcl.PUTFile(ctx, remoteuser, auth, urlpathng, stream)
// return c.WriteFile(ctx, uid, gid, path, fd.Name())
Expand Down
7 changes: 5 additions & 2 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ func (c *EOSHTTPClient) GETFile(ctx context.Context, remoteuser string, auth eos
}

// PUTFile does an entire PUT to upload a full file, taking the data from a stream.
func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eosclient.Authorization, urlpath string, stream io.ReadCloser, length int64) error {
func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eosclient.Authorization, urlpath string, stream io.ReadCloser, length int64, app string) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", urlpath).Int64("length", length).Msg("")
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", urlpath).Int64("length", length).Str("app", app).Msg("")

// Now send the req and see what happens
finalurl, err := c.buildFullURL(urlpath, auth)
Expand All @@ -376,6 +376,9 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
return err
}

if app != "" {
req.Header.Set("app", app)
}
req.Close = true

ntries := 0
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ func encodeLock(l *provider.Lock) (string, string, error) {
}
var a string
if l.AppName != "" {
a = l.AppName
// cf. upload implementation
r := strings.NewReplacer(" ", "_")
a = "reva_" + strings.ToLower(r.Replace(l.AppName))
} else {
a = "*"
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/storage/utils/eosfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
"path"
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
Expand Down Expand Up @@ -75,7 +76,15 @@ func (fs *eosfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadC
if err != nil {
return err
}
return fs.c.Write(ctx, auth, fn, r, metadata)

app := metadata["lockholder"]
if app == "" {
app = "reva_eosclient::write"
} else {
r := strings.NewReplacer(" ", "_")
app = "reva_" + strings.ToLower(r.Replace(app))
}
return fs.c.Write(ctx, auth, fn, r, app)
}

func (fs *eosfs) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) {
Expand Down

0 comments on commit 530db25

Please sign in to comment.