Merge pull request #1099 from harshavardhana/fix-lock

setBucketMetadata: Fix a deadlock
master
Harshavardhana 9 years ago
commit 7f7697ca38
  1. 4
      pkg/fs/fs-bucket.go
  2. 10
      pkg/fs/postpolicyform.go
  3. 2
      pkg/mimedb/db.go
  4. 4
      pkg/mimedb/util/gen-db.go

@ -223,8 +223,6 @@ func (fs Filesystem) GetBucketMetadata(bucket string) (BucketMetadata, *probe.Er
// SetBucketMetadata - set bucket metadata. // SetBucketMetadata - set bucket metadata.
func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string) *probe.Error { func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string) *probe.Error {
fs.rwLock.Lock()
defer fs.rwLock.Unlock()
// Input validation. // Input validation.
if !IsValidBucketName(bucket) { if !IsValidBucketName(bucket) {
return probe.NewError(BucketNameInvalid{Bucket: bucket}) return probe.NewError(BucketNameInvalid{Bucket: bucket})
@ -247,7 +245,9 @@ func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string
} }
return probe.NewError(e) return probe.NewError(e)
} }
fs.rwLock.RLock()
bucketMetadata, ok := fs.buckets.Metadata[bucket] bucketMetadata, ok := fs.buckets.Metadata[bucket]
fs.rwLock.RUnlock()
if !ok { if !ok {
bucketMetadata = &BucketMetadata{} bucketMetadata = &BucketMetadata{}
bucketMetadata.Name = fi.Name() bucketMetadata.Name = fi.Name()

@ -100,7 +100,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
for k, v := range condt { for k, v := range condt {
if !isString(v) { // Pre-check value type. if !isString(v) { // Pre-check value type.
// All values must be of type string. // All values must be of type string.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.", return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt)) reflect.TypeOf(condt).String(), condt))
} }
// {"acl": "public-read" } is an alternate way to indicate - [ "eq", "$acl", "public-read" ] // {"acl": "public-read" } is an alternate way to indicate - [ "eq", "$acl", "public-read" ]
@ -115,7 +115,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
} }
case []interface{}: // Handle array types. case []interface{}: // Handle array types.
if len(condt) != 3 { // Return error if we have insufficient elements. if len(condt) != 3 { // Return error if we have insufficient elements.
return parsedPolicy, probe.NewError(fmt.Errorf("Malformed conditional fields ‘%s’ of type ‘%s’ found in POST policy form.", return parsedPolicy, probe.NewError(fmt.Errorf("Malformed conditional fields %s of type %s found in POST policy form.",
condt, reflect.TypeOf(condt).String())) condt, reflect.TypeOf(condt).String()))
} }
switch toString(condt[0]) { switch toString(condt[0]) {
@ -123,7 +123,7 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
for _, v := range condt { // Pre-check all values for type. for _, v := range condt { // Pre-check all values for type.
if !isString(v) { if !isString(v) {
// All values must be of type string. // All values must be of type string.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.", return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt)) reflect.TypeOf(condt).String(), condt))
} }
} }
@ -145,11 +145,11 @@ func ParsePostPolicyForm(policy string) (PostPolicyForm, *probe.Error) {
} }
default: default:
// Condition should be valid. // Condition should be valid.
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type ‘%s’ of conditional field value ‘%s’ found in POST policy form.", return parsedPolicy, probe.NewError(fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form.",
reflect.TypeOf(condt).String(), condt)) reflect.TypeOf(condt).String(), condt))
} }
default: default:
return parsedPolicy, probe.NewError(fmt.Errorf("Unknown field ‘%s’ of type ‘%s’ found in POST policy form.", return parsedPolicy, probe.NewError(fmt.Errorf("Unknown field %s of type %s found in POST policy form.",
condt, reflect.TypeOf(condt).String())) condt, reflect.TypeOf(condt).String()))
} }
} }

@ -19,7 +19,7 @@
// Definitions are imported from NodeJS mime-db project under MIT license. // Definitions are imported from NodeJS mime-db project under MIT license.
package mimedb package mimedb
// Mime is a collection of mime types with extension as key and content-type as value. // DB - Mime is a collection of mime types with extension as key and content-type as value.
var DB = map[string]struct { var DB = map[string]struct {
ContentType string ContentType string
Compressible bool Compressible bool

@ -49,7 +49,7 @@ const progTempl = `// DO NOT EDIT THIS FILE. IT IS AUTO-GENERATED BY "gen-db.go"
// Definitions are imported from NodeJS mime-db project under MIT license. // Definitions are imported from NodeJS mime-db project under MIT license.
package mimedb package mimedb
// Mime is a collection of mime types with extension as key and content-type as value. // DB - Mime is a collection of mime types with extension as key and content-type as value.
var DB = map[string]struct { var DB = map[string]struct {
ContentType string ContentType string
Compressible bool Compressible bool
@ -68,8 +68,6 @@ type mimeEntry struct {
type mimeDB map[string]mimeEntry type mimeDB map[string]mimeEntry
var ()
// JSON data from gobindata and parse them into extDB. // JSON data from gobindata and parse them into extDB.
func convertDB(jsonFile string) (mimeDB, error) { func convertDB(jsonFile string) (mimeDB, error) {
// Structure of JSON data from mime-db project. // Structure of JSON data from mime-db project.

Loading…
Cancel
Save