Re: do we have a generic string-number sysctl mapping library ?
On 2014-06-27 05:50, Luigi Rizzo wrote: > On Fri, Jun 27, 2014 at 11:27:56AM +0200, Trond Endrest?l wrote: >> On Fri, 27 Jun 2014 11:14+0200, Luigi Rizzo wrote: >> >>> Hi, >>> I have frequently found myself using sysctls to control some kernel >>> feature where a string would be a better (and sometimes the only) >>> option than using a numeric value, yet the internal representation >>> should be numeric for speed and robustness. >>> Examples are the kern.timecounter, the default scheduler in dummynet, >>> and now in netmap the selection between native and emulated mode. >>> I am sure many of you can come up with other cases. >>> >>> I wonder if we have some support for that already in the sysctl code, >>> or i should build a generic one next time i need to do that. >> >> In C, according to sysctl(3) you could use sysctlnametomib(). >> I might have misinterpreted the problem domain. > > different problem. Example below: > right now i have dev.netmap.admode which can assume integer values, > i do not need a special handler, and the code in the kernel uses > 1, 2 or "everything else" to decide what to do (resetting > "everything else" to 0 opportunistically). > > I want to have a generic handler that accepts a set of predefined > string values (specifically "any native emulated") and converts > them to integers through some user-specificed mapping so the > kernel can still do the quick tests but users don't have > to remember what '2' means > > cheers > luigi > ___ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org" > If i understand what you are looking for, it sounds like what vfs.zfs.vol.mode uses. the values are 0, 1 or 2, but can also be assigned using the keywords 'geom', 'dev', or 'none' -- Allan Jude signature.asc Description: OpenPGP digital signature
Re: do we have a generic string-number sysctl mapping library ?
On Friday, June 27, 2014 5:14:59 am Luigi Rizzo wrote: > Hi, > I have frequently found myself using sysctls to control some kernel > feature where a string would be a better (and sometimes the only) > option than using a numeric value, yet the internal representation > should be numeric for speed and robustness. > Examples are the kern.timecounter, the default scheduler in dummynet, > and now in netmap the selection between native and emulated mode. > I am sure many of you can come up with other cases. > > I wonder if we have some support for that already in the sysctl code, > or i should build a generic one next time i need to do that. > > Feel free to criticise the approach and suggest better ones. > Right now i am using sysctls because i have a set of macros > and wrapper functions that let me convert them to sysfs > entries when building kernel code on linux, so I have a > portable solutions. > > For the details, I'd like to have a mechanism that requires the > kernel programmer supply a (possibly extensible) table of > supported values, and matching constants to be used within > the kernel. A single declaration should generate entries > to get/set the current value as well as list options. > We can discuss frills (such as wildcards, multiple values,etc). I am not aware of such a beast. Even just supporting a simple table to map labels to indices would be nice and would handle many cases. I.e. if you had something like: struct sysctl_table vals[] = { "foo", (void *)1, "bar", (void *)2, NULL, NULL }; static int myval; static int my_sysctl(SYSCTL_HANDLER_ARGS) { void *val; int error; val = (void *)myval; error = sysctl_handle_table(oidp, vals, &val, req); if (error || req->newptr == NULL) return (error); myval = (intptr_t)val; return (0); } sysctl_handle_table() would use the initial value to find a suitable string from the table for the "old" string, etc. Using void * for the value would let you store arbitrary data, etc. -- John Baldwin ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
Re: do we have a generic string-number sysctl mapping library ?
On Fri, Jun 27, 2014 at 11:27:56AM +0200, Trond Endrest?l wrote: > On Fri, 27 Jun 2014 11:14+0200, Luigi Rizzo wrote: > > > Hi, > > I have frequently found myself using sysctls to control some kernel > > feature where a string would be a better (and sometimes the only) > > option than using a numeric value, yet the internal representation > > should be numeric for speed and robustness. > > Examples are the kern.timecounter, the default scheduler in dummynet, > > and now in netmap the selection between native and emulated mode. > > I am sure many of you can come up with other cases. > > > > I wonder if we have some support for that already in the sysctl code, > > or i should build a generic one next time i need to do that. > > In C, according to sysctl(3) you could use sysctlnametomib(). > I might have misinterpreted the problem domain. different problem. Example below: right now i have dev.netmap.admode which can assume integer values, i do not need a special handler, and the code in the kernel uses 1, 2 or "everything else" to decide what to do (resetting "everything else" to 0 opportunistically). I want to have a generic handler that accepts a set of predefined string values (specifically "any native emulated") and converts them to integers through some user-specificed mapping so the kernel can still do the quick tests but users don't have to remember what '2' means cheers luigi ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
Re: do we have a generic string-number sysctl mapping library ?
On Fri, 27 Jun 2014 11:14+0200, Luigi Rizzo wrote: > Hi, > I have frequently found myself using sysctls to control some kernel > feature where a string would be a better (and sometimes the only) > option than using a numeric value, yet the internal representation > should be numeric for speed and robustness. > Examples are the kern.timecounter, the default scheduler in dummynet, > and now in netmap the selection between native and emulated mode. > I am sure many of you can come up with other cases. > > I wonder if we have some support for that already in the sysctl code, > or i should build a generic one next time i need to do that. In C, according to sysctl(3) you could use sysctlnametomib(). I might have misinterpreted the problem domain. > Feel free to criticise the approach and suggest better ones. > Right now i am using sysctls because i have a set of macros > and wrapper functions that let me convert them to sysfs > entries when building kernel code on linux, so I have a > portable solutions. > > For the details, I'd like to have a mechanism that requires the > kernel programmer supply a (possibly extensible) table of > supported values, and matching constants to be used within > the kernel. A single declaration should generate entries > to get/set the current value as well as list options. > We can discuss frills (such as wildcards, multiple values,etc). > > cheers > luigi -- +---++ | Vennlig hilsen, | Best regards, | | Trond Endrestøl, | Trond Endrestøl, | | IT-ansvarlig, | System administrator, | | Fagskolen Innlandet, | Gjøvik Technical College, Norway, | | tlf. mob. 952 62 567, | Cellular...: +47 952 62 567, | | sentralbord 61 14 54 00. | Switchboard: +47 61 14 54 00. | +---++ ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"