MCPcopy
hub / github.com/cilium/ebpf / structOpsFindTarget

Function structOpsFindTarget

struct_ops.go:97–116  ·  view source on GitHub ↗

structOpsFindTarget resolves the kernel-side "value struct" for a struct_ops map.

(userType *btf.Struct, cache *btf.Cache)

Source from the content-addressed store, hash-verified

95
96// structOpsFindTarget resolves the kernel-side "value struct" for a struct_ops map.
97func structOpsFindTarget(userType *btf.Struct, cache *btf.Cache) (vType *btf.Struct, id btf.TypeID, module *btf.Handle, err error) {
98 // the kernel value type name, e.g. "bpf_struct_ops_<name>"
99 vTypeName := structOpsValuePrefix + userType.Name
100
101 target := btf.Type((*btf.Struct)(nil))
102 spec, module, err := findTargetInKernel(vTypeName, &target, cache)
103 if errors.Is(err, btf.ErrNotFound) {
104 return nil, 0, nil, fmt.Errorf("%q doesn't exist in kernel: %w", vTypeName, ErrNotSupported)
105 }
106 if err != nil {
107 return nil, 0, nil, fmt.Errorf("lookup value type %q: %w", vTypeName, err)
108 }
109
110 id, err = spec.TypeID(target)
111 if err != nil {
112 return nil, 0, nil, err
113 }
114
115 return target.(*btf.Struct), id, module, nil
116}
117
118// structOpsPopulateValue writes a `prog FD` which references to `p` into the
119// struct_ops value buffer `kernVData` at byte offset `dstOff` corresponding to

Callers 2

createMapMethod · 0.85
populateStructOpsMethod · 0.85

Calls 4

TypeInterface · 0.92
findTargetInKernelFunction · 0.85
IsMethod · 0.45
TypeIDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…