Subject: Re: Easier vendor specific sysctl
To: None <bdev@hss.hns.com>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 11/28/2003 00:00:43
>and was wondering that there was no prepared interface to insert vendor
>specific sysctls. I have implemented the following generic code to the
>system
> [...]
>I was thinking that it would be a good idea to actually include this in the main source tree ( without the foo corporation of course )  as it would
>allow us to control vendor specific ctls in a more unified
>manner directly from sysctl.h and we would not need to change kern_sysctl.c for vendor specifc changes.

if you can hold on for just a little while longer...

i've been threatening to commit my brand new dynamic sysctl code for a
a couple of weeks now, and while i'm not yet completely satisfied with
the results, i must say that it runs quite well.

whereas some stuff came up that sucked away my available time (ie, my
pesky personal life stuff), at the moment i'm merely doing a last pass
over the code to make sure it's "good", taking care of some last
minute cleanups, making sure i've not forgotten anything from my todo
list, and building (and testing) as many kernels as i can manage.

once i'm done, you'll be able to do this from the command line:

    sysctl -w //create=vender.foo,type=int,symbol=thing,flags=w
    sysctl -w //create=vender.subtree
    sysctl -w //create=vender.subtree.bar,type=int,symbol=otherthing
    sysctl -w //create=vender.subtree.baz,type=struct,symbol=wibble,size=12
    ...

in order to create new nodes when you feel like it, or if you want
nodes compiled into the kernel (or nodes that have "helper functions"
to cons up a struct or add some things together), you can do this:

SYSCTL_SETUP(sysctl_vendor_setup, "sysctl vendor subtree setup")
{
	struct sysctlnode *n;
	int m;

	sysctl_createv(SYSCTL_PERMANENT,
		       CTLTYPE_NODE, "vendor", NULL,
		       NULL, 0, NULL, 0,
		       CTL_VENDOR, CTL_EOL);
	sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
		       CTLTYPE_INT, "foo", NULL,
		       NULL, 0, &thing, 0,
		       CTL_VENDOR, CTL_CREATE);
	n = NULL;
	sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
		       CTLTYPE_NODE, "subtree", &n,
		       NULL, 0, NULL, 0,
		       CTL_VENDOR, CTL_CREATE);
	m = n->sysctl_num;
	sysctl_createv(SYSCTL_PERMANENT,
		       CTLTYPE_INT, "bar", NULL,
		       NULL, 0, &otherthing, 0,
		       CTL_VENDOR, m, CTL_CREATE);
	sysctl_createv(SYSCTL_PERMANENT,
		       CTLTYPE_STRUCT, "baz", NULL,
		       helper_function, 0, NULL, 12,
		       CTL_VENDOR, m, CTL_CREATE);
	...

with the end result being that when your code is linked into the
kernel, your nodes show up in the sysctl mib, sysctl(8) can find them,
and will be able to print them (modulo any pretty printing of the
struct one).

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
werdna@squooshy.com       * "information is power -- share the wealth."