@@ -309,11 +309,6 @@ func (cs *CollectionSpec) LoadAndAssign(to interface{}, opts *CollectionOptions)
309
309
return err
310
310
}
311
311
312
- // load programs to struct_ops maps
313
- if err := loader .populateAndPutStructOpsProgFds (); err != nil {
314
- return err
315
- }
316
-
317
312
// Evaluate the loader's objects after all (lazy)loading has taken place.
318
313
for n , m := range loader .maps {
319
314
if m .typ .canStoreProgram () {
@@ -725,6 +720,34 @@ func (cl *collectionLoader) populateDeferredMaps() error {
725
720
}
726
721
}
727
722
723
+ if mapSpec .Type == StructOpsMap {
724
+ structOps , ok := cl .stOpsSpecs [mapName ]
725
+ if ! ok {
726
+ return fmt .Errorf ("struct_ops Map: %s is not initialized" , mapName )
727
+ }
728
+
729
+ for idx , progName := range structOps .programName {
730
+ if progName == "" {
731
+ continue // unlikely to happen
732
+ }
733
+ // loadProgram is idempotent and could return an existing Program.
734
+ prog , err := cl .loadProgram (progName )
735
+ if err != nil {
736
+ return fmt .Errorf ("loading program %s is not loaded, for map %s: %w" ,
737
+ progName , mapName , err )
738
+ }
739
+ defer prog .Close ()
740
+
741
+ // populate ProgFDs as Values
742
+ off := structOps .kernFuncOff [idx ]
743
+ ptr := unsafe .Pointer (& structOps .kernVData [0 ])
744
+ * (* uint64 )(unsafe .Pointer (uintptr (ptr ) + uintptr (off ))) = uint64 (prog .FD ())
745
+ }
746
+
747
+ mapSpec .Contents [0 ] =
748
+ MapKV {Key : uint32 (0 ), Value : structOps .kernVData }
749
+ }
750
+
728
751
// Populate and freeze the map if specified.
729
752
if err := m .finalize (mapSpec ); err != nil {
730
753
return fmt .Errorf ("populating map %s: %w" , mapName , err )
@@ -888,49 +911,6 @@ func (cl *collectionLoader) initKernStructOps(cs *CollectionSpec) error {
888
911
return nil
889
912
}
890
913
891
- // TODO: should be RENAMED AND MOVED!!!!
892
-
893
- // populateStructOpsProgFds runs after all maps and programs have been loaded.
894
- // It writes program FDs into struct_ops.KernVData and updates the map entry.
895
- func (cl * collectionLoader ) populateAndPutStructOpsProgFds () error {
896
- for mapName , m := range cl .maps {
897
- if m .Type () != StructOpsMap {
898
- continue
899
- }
900
-
901
- structOps , ok := cl .stOpsSpecs [mapName ]
902
- if ! ok {
903
- return fmt .Errorf ("struct_ops Map: %s is not initialized" , mapName )
904
- }
905
-
906
- for idx , progName := range structOps .programName {
907
- if progName == "" {
908
- continue
909
- }
910
-
911
- prog , ok := cl .programs [progName ]
912
- if ! ok {
913
- return fmt .Errorf ("program %s should be loaded" , progName )
914
- }
915
- defer prog .Close ()
916
-
917
- off := structOps .kernFuncOff [idx ]
918
- ptr := unsafe .Pointer (& structOps .kernVData [0 ])
919
- * (* uint64 )(unsafe .Pointer (uintptr (ptr ) + uintptr (off ))) = uint64 (prog .FD ())
920
- }
921
-
922
- m , ok := cl .maps [mapName ]
923
- if ! ok {
924
- return fmt .Errorf ("map %s should be loaded" , mapName )
925
- }
926
-
927
- if err := m .Put (uint32 (0 ), structOps .kernVData ); err != nil {
928
- return err
929
- }
930
- }
931
- return nil
932
- }
933
-
934
914
// resolveKconfig resolves all variables declared in .kconfig and populates
935
915
// m.Contents. Does nothing if the given m.Contents is non-empty.
936
916
func resolveKconfig (m * MapSpec ) error {
0 commit comments