Skip to content

Commit

Permalink
collection: rename CollectionSpec.BTF to .Types
Browse files Browse the repository at this point in the history
In preparation of renaming the btf.Spec type itself down the line, once
.BTF.ext data has been lifted into per-insn metadata, cement the interface
that will be used to query the CollectionSpec for its type information.

A CollectionSpec now provides Maps, Programs and Types.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed Feb 22, 2022
1 parent e7cfa57 commit 1b20c21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/bpf2go/output.go
Expand Up @@ -255,7 +255,7 @@ func output(args outputArgs) error {
}

// Collect any types which we've been asked for explicitly.
cTypes, err := collectCTypes(spec.BTF, args.cTypes)
cTypes, err := collectCTypes(spec.Types, args.cTypes)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions collection.go
Expand Up @@ -27,8 +27,8 @@ type CollectionSpec struct {
Maps map[string]*MapSpec
Programs map[string]*ProgramSpec

// The BTF used by maps and programs.
BTF *btf.Spec
// Types holds type information about Maps and Programs.
Types *btf.Spec

// ByteOrder specifies whether the ELF was compiled for
// big-endian or little-endian architectures.
Expand All @@ -45,7 +45,7 @@ func (cs *CollectionSpec) Copy() *CollectionSpec {
Maps: make(map[string]*MapSpec, len(cs.Maps)),
Programs: make(map[string]*ProgramSpec, len(cs.Programs)),
ByteOrder: cs.ByteOrder,
BTF: cs.BTF.Copy(),
Types: cs.Types.Copy(),
}

for name, spec := range cs.Maps {
Expand Down Expand Up @@ -413,7 +413,7 @@ func (cl *collectionLoader) loadMap(mapName string) (*Map, error) {
return nil, fmt.Errorf("missing map %s", mapName)
}

if mapSpec.BTF != nil && cl.coll.BTF != mapSpec.BTF.Spec {
if mapSpec.BTF != nil && cl.coll.Types != mapSpec.BTF.Spec {
return nil, fmt.Errorf("map %s: BTF doesn't match collection", mapName)
}

Expand Down Expand Up @@ -442,7 +442,7 @@ func (cl *collectionLoader) loadProgram(progName string) (*Program, error) {
return nil, fmt.Errorf("cannot load program %s: program type is unspecified", progName)
}

if progSpec.BTF != nil && cl.coll.BTF != progSpec.BTF.Spec() {
if progSpec.BTF != nil && cl.coll.Types != progSpec.BTF.Spec() {
return nil, fmt.Errorf("program %s: BTF doesn't match collection", progName)
}

Expand Down
6 changes: 3 additions & 3 deletions collection_test.go
Expand Up @@ -67,7 +67,7 @@ func TestCollectionSpecCopy(t *testing.T) {
License: "MIT",
},
},
BTF: &btf.Spec{},
Types: &btf.Spec{},
}
cpy := cs.Copy()

Expand All @@ -83,8 +83,8 @@ func TestCollectionSpecCopy(t *testing.T) {
t.Error("Copy returned same Programs")
}

if cpy.BTF == cs.BTF {
t.Error("Copy returned same BTF")
if cpy.Types == cs.Types {
t.Error("Copy returned same Types")
}
}

Expand Down

0 comments on commit 1b20c21

Please sign in to comment.