Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(scap,sinsp): Clean up proc callback handling code #1471

Merged
merged 24 commits into from Nov 10, 2023

Conversation

gnosek
Copy link
Contributor

@gnosek gnosek commented Nov 4, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap-engine-udig

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

This PR aims to simplify the infrastructure around the proc callback (a function called from scap for every new thread and fd discovered during the /proc scan). The end result is:

  • +274/-495: a bit of code removed, mostly in the dark corners of scap
  • reduced allocations during /proc scan (we freed most of them immediately)
  • fewer special cases all over the place

Summary of changes:

  • every place that used to check for m_proc_callback now calls it unconditionally
  • internal hash table manipulation (the m_proc_callback==NULL case) is now simply a different (default) callback
  • scap_proc_read_thread is no longer a special case with the procinfo param, just uses its own temporary proclist
  • scap_get_proc_table is gone (no longer used by sinsp)
  • all scap_tinfo/scap_fdinfo heap allocations now happen in the proc callback, only when really needed

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

I'd call the diff surprisingly readable for a PR that touches half the world. There were fairly few incidental changes (except for a massive tinfo->foo -> tinfo.foo in scap_proc_add_from_proc).

Note: I may have broken something around filtering captures (the code is... interesting, with sinsp storing bits in scap_threadinfos) so I'll try to come up with some tests for it. For now, I'm just letting CI have its fun with the PR.

Does this PR introduce a user-facing change?:

BREAKING CHANGE: scap_get_proc_table is gone

@gnosek gnosek changed the title cleanup(scap,sinsp): Clean up proc callback handling code wip: cleanup(scap,sinsp): Clean up proc callback handling code Nov 4, 2023
@gnosek
Copy link
Contributor Author

gnosek commented Nov 4, 2023

Yeah, we're completely bypassing capture filtering now. Will fix.

@gnosek
Copy link
Contributor Author

gnosek commented Nov 5, 2023

I dropped the more aggressive changes for now, if the tests pass, I'll probably submit the rest as a separate PR.

@gnosek gnosek changed the title wip: cleanup(scap,sinsp): Clean up proc callback handling code cleanup(scap,sinsp): Clean up proc callback handling code Nov 5, 2023
@Andreagit97 Andreagit97 added this to the 0.14.0 milestone Nov 6, 2023
@gnosek gnosek force-pushed the proc-callback-cleanup branch 2 times, most recently from 55a1823 to 27d66f7 Compare November 6, 2023 14:08
@gnosek gnosek force-pushed the proc-callback-cleanup branch 3 times, most recently from de0d670 to efcd9fa Compare November 7, 2023 17:17
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
This is effectively a special-case single-entry proclist

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
It was always unclear (to me) what the proclist is used for, exactly.
It turns out it's just a holder for the callback which was ignored
in the previous implementation and now is replaced by a completely
different temporary proclist.

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
We don't need a heap-allocated tinfo just to pass it to
sinsp_threadinfo::init

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
@gnosek
Copy link
Contributor Author

gnosek commented Nov 10, 2023

I know i am getting annoying...

Nah, this sort of annoying I fully approve :D

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Nov 10, 2023

LGTM label has been added.

Git tree hash: 73b4175fabdaa0defb245905a4a245a0c05d5109

Copy link
Contributor

@incertum incertum left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Nov 10, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, gnosek, incertum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [FedeDP,gnosek,incertum]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 3284fa8 into falcosecurity:master Nov 10, 2023
26 checks passed
@gnosek gnosek deleted the proc-callback-cleanup branch November 10, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants