Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Minor fixes in cephfs and eosfs (cs3org#2789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed May 5, 2022
1 parent f9cd20e commit 4986ec5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 89 deletions.
2 changes: 1 addition & 1 deletion pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,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) {
Expand Down
50 changes: 25 additions & 25 deletions pkg/storage/fs/cephfs/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand All @@ -174,7 +174,7 @@ func newAdminConn(conf *Options) *adminConn {
return nil
}

return &adminConn {
return &adminConn{
// poolName,
admin.NewFromConn(rados),
mount,
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/fs/cephfs/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/fs/cephfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -247,4 +247,4 @@ func (fs *cephfs) resolveIndex(oid string) (fullPath string, err error) {
currPath.Reset()
}
}
*/
*/
76 changes: 17 additions & 59 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,14 +870,26 @@ 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)
}

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)
Expand Down Expand Up @@ -907,69 +919,15 @@ 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)
}
}

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)

Expand Down Expand Up @@ -1763,8 +1721,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
Expand Down

0 comments on commit 4986ec5

Please sign in to comment.