Page MenuHomeFreeBSD

Enable iterating all sysctls, even ones with CTLFLAG_SKIP
ClosedPublic

Authored by freqlabs on Sep 25 2020, 6:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 14, 2:21 AM
Unknown Object (File)
Sun, Apr 14, 2:19 AM
Unknown Object (File)
Thu, Apr 11, 12:28 PM
Unknown Object (File)
Sun, Mar 31, 6:14 AM
Unknown Object (File)
Sat, Mar 23, 9:38 AM
Unknown Object (File)
Mar 8 2024, 12:28 PM
Unknown Object (File)
Mar 8 2024, 12:28 PM
Unknown Object (File)
Mar 8 2024, 12:28 PM

Details

Summary

Add an "nextnoskip" sysctl that allows for listing of sysctls intended to be normally skipped for cost reasons.

This makes it so the names/descriptions of those sysctls can be discovered with sysctl -aN/sysctl -ad/sysctl -at.

It also makes it so children are visited when a node flagged with CTLFLAG_SKIP is explicitly requested.

The intended use case is to mark the root "kstat" node with CTLFLAG_SKIP so that the extensive and expensive stats are skipped by default but may still be easily obtained without having to know them all (which may not even be possible) and request each one-by-one.

Test Plan

With the appropriate change in ZFS to give the root kstat node CTLFLAG_SKIP:

➜  ~ sysctl -a | grep kstat
➜  ~ sysctl -aN | grep kstat | wc -l
     688
➜  ~ sysctl -ad | grep kstat | wc -l
     688
➜  ~ sysctl -at | grep kstat | wc -l
     688
➜  ~ sysctl -N kstat | wc -l
     688
➜  ~ sysctl -d kstat | wc -l
     689
➜  ~ sysctl kstat | wc -l
   13590

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/kern/kern_sysctl.c
2758 ↗(On Diff #77533)

I think this could be useful, but I'm not sure it's actually a good idea

sbin/sysctl/sysctl.c
1200 ↗(On Diff #77533)

Maybe tflag too?

freqlabs edited the summary of this revision. (Show Details)

Also visit all with tflag

sbin/sysctl/sysctl.c
1200 ↗(On Diff #77533)

So the oid thing here might have an unusual effect. Specifically, suppose I have the following nodes:

foo (CTLFLAG_SKIP)
foo.bar
foo.bar.baz (CTLFLAG_SKIP)

I think your change might make it so that 'sysctl foo' would still do foo.bar.baz whereas I what we want is that 'sysctl foo' would ignore the SKIP flag on 'foo' but still honor it for any descendants.

(It should also be oid != NULL).

sys/kern/kern_sysctl.c
1176 ↗(On Diff #77536)

You could perhaps reduce some code duplication by replacing true with oidp->oid_number == CTL_SYSCTL_ALLNEXT and then reusing this handler function for the ALLNEXT oid.

1216 ↗(On Diff #77536)

Could possibly call this "next_noskip" rather than "allnext", but "allnext" is probably fine.

2758 ↗(On Diff #77533)

I would probably not make this change.

Addressed some feedback.

This will now skip descendent nodes marked CTLFLAG_SKIP, but not their children :/
Will have to think some more about that.

freqlabs marked 2 inline comments as done.

Thanks I think this looks good to me.

This revision is now accepted and ready to land.Sep 30 2020, 8:06 PM

Looks like I'm going to need to add this to py-sysctl, too. It's using sysctl(3) so won't benefit from the fixed sysctl(8). A few of the Python-based tools in OpenZFS use py-sysctl on FreeBSD to get at kstat sysctls, which are exactly what I have planned to SKIP.

I intend to commit this once https://github.com/william-gr/py-sysctl/pull/8 has merged and tagged and the port has been updated.