kernel module reading config file, design/code question

Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

kernel module reading config file, design/code question

Postby eyebone » 19 Apr 2010, 00:18

hi folks,

i coded a simple module, which shall read a configuration file residing in userland. now, here i am stuck first in a design question and secondly on "how to implement such".

the module is intended to handle certain requests onto a permission configuration file, which i don't want and can put hardcoded into the code(the module shall on a configuration change not recompiled the whole time ;))

first, and most, i wonder what would be the common/suggested way for a kernel module to get some kind of configuration(is this even intended?):stud.
is it usual read it at runtime(after loaded, after refresh), is it more suggested to have a userland daemon which is communicating with the module or a possible device driver?

now, secondly, in regard to the design question what would be the proper functions to do such in kernelland? i know a bit about the uio stuff for device drivers and copyin/copyout as well.

regards,
eyebone
Member
 
Posts: 148
Joined: 08 Dec 2009, 20:58

Postby crsd » 19 Apr 2010, 02:03

You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.
crsd
Member
 
Posts: 420
Joined: 24 Nov 2008, 02:15
Location: Russia, Krasnodar

Postby trasz@ » 19 Apr 2010, 07:14

It depends on e.g. how large and complicated the config file would be. I'd start with sysctl. Then you could just put the configuration variables into /etc/sysctl.conf; there is an rc script to set these values at system startup. If you want to be able to set configuration first and load the module later, you could implement them as tunables (see kenv(1)). There is an API for easily accessing both in the kernel.
trasz@
Member
 
Posts: 182
Joined: 20 Feb 2008, 22:44
Location: Warszawa, Poland

Postby phoenix » 19 Apr 2010, 15:46

crsd wrote:You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.


Using [file]/boot/loader.conf[/file] is a better solution. device.hints gets overwritten by mergemaster, while /boot/loader.conf doesn't get touched. Plus, it keeps everything nicely in one file.

Anything that can go in device.hints can also go into loader.conf.
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
User avatar
phoenix
MFC'd
 
Posts: 3349
Joined: 17 Nov 2008, 05:43
Location: Kamloops, BC, Canada

Postby eyebone » 21 Apr 2010, 19:14

hej guys,

first thank you for your input. wasn't a bit out of time. i decided to give it a first shot with sysctl and see how things are going and if the config gets not to complex.
i'll be back with module or thread here in some days i guess ;)

till then, best regards
eyebone
Member
 
Posts: 148
Joined: 08 Dec 2009, 20:58

Postby eyebone » 29 Apr 2010, 18:23

ok, i implemented some basic's but i am somehow stuck on the sysctl issues. i added a new branch with SYSCTL_ADD_NODE, i can add there strings and it is, working almost fine.
now i am looking for adding additional node to the already created node, to achieve this tree:

Code: Select all
application.node1
application.node1.family1
application.node1.family1.id=0
application.node1.family1.name=username
application.node1.family2
application.node1.family2.id=1
application.node1.family1.name=anothername


i tried to accomplish this through:

Code: Select all
test2 = SYSCTL_ADD_NODE( NULL, SYSCTL_STATIC_CHILDREN(test1),OID_AUTO, "family", CTLFLAG_RW, 0, "test2");


and resulted into a compiler error message:

Code: Select all
tester.c:314: error: 'sysctl_test1_children' undeclared (first use in this function)


i guess i made a basic mistake for SYSCTL declaration(do i need to use SYSCTL_DECL for instance?) or somekind of handler function(how would this look like?)

i wonder as well how i can implement a good way of searching through the sysctl values on module side to decide what actions to take. is there some kind like LIST_FOREACH mechanism?

additionally i figured after creating a node and not adding a string or integer results on my side with a kernel trap during kldload, is there a specifig reason for this?

someone can point me to a paper/book/self explaining module code for SYSCTL topic? :stud

best regards,
eyebone
Member
 
Posts: 148
Joined: 08 Dec 2009, 20:58

Postby eyebone » 29 Apr 2010, 20:45

ok, i found a perfect example:

http://fxr.googlebit.com/source/share/examples/kld/dyn_sysctl/dyn_sysctl.c?v=NETBSD-CURRENT

it is from netbsd and serves to understand the basics of the usage :)
eyebone
Member
 
Posts: 148
Joined: 08 Dec 2009, 20:58


Return to FreeBSD Development

Who is online

Users browsing this forum: No registered users and 0 guests