Subject: Re: sysctl: How to get softc address in a helper function?
To: TAMURA Kent <kent@NetBSD.org>
From: None <cube@cubidou.net>
List: tech-kern
Date: 10/24/2004 10:55:15
On Sun, Oct 24, 2004 at 03:35:02PM +0900, TAMURA Kent wrote:
> How to get softc address in a sysctl helper function? I'm
> trying to implement per-device-instance sysctl items (not
> per-device-driver like ath and bge.)
>
> The foo_attach() function creates a node and leaf items, and
> saves their MIB numbers into a softc instance. To check values
> in a helper function, we need to refer the softc to determine
> which sysctl item is processed. I have no idea how to pass the
> softc address to the helper function.
See how it is done in sys/lkm/net/ethfoo/ethfoo/ethfoo_lkm.c.
I'm fairly certain I've copied it from somewhere in the tree but
I don't remember exactly where.
The trick is to use the sysctl_data field to store the softc
pointer. In the handler function, you always work on a copy
of the sysctl_node structure, so what you can do is do that
copy (node = *rnode), get the softc from sysctl_data, but
then, before calling sysctl_lookup which will do all the
actual data manipulation, change the sysctl_data field of
'node' to the actual value of the sysctl.
Quentin Garnier.