Move lock to not surround pieces which don't use any internal members. (#7779)

Previously the read/write lock applied both for gateway use cases as
well the object store use case. Nothing from sys is touched or looked
at in the gateway usecase though, so we don't need to lock. Don't lock
to make the gateway policy getting a little more efficient, particularly
as where this is called from (checkRequestAuthType) is quite common.
This commit is contained in:
Cody Maloney 2019-06-15 10:11:10 -07:00 committed by kannappanr
parent 510ec153b9
commit 7b8beecc81

View file

@ -85,9 +85,6 @@ func (sys *PolicySys) Remove(bucketName string) {
// IsAllowed - checks given policy args is allowed to continue the Rest API.
func (sys *PolicySys) IsAllowed(args policy.Args) bool {
sys.RLock()
defer sys.RUnlock()
if globalIsGateway {
// When gateway is enabled, no cached value
// is used to validate bucket policies.
@ -99,6 +96,9 @@ func (sys *PolicySys) IsAllowed(args policy.Args) bool {
}
}
} else {
sys.RLock()
defer sys.RUnlock()
// If policy is available for given bucket, check the policy.
if p, found := sys.bucketPolicyMap[args.BucketName]; found {
return p.IsAllowed(args)