Page MenuHomeFreeBSD

Enable iterating all sysctls, even ones with CTLFLAG_SKIP

Authored by freqlabs on Fri, Sep 25, 6:33 PM.



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
➜  ~ sysctl -ad | grep kstat | wc -l
➜  ~ sysctl -at | grep kstat | wc -l
➜  ~ sysctl -N kstat | wc -l
➜  ~ sysctl -d kstat | wc -l
➜  ~ sysctl kstat | wc -l

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

2758 ↗(On Diff #77533)

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

1200 ↗(On Diff #77533)

Maybe tflag too?

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

Also visit all with tflag

1200 ↗(On Diff #77533)

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


I think your change might make it so that 'sysctl foo' would still do 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).

2758 ↗(On Diff #77533)

I would probably not make this change.

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.

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.Wed, Sep 30, 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 has merged and tagged and the port has been updated.