Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes in cephfs and eosfs #2789

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/eosfs-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Minor fixes in cephfs and eosfs

https://github.com/cs3org/reva/pull/2789
2 changes: 1 addition & 1 deletion pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/fs/cephfs/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
}
}
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 @@ -1269,14 +1269,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 @@ -1306,69 +1318,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 @@ -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
Expand Down