Skip to content

Commit

Permalink
Add more error handling and logging.
Browse files Browse the repository at this point in the history
Bugfix: return zero for free and avail so libfuse knows cloud storage is responding.
  • Loading branch information
foodprocessor committed Nov 2, 2024
1 parent b7374b3 commit 951fd02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,15 @@ func (fc *FileCache) StatFs() (*common.Statfs_t, bool, error) {
return fc.NextComponent().StatFs()
}

log.Trace("FileCache::StatFs")

// cache_size = f_blocks * f_frsize/1024
// cache_size - used = f_frsize * f_bavail/1024
// cache_size - used = vfs.f_bfree * vfs.f_frsize / 1024
// if cache size is set to 0 then we have the root mount usage
maxCacheSize := fc.maxCacheSize * MB
if maxCacheSize == 0 {
log.Err("FileCache::StatFs : Not responding to StatFs because max cache size is zero")
return nil, false, nil
}
usage, _ := common.GetUsage(fc.tmpPath)
Expand All @@ -400,6 +403,7 @@ func (fc *FileCache) StatFs() (*common.Statfs_t, bool, error) {
// how much space is available on the underlying file system?
availableOnCacheFS, err := fc.getAvailableSize()
if err != nil {
log.Err("FileCache::StatFs : Not responding to StatFs because getAvailableSize failed. Here's why: %v", err)
return nil, false, err
}

Expand All @@ -416,6 +420,7 @@ func (fc *FileCache) StatFs() (*common.Statfs_t, bool, error) {
Namemax: 255,
}

log.Debug("FileCache::StatFs : responding with free=%d avail=%d blocks=%d (bsize=%d)", stat.Bfree, stat.Bavail, stat.Blocks, stat.Bsize)
return &stat, true, nil
}

Expand Down
12 changes: 6 additions & 6 deletions component/s3storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,29 +1131,29 @@ func (cl *Client) combineSmallBlocks(name string, blockList []*common.Block) ([]
return newBlockList, nil
}

func (cl *Client) GetUsedSize() uint64 {
func (cl *Client) GetUsedSize() (uint64, error) {
headBucketOutput, err := cl.headBucket()
if err != nil {
return 0
return 0, err
}

response, ok := middleware.GetRawResponse(headBucketOutput.ResultMetadata).(*smithyHttp.Response)
if !ok || response == nil {
return 0
return 0, fmt.Errorf("Failed GetRawResponse from HeadBucketOutput")
}

headerValue, ok := response.Header["X-Rstor-Size"]
if !ok {
headerValue, ok = response.Header["X-Lyve-Size"]
}
if !ok || len(headerValue) == 0 {
return 0
return 0, fmt.Errorf("HeadBucket response has no size header (is the endpoint not Lyve Cloud?)")
}

bucketSizeBytes, err := strconv.ParseUint(headerValue[0], 10, 64)
if err != nil {
return 0
return 0, err
}

return bucketSizeBytes
return bucketSizeBytes, nil
}
2 changes: 1 addition & 1 deletion component/s3storage/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ type S3Connection interface {
StageAndCommit(name string, bol *common.BlockOffsetList) error

NewCredentialKey(_, _ string) error
GetUsedSize() uint64
GetUsedSize() (uint64, error)
}
18 changes: 14 additions & 4 deletions component/s3storage/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,33 @@ func (s3 *S3Storage) FlushFile(options internal.FlushFileOptions) error {
const blockSize = 4096

func (s3 *S3Storage) StatFs() (*common.Statfs_t, bool, error) {
log.Trace("S3Storage::StatFs")
// cache_size = f_blocks * f_frsize/1024
// cache_size - used = f_frsize * f_bavail/1024
// cache_size - used = vfs.f_bfree * vfs.f_frsize / 1024
// if cache size is set to 0 then we have the root mount usage
sizeUsed := s3.storage.GetUsedSize()
sizeUsed, err := s3.storage.GetUsedSize()
if err != nil {
// TODO: will returning EIO break any applications that depend on StatFs?
return nil, false, err
}

stat := common.Statfs_t{
Blocks: sizeUsed / blockSize,
Bavail: sizeUsed / blockSize,
Bfree: sizeUsed / blockSize,
Blocks: sizeUsed / blockSize,
// there is no set capacity limit in cloud storage
// so we use zero for free and avail
// this zero value is used in the libfuse component to recognize that cloud storage responded
Bavail: 0,
Bfree: 0,
Bsize: blockSize,
Ffree: 1e9,
Files: 1e9,
Frsize: blockSize,
Namemax: 255,
}

log.Debug("S3Storage::StatFs : responding with free=%d avail=%d blocks=%d (bsize=%d)", stat.Bfree, stat.Bavail, stat.Blocks, stat.Bsize)

return &stat, true, nil
}

Expand Down

0 comments on commit 951fd02

Please sign in to comment.