Skip to content

Commit

Permalink
chore: remove mutex from policies
Browse files Browse the repository at this point in the history
policies is now fully under the umbrella of PolicyManager, which already
has a mutex.
  • Loading branch information
geyslan committed Jul 4, 2024
1 parent 58fd97e commit e46e7bc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 27 deletions.
3 changes: 0 additions & 3 deletions pkg/policy/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,6 @@ func (ps *policies) updateBPF(
createNewMaps bool,
updateProcTree bool,
) (*PoliciesConfig, error) {
ps.rwmu.Lock()
defer ps.rwmu.Unlock()

if createNewMaps {
// Create new events map version
if err := ps.createNewEventsMapVersion(bpfModule, eventsState, eventsParams); err != nil {
Expand Down
24 changes: 0 additions & 24 deletions pkg/policy/policies.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package policy

import (
"sync"
"sync/atomic"

bpf "github.com/aquasecurity/libbpfgo"
Expand All @@ -23,8 +22,6 @@ var AlwaysSubmit = events.EventState{
}

type policies struct {
rwmu sync.RWMutex

bpfInnerMaps map[string]*bpf.BPFMapLow // BPF inner maps
policiesArray [PolicyMax]*Policy // underlying policies array for fast access of empty slots
policiesMapByID map[int]*Policy // all policies map by ID
Expand All @@ -46,7 +43,6 @@ type policies struct {

func NewPolicies() *policies {
return &policies{
rwmu: sync.RWMutex{},
bpfInnerMaps: map[string]*bpf.BPFMapLow{},
policiesArray: [PolicyMax]*Policy{},
policiesMapByID: map[int]*Policy{},
Expand Down Expand Up @@ -109,9 +105,6 @@ func set(ps *policies, id int, p *Policy) error {
// add adds a policy.
// The policy ID (index) is automatically assigned to the first empty slot.
func (ps *policies) add(p *Policy) error {
ps.rwmu.Lock()
defer ps.rwmu.Unlock()

if p == nil {
return PolicyNilError()
}
Expand All @@ -136,9 +129,6 @@ func (ps *policies) add(p *Policy) error {
// A policy overwrite is allowed only if the policy that is going to be overwritten
// has the same ID and name.
func (ps *policies) set(p *Policy) error {
ps.rwmu.Lock()
defer ps.rwmu.Unlock()

if p == nil {
return PolicyNilError()
}
Expand All @@ -158,9 +148,6 @@ func (ps *policies) set(p *Policy) error {

// remove removes a policy by name.
func (ps *policies) remove(name string) error {
ps.rwmu.Lock()
defer ps.rwmu.Unlock()

p, ok := ps.policiesMapByName[name]
if !ok {
return PolicyNotFoundByNameError(name)
Expand All @@ -183,9 +170,6 @@ func (ps *policies) lookupById(id int) (*Policy, error) {
return nil, PoliciesOutOfRangeError(id)
}

ps.rwmu.RLock()
defer ps.rwmu.RUnlock()

p := ps.policiesArray[id]
if p == nil {
return nil, PolicyNotFoundByIDError(id)
Expand All @@ -195,9 +179,6 @@ func (ps *policies) lookupById(id int) (*Policy, error) {

// lookupByName returns a policy by name.
func (ps *policies) lookupByName(name string) (*Policy, error) {
ps.rwmu.RLock()
defer ps.rwmu.RUnlock()

if p, ok := ps.policiesMapByName[name]; ok {
return p, nil
}
Expand All @@ -208,9 +189,6 @@ func (ps *policies) lookupByName(name string) (*Policy, error) {
// matchedNames returns a list of matched policies names based on
// the given matched bitmap.
func (ps *policies) matchedNames(matched uint64) []string {
ps.rwmu.RLock()
defer ps.rwmu.RUnlock()

names := []string{}

for _, p := range ps.allFromMap() {
Expand Down Expand Up @@ -247,8 +225,6 @@ func (ps *policies) Clone() *policies {
nPols := NewPolicies()

// Deep copy of all policies
ps.rwmu.RLock()
defer ps.rwmu.RUnlock()
for _, p := range ps.allFromArray() {
if p == nil {
continue
Expand Down

0 comments on commit e46e7bc

Please sign in to comment.