Skip to content

Commit

Permalink
Handle quota requests for arbitrary resources in EOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Jun 3, 2022
1 parent a776864 commit b5ab8de
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,22 +1029,39 @@ func (fs *eosfs) listShareFolderRoot(ctx context.Context, p string) (finfos []*p
}

func (fs *eosfs) GetQuota(ctx context.Context, ref *provider.Reference) (uint64, uint64, uint64, error) {
// Check if the quota request is for the user's home or a project space
u, err := getUser(ctx)
if err != nil {
return 0, 0, 0, errors.Wrap(err, "eosfs: no user in ctx")
}
// lightweight accounts don't have quota nodes, so we're passing an empty string as path
auth, err := fs.getUserAuth(ctx, u, "")
if err != nil {
return 0, 0, 0, errors.Wrap(err, "eosfs: error getting uid and gid for user")

// If the quota request is for a resource different than the user home,
// we impersonate the owner in that case
uid := strconv.FormatInt(u.UidNumber, 10)
if ref.ResourceId != nil {
fid, err := strconv.ParseUint(ref.ResourceId.OpaqueId, 10, 64)
if err != nil {
return 0, 0, 0, fmt.Errorf("error converting string to int for eos fileid: %s", ref.ResourceId.OpaqueId)
}

// lightweight accounts don't have quota nodes, so we're passing an empty string as path
auth, err := fs.getUserAuth(ctx, u, "")
if err != nil {
return 0, 0, 0, errors.Wrap(err, "eosfs: error getting uid and gid for user")
}
eosFileInfo, err := fs.c.GetFileInfoByInode(ctx, auth, fid)
if err != nil {
return 0, 0, 0, err
}
uid = strconv.FormatUint(eosFileInfo.UID, 10)
}

rootAuth, err := fs.getRootAuth(ctx)
if err != nil {
return 0, 0, 0, err
}

qi, err := fs.c.GetQuota(ctx, auth.Role.UID, rootAuth, fs.conf.QuotaNode)
qi, err := fs.c.GetQuota(ctx, uid, rootAuth, fs.conf.QuotaNode)
if err != nil {
err := errors.Wrap(err, "eosfs: error getting quota")
return 0, 0, 0, err
Expand Down

0 comments on commit b5ab8de

Please sign in to comment.