From b4615a9e43afd7e477c565038515c0263a5c601d Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 28 Apr 2022 10:56:05 +0200 Subject: [PATCH] Minor fixes in cephfs and eosfs --- changelog/unreleased/eosfs-fixes.md | 3 ++ pkg/eosclient/eosbinary/eosbinary.go | 2 +- pkg/storage/fs/cephfs/cephfs.go | 6 +-- pkg/storage/fs/cephfs/connections.go | 50 +++++++++--------- pkg/storage/fs/cephfs/options.go | 4 +- pkg/storage/fs/cephfs/utils.go | 4 +- pkg/storage/utils/eosfs/eosfs.go | 76 +++++++--------------------- 7 files changed, 53 insertions(+), 92 deletions(-) create mode 100644 changelog/unreleased/eosfs-fixes.md diff --git a/changelog/unreleased/eosfs-fixes.md b/changelog/unreleased/eosfs-fixes.md new file mode 100644 index 0000000000..033e910bc1 --- /dev/null +++ b/changelog/unreleased/eosfs-fixes.md @@ -0,0 +1,3 @@ +Bugfix: Minor fixes in cephfs and eosfs + +https://github.com/cs3org/reva/pull/2789 \ No newline at end of file diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 8e63170c4f..abd36f6e14 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -852,7 +852,7 @@ func (c *Client) GenerateToken(ctx context.Context, auth eosclient.Authorization expiration := strconv.FormatInt(time.Now().Add(time.Duration(c.opt.TokenExpiry)*time.Second).Unix(), 10) args := []string{"token", "--permission", a.Permissions, "--tree", "--path", p, "--expires", expiration} stdout, _, err := c.executeEOS(ctx, args, auth) - return stdout, err + return strings.TrimSpace(stdout), err } func (c *Client) getVersionFolderInode(ctx context.Context, auth eosclient.Authorization, p string) (uint64, error) { diff --git a/pkg/storage/fs/cephfs/cephfs.go b/pkg/storage/fs/cephfs/cephfs.go index b4c2ebaa1a..282eb4645d 100644 --- a/pkg/storage/fs/cephfs/cephfs.go +++ b/pkg/storage/fs/cephfs/cephfs.go @@ -572,7 +572,7 @@ func (fs *cephfs) TouchFile(ctx context.Context, ref *provider.Reference) error user.op(func(cv *cacheVal) { var file *cephfs2.File defer closeFile(file) - if file, err = cv.mount.Open(path, os.O_CREATE | os.O_WRONLY, fs.conf.FilePerms); err != nil { + if file, err = cv.mount.Open(path, os.O_CREATE|os.O_WRONLY, fs.conf.FilePerms); err != nil { return } @@ -622,6 +622,6 @@ func (fs *cephfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock return errtypes.NotSupported("unimplemented") } -func (fs *cephfs) Unlock(ctx context.Context, ref *provider.Reference) error { +func (fs *cephfs) Unlock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error { return errtypes.NotSupported("unimplemented") -} \ No newline at end of file +} diff --git a/pkg/storage/fs/cephfs/connections.go b/pkg/storage/fs/cephfs/connections.go index 9710c5b084..ef37870490 100644 --- a/pkg/storage/fs/cephfs/connections.go +++ b/pkg/storage/fs/cephfs/connections.go @@ -109,9 +109,9 @@ func (c *connections) clearCache() { type adminConn struct { // indexPoolName string - subvolAdmin *admin.FSAdmin - adminMount Mount - radosConn *rados2.Conn + subvolAdmin *admin.FSAdmin + adminMount Mount + radosConn *rados2.Conn // radosIO *rados2.IOContext } @@ -134,32 +134,32 @@ func newAdminConn(conf *Options) *adminConn { // TODO: May use later for file ids /* - pools, err := rados.ListPools() - if err != nil { - rados.Shutdown() - return nil - } - - var radosIO *rados2.IOContext - poolName := conf.IndexPool - if in(poolName, pools) { - radosIO, err = rados.OpenIOContext(poolName) - if err != nil { - rados.Shutdown() - return nil - } - } else { - err = rados.MakePool(poolName) + pools, err := rados.ListPools() if err != nil { rados.Shutdown() return nil } - radosIO, err = rados.OpenIOContext(poolName) - if err != nil { - rados.Shutdown() - return nil + + var radosIO *rados2.IOContext + poolName := conf.IndexPool + if in(poolName, pools) { + radosIO, err = rados.OpenIOContext(poolName) + if err != nil { + rados.Shutdown() + return nil + } + } else { + err = rados.MakePool(poolName) + if err != nil { + rados.Shutdown() + return nil + } + radosIO, err = rados.OpenIOContext(poolName) + if err != nil { + rados.Shutdown() + return nil + } } - } */ mount, err := cephfs2.CreateFromRados(rados) @@ -174,7 +174,7 @@ func newAdminConn(conf *Options) *adminConn { return nil } - return &adminConn { + return &adminConn{ // poolName, admin.NewFromConn(rados), mount, diff --git a/pkg/storage/fs/cephfs/options.go b/pkg/storage/fs/cephfs/options.go index 93baff609a..91589097f2 100644 --- a/pkg/storage/fs/cephfs/options.go +++ b/pkg/storage/fs/cephfs/options.go @@ -29,8 +29,8 @@ import ( // Options for the cephfs module type Options struct { - ClientID string `mapstructure:"client_id"` - Config string `mapstructure:"config"` + ClientID string `mapstructure:"client_id"` + Config string `mapstructure:"config"` GatewaySvc string `mapstructure:"gatewaysvc"` IndexPool string `mapstructure:"index_pool"` Keyring string `mapstructure:"keyring"` diff --git a/pkg/storage/fs/cephfs/utils.go b/pkg/storage/fs/cephfs/utils.go index b54b76cb91..f2b9a4f703 100644 --- a/pkg/storage/fs/cephfs/utils.go +++ b/pkg/storage/fs/cephfs/utils.go @@ -100,7 +100,7 @@ func (fs *cephfs) getFIDPath(cv *cacheVal, path string) (fid string, err error) return fs.makeFIDPath(string(buffer)), err } - */ +*/ func calcChecksum(filepath string, mt Mount, stat Statx) (checksum string, err error) { file, err := mt.Open(filepath, os.O_RDONLY, 0) @@ -247,4 +247,4 @@ func (fs *cephfs) resolveIndex(oid string) (fullPath string, err error) { currPath.Reset() } } - */ +*/ diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 2784b39a85..9635549d57 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1269,7 +1269,6 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys return nil, errors.Wrap(err, "eosfs: error resolving reference") } - // if path is home we need to add in the response any shadow folder in the shadow homedirectory. if fs.conf.EnableHome { return fs.listWithHome(ctx, p) } @@ -1277,6 +1276,19 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys return fs.listWithNominalHome(ctx, p) } +func (fs *eosfs) listWithHome(ctx context.Context, p string) ([]*provider.ResourceInfo, error) { + if fs.isShareFolderRoot(ctx, p) { + return fs.listShareFolderRoot(ctx, p) + } + + if fs.isShareFolderChild(ctx, p) { + return nil, errtypes.PermissionDenied("eos: error listing folders inside the shared folder, only file references are stored inside") + } + + // path points to a resource in the nominal home + return fs.listWithNominalHome(ctx, p) +} + func (fs *eosfs) listWithNominalHome(ctx context.Context, p string) (finfos []*provider.ResourceInfo, err error) { log := appctx.GetLogger(ctx) fn := fs.wrap(ctx, p) @@ -1306,7 +1318,8 @@ func (fs *eosfs) listWithNominalHome(ctx context.Context, p string) (finfos []*p } // Remove the hidden folders in the topmost directory - if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") { + if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil && + finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") { finfos = append(finfos, finfo) } } @@ -1314,61 +1327,6 @@ func (fs *eosfs) listWithNominalHome(ctx context.Context, p string) (finfos []*p return finfos, nil } -func (fs *eosfs) listWithHome(ctx context.Context, p string) ([]*provider.ResourceInfo, error) { - if p == "/" { - return fs.listHome(ctx) - } - - if fs.isShareFolderRoot(ctx, p) { - return fs.listShareFolderRoot(ctx, p) - } - - if fs.isShareFolderChild(ctx, p) { - return nil, errtypes.PermissionDenied("eosfs: error listing folders inside the shared folder, only file references are stored inside") - } - - // path points to a resource in the nominal home - return fs.listWithNominalHome(ctx, p) -} - -func (fs *eosfs) listHome(ctx context.Context) ([]*provider.ResourceInfo, error) { - fns := []string{fs.wrap(ctx, "/"), fs.wrapShadow(ctx, "/")} - - u, err := getUser(ctx) - if err != nil { - return nil, errors.Wrap(err, "eosfs: no user in ctx") - } - // lightweight accounts don't have home folders, so we're passing an empty string as path - auth, err := fs.getUserAuth(ctx, u, "") - if err != nil { - return nil, err - } - - finfos := []*provider.ResourceInfo{} - for _, fn := range fns { - eosFileInfos, err := fs.c.List(ctx, auth, fn) - if err != nil { - return nil, errors.Wrap(err, "eosfs: error listing") - } - - for _, eosFileInfo := range eosFileInfos { - // filter out sys files - if !fs.conf.ShowHiddenSysFiles { - base := path.Base(eosFileInfo.File) - if hiddenReg.MatchString(base) { - continue - } - } - - if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") { - finfos = append(finfos, finfo) - } - } - - } - return finfos, nil -} - func (fs *eosfs) listShareFolderRoot(ctx context.Context, p string) (finfos []*provider.ResourceInfo, err error) { fn := fs.wrapShadow(ctx, p) @@ -2174,8 +2132,8 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) ( } var xs provider.ResourceChecksum - if eosFileInfo.XS != nil { - xs.Sum = eosFileInfo.XS.XSSum + if eosFileInfo.Size != 0 && eosFileInfo.XS != nil { + xs.Sum = strings.TrimLeft(eosFileInfo.XS.XSSum, "0") switch eosFileInfo.XS.XSType { case "adler": xs.Type = provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_ADLER32