-
Notifications
You must be signed in to change notification settings - Fork 10
/
manager_perfmap.go
63 lines (53 loc) · 1.72 KB
/
manager_perfmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package manager
import (
"fmt"
"github.com/cilium/ebpf"
)
// NewPerfRing - Creates a new perf ring and start listening for events.
// Use a MapRoute to make this map available to the programs of the manager.
func (m *Manager) NewPerfRing(spec *ebpf.MapSpec, options MapOptions, perfMapOptions PerfMapOptions) (*ebpf.Map, error) {
m.stateLock.Lock()
defer m.stateLock.Unlock()
if m.state < initialized {
return nil, ErrManagerNotInitialized
}
// check if the name of the new map is available
_, exists, _ := m.getMap(spec.Name)
if exists {
return nil, ErrMapNameInUse
}
// Create new map and perf ring buffer reader
perfMap, err := loadNewPerfMap(spec, options, perfMapOptions)
if err != nil {
return nil, err
}
// Setup perf buffer reader
if err := perfMap.init(m); err != nil {
return nil, err
}
// Start perf buffer reader
if err := perfMap.Start(); err != nil {
// clean up
_ = perfMap.Stop(CleanInternal)
return nil, err
}
// Add map to the list of perf ring managed by the manager
m.PerfMaps = append(m.PerfMaps, perfMap)
return perfMap.array, nil
}
// ClonePerfRing - Clone an existing perf map and create a new one with the same spec.
// Use a MapRoute to make this map available to the programs of the manager.
func (m *Manager) ClonePerfRing(name string, newName string, options MapOptions, perfMapOptions PerfMapOptions) (*ebpf.Map, error) {
// Select map to clone
oldSpec, exists, err := m.GetMapSpec(name)
if err != nil {
return nil, err
}
if !exists {
return nil, fmt.Errorf("failed to clone maps/%s: couldn't find map: %w", name, ErrUnknownSection)
}
// Duplicate spec and create a new map
spec := oldSpec.Copy()
spec.Name = newName
return m.NewPerfRing(spec, options, perfMapOptions)
}