diff --git a/pkg/fs/fs-bucket-acl.go b/pkg/fs/fs-bucket-acl.go index 46a61020e..fe2c9d26b 100644 --- a/pkg/fs/fs-bucket-acl.go +++ b/pkg/fs/fs-bucket-acl.go @@ -18,8 +18,8 @@ package fs // IsPrivateBucket - is private bucket func (fs Filesystem) IsPrivateBucket(bucket string) bool { - fs.rwLock.Lock() - defer fs.rwLock.Unlock() + fs.rwLock.RLock() + defer fs.rwLock.RUnlock() bucketMetadata, ok := fs.buckets.Metadata[bucket] if !ok { return true @@ -29,8 +29,8 @@ func (fs Filesystem) IsPrivateBucket(bucket string) bool { // IsPublicBucket - is public bucket func (fs Filesystem) IsPublicBucket(bucket string) bool { - fs.rwLock.Lock() - defer fs.rwLock.Unlock() + fs.rwLock.RLock() + defer fs.rwLock.RUnlock() bucketMetadata, ok := fs.buckets.Metadata[bucket] if !ok { return true @@ -40,8 +40,8 @@ func (fs Filesystem) IsPublicBucket(bucket string) bool { // IsReadOnlyBucket - is read only bucket func (fs Filesystem) IsReadOnlyBucket(bucket string) bool { - fs.rwLock.Lock() - defer fs.rwLock.Unlock() + fs.rwLock.RLock() + defer fs.rwLock.RUnlock() bucketMetadata, ok := fs.buckets.Metadata[bucket] if !ok { return true diff --git a/pkg/fs/fs-bucket.go b/pkg/fs/fs-bucket.go index f366e286d..686bc6432 100644 --- a/pkg/fs/fs-bucket.go +++ b/pkg/fs/fs-bucket.go @@ -58,12 +58,12 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error { // Critical region hold write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() + delete(fs.buckets.Metadata, bucket) if err := saveBucketsMetadata(*fs.buckets); err != nil { - fs.rwLock.Unlock() return err.Trace(bucket) } - fs.rwLock.Unlock() return nil } @@ -171,12 +171,12 @@ func (fs Filesystem) MakeBucket(bucket, acl string) *probe.Error { // Critical region hold a write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() + fs.buckets.Metadata[bucket] = bucketMetadata if err := saveBucketsMetadata(*fs.buckets); err != nil { - fs.rwLock.Unlock() return err.Trace(bucket) } - fs.rwLock.Unlock() return nil } @@ -266,11 +266,11 @@ func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string // Critical region handle write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() + fs.buckets.Metadata[bucket] = bucketMetadata if err := saveBucketsMetadata(*fs.buckets); err != nil { - fs.rwLock.Unlock() return err.Trace(bucket) } - fs.rwLock.Unlock() return nil } diff --git a/pkg/fs/fs-multipart.go b/pkg/fs/fs-multipart.go index 4ac9856ec..ddb9da6e2 100644 --- a/pkg/fs/fs-multipart.go +++ b/pkg/fs/fs-multipart.go @@ -276,6 +276,7 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E // Critical region requiring write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() // Initialize multipart session. mpartSession := &MultipartSession{} mpartSession.TotalParts = 0 @@ -288,10 +289,8 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E fs.multiparts.ActiveSession[uploadID] = mpartSession if err := saveMultipartsSession(*fs.multiparts); err != nil { - fs.rwLock.Unlock() return "", err.Trace(objectPath) } - fs.rwLock.Unlock() return uploadID, nil } @@ -445,12 +444,12 @@ func (fs Filesystem) CreateObjectPart(bucket, object, uploadID, expectedMD5Sum s // Critical region requiring write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() + fs.multiparts.ActiveSession[uploadID] = deserializedMultipartSession if err := saveMultipartsSession(*fs.multiparts); err != nil { - fs.rwLock.Unlock() return "", err.Trace(partPathPrefix) } - fs.rwLock.Unlock() // Return etag. return partMetadata.ETag, nil @@ -693,11 +692,11 @@ func (fs Filesystem) AbortMultipartUpload(bucket, object, uploadID string) *prob // Critical region requiring write lock. fs.rwLock.Lock() + defer fs.rwLock.Unlock() + delete(fs.multiparts.ActiveSession, uploadID) if err := saveMultipartsSession(*fs.multiparts); err != nil { - fs.rwLock.Unlock() return err.Trace(partPathPrefix) } - fs.rwLock.Unlock() return nil }