From 530db25347e158c38b2d2f4f6095efcf5c9cef93 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Wed, 14 Feb 2024 13:47:41 +0100 Subject: [PATCH] Propagate lock holder to eos --- pkg/eosclient/eosbinary/eosbinary.go | 6 +++--- pkg/eosclient/eosclient.go | 2 +- pkg/eosclient/eosgrpc/eosgrpc.go | 6 +++--- pkg/eosclient/eosgrpc/eoshttp.go | 7 +++++-- pkg/storage/utils/eosfs/eosfs.go | 4 +++- pkg/storage/utils/eosfs/upload.go | 11 ++++++++++- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 0f4400e2dd6..3b6dc1a1c98 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -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 @@ -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. @@ -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) diff --git a/pkg/eosclient/eosclient.go b/pkg/eosclient/eosclient.go index 23eaeb9c119..d4a5f0a0b37 100644 --- a/pkg/eosclient/eosclient.go +++ b/pkg/eosclient/eosclient.go @@ -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 diff --git a/pkg/eosclient/eosgrpc/eosgrpc.go b/pkg/eosclient/eosgrpc/eosgrpc.go index 9ce7099ae3d..54c11d6426a 100644 --- a/pkg/eosclient/eosgrpc/eosgrpc.go +++ b/pkg/eosclient/eosgrpc/eosgrpc.go @@ -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 @@ -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()) diff --git a/pkg/eosclient/eosgrpc/eoshttp.go b/pkg/eosclient/eosgrpc/eoshttp.go index e75fc8c4097..b78312d634e 100644 --- a/pkg/eosclient/eosgrpc/eoshttp.go +++ b/pkg/eosclient/eosgrpc/eoshttp.go @@ -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) @@ -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 diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 60d6bc9b02b..ca85f677ea4 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -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 = "*" } diff --git a/pkg/storage/utils/eosfs/upload.go b/pkg/storage/utils/eosfs/upload.go index 5d2818f86f1..0213dd78cb6 100644 --- a/pkg/storage/utils/eosfs/upload.go +++ b/pkg/storage/utils/eosfs/upload.go @@ -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" @@ -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) {