Skip to content

Commit 307c84b

Browse files
authored
feat(readdir): fix inode leak (#17)
* feat(readdir): fix inode leak kahing#786
1 parent 4225edb commit 307c84b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

internal/backend_s3.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (s *S3Backend) Init(key string) error {
290290
}
291291

292292
func (s *S3Backend) ListObjectsV2(params *s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, string, error) {
293-
s3Log.Debugf("MATHIS TEST: params %v, backend %v", params, s)
293+
s3Log.Debugf("ListObjectsV2: params %v, backend %v", params, s)
294294
if s.aws {
295295
req, resp := s.S3.ListObjectsV2Request(params)
296296
err := req.Send()
@@ -317,7 +317,7 @@ func (s *S3Backend) ListObjectsV2(params *s3.ListObjectsV2Input) (*s3.ListObject
317317
if err != nil {
318318
return nil, "", err
319319
}
320-
s3Log.Debugf("MATHIS TEST: objs %v, err %v", objs, err)
320+
s3Log.Debugf("ListObjectsV2: objs %v, err %v", objs, err)
321321
count := int64(len(objs.Contents))
322322
v2Objs := s3.ListObjectsV2Output{
323323
CommonPrefixes: objs.CommonPrefixes,
@@ -392,7 +392,7 @@ func (s *S3Backend) HeadBlob(param *HeadBlobInput) (*HeadBlobOutput, error) {
392392

393393
func (s *S3Backend) ListBlobs(param *ListBlobsInput) (*ListBlobsOutput, error) {
394394
var maxKeys *int64
395-
s3Log.Debugf("MATHIS TEST")
395+
s3Log.Debugf("ListBlobs")
396396
if param.MaxKeys != nil {
397397
maxKeys = aws.Int64(int64(*param.MaxKeys))
398398
}
@@ -405,7 +405,7 @@ func (s *S3Backend) ListBlobs(param *ListBlobsInput) (*ListBlobsOutput, error) {
405405
StartAfter: param.StartAfter,
406406
ContinuationToken: param.ContinuationToken,
407407
})
408-
s3Log.Debugf("MATHIS TEST: resp %v, reqid %v, err %v", resp, reqId, err)
408+
s3Log.Debugf("ListBlobs: resp %v, reqid %v, err %v", resp, reqId, err)
409409
if err != nil {
410410
return nil, mapAwsError(err)
411411
}
@@ -425,12 +425,12 @@ func (s *S3Backend) ListBlobs(param *ListBlobsInput) (*ListBlobsOutput, error) {
425425
StorageClass: i.StorageClass,
426426
})
427427
}
428-
s3Log.Debugf("MATHIS TEST: prefixes %v, items %v", prefixes, items)
428+
s3Log.Debugf("ListBlobs: prefixes %v, items %v", prefixes, items)
429429
isTruncatedFlag := false
430430
if resp.IsTruncated != nil {
431431
isTruncatedFlag = *resp.IsTruncated
432432
} else {
433-
s3Log.Debugf("MATHIS TEST: nil pointer catch")
433+
s3Log.Debugf("ListBlobs: nil pointer catch")
434434
}
435435
return &ListBlobsOutput{
436436
Prefixes: prefixes,

internal/goofys.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,19 @@ func (fs *Goofys) ForgetInode(
764764
fs.mu.Lock()
765765
defer fs.mu.Unlock()
766766

767+
// Fix ReadDir inode leak
768+
// https://github.com/kahing/goofys/pull/786
769+
if inode.isDir() {
770+
for _, child := range inode.dir.Children {
771+
if *child.Name == "." || *child.Name == ".." {
772+
continue
773+
}
774+
s3Log.Debugf("Goofys Upstream PR: Inode Dir Leak fix")
775+
delete(fs.inodes, child.Id)
776+
fs.forgotCnt += 1
777+
}
778+
}
779+
767780
delete(fs.inodes, op.Inode)
768781
fs.forgotCnt += 1
769782

0 commit comments

Comments
 (0)