@@ -6,7 +6,6 @@ package bugtool
6
6
import (
7
7
"errors"
8
8
"fmt"
9
- "io/fs"
10
9
"iter"
11
10
"maps"
12
11
"os"
@@ -89,31 +88,24 @@ func FindAllMaps() ([]bpf.ExtendedMapInfo, error) {
89
88
// specified as argument.
90
89
func FindPinnedMaps (path string ) ([]bpf.ExtendedMapInfo , error ) {
91
90
var infos []bpf.ExtendedMapInfo
92
-
93
- err := pin . WalkDir ( path , func ( _ string , d fs. DirEntry , obj pin. Pinner , err error ) error {
91
+ iter := pin . WalkDir ( path , & ebpf. LoadPinOptions { ReadOnly : true })
92
+ for pin , err := range iter {
94
93
if err != nil {
95
- return err
96
- }
97
- if d .IsDir () {
98
- return nil // skip directories
94
+ return nil , fmt .Errorf ("failed walking the bpf fs %q: %w" , path , err )
99
95
}
100
96
101
- m , ok := obj .(* ebpf.Map )
97
+ m , ok := pin . Object .(* ebpf.Map )
102
98
if ! ok {
103
- return nil // skip non map
99
+ continue
104
100
}
105
- defer m .Close ()
106
101
107
102
xInfo , err := bpf .ExtendedInfoFromMap (m )
108
103
if err != nil {
109
- return fmt .Errorf ("failed to retrieve extended info from map %v: %w" , m , err )
104
+ return nil , fmt .Errorf ("failed to retrieve extended info from map %v: %w" , m , err )
110
105
}
111
106
infos = append (infos , xInfo )
112
- return nil
113
- })
114
- if err != nil {
115
- return nil , err
116
107
}
108
+
117
109
return infos , nil
118
110
}
119
111
@@ -145,37 +137,29 @@ func mapIDsFromProgs(prog *ebpf.Program) (iter.Seq[int], error) {
145
137
func mapIDsFromPinnedProgs (path string ) (iter.Seq [int ], error ) {
146
138
mapSet := map [int ]bool {}
147
139
progArrays := []* ebpf.Map {}
148
- err := pin .WalkDir (path , func (_ string , d fs.DirEntry , obj pin.Pinner , err error ) error {
140
+
141
+ iter := pin .WalkDir (path , & ebpf.LoadPinOptions {ReadOnly : true })
142
+ for pin , err := range iter {
149
143
if err != nil {
150
- return err
151
- }
152
- if d .IsDir () {
153
- return nil // skip directories
144
+ return nil , fmt .Errorf ("failed walking the bpf fs %q: %w" , path , err )
154
145
}
155
146
156
- switch typedObj := obj .(type ) {
147
+ switch typedObj := pin . Object .(type ) {
157
148
case * ebpf.Program :
158
149
newIDs , err := mapIDsFromProgs (typedObj )
159
150
if err != nil {
160
- return fmt .Errorf ("failed to retrieve map IDs from prog: %w" , err )
151
+ return nil , fmt .Errorf ("failed to retrieve map IDs from prog: %w" , err )
161
152
}
162
- typedObj .Close ()
163
153
for id := range newIDs {
164
154
mapSet [id ] = true
165
155
}
166
156
case * ebpf.Map :
167
157
if typedObj .Type () == ebpf .ProgramArray {
168
158
progArrays = append (progArrays , typedObj )
169
159
// don't forget to close those files when used later on
170
- } else {
171
- typedObj .Close ()
160
+ pin .Take ()
172
161
}
173
162
}
174
-
175
- return nil
176
- })
177
- if err != nil {
178
- return nil , fmt .Errorf ("failed walking the path %q: %w" , path , err )
179
163
}
180
164
181
165
// retrieve all the program IDs from prog array maps
0 commit comments