Skip to content

bpf_iter and cgroup support#110

Merged
lmb merged 2 commits intomasterfrom
iter-and-cgroup
Jun 17, 2020
Merged

bpf_iter and cgroup support#110
lmb merged 2 commits intomasterfrom
iter-and-cgroup

Conversation

@lmb
Copy link
Copy Markdown
Contributor

@lmb lmb commented Jun 16, 2020

Use the low-level APIs to construct high-level Links for attaching to cgroups and bpf_iter. Especially the cgroup support is interesting, because it falls back to BPF_PROG_ATTACH after trying bpf_link on older kernel.

New API:

 var ErrNotSupported = internal.ErrNotSupported
 func RawAttachProgram(opts RawAttachProgramOptions) error
 func RawDetachProgram(opts RawDetachProgramOptions) error
+type CgroupOptions struct{ ... }
+type Iter struct{ ... }
+    func AttachIter(opts IterOptions) (*Iter, error)
+    func LoadPinnedIter(fileName string) (*Iter, error)
+type IterOptions struct{ ... }
 type Link interface{ ... }
+    func AttachCgroup(opts CgroupOptions) (Link, error)
+    func LoadPinnedCgroup(fileName string) (Link, error)
 type RawAttachProgramOptions struct{ ... }
 type RawDetachProgramOptions struct{ ... }
 type RawLink struct{ ... }

lmb added 2 commits June 16, 2020 15:16
Use the BPF_PROG_ATTACH and bpf_link infrastructure to implement a
generic way to attach to cgroups. Older kernels will use BPF_PROG_ATTACH,
newer ones bpf_link.
bpf_iter allows writing dumpers for various kernel data structures like BPF maps.
@lmb lmb requested review from florianl, jrfastab and tklauser June 16, 2020 14:22
@lmb
Copy link
Copy Markdown
Contributor Author

lmb commented Jun 16, 2020

I'm not sure about the LoadPinned* methods. I think it might be possible to write a LoadPinnedLink function which uses BPF_GET_OBJ_INFO (or whatever that is called) to determine what kind of Link we are dealing with, which would make these obsolete.

Copy link
Copy Markdown
Contributor

@florianl florianl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! and great work!

Do you think raw_tracepoints should also be in link?

@lmb
Copy link
Copy Markdown
Contributor Author

lmb commented Jun 17, 2020

Yes, if we can make them conform to Link and if we don't need new dependencies.

Copy link
Copy Markdown
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants